PM: Inject providers to RealState and PolicyManager.
Since RealState allocated a set of hard-coded real providers, it was
necessary for us to pass in underlying interfaces in order to be able to
mock dependencies like DBus or a system clock. This worked but scaled
poorly as we needed to test higher level classes like PolicyManager.
Instead, we now allow to inject the provider objects themselves into
RealState, and a State object into PolicyManager, which allows us to
easily fake them at each level for testing purposes.
BUG=None
TEST=Unit tests.
Change-Id: I85b38990e42039cb6cf37e97234fd18e2c3fea2e
Reviewed-on: https://chromium-review.googlesource.com/189776
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/policy_manager.cc b/policy_manager/policy_manager.cc
index 027a4fe..1357707 100644
--- a/policy_manager/policy_manager.cc
+++ b/policy_manager/policy_manager.cc
@@ -17,15 +17,14 @@
return handle_ptr->get() && (*handle_ptr)->Init();
}
-bool PolicyManager::Init(chromeos_update_engine::DBusWrapperInterface* dbus,
- chromeos_update_engine::ClockInterface* clock) {
+bool PolicyManager::Init(State* state) {
// TODO(deymo): Make it possible to replace this policy with a different
// implementation with a build-time flag.
policy_.reset(new ChromeOSPolicy());
- state_.reset(new RealState(dbus, clock));
+ state_.reset(state);
- return state_->Init();
+ return true;
}
void PolicyManager::RunFromMainLoop(const Closure& callback) {