Make RealDevicePolicyProvider own session_manager.
It's the only class using this proxy.
Bug: 28800946
Test: mma
Change-Id: I4a7e5469aa0a27d5756a88a0d6af4017737b70fc
diff --git a/real_system_state.cc b/real_system_state.cc
index 8ab18ff..16d8876 100644
--- a/real_system_state.cc
+++ b/real_system_state.cc
@@ -38,8 +38,7 @@
namespace chromeos_update_engine {
RealSystemState::RealSystemState(const scoped_refptr<dbus::Bus>& bus)
- : debugd_proxy_(bus),
- session_manager_proxy_(bus) {}
+ : debugd_proxy_(bus) {}
RealSystemState::~RealSystemState() {
// Prevent any DBus communication from UpdateAttempter when shutting down the
@@ -146,7 +145,7 @@
// Initialize the Update Manager using the default state factory.
chromeos_update_manager::State* um_state =
chromeos_update_manager::DefaultStateFactory(
- &policy_provider_, &session_manager_proxy_, &libcros_proxy_, this);
+ &policy_provider_, &libcros_proxy_, this);
if (!um_state) {
LOG(ERROR) << "Failed to initialize the Update Manager.";
return false;
diff --git a/real_system_state.h b/real_system_state.h
index 8e7acef..65175ae 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -24,7 +24,6 @@
#include <debugd/dbus-proxies.h>
#include <metrics/metrics_library.h>
#include <policy/device_policy.h>
-#include <session_manager/dbus-proxies.h>
#include "update_engine/common/boot_control_interface.h"
#include "update_engine/common/certificate_checker.h"
@@ -129,7 +128,6 @@
private:
// Real DBus proxies using the DBus connection.
org::chromium::debugdProxy debugd_proxy_;
- org::chromium::SessionManagerInterfaceProxy session_manager_proxy_;
LibCrosProxy libcros_proxy_;
// Interface for the power manager.
diff --git a/update_manager/real_device_policy_provider.h b/update_manager/real_device_policy_provider.h
index 1ccf45b..51c7db9 100644
--- a/update_manager/real_device_policy_provider.h
+++ b/update_manager/real_device_policy_provider.h
@@ -17,6 +17,7 @@
#ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_DEVICE_POLICY_PROVIDER_H_
#define UPDATE_ENGINE_UPDATE_MANAGER_REAL_DEVICE_POLICY_PROVIDER_H_
+#include <memory>
#include <set>
#include <string>
@@ -33,11 +34,12 @@
// DevicePolicyProvider concrete implementation.
class RealDevicePolicyProvider : public DevicePolicyProvider {
public:
- RealDevicePolicyProvider(org::chromium::SessionManagerInterfaceProxyInterface*
- session_manager_proxy,
- policy::PolicyProvider* policy_provider)
+ RealDevicePolicyProvider(
+ std::unique_ptr<org::chromium::SessionManagerInterfaceProxyInterface>
+ session_manager_proxy,
+ policy::PolicyProvider* policy_provider)
: policy_provider_(policy_provider),
- session_manager_proxy_(session_manager_proxy) {}
+ session_manager_proxy_(std::move(session_manager_proxy)) {}
~RealDevicePolicyProvider();
// Initializes the provider and returns whether it succeeded.
@@ -139,9 +141,9 @@
brillo::MessageLoop::TaskId scheduled_refresh_{
brillo::MessageLoop::kTaskIdNull};
- // The DBus (mockable) session manager proxy, owned by the caller.
- org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy_{
- nullptr};
+ // The DBus (mockable) session manager proxy.
+ std::unique_ptr<org::chromium::SessionManagerInterfaceProxyInterface>
+ session_manager_proxy_;
// Variable exposing whether the policy is loaded.
AsyncCopyVariable<bool> var_device_policy_is_loaded_{
diff --git a/update_manager/real_device_policy_provider_unittest.cc b/update_manager/real_device_policy_provider_unittest.cc
index 45aca56..94746b7 100644
--- a/update_manager/real_device_policy_provider_unittest.cc
+++ b/update_manager/real_device_policy_provider_unittest.cc
@@ -18,6 +18,7 @@
#include <memory>
+#include <brillo/make_unique_ptr.h>
#include <brillo/message_loops/fake_message_loop.h>
#include <brillo/message_loops/message_loop.h>
#include <brillo/message_loops/message_loop_utils.h>
@@ -52,8 +53,11 @@
protected:
void SetUp() override {
loop_.SetAsCurrent();
- provider_.reset(new RealDevicePolicyProvider(&session_manager_proxy_mock_,
- &mock_policy_provider_));
+ auto session_manager_proxy_mock =
+ new org::chromium::SessionManagerInterfaceProxyMock();
+ provider_.reset(new RealDevicePolicyProvider(
+ brillo::make_unique_ptr(session_manager_proxy_mock),
+ &mock_policy_provider_));
// By default, we have a device policy loaded. Tests can call
// SetUpNonExistentDevicePolicy() to override this.
SetUpExistentDevicePolicy();
@@ -61,7 +65,7 @@
// Setup the session manager_proxy such that it will accept the signal
// handler and store it in the |property_change_complete_| once registered.
MOCK_SIGNAL_HANDLER_EXPECT_SIGNAL_HANDLER(property_change_complete_,
- session_manager_proxy_mock_,
+ *session_manager_proxy_mock,
PropertyChangeComplete);
}
@@ -90,7 +94,6 @@
}
brillo::FakeMessageLoop loop_{nullptr};
- org::chromium::SessionManagerInterfaceProxyMock session_manager_proxy_mock_;
testing::NiceMock<policy::MockDevicePolicy> mock_device_policy_;
testing::NiceMock<policy::MockPolicyProvider> mock_policy_provider_;
unique_ptr<RealDevicePolicyProvider> provider_;
diff --git a/update_manager/state_factory.cc b/update_manager/state_factory.cc
index 822f943..bd7160a 100644
--- a/update_manager/state_factory.cc
+++ b/update_manager/state_factory.cc
@@ -19,8 +19,11 @@
#include <memory>
#include <base/logging.h>
+#include <brillo/make_unique_ptr.h>
+#include <session_manager/dbus-proxies.h>
#include "update_engine/common/clock_interface.h"
+#include "update_engine/dbus_connection.h"
#include "update_engine/libcros_proxy.h"
#include "update_engine/shill_proxy.h"
#include "update_engine/update_manager/real_config_provider.h"
@@ -38,14 +41,18 @@
State* DefaultStateFactory(
policy::PolicyProvider* policy_provider,
- org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
chromeos_update_engine::LibCrosProxy* libcros_proxy,
chromeos_update_engine::SystemState* system_state) {
chromeos_update_engine::ClockInterface* const clock = system_state->clock();
unique_ptr<RealConfigProvider> config_provider(
new RealConfigProvider(system_state->hardware()));
+ scoped_refptr<dbus::Bus> bus =
+ chromeos_update_engine::DBusConnection::Get()->GetDBus();
unique_ptr<RealDevicePolicyProvider> device_policy_provider(
- new RealDevicePolicyProvider(session_manager_proxy, policy_provider));
+ new RealDevicePolicyProvider(
+ brillo::make_unique_ptr(
+ new org::chromium::SessionManagerInterfaceProxy(bus)),
+ policy_provider));
unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
unique_ptr<RealShillProvider> shill_provider(
new RealShillProvider(new chromeos_update_engine::ShillProxy(), clock));
diff --git a/update_manager/state_factory.h b/update_manager/state_factory.h
index 96f62f0..f1b576c 100644
--- a/update_manager/state_factory.h
+++ b/update_manager/state_factory.h
@@ -17,8 +17,6 @@
#ifndef UPDATE_ENGINE_UPDATE_MANAGER_STATE_FACTORY_H_
#define UPDATE_ENGINE_UPDATE_MANAGER_STATE_FACTORY_H_
-#include <session_manager/dbus-proxies.h>
-
#include "update_engine/system_state.h"
#include "update_engine/update_manager/state.h"
@@ -35,7 +33,6 @@
// to initialize.
State* DefaultStateFactory(
policy::PolicyProvider* policy_provider,
- org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
chromeos_update_engine::LibCrosProxy* libcros_proxy,
chromeos_update_engine::SystemState* system_state);