Make DBus a singleton.
All the proxies need dbus to initialize, so we are passing dbus around,
to make it easier to compile dbus conditionally, this patch makes it a
singleton so that the proxies can get dbus on their own.
Test: mma
Bug: 28800946
Change-Id: Idf062c843aa34a431c2201bae5b895dc1d0ea787
diff --git a/daemon.cc b/daemon.cc
index 6b2d317..4155243 100644
--- a/daemon.cc
+++ b/daemon.cc
@@ -20,7 +20,6 @@
#include <base/bind.h>
#include <base/location.h>
-#include <base/time/time.h>
#if USE_WEAVE || USE_BINDER
#include <binderwrapper/binder_wrapper.h>
#endif // USE_WEAVE || USE_BINDER
@@ -31,12 +30,6 @@
#include "update_engine/daemon_state_android.h"
#endif // USE_OMAHA
-#if USE_DBUS
-namespace {
-const int kDBusSystemMaxWaitSeconds = 2 * 60;
-} // namespace
-#endif // USE_DBUS
-
namespace chromeos_update_engine {
int UpdateEngineDaemon::OnInit() {
@@ -53,28 +46,12 @@
binder_watcher_.Init();
#endif // USE_WEAVE || USE_BINDER
-#if USE_DBUS
- // We wait for the D-Bus connection for up two minutes to avoid re-spawning
- // the daemon too fast causing thrashing if dbus-daemon is not running.
- scoped_refptr<dbus::Bus> bus = dbus_connection_.ConnectWithTimeout(
- base::TimeDelta::FromSeconds(kDBusSystemMaxWaitSeconds));
-
- if (!bus) {
- // TODO(deymo): Make it possible to run update_engine even if dbus-daemon
- // is not running or constantly crashing.
- LOG(ERROR) << "Failed to initialize DBus, aborting.";
- return 1;
- }
-
- CHECK(bus->SetUpAsyncOperations());
-#endif // USE_DBUS
-
#if USE_OMAHA
// Initialize update engine global state but continue if something fails.
// TODO(deymo): Move the daemon_state_ initialization to a factory method
// avoiding the explicit re-usage of the |bus| instance, shared between
// D-Bus service and D-Bus client calls.
- RealSystemState* real_system_state = new RealSystemState(bus);
+ RealSystemState* real_system_state = new RealSystemState();
daemon_state_.reset(real_system_state);
LOG_IF(ERROR, !real_system_state->Initialize())
<< "Failed to initialize system state.";
@@ -104,7 +81,7 @@
#if USE_DBUS
// Create the DBus service.
- dbus_adaptor_.reset(new UpdateEngineAdaptor(real_system_state, bus));
+ dbus_adaptor_.reset(new UpdateEngineAdaptor(real_system_state));
daemon_state_->AddObserver(dbus_adaptor_.get());
dbus_adaptor_->RegisterAsync(base::Bind(&UpdateEngineDaemon::OnDBusRegistered,