dbus: perform D-Bus initialization in DBusControl

This moves the RPC specific initialization out of the Daemon class,
which makes it agnostic of the underlying RPC implementation.

Also move the ownership of Manager from Daemon to the ControlInterface
implementation. So the ControlInterface is now responsible for
creating Manager and exposing it through the underlying RPC interface.
This makes it easier to maintain the relevant objects (e.g. Manager,
ObjectManager), and avoids possible confusion during cleanup.

Bug: 25654681
TEST=Verify device setup works on Brillo device

Change-Id: Id2eb8d08346841e294f8286fe191708caa2cbc24
diff --git a/daemon.cc b/daemon.cc
index 696cea2..5980a77 100644
--- a/daemon.cc
+++ b/daemon.cc
@@ -19,18 +19,11 @@
 #include <sysexits.h>
 
 #include <base/logging.h>
-#include <base/message_loop/message_loop_proxy.h>
-#include <base/run_loop.h>
 
 #include "apmanager/dbus/dbus_control.h"
 
 namespace apmanager {
 
-namespace {
-const char kAPManagerServiceName[] = "org.chromium.apmanager";
-const char kAPMRootServicePath[] = "/org/chromium/apmanager";
-}  // namespace
-
 // static
 #if !defined(__ANDROID__)
 const char Daemon::kAPManagerGroupName[] = "apmanager";
@@ -41,40 +34,28 @@
 #endif  // __ANDROID__
 
 Daemon::Daemon(const base::Closure& startup_callback)
-    : DBusServiceDaemon(kAPManagerServiceName, kAPMRootServicePath),
-      startup_callback_(startup_callback) {
+    : startup_callback_(startup_callback) {
 }
 
 int Daemon::OnInit() {
-  int return_code = brillo::DBusServiceDaemon::OnInit();
+  int return_code = brillo::Daemon::OnInit();
   if (return_code != EX_OK) {
     return return_code;
   }
 
+  // Setup control interface. The control interface will expose
+  // our service (Manager) through its RPC interface.
+  control_interface_.reset(new DBusControl());
+  control_interface_->Init();
+
   // Signal that we've acquired all resources.
   startup_callback_.Run();
 
-  // Start manager.
-  manager_->Start();
-
   return EX_OK;
 }
 
 void Daemon::OnShutdown(int* return_code) {
-  manager_.reset();
-  brillo::DBusServiceDaemon::OnShutdown(return_code);
-}
-
-void Daemon::RegisterDBusObjectsAsync(
-    brillo::dbus_utils::AsyncEventSequencer* sequencer) {
-  control_interface_.reset(new DBusControl(bus_));
-  manager_.reset(new apmanager::Manager());
-  // TODO(zqiu): remove object_manager_ and bus_ references once we moved over
-  // to use control interface for creating adaptors.
-  manager_->RegisterAsync(control_interface_.get(),
-                          object_manager_.get(),
-                          bus_,
-                          sequencer);
+  control_interface_->Shutdown();
 }
 
 }  // namespace apmanager