diff options
Diffstat (limited to 'chromeos/dbus')
109 files changed, 902 insertions, 766 deletions
diff --git a/chromeos/dbus/bluetooth_adapter_client.cc b/chromeos/dbus/bluetooth_adapter_client.cc index c822e3a..d7c383f 100644 --- a/chromeos/dbus/bluetooth_adapter_client.cc +++ b/chromeos/dbus/bluetooth_adapter_client.cc @@ -51,16 +51,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient, public dbus::ObjectManager::Interface { public: - explicit BluetoothAdapterClientImpl(dbus::Bus* bus) - : bus_(bus), - weak_ptr_factory_(this) { - object_manager_ = bus_->GetObjectManager( - bluetooth_object_manager::kBluetoothObjectManagerServiceName, - dbus::ObjectPath( - bluetooth_object_manager::kBluetoothObjectManagerServicePath)); - object_manager_->RegisterInterface( - bluetooth_adapter::kBluetoothAdapterInterface, this); - } + BluetoothAdapterClientImpl() : weak_ptr_factory_(this) {} virtual ~BluetoothAdapterClientImpl() { object_manager_->UnregisterInterface( @@ -186,6 +177,16 @@ class BluetoothAdapterClientImpl weak_ptr_factory_.GetWeakPtr(), error_callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + object_manager_ = bus->GetObjectManager( + bluetooth_object_manager::kBluetoothObjectManagerServiceName, + dbus::ObjectPath( + bluetooth_object_manager::kBluetoothObjectManagerServicePath)); + object_manager_->RegisterInterface( + bluetooth_adapter::kBluetoothAdapterInterface, this); + } + private: // Called by dbus::ObjectManager when an object with the adapter interface // is created. Informs observers. @@ -236,7 +237,6 @@ class BluetoothAdapterClientImpl error_callback.Run(error_name, error_message); } - dbus::Bus* bus_; dbus::ObjectManager* object_manager_; // List of observers interested in event notifications from us. @@ -259,10 +259,9 @@ BluetoothAdapterClient::~BluetoothAdapterClient() { } BluetoothAdapterClient* BluetoothAdapterClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new BluetoothAdapterClientImpl(bus); + return new BluetoothAdapterClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new FakeBluetoothAdapterClient(); } diff --git a/chromeos/dbus/bluetooth_adapter_client.h b/chromeos/dbus/bluetooth_adapter_client.h index 60eaff8..5873e6b 100644 --- a/chromeos/dbus/bluetooth_adapter_client.h +++ b/chromeos/dbus/bluetooth_adapter_client.h @@ -12,19 +12,16 @@ #include "base/observer_list.h" #include "base/values.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "dbus/object_path.h" #include "dbus/property.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // BluetoothAdapterClient is used to communicate with objects representing // local Bluetooth Adapters. -class CHROMEOS_EXPORT BluetoothAdapterClient { +class CHROMEOS_EXPORT BluetoothAdapterClient : public DBusClient { public: // Structure of properties associated with bluetooth adapters. struct Properties : public dbus::PropertySet { @@ -142,8 +139,7 @@ class CHROMEOS_EXPORT BluetoothAdapterClient { const ErrorCallback& error_callback) = 0; // Creates the instance. - static BluetoothAdapterClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static BluetoothAdapterClient* Create(DBusClientImplementationType type); // Constants used to indicate exceptional error conditions. static const char kNoResponseError[]; diff --git a/chromeos/dbus/bluetooth_agent_manager_client.cc b/chromeos/dbus/bluetooth_agent_manager_client.cc index 7f96406..5bf534f 100644 --- a/chromeos/dbus/bluetooth_agent_manager_client.cc +++ b/chromeos/dbus/bluetooth_agent_manager_client.cc @@ -22,15 +22,7 @@ const char BluetoothAgentManagerClient::kNoResponseError[] = class BluetoothAgentManagerClientImpl : public BluetoothAgentManagerClient { public: - explicit BluetoothAgentManagerClientImpl(dbus::Bus* bus) - : bus_(bus), - weak_ptr_factory_(this) { - DCHECK(bus_); - object_proxy_ = bus_->GetObjectProxy( - bluetooth_agent_manager::kBluetoothAgentManagerServiceName, - dbus::ObjectPath( - bluetooth_agent_manager::kBluetoothAgentManagerServicePath)); - } + BluetoothAgentManagerClientImpl() : weak_ptr_factory_(this) {} virtual ~BluetoothAgentManagerClientImpl() { } @@ -99,6 +91,15 @@ class BluetoothAgentManagerClientImpl weak_ptr_factory_.GetWeakPtr(), error_callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + DCHECK(bus); + object_proxy_ = bus->GetObjectProxy( + bluetooth_agent_manager::kBluetoothAgentManagerServiceName, + dbus::ObjectPath( + bluetooth_agent_manager::kBluetoothAgentManagerServicePath)); + } + private: // Called when a response for successful method call is received. void OnSuccess(const base::Closure& callback, @@ -124,7 +125,6 @@ class BluetoothAgentManagerClientImpl error_callback.Run(error_name, error_message); } - dbus::Bus* bus_; dbus::ObjectProxy* object_proxy_; // Weak pointer factory for generating 'this' pointers that might live longer @@ -144,10 +144,9 @@ BluetoothAgentManagerClient::~BluetoothAgentManagerClient() { } BluetoothAgentManagerClient* BluetoothAgentManagerClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new BluetoothAgentManagerClientImpl(bus); + return new BluetoothAgentManagerClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new FakeBluetoothAgentManagerClient(); } diff --git a/chromeos/dbus/bluetooth_agent_manager_client.h b/chromeos/dbus/bluetooth_agent_manager_client.h index acf0465..b3e481e 100644 --- a/chromeos/dbus/bluetooth_agent_manager_client.h +++ b/chromeos/dbus/bluetooth_agent_manager_client.h @@ -11,18 +11,15 @@ #include "base/callback.h" #include "base/values.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "dbus/object_path.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // BluetoothAgentManagerClient is used to communicate with the agent manager // object of the Bluetooth daemon. -class CHROMEOS_EXPORT BluetoothAgentManagerClient { +class CHROMEOS_EXPORT BluetoothAgentManagerClient : public DBusClient { public: virtual ~BluetoothAgentManagerClient(); @@ -54,9 +51,8 @@ class CHROMEOS_EXPORT BluetoothAgentManagerClient { const base::Closure& callback, const ErrorCallback& error_callback) = 0; - // Creates the instance. - static BluetoothAgentManagerClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + // Creates the instance. + static BluetoothAgentManagerClient* Create(DBusClientImplementationType type); // Constants used to indicate exceptional error conditions. static const char kNoResponseError[]; diff --git a/chromeos/dbus/bluetooth_device_client.cc b/chromeos/dbus/bluetooth_device_client.cc index 62fbab8..605872c 100644 --- a/chromeos/dbus/bluetooth_device_client.cc +++ b/chromeos/dbus/bluetooth_device_client.cc @@ -53,16 +53,7 @@ class BluetoothDeviceClientImpl : public BluetoothDeviceClient, public dbus::ObjectManager::Interface { public: - explicit BluetoothDeviceClientImpl(dbus::Bus* bus) - : bus_(bus), - weak_ptr_factory_(this) { - object_manager_ = bus_->GetObjectManager( - bluetooth_object_manager::kBluetoothObjectManagerServiceName, - dbus::ObjectPath( - bluetooth_object_manager::kBluetoothObjectManagerServicePath)); - object_manager_->RegisterInterface( - bluetooth_device::kBluetoothDeviceInterface, this); - } + BluetoothDeviceClientImpl() : weak_ptr_factory_(this) {} virtual ~BluetoothDeviceClientImpl() { object_manager_->UnregisterInterface( @@ -277,6 +268,16 @@ class BluetoothDeviceClientImpl weak_ptr_factory_.GetWeakPtr(), error_callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + object_manager_ = bus->GetObjectManager( + bluetooth_object_manager::kBluetoothObjectManagerServiceName, + dbus::ObjectPath( + bluetooth_object_manager::kBluetoothObjectManagerServicePath)); + object_manager_->RegisterInterface( + bluetooth_device::kBluetoothDeviceInterface, this); + } + private: // Called by dbus::ObjectManager when an object with the device interface // is created. Informs observers. @@ -327,7 +328,6 @@ class BluetoothDeviceClientImpl error_callback.Run(error_name, error_message); } - dbus::Bus* bus_; dbus::ObjectManager* object_manager_; // List of observers interested in event notifications from us. @@ -349,10 +349,9 @@ BluetoothDeviceClient::~BluetoothDeviceClient() { } BluetoothDeviceClient* BluetoothDeviceClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new BluetoothDeviceClientImpl(bus); + return new BluetoothDeviceClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new FakeBluetoothDeviceClient(); } diff --git a/chromeos/dbus/bluetooth_device_client.h b/chromeos/dbus/bluetooth_device_client.h index a0066e0..fcb0483 100644 --- a/chromeos/dbus/bluetooth_device_client.h +++ b/chromeos/dbus/bluetooth_device_client.h @@ -12,19 +12,16 @@ #include "base/observer_list.h" #include "base/values.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "dbus/object_path.h" #include "dbus/property.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // BluetoothDeviceClient is used to communicate with objects representing // remote Bluetooth Devices. -class CHROMEOS_EXPORT BluetoothDeviceClient { +class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient { public: // Structure of properties associated with bluetooth devices. struct Properties : public dbus::PropertySet { @@ -174,8 +171,7 @@ class CHROMEOS_EXPORT BluetoothDeviceClient { const ErrorCallback& error_callback) = 0; // Creates the instance. - static BluetoothDeviceClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static BluetoothDeviceClient* Create(DBusClientImplementationType type); // Constants used to indicate exceptional error conditions. static const char kNoResponseError[]; diff --git a/chromeos/dbus/bluetooth_input_client.cc b/chromeos/dbus/bluetooth_input_client.cc index 0d1eb53..ddbc7a4 100644 --- a/chromeos/dbus/bluetooth_input_client.cc +++ b/chromeos/dbus/bluetooth_input_client.cc @@ -35,16 +35,7 @@ class BluetoothInputClientImpl : public BluetoothInputClient, public dbus::ObjectManager::Interface { public: - explicit BluetoothInputClientImpl(dbus::Bus* bus) - : bus_(bus), - weak_ptr_factory_(this) { - object_manager_ = bus_->GetObjectManager( - bluetooth_object_manager::kBluetoothObjectManagerServiceName, - dbus::ObjectPath( - bluetooth_object_manager::kBluetoothObjectManagerServicePath)); - object_manager_->RegisterInterface( - bluetooth_input::kBluetoothInputInterface, this); - } + BluetoothInputClientImpl() : weak_ptr_factory_(this) {} virtual ~BluetoothInputClientImpl() { object_manager_->UnregisterInterface( @@ -88,6 +79,16 @@ class BluetoothInputClientImpl bluetooth_input::kBluetoothInputInterface)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + object_manager_ = bus->GetObjectManager( + bluetooth_object_manager::kBluetoothObjectManagerServiceName, + dbus::ObjectPath( + bluetooth_object_manager::kBluetoothObjectManagerServicePath)); + object_manager_->RegisterInterface( + bluetooth_input::kBluetoothInputInterface, this); + } + private: // Called by dbus::ObjectManager when an object with the input interface // is created. Informs observers. @@ -114,7 +115,6 @@ class BluetoothInputClientImpl InputPropertyChanged(object_path, property_name)); } - dbus::Bus* bus_; dbus::ObjectManager* object_manager_; // List of observers interested in event notifications from us. @@ -136,10 +136,9 @@ BluetoothInputClient::~BluetoothInputClient() { } BluetoothInputClient* BluetoothInputClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new BluetoothInputClientImpl(bus); + return new BluetoothInputClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new FakeBluetoothInputClient(); } diff --git a/chromeos/dbus/bluetooth_input_client.h b/chromeos/dbus/bluetooth_input_client.h index d4d25d3..0e0bee5 100644 --- a/chromeos/dbus/bluetooth_input_client.h +++ b/chromeos/dbus/bluetooth_input_client.h @@ -11,19 +11,16 @@ #include "base/callback.h" #include "base/observer_list.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "dbus/object_path.h" #include "dbus/property.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // BluetoothInputClient is used to communicate with objects representing // Bluetooth Input (HID) devices. -class CHROMEOS_EXPORT BluetoothInputClient { +class CHROMEOS_EXPORT BluetoothInputClient : public DBusClient { public: // Structure of properties associated with bluetooth input devices. struct Properties : public dbus::PropertySet { @@ -71,8 +68,7 @@ class CHROMEOS_EXPORT BluetoothInputClient { virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; // Creates the instance. - static BluetoothInputClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static BluetoothInputClient* Create(DBusClientImplementationType type); protected: BluetoothInputClient(); diff --git a/chromeos/dbus/bluetooth_profile_manager_client.cc b/chromeos/dbus/bluetooth_profile_manager_client.cc index 6f2875b..aebd0d8 100644 --- a/chromeos/dbus/bluetooth_profile_manager_client.cc +++ b/chromeos/dbus/bluetooth_profile_manager_client.cc @@ -33,15 +33,7 @@ BluetoothProfileManagerClient::Options::~Options() { class BluetoothProfileManagerClientImpl : public BluetoothProfileManagerClient { public: - explicit BluetoothProfileManagerClientImpl(dbus::Bus* bus) - : bus_(bus), - weak_ptr_factory_(this) { - DCHECK(bus_); - object_proxy_ = bus_->GetObjectProxy( - bluetooth_profile_manager::kBluetoothProfileManagerServiceName, - dbus::ObjectPath( - bluetooth_profile_manager::kBluetoothProfileManagerServicePath)); - } + BluetoothProfileManagerClientImpl() : weak_ptr_factory_(this) {} virtual ~BluetoothProfileManagerClientImpl() { } @@ -191,6 +183,15 @@ class BluetoothProfileManagerClientImpl weak_ptr_factory_.GetWeakPtr(), error_callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + DCHECK(bus); + object_proxy_ = bus->GetObjectProxy( + bluetooth_profile_manager::kBluetoothProfileManagerServiceName, + dbus::ObjectPath( + bluetooth_profile_manager::kBluetoothProfileManagerServicePath)); + } + private: // Called when a response for successful method call is received. void OnSuccess(const base::Closure& callback, @@ -216,7 +217,6 @@ class BluetoothProfileManagerClientImpl error_callback.Run(error_name, error_message); } - dbus::Bus* bus_; dbus::ObjectProxy* object_proxy_; // Weak pointer factory for generating 'this' pointers that might live longer @@ -235,10 +235,9 @@ BluetoothProfileManagerClient::~BluetoothProfileManagerClient() { } BluetoothProfileManagerClient* BluetoothProfileManagerClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new BluetoothProfileManagerClientImpl(bus); + return new BluetoothProfileManagerClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new FakeBluetoothProfileManagerClient(); } diff --git a/chromeos/dbus/bluetooth_profile_manager_client.h b/chromeos/dbus/bluetooth_profile_manager_client.h index bcf92ddb..771fbaf 100644 --- a/chromeos/dbus/bluetooth_profile_manager_client.h +++ b/chromeos/dbus/bluetooth_profile_manager_client.h @@ -11,18 +11,15 @@ #include "base/callback.h" #include "base/values.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "dbus/object_path.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // BluetoothProfileManagerClient is used to communicate with the profile // manager object of the Bluetooth daemon. -class CHROMEOS_EXPORT BluetoothProfileManagerClient { +class CHROMEOS_EXPORT BluetoothProfileManagerClient : public DBusClient { public: // Species the role of the object within the profile. SYMMETRIC should be // usually used unless the profile requires you specify as a CLIENT or as a @@ -99,8 +96,7 @@ class CHROMEOS_EXPORT BluetoothProfileManagerClient { // Creates the instance. static BluetoothProfileManagerClient* Create( - DBusClientImplementationType type, - dbus::Bus* bus); + DBusClientImplementationType type); // Constants used to indicate exceptional error conditions. static const char kNoResponseError[]; diff --git a/chromeos/dbus/cras_audio_client.cc b/chromeos/dbus/cras_audio_client.cc index 411314e..7a0b1c3 100644 --- a/chromeos/dbus/cras_audio_client.cc +++ b/chromeos/dbus/cras_audio_client.cc @@ -19,63 +19,7 @@ namespace chromeos { // The CrasAudioClient implementation used in production. class CrasAudioClientImpl : public CrasAudioClient { public: - explicit CrasAudioClientImpl(dbus::Bus* bus) - : cras_proxy_(NULL), - weak_ptr_factory_(this) { - cras_proxy_ = bus->GetObjectProxy( - cras::kCrasServiceName, - dbus::ObjectPath(cras::kCrasServicePath)); - - // Monitor NameOwnerChanged signal. - cras_proxy_->SetNameOwnerChangedCallback( - base::Bind(&CrasAudioClientImpl::NameOwnerChangedReceived, - weak_ptr_factory_.GetWeakPtr())); - - // Monitor the D-Bus signal for output mute change. - cras_proxy_->ConnectToSignal( - cras::kCrasControlInterface, - cras::kOutputMuteChanged, - base::Bind(&CrasAudioClientImpl::OutputMuteChangedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&CrasAudioClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - // Monitor the D-Bus signal for input mute change. - cras_proxy_->ConnectToSignal( - cras::kCrasControlInterface, - cras::kInputMuteChanged, - base::Bind(&CrasAudioClientImpl::InputMuteChangedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&CrasAudioClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - // Monitor the D-Bus signal for nodes change. - cras_proxy_->ConnectToSignal( - cras::kCrasControlInterface, - cras::kNodesChanged, - base::Bind(&CrasAudioClientImpl::NodesChangedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&CrasAudioClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - // Monitor the D-Bus signal for active output node change. - cras_proxy_->ConnectToSignal( - cras::kCrasControlInterface, - cras::kActiveOutputNodeChanged, - base::Bind(&CrasAudioClientImpl::ActiveOutputNodeChangedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&CrasAudioClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - // Monitor the D-Bus signal for active input node change. - cras_proxy_->ConnectToSignal( - cras::kCrasControlInterface, - cras::kActiveInputNodeChanged, - base::Bind(&CrasAudioClientImpl::ActiveInputNodeChangedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&CrasAudioClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - } + CrasAudioClientImpl() : cras_proxy_(NULL), weak_ptr_factory_(this) {} virtual ~CrasAudioClientImpl() { } @@ -181,6 +125,62 @@ class CrasAudioClientImpl : public CrasAudioClient { dbus::ObjectProxy::EmptyResponseCallback()); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + cras_proxy_ = bus->GetObjectProxy(cras::kCrasServiceName, + dbus::ObjectPath(cras::kCrasServicePath)); + + // Monitor NameOwnerChanged signal. + cras_proxy_->SetNameOwnerChangedCallback( + base::Bind(&CrasAudioClientImpl::NameOwnerChangedReceived, + weak_ptr_factory_.GetWeakPtr())); + + // Monitor the D-Bus signal for output mute change. + cras_proxy_->ConnectToSignal( + cras::kCrasControlInterface, + cras::kOutputMuteChanged, + base::Bind(&CrasAudioClientImpl::OutputMuteChangedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&CrasAudioClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + // Monitor the D-Bus signal for input mute change. + cras_proxy_->ConnectToSignal( + cras::kCrasControlInterface, + cras::kInputMuteChanged, + base::Bind(&CrasAudioClientImpl::InputMuteChangedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&CrasAudioClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + // Monitor the D-Bus signal for nodes change. + cras_proxy_->ConnectToSignal( + cras::kCrasControlInterface, + cras::kNodesChanged, + base::Bind(&CrasAudioClientImpl::NodesChangedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&CrasAudioClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + // Monitor the D-Bus signal for active output node change. + cras_proxy_->ConnectToSignal( + cras::kCrasControlInterface, + cras::kActiveOutputNodeChanged, + base::Bind(&CrasAudioClientImpl::ActiveOutputNodeChangedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&CrasAudioClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + // Monitor the D-Bus signal for active input node change. + cras_proxy_->ConnectToSignal( + cras::kCrasControlInterface, + cras::kActiveInputNodeChanged, + base::Bind(&CrasAudioClientImpl::ActiveInputNodeChangedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&CrasAudioClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + } + private: // Called when the cras signal is initially connected. void SignalConnected(const std::string& interface_name, @@ -379,11 +379,9 @@ CrasAudioClient::~CrasAudioClient() { } // static -CrasAudioClient* CrasAudioClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { +CrasAudioClient* CrasAudioClient::Create(DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { - return new CrasAudioClientImpl(bus); + return new CrasAudioClientImpl(); } DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new CrasAudioClientStubImpl(); diff --git a/chromeos/dbus/cras_audio_client.h b/chromeos/dbus/cras_audio_client.h index f056099..23063d8 100644 --- a/chromeos/dbus/cras_audio_client.h +++ b/chromeos/dbus/cras_audio_client.h @@ -9,17 +9,14 @@ #include "base/observer_list.h" #include "chromeos/chromeos_export.h" #include "chromeos/dbus/audio_node.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/volume_state.h" -namespace dbus { -class Bus; -} - namespace chromeos { // CrasAudioClient is used to communicate with the cras audio dbus interface. -class CHROMEOS_EXPORT CrasAudioClient { +class CHROMEOS_EXPORT CrasAudioClient : public DBusClient { public: // Interface for observing changes from the cras audio changes. class Observer { @@ -93,8 +90,7 @@ class CHROMEOS_EXPORT CrasAudioClient { virtual void SetActiveInputNode(uint64 node_id) = 0; // Creates the instance. - static CrasAudioClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static CrasAudioClient* Create(DBusClientImplementationType type); protected: // Create() should be used instead. diff --git a/chromeos/dbus/cras_audio_client_stub_impl.cc b/chromeos/dbus/cras_audio_client_stub_impl.cc index 4efa107..6c7a155 100644 --- a/chromeos/dbus/cras_audio_client_stub_impl.cc +++ b/chromeos/dbus/cras_audio_client_stub_impl.cc @@ -6,7 +6,9 @@ namespace chromeos { -CrasAudioClientStubImpl::CrasAudioClientStubImpl() { +CrasAudioClientStubImpl::CrasAudioClientStubImpl() {} + +void CrasAudioClientStubImpl::Init(dbus::Bus* bus) { VLOG(1) << "CrasAudioClientStubImpl is created"; // Fake audio output nodes. diff --git a/chromeos/dbus/cras_audio_client_stub_impl.h b/chromeos/dbus/cras_audio_client_stub_impl.h index 032305f..0f57f02 100644 --- a/chromeos/dbus/cras_audio_client_stub_impl.h +++ b/chromeos/dbus/cras_audio_client_stub_impl.h @@ -17,7 +17,8 @@ class CrasAudioClientStubImpl : public CrasAudioClient { CrasAudioClientStubImpl(); virtual ~CrasAudioClientStubImpl(); - // CrasAudioClient overrides: + // CrasAudioClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool HasObserver(Observer* observer) OVERRIDE; diff --git a/chromeos/dbus/cros_disks_client.cc b/chromeos/dbus/cros_disks_client.cc index 84ae312..7233786 100644 --- a/chromeos/dbus/cros_disks_client.cc +++ b/chromeos/dbus/cros_disks_client.cc @@ -79,12 +79,7 @@ DeviceType DeviceMediaTypeToDeviceType(uint32 media_type_uint32) { // The CrosDisksClient implementation. class CrosDisksClientImpl : public CrosDisksClient { public: - explicit CrosDisksClientImpl(dbus::Bus* bus) - : proxy_(bus->GetObjectProxy( - cros_disks::kCrosDisksServiceName, - dbus::ObjectPath(cros_disks::kCrosDisksServicePath))), - weak_ptr_factory_(this) { - } + CrosDisksClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} // CrosDisksClient override. virtual void Mount(const std::string& source_path, @@ -223,6 +218,13 @@ class CrosDisksClientImpl : public CrosDisksClient { weak_ptr_factory_.GetWeakPtr())); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + proxy_ = bus->GetObjectProxy( + cros_disks::kCrosDisksServiceName, + dbus::ObjectPath(cros_disks::kCrosDisksServicePath)); + } + private: // A struct to contain a pair of signal name and mount event type. // Used by SetUpConnections. @@ -363,6 +365,7 @@ class CrosDisksClientStubImpl : public CrosDisksClient { virtual ~CrosDisksClientStubImpl() {} // CrosDisksClient overrides: + virtual void Init(dbus::Bus* bus) OVERRIDE {} virtual void Mount(const std::string& source_path, const std::string& source_format, const std::string& mount_label, @@ -693,10 +696,9 @@ CrosDisksClient::CrosDisksClient() {} CrosDisksClient::~CrosDisksClient() {} // static -CrosDisksClient* CrosDisksClient::Create(DBusClientImplementationType type, - dbus::Bus* bus) { +CrosDisksClient* CrosDisksClient::Create(DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new CrosDisksClientImpl(bus); + return new CrosDisksClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new CrosDisksClientStubImpl(); } diff --git a/chromeos/dbus/cros_disks_client.h b/chromeos/dbus/cros_disks_client.h index 4d65b2c..c477da1 100644 --- a/chromeos/dbus/cros_disks_client.h +++ b/chromeos/dbus/cros_disks_client.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/callback_forward.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" namespace base { @@ -18,7 +19,6 @@ class FilePath; } namespace dbus { -class Bus; class Response; } @@ -190,7 +190,7 @@ class CHROMEOS_EXPORT DiskInfo { // A class to make the actual DBus calls for cros-disks service. // This class only makes calls, result/error handling should be done // by callbacks. -class CHROMEOS_EXPORT CrosDisksClient { +class CHROMEOS_EXPORT CrosDisksClient : public DBusClient { public: // A callback to handle the result of EnumerateAutoMountableDevices. // The argument is the enumerated device paths. @@ -276,8 +276,7 @@ class CHROMEOS_EXPORT CrosDisksClient { // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via DBusThreadManager::Get(). - static CrosDisksClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static CrosDisksClient* Create(DBusClientImplementationType type); // Returns the path of the mount point for archive files. static base::FilePath GetArchiveMountPoint(); diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc index 965ef92..c117f58 100644 --- a/chromeos/dbus/cryptohome_client.cc +++ b/chromeos/dbus/cryptohome_client.cc @@ -28,27 +28,7 @@ static const char kUserIdStubHashSuffix[] = "-hash"; // The CryptohomeClient implementation. class CryptohomeClientImpl : public CryptohomeClient { public: - explicit CryptohomeClientImpl(dbus::Bus* bus) - : proxy_(bus->GetObjectProxy( - cryptohome::kCryptohomeServiceName, - dbus::ObjectPath(cryptohome::kCryptohomeServicePath))), - blocking_method_caller_(bus, proxy_), - weak_ptr_factory_(this) { - proxy_->ConnectToSignal( - cryptohome::kCryptohomeInterface, - cryptohome::kSignalAsyncCallStatus, - base::Bind(&CryptohomeClientImpl::OnAsyncCallStatus, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&CryptohomeClientImpl::OnSignalConnected, - weak_ptr_factory_.GetWeakPtr())); - proxy_->ConnectToSignal( - cryptohome::kCryptohomeInterface, - cryptohome::kSignalAsyncCallStatusWithData, - base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&CryptohomeClientImpl::OnSignalConnected, - weak_ptr_factory_.GetWeakPtr())); - } + CryptohomeClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} // CryptohomeClient override. virtual void SetAsyncCallStatusHandlers( @@ -128,7 +108,7 @@ class CryptohomeClientImpl : public CryptohomeClient { dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, cryptohome::kCryptohomeGetSystemSalt); scoped_ptr<dbus::Response> response( - blocking_method_caller_.CallMethodAndBlock(&method_call)); + blocking_method_caller_->CallMethodAndBlock(&method_call)); if (!response.get()) return false; dbus::MessageReader reader(response.get()); @@ -163,7 +143,7 @@ class CryptohomeClientImpl : public CryptohomeClient { writer.AppendString(username); scoped_ptr<dbus::Response> response = - blocking_method_caller_.CallMethodAndBlock(&method_call); + blocking_method_caller_->CallMethodAndBlock(&method_call); std::string sanitized_username; if (response) { @@ -324,7 +304,7 @@ class CryptohomeClientImpl : public CryptohomeClient { dbus::MethodCall method_call(cryptohome::kCryptohomeInterface, cryptohome::kCryptohomeTpmClearStoredPassword); scoped_ptr<dbus::Response> response( - blocking_method_caller_.CallMethodAndBlock(&method_call)); + blocking_method_caller_->CallMethodAndBlock(&method_call)); return response.get() != NULL; } @@ -358,7 +338,7 @@ class CryptohomeClientImpl : public CryptohomeClient { dbus::MessageWriter writer(&method_call); writer.AppendString(name); scoped_ptr<dbus::Response> response( - blocking_method_caller_.CallMethodAndBlock(&method_call)); + blocking_method_caller_->CallMethodAndBlock(&method_call)); if (!response.get()) return false; dbus::MessageReader reader(response.get()); @@ -661,6 +641,29 @@ class CryptohomeClientImpl : public CryptohomeClient { CallBoolMethod(&method_call, callback); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + proxy_ = bus->GetObjectProxy( + cryptohome::kCryptohomeServiceName, + dbus::ObjectPath(cryptohome::kCryptohomeServicePath)); + + blocking_method_caller_.reset(new BlockingMethodCaller(bus, proxy_)); + + proxy_->ConnectToSignal(cryptohome::kCryptohomeInterface, + cryptohome::kSignalAsyncCallStatus, + base::Bind(&CryptohomeClientImpl::OnAsyncCallStatus, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&CryptohomeClientImpl::OnSignalConnected, + weak_ptr_factory_.GetWeakPtr())); + proxy_->ConnectToSignal( + cryptohome::kCryptohomeInterface, + cryptohome::kSignalAsyncCallStatusWithData, + base::Bind(&CryptohomeClientImpl::OnAsyncCallStatusWithData, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&CryptohomeClientImpl::OnSignalConnected, + weak_ptr_factory_.GetWeakPtr())); + } + private: // Handles the result of AsyncXXX methods. void OnAsyncMethodCall(const AsyncMethodCallback& callback, @@ -698,7 +701,7 @@ class CryptohomeClientImpl : public CryptohomeClient { bool CallBoolMethodAndBlock(dbus::MethodCall* method_call, bool* result) { scoped_ptr<dbus::Response> response( - blocking_method_caller_.CallMethodAndBlock(method_call)); + blocking_method_caller_->CallMethodAndBlock(method_call)); if (!response.get()) return false; dbus::MessageReader reader(response.get()); @@ -829,7 +832,7 @@ class CryptohomeClientImpl : public CryptohomeClient { } dbus::ObjectProxy* proxy_; - BlockingMethodCaller blocking_method_caller_; + scoped_ptr<BlockingMethodCaller> blocking_method_caller_; AsyncCallStatusHandler async_call_status_handler_; AsyncCallStatusWithDataHandler async_call_status_data_handler_; @@ -850,10 +853,9 @@ CryptohomeClient::CryptohomeClient() {} CryptohomeClient::~CryptohomeClient() {} // static -CryptohomeClient* CryptohomeClient::Create(DBusClientImplementationType type, - dbus::Bus* bus) { +CryptohomeClient* CryptohomeClient::Create(DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new CryptohomeClientImpl(bus); + return new CryptohomeClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new CryptohomeClientStubImpl(); } diff --git a/chromeos/dbus/cryptohome_client.h b/chromeos/dbus/cryptohome_client.h index 38d4880..b1019c5 100644 --- a/chromeos/dbus/cryptohome_client.h +++ b/chromeos/dbus/cryptohome_client.h @@ -12,19 +12,16 @@ #include "base/callback.h" #include "chromeos/attestation/attestation_constants.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/dbus_method_call_status.h" -namespace dbus { -class Bus; -} - namespace chromeos { // CryptohomeClient is used to communicate with the Cryptohome service. // All method should be called from the origin thread (UI thread) which // initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT CryptohomeClient { +class CHROMEOS_EXPORT CryptohomeClient : public DBusClient { public: // A callback to handle AsyncCallStatus signals. typedef base::Callback<void(int async_id, @@ -52,8 +49,7 @@ class CHROMEOS_EXPORT CryptohomeClient { // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via DBusThreadManager::Get(). - static CryptohomeClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static CryptohomeClient* Create(DBusClientImplementationType type); // Returns the sanitized |username| that the stub implementation would return. static std::string GetStubSanitizedUsername(const std::string& username); diff --git a/chromeos/dbus/cryptohome_client_stub.cc b/chromeos/dbus/cryptohome_client_stub.cc index 9942538..eee96e4 100644 --- a/chromeos/dbus/cryptohome_client_stub.cc +++ b/chromeos/dbus/cryptohome_client_stub.cc @@ -20,6 +20,9 @@ CryptohomeClientStubImpl::CryptohomeClientStubImpl() CryptohomeClientStubImpl::~CryptohomeClientStubImpl() {} +void CryptohomeClientStubImpl::Init(dbus::Bus* bus) { +} + void CryptohomeClientStubImpl::SetAsyncCallStatusHandlers( const AsyncCallStatusHandler& handler, const AsyncCallStatusWithDataHandler& data_handler) { diff --git a/chromeos/dbus/cryptohome_client_stub.h b/chromeos/dbus/cryptohome_client_stub.h index 8192600..0e90f88 100644 --- a/chromeos/dbus/cryptohome_client_stub.h +++ b/chromeos/dbus/cryptohome_client_stub.h @@ -13,11 +13,12 @@ namespace chromeos { -class CryptohomeClientStubImpl : public CryptohomeClient { +class CHROMEOS_EXPORT CryptohomeClientStubImpl : public CryptohomeClient { public: CryptohomeClientStubImpl(); virtual ~CryptohomeClientStubImpl(); + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void SetAsyncCallStatusHandlers( const AsyncCallStatusHandler& handler, const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE; diff --git a/chromeos/dbus/dbus_client.h b/chromeos/dbus/dbus_client.h new file mode 100644 index 0000000..902d533 --- /dev/null +++ b/chromeos/dbus/dbus_client.h @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMEOS_DBUS_DBUS_CLIENT_H_ +#define CHROMEOS_DBUS_DBUS_CLIENT_H_ + +namespace dbus { +class Bus; +}; + +namespace chromeos { + +// Interface for all DBus clients handled by DBusThreadManager. It restricts +// access to the Init function to DBusThreadManagerImpl only to prevent +// incorrect calls. Stub clients may lift that restriction however. +class DBusClient { + protected: + friend class DBusThreadManagerImpl; + + virtual ~DBusClient() {} + + // This function is called by DBusThreadManager. Only in unit tests, which + // don't use DBusThreadManager, this function can be called through Stub + // implementations (they change Init's member visibility to public). + virtual void Init(dbus::Bus* bus) = 0; + + private: + DISALLOW_ASSIGN(DBusClient); +}; + +} // namespace chromeos + +#endif // CHROMEOS_DBUS_DBUS_CLIENT_H_ diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc index 70ed816..58f2bd6 100644 --- a/chromeos/dbus/dbus_thread_manager.cc +++ b/chromeos/dbus/dbus_thread_manager.cc @@ -54,14 +54,13 @@ static bool g_dbus_thread_manager_set_for_testing = false; // The DBusThreadManager implementation used in production. class DBusThreadManagerImpl : public DBusThreadManager { public: - explicit DBusThreadManagerImpl(DBusClientImplementationType client_type) - : client_type_(client_type), - client_type_override_(client_type) { + explicit DBusThreadManagerImpl(DBusClientImplementationType client_type) { + DBusClientImplementationType client_type_override = client_type; // If --dbus-stub was requested, pass STUB to specific components; // Many components like login are not useful with a stub implementation. if (CommandLine::ForCurrentProcess()->HasSwitch( chromeos::switches::kDbusStub)) { - client_type_override_ = STUB_DBUS_CLIENT_IMPLEMENTATION; + client_type_override = STUB_DBUS_CLIENT_IMPLEMENTATION; } // Create the D-Bus thread. @@ -76,46 +75,34 @@ class DBusThreadManagerImpl : public DBusThreadManager { system_bus_options.connection_type = dbus::Bus::PRIVATE; system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); system_bus_ = new dbus::Bus(system_bus_options); + + CreateDefaultClients(client_type, client_type_override); } // InitializeClients gets called after g_dbus_thread_manager is set. - // NOTE: Clients that access other clients in their constructor must be - // construced in the correct order. + // NOTE: Clients that access other clients in their Init() must be + // initialized in the correct order. This is the only place where Clients' + // Init() should be called if DBusThreadManager is being used. void InitializeClients() { - bluetooth_adapter_client_.reset( - BluetoothAdapterClient::Create(client_type_, system_bus_.get())); - bluetooth_agent_manager_client_.reset( - BluetoothAgentManagerClient::Create(client_type_, system_bus_.get())); - bluetooth_device_client_.reset( - BluetoothDeviceClient::Create(client_type_, system_bus_.get())); - bluetooth_input_client_.reset( - BluetoothInputClient::Create(client_type_, system_bus_.get())); - bluetooth_profile_manager_client_.reset( - BluetoothProfileManagerClient::Create(client_type_, system_bus_.get())); - cras_audio_client_.reset(CrasAudioClient::Create( - client_type_, system_bus_.get())); - cros_disks_client_.reset( - CrosDisksClient::Create(client_type_, system_bus_.get())); - cryptohome_client_.reset( - CryptohomeClient::Create(client_type_, system_bus_.get())); - debug_daemon_client_.reset( - DebugDaemonClient::Create(client_type_, system_bus_.get())); - - // Construction order of the Stub implementations of the Shill clients - // matters; stub clients may only have construction dependencies on clients - // previously constructed. - shill_manager_client_.reset( - ShillManagerClient::Create(client_type_override_, system_bus_.get())); - shill_device_client_.reset( - ShillDeviceClient::Create(client_type_override_, system_bus_.get())); - shill_ipconfig_client_.reset( - ShillIPConfigClient::Create(client_type_override_, system_bus_.get())); - shill_service_client_.reset( - ShillServiceClient::Create(client_type_override_, system_bus_.get())); - shill_profile_client_.reset( - ShillProfileClient::Create(client_type_override_, system_bus_.get())); - gsm_sms_client_.reset( - GsmSMSClient::Create(client_type_override_, system_bus_.get())); + InitClient(bluetooth_adapter_client_.get()); + InitClient(bluetooth_agent_manager_client_.get()); + InitClient(bluetooth_device_client_.get()); + InitClient(bluetooth_input_client_.get()); + InitClient(bluetooth_profile_manager_client_.get()); + InitClient(cras_audio_client_.get()); + InitClient(cros_disks_client_.get()); + InitClient(cryptohome_client_.get()); + InitClient(debug_daemon_client_.get()); + + // Initialization order of the Stub implementations of the Shill clients + // matters; stub clients may only have initialization dependencies on + // clients previously initialized. + InitClient(shill_manager_client_.get()); + InitClient(shill_device_client_.get()); + InitClient(shill_ipconfig_client_.get()); + InitClient(shill_service_client_.get()); + InitClient(shill_profile_client_.get()); + InitClient(gsm_sms_client_.get()); // If the Service client has a TestInterface, add the default services. ShillServiceClient::TestInterface* service_client_test = @@ -123,24 +110,15 @@ class DBusThreadManagerImpl : public DBusThreadManager { if (service_client_test) service_client_test->AddDefaultServices(); - image_burner_client_.reset(ImageBurnerClient::Create(client_type_, - system_bus_.get())); - introspectable_client_.reset( - IntrospectableClient::Create(client_type_, system_bus_.get())); - modem_messaging_client_.reset( - ModemMessagingClient::Create(client_type_, system_bus_.get())); - permission_broker_client_.reset( - PermissionBrokerClient::Create(client_type_, system_bus_.get())); - power_manager_client_.reset( - PowerManagerClient::Create(client_type_override_, system_bus_.get())); - session_manager_client_.reset( - SessionManagerClient::Create(client_type_, system_bus_.get())); - sms_client_.reset( - SMSClient::Create(client_type_, system_bus_.get())); - system_clock_client_.reset( - SystemClockClient::Create(client_type_, system_bus_.get())); - update_engine_client_.reset( - UpdateEngineClient::Create(client_type_, system_bus_.get())); + InitClient(image_burner_client_.get()); + InitClient(introspectable_client_.get()); + InitClient(modem_messaging_client_.get()); + InitClient(permission_broker_client_.get()); + InitClient(power_manager_client_.get()); + InitClient(session_manager_client_.get()); + InitClient(sms_client_.get()); + InitClient(system_clock_client_.get()); + InitClient(update_engine_client_.get()); // PowerPolicyController is dependent on PowerManagerClient, so // initialize it after the main list of clients. @@ -365,8 +343,52 @@ class DBusThreadManagerImpl : public DBusThreadManager { return ibus_panel_service_.get(); } - DBusClientImplementationType client_type_; - DBusClientImplementationType client_type_override_; + private: + // Initializes |client| with the |system_bus_|. + void InitClient(DBusClient* client) { + client->Init(system_bus_.get()); + } + + // Constructs all clients -- stub or real implementation according to + // |client_type| and |client_type_override| -- and stores them in the + // respective *_client_ member variable. + void CreateDefaultClients(DBusClientImplementationType client_type, + DBusClientImplementationType client_type_override) { + bluetooth_adapter_client_.reset( + BluetoothAdapterClient::Create(client_type)); + bluetooth_agent_manager_client_.reset( + BluetoothAgentManagerClient::Create(client_type)); + bluetooth_device_client_.reset(BluetoothDeviceClient::Create(client_type)); + bluetooth_input_client_.reset(BluetoothInputClient::Create(client_type)); + bluetooth_profile_manager_client_.reset( + BluetoothProfileManagerClient::Create(client_type)); + cras_audio_client_.reset(CrasAudioClient::Create(client_type)); + cros_disks_client_.reset(CrosDisksClient::Create(client_type)); + cryptohome_client_.reset(CryptohomeClient::Create(client_type)); + debug_daemon_client_.reset(DebugDaemonClient::Create(client_type)); + shill_manager_client_.reset( + ShillManagerClient::Create(client_type_override)); + shill_device_client_.reset( + ShillDeviceClient::Create(client_type_override)); + shill_ipconfig_client_.reset( + ShillIPConfigClient::Create(client_type_override)); + shill_service_client_.reset( + ShillServiceClient::Create(client_type_override)); + shill_profile_client_.reset( + ShillProfileClient::Create(client_type_override)); + gsm_sms_client_.reset(GsmSMSClient::Create(client_type_override)); + image_burner_client_.reset(ImageBurnerClient::Create(client_type)); + introspectable_client_.reset(IntrospectableClient::Create(client_type)); + modem_messaging_client_.reset(ModemMessagingClient::Create(client_type)); + permission_broker_client_.reset( + PermissionBrokerClient::Create(client_type)); + power_manager_client_.reset( + PowerManagerClient::Create(client_type_override)); + session_manager_client_.reset(SessionManagerClient::Create(client_type)); + sms_client_.reset(SMSClient::Create(client_type)); + system_clock_client_.reset(SystemClockClient::Create(client_type)); + update_engine_client_.reset(UpdateEngineClient::Create(client_type)); + } // Note: Keep this before other members so they can call AddObserver() in // their c'tors. diff --git a/chromeos/dbus/debug_daemon_client.cc b/chromeos/dbus/debug_daemon_client.cc index cfb36c2..c9b760f 100644 --- a/chromeos/dbus/debug_daemon_client.cc +++ b/chromeos/dbus/debug_daemon_client.cc @@ -139,13 +139,7 @@ namespace chromeos { // The DebugDaemonClient implementation used in production. class DebugDaemonClientImpl : public DebugDaemonClient { public: - explicit DebugDaemonClientImpl(dbus::Bus* bus) - : debugdaemon_proxy_(NULL), - weak_ptr_factory_(this) { - debugdaemon_proxy_ = bus->GetObjectProxy( - debugd::kDebugdServiceName, - dbus::ObjectPath(debugd::kDebugdServicePath)); - } + DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {} virtual ~DebugDaemonClientImpl() {} @@ -402,6 +396,13 @@ class DebugDaemonClientImpl : public DebugDaemonClient { callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + debugdaemon_proxy_ = + bus->GetObjectProxy(debugd::kDebugdServiceName, + dbus::ObjectPath(debugd::kDebugdServicePath)); + } + private: // Called to check descriptor validity on a thread where i/o is permitted. static void CheckValidity(dbus::FileDescriptor* file_descriptor) { @@ -619,6 +620,7 @@ class DebugDaemonClientImpl : public DebugDaemonClient { // which does nothing. class DebugDaemonClientStubImpl : public DebugDaemonClient { // DebugDaemonClient overrides. + virtual void Init(dbus::Bus* bus) OVERRIDE {} virtual void GetDebugLogs(base::PlatformFile file, const GetDebugLogsCallback& callback) OVERRIDE { callback.Run(false); @@ -715,10 +717,10 @@ DebugDaemonClient::EmptyStopSystemTracingCallback() { } // static -DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, - dbus::Bus* bus) { +DebugDaemonClient* DebugDaemonClient::Create( + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new DebugDaemonClientImpl(bus); + return new DebugDaemonClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new DebugDaemonClientStubImpl(); } diff --git a/chromeos/dbus/debug_daemon_client.h b/chromeos/dbus/debug_daemon_client.h index 7c09a78..711c2cb 100644 --- a/chromeos/dbus/debug_daemon_client.h +++ b/chromeos/dbus/debug_daemon_client.h @@ -9,14 +9,11 @@ #include "base/platform_file.h" #include "base/memory/ref_counted_memory.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include <map> -namespace dbus { -class Bus; -} // namespace dbus - namespace metrics { class PerfDataProto; } @@ -24,7 +21,7 @@ class PerfDataProto; namespace chromeos { // DebugDaemonClient is used to communicate with the debug daemon. -class CHROMEOS_EXPORT DebugDaemonClient { +class CHROMEOS_EXPORT DebugDaemonClient : public DBusClient { public: virtual ~DebugDaemonClient(); @@ -146,8 +143,8 @@ class CHROMEOS_EXPORT DebugDaemonClient { // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via DBusThreadManager::Get(). - static DebugDaemonClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static DebugDaemonClient* Create(DBusClientImplementationType type); + protected: // Create() should be used instead. DebugDaemonClient(); diff --git a/chromeos/dbus/fake_bluetooth_adapter_client.cc b/chromeos/dbus/fake_bluetooth_adapter_client.cc index f993d20..93c0e06 100644 --- a/chromeos/dbus/fake_bluetooth_adapter_client.cc +++ b/chromeos/dbus/fake_bluetooth_adapter_client.cc @@ -70,14 +70,12 @@ void FakeBluetoothAdapterClient::Properties::Set( } } - FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() : visible_(true), second_visible_(false), discovering_count_(0) { properties_.reset(new Properties(base::Bind( - &FakeBluetoothAdapterClient::OnPropertyChanged, - base::Unretained(this)))); + &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); properties_->address.ReplaceValue(kAdapterAddress); properties_->name.ReplaceValue("Fake Adapter (Name)"); @@ -85,8 +83,7 @@ FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() properties_->pairable.ReplaceValue(true); second_properties_.reset(new Properties(base::Bind( - &FakeBluetoothAdapterClient::OnPropertyChanged, - base::Unretained(this)))); + &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); second_properties_->address.ReplaceValue(kSecondAdapterAddress); second_properties_->name.ReplaceValue("Second Fake Adapter (Name)"); @@ -97,6 +94,9 @@ FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() FakeBluetoothAdapterClient::~FakeBluetoothAdapterClient() { } +void FakeBluetoothAdapterClient::Init(dbus::Bus* bus) { +} + void FakeBluetoothAdapterClient::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/chromeos/dbus/fake_bluetooth_adapter_client.h b/chromeos/dbus/fake_bluetooth_adapter_client.h index 6eb994a..051368f 100644 --- a/chromeos/dbus/fake_bluetooth_adapter_client.h +++ b/chromeos/dbus/fake_bluetooth_adapter_client.h @@ -39,7 +39,8 @@ class CHROMEOS_EXPORT FakeBluetoothAdapterClient FakeBluetoothAdapterClient(); virtual ~FakeBluetoothAdapterClient(); - // BluetoothAdapterClient override + // BluetoothAdapterClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual std::vector<dbus::ObjectPath> GetAdapters() OVERRIDE; diff --git a/chromeos/dbus/fake_bluetooth_agent_manager_client.cc b/chromeos/dbus/fake_bluetooth_agent_manager_client.cc index 57759ff..2672ad5 100644 --- a/chromeos/dbus/fake_bluetooth_agent_manager_client.cc +++ b/chromeos/dbus/fake_bluetooth_agent_manager_client.cc @@ -19,6 +19,9 @@ FakeBluetoothAgentManagerClient::FakeBluetoothAgentManagerClient() FakeBluetoothAgentManagerClient::~FakeBluetoothAgentManagerClient() { } +void FakeBluetoothAgentManagerClient::Init(dbus::Bus* bus) { +} + void FakeBluetoothAgentManagerClient::RegisterAgent( const dbus::ObjectPath& agent_path, const std::string& capability, diff --git a/chromeos/dbus/fake_bluetooth_agent_manager_client.h b/chromeos/dbus/fake_bluetooth_agent_manager_client.h index 315fd5e..98ecdb2 100644 --- a/chromeos/dbus/fake_bluetooth_agent_manager_client.h +++ b/chromeos/dbus/fake_bluetooth_agent_manager_client.h @@ -27,7 +27,8 @@ class CHROMEOS_EXPORT FakeBluetoothAgentManagerClient FakeBluetoothAgentManagerClient(); virtual ~FakeBluetoothAgentManagerClient(); - // BluetoothAgentManagerClient override + // BluetoothAgentManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void RegisterAgent(const dbus::ObjectPath& agent_path, const std::string& capability, const base::Closure& callback, diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/chromeos/dbus/fake_bluetooth_device_client.cc index 4146163..08f748a 100644 --- a/chromeos/dbus/fake_bluetooth_device_client.cc +++ b/chromeos/dbus/fake_bluetooth_device_client.cc @@ -62,7 +62,7 @@ void SimulatedProfileSocket(int fd) { close(fd); } -} +} // namespace namespace chromeos { @@ -188,7 +188,6 @@ void FakeBluetoothDeviceClient::Properties::Set( } } - FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() : simulation_interval_ms_(kSimulationIntervalMs), discovery_simulation_step_(0), @@ -222,6 +221,9 @@ FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() { STLDeleteValues(&properties_map_); } +void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) { +} + void FakeBluetoothDeviceClient::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/chromeos/dbus/fake_bluetooth_device_client.h b/chromeos/dbus/fake_bluetooth_device_client.h index e5cfc51..ccb68b7 100644 --- a/chromeos/dbus/fake_bluetooth_device_client.h +++ b/chromeos/dbus/fake_bluetooth_device_client.h @@ -42,7 +42,8 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient FakeBluetoothDeviceClient(); virtual ~FakeBluetoothDeviceClient(); - // BluetoothDeviceClient override + // BluetoothDeviceClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( diff --git a/chromeos/dbus/fake_bluetooth_input_client.cc b/chromeos/dbus/fake_bluetooth_input_client.cc index 717df07..9e40f6e 100644 --- a/chromeos/dbus/fake_bluetooth_input_client.cc +++ b/chromeos/dbus/fake_bluetooth_input_client.cc @@ -56,6 +56,9 @@ FakeBluetoothInputClient::~FakeBluetoothInputClient() { STLDeleteValues(&properties_map_); } +void FakeBluetoothInputClient::Init(dbus::Bus* bus) { +} + void FakeBluetoothInputClient::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/chromeos/dbus/fake_bluetooth_input_client.h b/chromeos/dbus/fake_bluetooth_input_client.h index 8152668..3a284ae 100644 --- a/chromeos/dbus/fake_bluetooth_input_client.h +++ b/chromeos/dbus/fake_bluetooth_input_client.h @@ -36,7 +36,8 @@ class CHROMEOS_EXPORT FakeBluetoothInputClient FakeBluetoothInputClient(); virtual ~FakeBluetoothInputClient(); - // BluetoothInputClient override + // BluetoothInputClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual Properties* GetProperties(const dbus::ObjectPath& object_path) diff --git a/chromeos/dbus/fake_bluetooth_profile_manager_client.cc b/chromeos/dbus/fake_bluetooth_profile_manager_client.cc index 4c7e0a4..784a84f 100644 --- a/chromeos/dbus/fake_bluetooth_profile_manager_client.cc +++ b/chromeos/dbus/fake_bluetooth_profile_manager_client.cc @@ -29,6 +29,9 @@ FakeBluetoothProfileManagerClient::FakeBluetoothProfileManagerClient() { FakeBluetoothProfileManagerClient::~FakeBluetoothProfileManagerClient() { } +void FakeBluetoothProfileManagerClient::Init(dbus::Bus* bus) { +} + void FakeBluetoothProfileManagerClient::RegisterProfile( const dbus::ObjectPath& profile_path, const std::string& uuid, diff --git a/chromeos/dbus/fake_bluetooth_profile_manager_client.h b/chromeos/dbus/fake_bluetooth_profile_manager_client.h index 8bfeaaf..c7fb935 100644 --- a/chromeos/dbus/fake_bluetooth_profile_manager_client.h +++ b/chromeos/dbus/fake_bluetooth_profile_manager_client.h @@ -30,7 +30,8 @@ class CHROMEOS_EXPORT FakeBluetoothProfileManagerClient FakeBluetoothProfileManagerClient(); virtual ~FakeBluetoothProfileManagerClient(); - // BluetoothProfileManagerClient override + // BluetoothProfileManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void RegisterProfile(const dbus::ObjectPath& profile_path, const std::string& uuid, const Options& options, diff --git a/chromeos/dbus/fake_cros_disks_client.cc b/chromeos/dbus/fake_cros_disks_client.cc index 30c89b0..b152f72 100644 --- a/chromeos/dbus/fake_cros_disks_client.cc +++ b/chromeos/dbus/fake_cros_disks_client.cc @@ -10,13 +10,17 @@ namespace chromeos { FakeCrosDisksClient::FakeCrosDisksClient() - : unmount_call_count_(0), - unmount_success_(true), - format_device_call_count_(0), - format_device_success_(true) { + : unmount_call_count_(0), + unmount_success_(true), + format_device_call_count_(0), + format_device_success_(true) { } -FakeCrosDisksClient::~FakeCrosDisksClient() {} +FakeCrosDisksClient::~FakeCrosDisksClient() { +} + +void FakeCrosDisksClient::Init(dbus::Bus* bus) { +} void FakeCrosDisksClient::Mount(const std::string& source_path, const std::string& source_format, @@ -37,7 +41,7 @@ void FakeCrosDisksClient::Unmount(const std::string& device_path, last_unmount_options_ = options; base::MessageLoopProxy::current()->PostTask( FROM_HERE, unmount_success_ ? callback : error_callback); - if(!unmount_listener_.is_null()) + if (!unmount_listener_.is_null()) unmount_listener_.Run(); } diff --git a/chromeos/dbus/fake_cros_disks_client.h b/chromeos/dbus/fake_cros_disks_client.h index 49e8fba..855a3c1 100644 --- a/chromeos/dbus/fake_cros_disks_client.h +++ b/chromeos/dbus/fake_cros_disks_client.h @@ -19,7 +19,8 @@ class FakeCrosDisksClient : public CrosDisksClient { FakeCrosDisksClient(); virtual ~FakeCrosDisksClient(); - // CrosDisksClient overrides. + // CrosDisksClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void Mount(const std::string& source_path, const std::string& source_format, const std::string& mount_label, diff --git a/chromeos/dbus/fake_cryptohome_client.cc b/chromeos/dbus/fake_cryptohome_client.cc index c5df786..1d224d9 100644 --- a/chromeos/dbus/fake_cryptohome_client.cc +++ b/chromeos/dbus/fake_cryptohome_client.cc @@ -23,6 +23,9 @@ FakeCryptohomeClient::FakeCryptohomeClient() : unmount_result_(false) { FakeCryptohomeClient::~FakeCryptohomeClient() { } +void FakeCryptohomeClient::Init(dbus::Bus* bus) { +} + void FakeCryptohomeClient::TpmIsBeingOwned( const BoolDBusMethodCallback& callback) { } diff --git a/chromeos/dbus/fake_cryptohome_client.h b/chromeos/dbus/fake_cryptohome_client.h index e254648..74d9e81 100644 --- a/chromeos/dbus/fake_cryptohome_client.h +++ b/chromeos/dbus/fake_cryptohome_client.h @@ -18,7 +18,8 @@ class FakeCryptohomeClient : public CryptohomeClient { FakeCryptohomeClient(); virtual ~FakeCryptohomeClient(); - // CryptohomeClient overrides. + // CryptohomeClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void SetAsyncCallStatusHandlers( const AsyncCallStatusHandler& handler, const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE; diff --git a/chromeos/dbus/fake_gsm_sms_client.cc b/chromeos/dbus/fake_gsm_sms_client.cc index d1904d7..4d4452f 100644 --- a/chromeos/dbus/fake_gsm_sms_client.cc +++ b/chromeos/dbus/fake_gsm_sms_client.cc @@ -9,9 +9,9 @@ namespace chromeos { FakeGsmSMSClient::FakeGsmSMSClient() - : test_index_(-1), - sms_test_message_switch_present_(false), - weak_ptr_factory_(this) { + : test_index_(-1), + sms_test_message_switch_present_(false), + weak_ptr_factory_(this) { test_messages_.push_back("Test Message 0"); test_messages_.push_back("Test Message 1"); test_messages_.push_back("Test a relatively long message 2"); @@ -22,7 +22,11 @@ FakeGsmSMSClient::FakeGsmSMSClient() test_messages_.push_back("Test Message 6"); } -FakeGsmSMSClient::~FakeGsmSMSClient() {} +FakeGsmSMSClient::~FakeGsmSMSClient() { +} + +void FakeGsmSMSClient::Init(dbus::Bus* bus) { +} void FakeGsmSMSClient::SetSmsReceivedHandler( const std::string& service_name, diff --git a/chromeos/dbus/fake_gsm_sms_client.h b/chromeos/dbus/fake_gsm_sms_client.h index 1a846ee..321c9f6 100644 --- a/chromeos/dbus/fake_gsm_sms_client.h +++ b/chromeos/dbus/fake_gsm_sms_client.h @@ -20,7 +20,8 @@ class FakeGsmSMSClient : public GsmSMSClient { FakeGsmSMSClient(); virtual ~FakeGsmSMSClient(); - // GsmSMSClient overrides. + // GsmSMSClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void SetSmsReceivedHandler(const std::string& service_name, const dbus::ObjectPath& object_path, const SmsReceivedHandler& handler) diff --git a/chromeos/dbus/fake_image_burner_client.cc b/chromeos/dbus/fake_image_burner_client.cc index 978687e..01683b5 100644 --- a/chromeos/dbus/fake_image_burner_client.cc +++ b/chromeos/dbus/fake_image_burner_client.cc @@ -12,6 +12,9 @@ FakeImageBurnerClient::FakeImageBurnerClient() { FakeImageBurnerClient::~FakeImageBurnerClient() { } +void FakeImageBurnerClient::Init(dbus::Bus* bus) { +} + void FakeImageBurnerClient::ResetEventHandlers() { } diff --git a/chromeos/dbus/fake_image_burner_client.h b/chromeos/dbus/fake_image_burner_client.h index cb18bcf..b730ad2 100644 --- a/chromeos/dbus/fake_image_burner_client.h +++ b/chromeos/dbus/fake_image_burner_client.h @@ -17,7 +17,8 @@ class FakeImageBurnerClient : public ImageBurnerClient { FakeImageBurnerClient(); virtual ~FakeImageBurnerClient(); - // ImageBurnerClient overrides. + // ImageBurnerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void BurnImage(const std::string& from_path, const std::string& to_path, const ErrorCallback& error_callback) OVERRIDE; diff --git a/chromeos/dbus/fake_power_manager_client.cc b/chromeos/dbus/fake_power_manager_client.cc index 3fda910..a0762ef 100644 --- a/chromeos/dbus/fake_power_manager_client.cc +++ b/chromeos/dbus/fake_power_manager_client.cc @@ -8,12 +8,15 @@ namespace chromeos { FakePowerManagerClient::FakePowerManagerClient() - : request_restart_call_count_(0) { + : request_restart_call_count_(0) { } FakePowerManagerClient::~FakePowerManagerClient() { } +void FakePowerManagerClient::Init(dbus::Bus* bus) { +} + void FakePowerManagerClient::AddObserver(Observer* observer) { } diff --git a/chromeos/dbus/fake_power_manager_client.h b/chromeos/dbus/fake_power_manager_client.h index 31dd227..001d783 100644 --- a/chromeos/dbus/fake_power_manager_client.h +++ b/chromeos/dbus/fake_power_manager_client.h @@ -20,7 +20,8 @@ class FakePowerManagerClient : public PowerManagerClient { FakePowerManagerClient(); virtual ~FakePowerManagerClient(); - // PowerManagerClient overrides. + // PowerManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool HasObserver(Observer* observer) OVERRIDE; diff --git a/chromeos/dbus/fake_session_manager_client.cc b/chromeos/dbus/fake_session_manager_client.cc index 37d90da..b384a03 100644 --- a/chromeos/dbus/fake_session_manager_client.cc +++ b/chromeos/dbus/fake_session_manager_client.cc @@ -13,14 +13,17 @@ namespace chromeos { FakeSessionManagerClient::FakeSessionManagerClient() - : emit_login_prompt_ready_call_count_(0) , - notify_lock_screen_shown_call_count_(0), - notify_lock_screen_dismissed_call_count_(0){ + : emit_login_prompt_ready_call_count_(0), + notify_lock_screen_shown_call_count_(0), + notify_lock_screen_dismissed_call_count_(0) { } FakeSessionManagerClient::~FakeSessionManagerClient() { } +void FakeSessionManagerClient::Init(dbus::Bus* bus) { +} + void FakeSessionManagerClient::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/chromeos/dbus/fake_session_manager_client.h b/chromeos/dbus/fake_session_manager_client.h index 5c8941b3..993a071 100644 --- a/chromeos/dbus/fake_session_manager_client.h +++ b/chromeos/dbus/fake_session_manager_client.h @@ -17,12 +17,13 @@ namespace chromeos { // A fake implementation of session_manager. Accepts policy blobs to be set and // returns them unmodified. -class FakeSessionManagerClient : public chromeos::SessionManagerClient { +class FakeSessionManagerClient : public SessionManagerClient { public: FakeSessionManagerClient(); virtual ~FakeSessionManagerClient(); - // SessionManagerClient: + // SessionManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool HasObserver(Observer* observer) OVERRIDE; diff --git a/chromeos/dbus/fake_shill_device_client.cc b/chromeos/dbus/fake_shill_device_client.cc index 4d8c7f3..2bf0b65 100644 --- a/chromeos/dbus/fake_shill_device_client.cc +++ b/chromeos/dbus/fake_shill_device_client.cc @@ -12,6 +12,9 @@ FakeShillDeviceClient::FakeShillDeviceClient() { FakeShillDeviceClient::~FakeShillDeviceClient() { } +void FakeShillDeviceClient::Init(dbus::Bus* bus) { +} + void FakeShillDeviceClient::AddPropertyChangedObserver( const dbus::ObjectPath& device_path, ShillPropertyChangedObserver* observer) { diff --git a/chromeos/dbus/fake_shill_device_client.h b/chromeos/dbus/fake_shill_device_client.h index b887bb7..c97bae1 100644 --- a/chromeos/dbus/fake_shill_device_client.h +++ b/chromeos/dbus/fake_shill_device_client.h @@ -18,7 +18,8 @@ class FakeShillDeviceClient : public ShillDeviceClient { FakeShillDeviceClient(); virtual ~FakeShillDeviceClient(); - // ShillDeviceClient overrides. + // ShillDeviceClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( const dbus::ObjectPath& device_path, ShillPropertyChangedObserver* observer) OVERRIDE; diff --git a/chromeos/dbus/fake_shill_manager_client.cc b/chromeos/dbus/fake_shill_manager_client.cc index 35b256a..faab3d5 100644 --- a/chromeos/dbus/fake_shill_manager_client.cc +++ b/chromeos/dbus/fake_shill_manager_client.cc @@ -12,6 +12,9 @@ FakeShillManagerClient::FakeShillManagerClient() { FakeShillManagerClient::~FakeShillManagerClient() { } +void FakeShillManagerClient::Init(dbus::Bus* bus) { +} + void FakeShillManagerClient::RequestScan(const std::string& type, const base::Closure& callback, const ErrorCallback& error_callback) { diff --git a/chromeos/dbus/fake_shill_manager_client.h b/chromeos/dbus/fake_shill_manager_client.h index 2a1c0e72..1d1ba1a 100644 --- a/chromeos/dbus/fake_shill_manager_client.h +++ b/chromeos/dbus/fake_shill_manager_client.h @@ -17,7 +17,8 @@ class FakeShillManagerClient : public ShillManagerClient { FakeShillManagerClient(); virtual ~FakeShillManagerClient(); - // ShillManagerClient overrides. + // ShillManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( ShillPropertyChangedObserver* observer) OVERRIDE; virtual void RemovePropertyChangedObserver( diff --git a/chromeos/dbus/fake_system_clock_client.cc b/chromeos/dbus/fake_system_clock_client.cc index ea1b737..92a8dd3 100644 --- a/chromeos/dbus/fake_system_clock_client.cc +++ b/chromeos/dbus/fake_system_clock_client.cc @@ -12,6 +12,9 @@ FakeSystemClockClient::FakeSystemClockClient() { FakeSystemClockClient::~FakeSystemClockClient() { } +void FakeSystemClockClient::Init(dbus::Bus* bus) { +} + void FakeSystemClockClient::AddObserver(Observer* observer) { } diff --git a/chromeos/dbus/fake_system_clock_client.h b/chromeos/dbus/fake_system_clock_client.h index cea91a6..31a3ebc 100644 --- a/chromeos/dbus/fake_system_clock_client.h +++ b/chromeos/dbus/fake_system_clock_client.h @@ -15,7 +15,8 @@ class FakeSystemClockClient : public SystemClockClient { FakeSystemClockClient(); virtual ~FakeSystemClockClient(); - // SystemClockClient overrides. + // SystemClockClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool HasObserver(Observer* observer) OVERRIDE; diff --git a/chromeos/dbus/fake_update_engine_client.cc b/chromeos/dbus/fake_update_engine_client.cc index b9f40a2..a246c41 100644 --- a/chromeos/dbus/fake_update_engine_client.cc +++ b/chromeos/dbus/fake_update_engine_client.cc @@ -7,13 +7,16 @@ namespace chromeos { FakeUpdateEngineClient::FakeUpdateEngineClient() - : update_check_result_(UpdateEngineClient::UPDATE_RESULT_SUCCESS), - reboot_after_update_call_count_(0) { + : update_check_result_(UpdateEngineClient::UPDATE_RESULT_SUCCESS), + reboot_after_update_call_count_(0) { } FakeUpdateEngineClient::~FakeUpdateEngineClient() { } +void FakeUpdateEngineClient::Init(dbus::Bus* bus) { +} + void FakeUpdateEngineClient::AddObserver(Observer* observer) { } diff --git a/chromeos/dbus/fake_update_engine_client.h b/chromeos/dbus/fake_update_engine_client.h index 605d161..c5afe18 100644 --- a/chromeos/dbus/fake_update_engine_client.h +++ b/chromeos/dbus/fake_update_engine_client.h @@ -21,7 +21,8 @@ class FakeUpdateEngineClient : public UpdateEngineClient { FakeUpdateEngineClient(); virtual ~FakeUpdateEngineClient(); - // Overrides + // UpdateEngineClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool HasObserver(Observer* observer) OVERRIDE; diff --git a/chromeos/dbus/gsm_sms_client.cc b/chromeos/dbus/gsm_sms_client.cc index ae9b900..4fead8d 100644 --- a/chromeos/dbus/gsm_sms_client.cc +++ b/chromeos/dbus/gsm_sms_client.cc @@ -165,10 +165,7 @@ class SMSProxy { // The GsmSMSClient implementation. class GsmSMSClientImpl : public GsmSMSClient { public: - explicit GsmSMSClientImpl(dbus::Bus* bus) - : bus_(bus), - proxies_deleter_(&proxies_) { - } + GsmSMSClientImpl() : bus_(NULL), proxies_deleter_(&proxies_) {} // GsmSMSClient override. virtual void SetSmsReceivedHandler( @@ -213,6 +210,9 @@ class GsmSMSClientImpl : public GsmSMSClient { const dbus::ObjectPath& object_path) OVERRIDE { } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { bus_ = bus; } + private: typedef std::map<std::pair<std::string, std::string>, SMSProxy*> ProxyMap; @@ -247,10 +247,9 @@ GsmSMSClient::GsmSMSClient() {} GsmSMSClient::~GsmSMSClient() {} // static -GsmSMSClient* GsmSMSClient::Create(DBusClientImplementationType type, - dbus::Bus* bus) { +GsmSMSClient* GsmSMSClient::Create(DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new GsmSMSClientImpl(bus); + return new GsmSMSClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); FakeGsmSMSClient* fake = new FakeGsmSMSClient(); diff --git a/chromeos/dbus/gsm_sms_client.h b/chromeos/dbus/gsm_sms_client.h index 4effeff..af30753 100644 --- a/chromeos/dbus/gsm_sms_client.h +++ b/chromeos/dbus/gsm_sms_client.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" namespace base { @@ -18,7 +19,6 @@ class ListValue; } namespace dbus { -class Bus; class ObjectPath; } @@ -28,7 +28,7 @@ namespace chromeos { // org.freedesktop.ModemManager.Modem.Gsm.SMS service. // All methods should be called from the origin thread (UI thread) which // initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT GsmSMSClient { +class CHROMEOS_EXPORT GsmSMSClient : public DBusClient { public: typedef base::Callback<void(uint32 index, bool complete)> SmsReceivedHandler; typedef base::Callback<void()> DeleteCallback; @@ -39,8 +39,7 @@ class CHROMEOS_EXPORT GsmSMSClient { // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via DBusThreadManager::Get(). - static GsmSMSClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static GsmSMSClient* Create(DBusClientImplementationType type); // Sets SmsReceived signal handler. virtual void SetSmsReceivedHandler(const std::string& service_name, @@ -74,6 +73,8 @@ class CHROMEOS_EXPORT GsmSMSClient { const dbus::ObjectPath& object_path) = 0; protected: + friend class GsmSMSClientTest; + // Create() should be used instead. GsmSMSClient(); diff --git a/chromeos/dbus/gsm_sms_client_unittest.cc b/chromeos/dbus/gsm_sms_client_unittest.cc index baed2f7..8a956c4 100644 --- a/chromeos/dbus/gsm_sms_client_unittest.cc +++ b/chromeos/dbus/gsm_sms_client_unittest.cc @@ -99,8 +99,8 @@ class GsmSMSClientTest : public testing::Test { EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); // Create a client with the mock bus. - client_.reset( - GsmSMSClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, mock_bus_.get())); + client_.reset(GsmSMSClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); + client_->Init(mock_bus_.get()); } virtual void TearDown() OVERRIDE { diff --git a/chromeos/dbus/image_burner_client.cc b/chromeos/dbus/image_burner_client.cc index 86c4249a8..a807f07 100644 --- a/chromeos/dbus/image_burner_client.cc +++ b/chromeos/dbus/image_burner_client.cc @@ -20,27 +20,8 @@ namespace { // The ImageBurnerClient implementation. class ImageBurnerClientImpl : public ImageBurnerClient { public: - explicit ImageBurnerClientImpl(dbus::Bus* bus) - : proxy_(NULL), - weak_ptr_factory_(this) { - proxy_ = bus->GetObjectProxy( - imageburn::kImageBurnServiceName, - dbus::ObjectPath(imageburn::kImageBurnServicePath)); - proxy_->ConnectToSignal( - imageburn::kImageBurnServiceInterface, - imageburn::kSignalBurnFinishedName, - base::Bind(&ImageBurnerClientImpl::OnBurnFinished, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&ImageBurnerClientImpl::OnSignalConnected, - weak_ptr_factory_.GetWeakPtr())); - proxy_->ConnectToSignal( - imageburn::kImageBurnServiceInterface, - imageburn::kSignalBurnUpdateName, - base::Bind(&ImageBurnerClientImpl::OnBurnProgressUpdate, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&ImageBurnerClientImpl::OnSignalConnected, - weak_ptr_factory_.GetWeakPtr())); - } + ImageBurnerClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} + virtual ~ImageBurnerClientImpl() {} // ImageBurnerClient override. @@ -72,6 +53,27 @@ class ImageBurnerClientImpl : public ImageBurnerClient { burn_progress_update_handler_.Reset(); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + proxy_ = + bus->GetObjectProxy(imageburn::kImageBurnServiceName, + dbus::ObjectPath(imageburn::kImageBurnServicePath)); + proxy_->ConnectToSignal( + imageburn::kImageBurnServiceInterface, + imageburn::kSignalBurnFinishedName, + base::Bind(&ImageBurnerClientImpl::OnBurnFinished, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&ImageBurnerClientImpl::OnSignalConnected, + weak_ptr_factory_.GetWeakPtr())); + proxy_->ConnectToSignal( + imageburn::kImageBurnServiceInterface, + imageburn::kSignalBurnUpdateName, + base::Bind(&ImageBurnerClientImpl::OnBurnProgressUpdate, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&ImageBurnerClientImpl::OnSignalConnected, + weak_ptr_factory_.GetWeakPtr())); + } + private: // Called when a response for BurnImage is received void OnBurnImage(ErrorCallback error_callback, dbus::Response* response) { @@ -142,10 +144,10 @@ ImageBurnerClient::~ImageBurnerClient() { } // static -ImageBurnerClient* ImageBurnerClient::Create(DBusClientImplementationType type, - dbus::Bus* bus) { +ImageBurnerClient* ImageBurnerClient::Create( + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new ImageBurnerClientImpl(bus); + return new ImageBurnerClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new FakeImageBurnerClient(); } diff --git a/chromeos/dbus/image_burner_client.h b/chromeos/dbus/image_burner_client.h index 053b430..c6f65ef 100644 --- a/chromeos/dbus/image_burner_client.h +++ b/chromeos/dbus/image_burner_client.h @@ -10,18 +10,15 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" -namespace dbus { -class Bus; -} - namespace chromeos { // ImageBurnerClient is used to communicate with the image burner. // All method should be called from the origin thread (UI thread) which // initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT ImageBurnerClient { +class CHROMEOS_EXPORT ImageBurnerClient : public DBusClient { public: virtual ~ImageBurnerClient(); @@ -57,8 +54,7 @@ class CHROMEOS_EXPORT ImageBurnerClient { // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via DBusThreadManager::Get(). - static ImageBurnerClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static ImageBurnerClient* Create(DBusClientImplementationType type); protected: // Create() should be used instead. diff --git a/chromeos/dbus/introspectable_client.cc b/chromeos/dbus/introspectable_client.cc index 83b09a3..81cc8a1 100644 --- a/chromeos/dbus/introspectable_client.cc +++ b/chromeos/dbus/introspectable_client.cc @@ -32,10 +32,7 @@ namespace chromeos { // The IntrospectableClient implementation used in production. class IntrospectableClientImpl : public IntrospectableClient { public: - explicit IntrospectableClientImpl(dbus::Bus* bus) - : bus_(bus), - weak_ptr_factory_(this) { - } + IntrospectableClientImpl() : bus_(NULL), weak_ptr_factory_(this) {} virtual ~IntrospectableClientImpl() { } @@ -57,6 +54,9 @@ class IntrospectableClientImpl : public IntrospectableClient { service_name, object_path, callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { bus_ = bus; } + private: // Called by dbus:: when a response for Introspect() is recieved. void OnIntrospect(const std::string& service_name, @@ -96,6 +96,7 @@ class IntrospectableClientImpl : public IntrospectableClient { class IntrospectableClientStubImpl : public IntrospectableClient { public: // IntrospectableClient override. + virtual void Init(dbus::Bus* bus) OVERRIDE {} virtual void Introspect(const std::string& service_name, const dbus::ObjectPath& object_path, const IntrospectCallback& callback) OVERRIDE { @@ -145,10 +146,9 @@ IntrospectableClient::GetInterfacesFromIntrospectResult( // static IntrospectableClient* IntrospectableClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new IntrospectableClientImpl(bus); + return new IntrospectableClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new IntrospectableClientStubImpl(); } diff --git a/chromeos/dbus/introspectable_client.h b/chromeos/dbus/introspectable_client.h index 1ee15d6..573b9f9 100644 --- a/chromeos/dbus/introspectable_client.h +++ b/chromeos/dbus/introspectable_client.h @@ -10,18 +10,15 @@ #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "dbus/object_path.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // IntrospectableClient is used to retrieve the D-Bus introspection data // from a remote object. -class CHROMEOS_EXPORT IntrospectableClient { +class CHROMEOS_EXPORT IntrospectableClient : public DBusClient { public: virtual ~IntrospectableClient(); @@ -48,8 +45,7 @@ class CHROMEOS_EXPORT IntrospectableClient { const std::string& xml_data); // Creates the instance - static IntrospectableClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static IntrospectableClient* Create(DBusClientImplementationType type); protected: IntrospectableClient(); diff --git a/chromeos/dbus/mock_cryptohome_client.h b/chromeos/dbus/mock_cryptohome_client.h index 86986e6..f057709 100644 --- a/chromeos/dbus/mock_cryptohome_client.h +++ b/chromeos/dbus/mock_cryptohome_client.h @@ -17,6 +17,7 @@ class MockCryptohomeClient : public CryptohomeClient { MockCryptohomeClient(); virtual ~MockCryptohomeClient(); + MOCK_METHOD1(Init, void(dbus::Bus* bus)); MOCK_METHOD2(SetAsyncCallStatusHandlers, void(const AsyncCallStatusHandler& handler, const AsyncCallStatusWithDataHandler& data_handler)); diff --git a/chromeos/dbus/mock_gsm_sms_client.h b/chromeos/dbus/mock_gsm_sms_client.h index bc0bee9..aa522c5 100644 --- a/chromeos/dbus/mock_gsm_sms_client.h +++ b/chromeos/dbus/mock_gsm_sms_client.h @@ -19,6 +19,7 @@ class MockGsmSMSClient : public GsmSMSClient { MockGsmSMSClient(); virtual ~MockGsmSMSClient(); + MOCK_METHOD1(Init, void(dbus::Bus* bus)); MOCK_METHOD3(SetSmsReceivedHandler, void(const std::string& service_name, const dbus::ObjectPath& object_path, const SmsReceivedHandler& handler)); diff --git a/chromeos/dbus/mock_session_manager_client.h b/chromeos/dbus/mock_session_manager_client.h index afe8e37..14e879b 100644 --- a/chromeos/dbus/mock_session_manager_client.h +++ b/chromeos/dbus/mock_session_manager_client.h @@ -17,6 +17,7 @@ class MockSessionManagerClient : public SessionManagerClient { MockSessionManagerClient(); virtual ~MockSessionManagerClient(); + MOCK_METHOD1(Init, void(dbus::Bus* bus)); MOCK_METHOD1(AddObserver, void(Observer*)); MOCK_METHOD1(RemoveObserver, void(Observer*)); MOCK_METHOD1(HasObserver, bool(Observer*)); diff --git a/chromeos/dbus/mock_shill_device_client.h b/chromeos/dbus/mock_shill_device_client.h index eef766f..d473ed7 100644 --- a/chromeos/dbus/mock_shill_device_client.h +++ b/chromeos/dbus/mock_shill_device_client.h @@ -18,6 +18,7 @@ class MockShillDeviceClient : public ShillDeviceClient { MockShillDeviceClient(); virtual ~MockShillDeviceClient(); + MOCK_METHOD1(Init, void(dbus::Bus* bus)); MOCK_METHOD2(AddPropertyChangedObserver, void(const dbus::ObjectPath& device_path, ShillPropertyChangedObserver* observer)); diff --git a/chromeos/dbus/mock_shill_ipconfig_client.h b/chromeos/dbus/mock_shill_ipconfig_client.h index 4a4bea3..4a35b37 100644 --- a/chromeos/dbus/mock_shill_ipconfig_client.h +++ b/chromeos/dbus/mock_shill_ipconfig_client.h @@ -18,6 +18,7 @@ class MockShillIPConfigClient : public ShillIPConfigClient { MockShillIPConfigClient(); virtual ~MockShillIPConfigClient(); + MOCK_METHOD1(Init, void(dbus::Bus* bus)); MOCK_METHOD2(AddPropertyChangedObserver, void(const dbus::ObjectPath& ipconfig_path, ShillPropertyChangedObserver* observer)); diff --git a/chromeos/dbus/mock_shill_manager_client.h b/chromeos/dbus/mock_shill_manager_client.h index b62aebd..bf80b64 100644 --- a/chromeos/dbus/mock_shill_manager_client.h +++ b/chromeos/dbus/mock_shill_manager_client.h @@ -17,6 +17,7 @@ class MockShillManagerClient : public ShillManagerClient { MockShillManagerClient(); virtual ~MockShillManagerClient(); + MOCK_METHOD1(Init, void(dbus::Bus* bus)); MOCK_METHOD1(AddPropertyChangedObserver, void(ShillPropertyChangedObserver* observer)); MOCK_METHOD1(RemovePropertyChangedObserver, diff --git a/chromeos/dbus/mock_shill_profile_client.h b/chromeos/dbus/mock_shill_profile_client.h index b18a843..9bf2012 100644 --- a/chromeos/dbus/mock_shill_profile_client.h +++ b/chromeos/dbus/mock_shill_profile_client.h @@ -20,6 +20,7 @@ class MockShillProfileClient : public ShillProfileClient { MockShillProfileClient(); virtual ~MockShillProfileClient(); + MOCK_METHOD1(Init, void(dbus::Bus* bus)); MOCK_METHOD2(AddPropertyChangedObserver, void(const dbus::ObjectPath& profile_path, ShillPropertyChangedObserver* observer)); diff --git a/chromeos/dbus/mock_shill_service_client.h b/chromeos/dbus/mock_shill_service_client.h index 6f4ab29..a890b51 100644 --- a/chromeos/dbus/mock_shill_service_client.h +++ b/chromeos/dbus/mock_shill_service_client.h @@ -18,6 +18,7 @@ class MockShillServiceClient : public ShillServiceClient { MockShillServiceClient(); virtual ~MockShillServiceClient(); + MOCK_METHOD1(Init, void(dbus::Bus* dbus)); MOCK_METHOD2(AddPropertyChangedObserver, void(const dbus::ObjectPath& service_path, ShillPropertyChangedObserver* observer)); diff --git a/chromeos/dbus/modem_messaging_client.cc b/chromeos/dbus/modem_messaging_client.cc index 2aa12de..b421b7c 100644 --- a/chromeos/dbus/modem_messaging_client.cc +++ b/chromeos/dbus/modem_messaging_client.cc @@ -135,12 +135,11 @@ class ModemMessagingProxy { class CHROMEOS_EXPORT ModemMessagingClientImpl : public ModemMessagingClient { public: - explicit ModemMessagingClientImpl(dbus::Bus *bus) - : bus_(bus), + ModemMessagingClientImpl() + : bus_(NULL), proxies_deleter_(&proxies_) { } - // ModemMessagingClient override. virtual void SetSmsReceivedHandler( const std::string& service_name, const dbus::ObjectPath& object_path, @@ -148,14 +147,12 @@ class CHROMEOS_EXPORT ModemMessagingClientImpl : public ModemMessagingClient { GetProxy(service_name, object_path)->SetSmsReceivedHandler(handler); } - // ModemMessagingClient override. virtual void ResetSmsReceivedHandler( const std::string& service_name, const dbus::ObjectPath& object_path) OVERRIDE { GetProxy(service_name, object_path)->ResetSmsReceivedHandler(); } - // ModemMessagingClient override. virtual void Delete(const std::string& service_name, const dbus::ObjectPath& object_path, const dbus::ObjectPath& sms_path, @@ -163,13 +160,17 @@ class CHROMEOS_EXPORT ModemMessagingClientImpl : public ModemMessagingClient { GetProxy(service_name, object_path)->Delete(sms_path, callback); } - // ModemMessagingClient override. virtual void List(const std::string& service_name, const dbus::ObjectPath& object_path, const ListCallback& callback) OVERRIDE { GetProxy(service_name, object_path)->List(callback); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + bus_ = bus; + }; + private: typedef std::map<std::pair<std::string, std::string>, ModemMessagingProxy*> ProxyMap; @@ -203,6 +204,7 @@ class CHROMEOS_EXPORT ModemMessagingClientStubImpl virtual ~ModemMessagingClientStubImpl() {} // ModemMessagingClient override. + virtual void Init(dbus::Bus* bus) OVERRIDE {} virtual void SetSmsReceivedHandler( const std::string& service_name, const dbus::ObjectPath& object_path, @@ -268,10 +270,9 @@ ModemMessagingClient::~ModemMessagingClient() {} // static ModemMessagingClient* ModemMessagingClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { - return new ModemMessagingClientImpl(bus); + return new ModemMessagingClientImpl(); } DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new ModemMessagingClientStubImpl(); diff --git a/chromeos/dbus/modem_messaging_client.h b/chromeos/dbus/modem_messaging_client.h index 8a5eb3d..d3ebc33 100644 --- a/chromeos/dbus/modem_messaging_client.h +++ b/chromeos/dbus/modem_messaging_client.h @@ -11,10 +11,10 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" namespace dbus { -class Bus; class ObjectPath; } @@ -24,7 +24,7 @@ namespace chromeos { // org.freedesktop.ModemManager1.Modem.Messaging service. All methods // should be called from the origin thread (UI thread) which // initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT ModemMessagingClient { +class CHROMEOS_EXPORT ModemMessagingClient : public DBusClient { public: typedef base::Callback<void()> DeleteCallback; typedef base::Callback<void(const dbus::ObjectPath& message_path, @@ -36,8 +36,7 @@ class CHROMEOS_EXPORT ModemMessagingClient { // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via DBusThreadManager::Get(). - static ModemMessagingClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static ModemMessagingClient* Create(DBusClientImplementationType type); // Sets SmsReceived signal handler. virtual void SetSmsReceivedHandler(const std::string& service_name, @@ -60,6 +59,8 @@ class CHROMEOS_EXPORT ModemMessagingClient { const ListCallback& callback) = 0; protected: + friend class ModemMessagingClientTest; + // Create() should be used instead. ModemMessagingClient(); diff --git a/chromeos/dbus/modem_messaging_client_unittest.cc b/chromeos/dbus/modem_messaging_client_unittest.cc index f51e9f4..506ef9b 100644 --- a/chromeos/dbus/modem_messaging_client_unittest.cc +++ b/chromeos/dbus/modem_messaging_client_unittest.cc @@ -93,8 +93,9 @@ class ModemMessagingClientTest : public testing::Test { EXPECT_CALL(*mock_bus_.get(), ShutdownAndBlock()).WillOnce(Return()); // Create a client with the mock bus. - client_.reset(ModemMessagingClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, - mock_bus_.get())); + client_.reset( + ModemMessagingClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); + client_->Init(mock_bus_.get()); } virtual void TearDown() OVERRIDE { diff --git a/chromeos/dbus/permission_broker_client.cc b/chromeos/dbus/permission_broker_client.cc index cd86eba..4bf2699 100644 --- a/chromeos/dbus/permission_broker_client.cc +++ b/chromeos/dbus/permission_broker_client.cc @@ -22,10 +22,7 @@ namespace chromeos { class PermissionBrokerClientImpl : public PermissionBrokerClient { public: - explicit PermissionBrokerClientImpl(dbus::Bus* bus) - : proxy_(bus->GetObjectProxy(kPermissionBrokerServiceName, - dbus::ObjectPath(kPermissionBrokerServicePath))), - weak_ptr_factory_(this) {} + PermissionBrokerClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} virtual void RequestPathAccess(const std::string& path, const int interface_id, @@ -56,6 +53,13 @@ class PermissionBrokerClientImpl : public PermissionBrokerClient { weak_ptr_factory_.GetWeakPtr(), callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + proxy_ = + bus->GetObjectProxy(kPermissionBrokerServiceName, + dbus::ObjectPath(kPermissionBrokerServicePath)); + } + private: // Handle a DBus response from the permission broker, invoking the callback // that the method was originally called with with the success response. @@ -88,6 +92,7 @@ class PermissionBrokerClientStubImpl : public PermissionBrokerClient { PermissionBrokerClientStubImpl() {} virtual ~PermissionBrokerClientStubImpl() {} + virtual void Init(dbus::Bus* bus) OVERRIDE {} virtual void RequestPathAccess(const std::string& path, int interface_id, const ResultCallback& callback) OVERRIDE { @@ -110,9 +115,9 @@ PermissionBrokerClient::PermissionBrokerClient() {} PermissionBrokerClient::~PermissionBrokerClient() {} PermissionBrokerClient* PermissionBrokerClient::Create( - DBusClientImplementationType type, dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new PermissionBrokerClientImpl(bus); + return new PermissionBrokerClientImpl(); return new PermissionBrokerClientStubImpl(); } diff --git a/chromeos/dbus/permission_broker_client.h b/chromeos/dbus/permission_broker_client.h index 645bcca..5780d8c 100644 --- a/chromeos/dbus/permission_broker_client.h +++ b/chromeos/dbus/permission_broker_client.h @@ -10,12 +10,9 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // PermissionBrokerClient is used to communicate with the permission broker, a @@ -25,7 +22,7 @@ namespace chromeos { // which the user the browser runs under normally wouldn't have access to. For // more details on the permission broker see: // http://git.chromium.org/gitweb/?p=chromiumos/platform/permission_broker.git -class CHROMEOS_EXPORT PermissionBrokerClient { +class CHROMEOS_EXPORT PermissionBrokerClient : public DBusClient { public: // The ResultCallback is used for both the RequestPathAccess and // RequestUsbAcess methods. Its boolean parameter represents the result of the @@ -34,8 +31,7 @@ class CHROMEOS_EXPORT PermissionBrokerClient { virtual ~PermissionBrokerClient(); - static PermissionBrokerClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static PermissionBrokerClient* Create(DBusClientImplementationType type); // RequestPathAccess requests access to a single device node identified by // |path|. If |interface_id| value is passed (different than diff --git a/chromeos/dbus/power_manager_client.cc b/chromeos/dbus/power_manager_client.cc index 0669b44..548b053 100644 --- a/chromeos/dbus/power_manager_client.cc +++ b/chromeos/dbus/power_manager_client.cc @@ -41,7 +41,7 @@ const char kSuspendDelayDescription[] = "chrome"; // The PowerManagerClient implementation used in production. class PowerManagerClientImpl : public PowerManagerClient { public: - explicit PowerManagerClientImpl(dbus::Bus* bus) + PowerManagerClientImpl() : origin_thread_id_(base::PlatformThread::CurrentId()), power_manager_proxy_(NULL), suspend_delay_id_(-1), @@ -50,95 +50,7 @@ class PowerManagerClientImpl : public PowerManagerClient { suspend_is_pending_(false), num_pending_suspend_readiness_callbacks_(0), last_is_projecting_(false), - weak_ptr_factory_(this) { - power_manager_proxy_ = bus->GetObjectProxy( - power_manager::kPowerManagerServiceName, - dbus::ObjectPath(power_manager::kPowerManagerServicePath)); - - power_manager_proxy_->SetNameOwnerChangedCallback( - base::Bind(&PowerManagerClientImpl::NameOwnerChangedReceived, - weak_ptr_factory_.GetWeakPtr())); - - // Monitor the D-Bus signal for brightness changes. Only the power - // manager knows the actual brightness level. We don't cache the - // brightness level in Chrome as it'll make things less reliable. - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kBrightnessChangedSignal, - base::Bind(&PowerManagerClientImpl::BrightnessChangedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kPeripheralBatteryStatusSignal, - base::Bind(&PowerManagerClientImpl::PeripheralBatteryStatusReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kPowerSupplyPollSignal, - base::Bind(&PowerManagerClientImpl::PowerSupplyPollReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kIdleNotifySignal, - base::Bind(&PowerManagerClientImpl::IdleNotifySignalReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kInputEventSignal, - base::Bind(&PowerManagerClientImpl::InputEventReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kSuspendStateChangedSignal, - base::Bind(&PowerManagerClientImpl::SuspendStateChangedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kSuspendImminentSignal, - base::Bind( - &PowerManagerClientImpl::SuspendImminentReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kIdleActionImminentSignal, - base::Bind( - &PowerManagerClientImpl::IdleActionImminentReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - power_manager_proxy_->ConnectToSignal( - power_manager::kPowerManagerInterface, - power_manager::kIdleActionDeferredSignal, - base::Bind( - &PowerManagerClientImpl::IdleActionDeferredReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - RegisterSuspendDelay(); - } + weak_ptr_factory_(this) {} virtual ~PowerManagerClientImpl() { // Here we should unregister suspend notifications from powerd, @@ -311,6 +223,97 @@ class PowerManagerClientImpl : public PowerManagerClient { weak_ptr_factory_.GetWeakPtr(), pending_suspend_id_); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + power_manager_proxy_ = bus->GetObjectProxy( + power_manager::kPowerManagerServiceName, + dbus::ObjectPath(power_manager::kPowerManagerServicePath)); + + power_manager_proxy_->SetNameOwnerChangedCallback( + base::Bind(&PowerManagerClientImpl::NameOwnerChangedReceived, + weak_ptr_factory_.GetWeakPtr())); + + // Monitor the D-Bus signal for brightness changes. Only the power + // manager knows the actual brightness level. We don't cache the + // brightness level in Chrome as it'll make things less reliable. + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kBrightnessChangedSignal, + base::Bind(&PowerManagerClientImpl::BrightnessChangedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kPeripheralBatteryStatusSignal, + base::Bind(&PowerManagerClientImpl::PeripheralBatteryStatusReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kPowerSupplyPollSignal, + base::Bind(&PowerManagerClientImpl::PowerSupplyPollReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kIdleNotifySignal, + base::Bind(&PowerManagerClientImpl::IdleNotifySignalReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kInputEventSignal, + base::Bind(&PowerManagerClientImpl::InputEventReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kSuspendStateChangedSignal, + base::Bind(&PowerManagerClientImpl::SuspendStateChangedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kSuspendImminentSignal, + base::Bind( + &PowerManagerClientImpl::SuspendImminentReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kIdleActionImminentSignal, + base::Bind( + &PowerManagerClientImpl::IdleActionImminentReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + power_manager_proxy_->ConnectToSignal( + power_manager::kPowerManagerInterface, + power_manager::kIdleActionDeferredSignal, + base::Bind( + &PowerManagerClientImpl::IdleActionDeferredReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&PowerManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + RegisterSuspendDelay(); + } + private: // Returns true if the current thread is the origin thread. bool OnOriginThread() { @@ -671,7 +674,12 @@ class PowerManagerClientStubImpl : public PowerManagerClient { brightness_(50.0), pause_count_(2), cycle_count_(0), - weak_ptr_factory_(this) { + weak_ptr_factory_(this) {} + + virtual ~PowerManagerClientStubImpl() {} + + // PowerManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE { if (CommandLine::ForCurrentProcess()->HasSwitch( chromeos::switches::kEnableStubInteractive)) { const int kStatusUpdateMs = 1000; @@ -681,10 +689,6 @@ class PowerManagerClientStubImpl : public PowerManagerClient { } } - virtual ~PowerManagerClientStubImpl() {} - - // PowerManagerClient overrides: - virtual void AddObserver(Observer* observer) OVERRIDE { observers_.AddObserver(observer); } @@ -856,10 +860,9 @@ PowerManagerClient::~PowerManagerClient() { // static PowerManagerClient* PowerManagerClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new PowerManagerClientImpl(bus); + return new PowerManagerClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new PowerManagerClientStubImpl(); } diff --git a/chromeos/dbus/power_manager_client.h b/chromeos/dbus/power_manager_client.h index 5ddd711..e728f10 100644 --- a/chromeos/dbus/power_manager_client.h +++ b/chromeos/dbus/power_manager_client.h @@ -11,13 +11,10 @@ #include "base/callback.h" #include "base/time/time.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "third_party/cros_system_api/dbus/service_constants.h" -namespace dbus { -class Bus; -} - namespace power_manager { class PowerManagementPolicy; class PowerSupplyProperties; @@ -32,7 +29,7 @@ typedef base::Callback<void(void)> IdleNotificationCallback; typedef base::Callback<void(double)> GetScreenBrightnessPercentCallback; // PowerManagerClient is used to communicate with the power manager. -class CHROMEOS_EXPORT PowerManagerClient { +class CHROMEOS_EXPORT PowerManagerClient : public DBusClient { public: // Interface for observing changes from the power manager. class Observer { @@ -161,8 +158,7 @@ class CHROMEOS_EXPORT PowerManagerClient { virtual base::Closure GetSuspendReadinessCallback() = 0; // Creates the instance. - static PowerManagerClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static PowerManagerClient* Create(DBusClientImplementationType type); virtual ~PowerManagerClient(); diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc index e842f88..f75a9d4 100644 --- a/chromeos/dbus/session_manager_client.cc +++ b/chromeos/dbus/session_manager_client.cc @@ -28,66 +28,9 @@ namespace chromeos { // The SessionManagerClient implementation used in production. class SessionManagerClientImpl : public SessionManagerClient { public: - explicit SessionManagerClientImpl(dbus::Bus* bus) - : session_manager_proxy_(bus->GetObjectProxy( - login_manager::kSessionManagerServiceName, - dbus::ObjectPath(login_manager::kSessionManagerServicePath))), - blocking_method_caller_(bus, session_manager_proxy_), - weak_ptr_factory_(this) { - // Signals emitted on Chromium's interface. Many of these ought to be - // method calls instead. - session_manager_proxy_->ConnectToSignal( - chromium::kChromiumInterface, - chromium::kOwnerKeySetSignal, - base::Bind(&SessionManagerClientImpl::OwnerKeySetReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SessionManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - session_manager_proxy_->ConnectToSignal( - chromium::kChromiumInterface, - chromium::kPropertyChangeCompleteSignal, - base::Bind(&SessionManagerClientImpl::PropertyChangeCompleteReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SessionManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - session_manager_proxy_->ConnectToSignal( - chromium::kChromiumInterface, - chromium::kLockScreenSignal, - base::Bind(&SessionManagerClientImpl::ScreenLockReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SessionManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - session_manager_proxy_->ConnectToSignal( - chromium::kChromiumInterface, - chromium::kUnlockScreenSignal, - base::Bind(&SessionManagerClientImpl::ScreenUnlockReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SessionManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - session_manager_proxy_->ConnectToSignal( - chromium::kChromiumInterface, - chromium::kLivenessRequestedSignal, - base::Bind(&SessionManagerClientImpl::LivenessRequestedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SessionManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - // Signals emitted on the session manager's interface. - session_manager_proxy_->ConnectToSignal( - login_manager::kSessionManagerInterface, - login_manager::kScreenIsLockedSignal, - base::Bind(&SessionManagerClientImpl::ScreenIsLockedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SessionManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - session_manager_proxy_->ConnectToSignal( - login_manager::kSessionManagerInterface, - login_manager::kScreenIsUnlockedSignal, - base::Bind(&SessionManagerClientImpl::ScreenIsUnlockedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SessionManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - } + SessionManagerClientImpl() + : session_manager_proxy_(NULL), + weak_ptr_factory_(this) {} virtual ~SessionManagerClientImpl() { } @@ -231,7 +174,7 @@ class SessionManagerClientImpl : public SessionManagerClient { dbus::MessageWriter writer(&method_call); writer.AppendString(username); scoped_ptr<dbus::Response> response = - blocking_method_caller_.CallMethodAndBlock(&method_call); + blocking_method_caller_->CallMethodAndBlock(&method_call); std::string policy; ExtractString(login_manager::kSessionManagerRetrievePolicyForUser, response.get(), @@ -300,6 +243,69 @@ class SessionManagerClientImpl : public SessionManagerClient { dbus::ObjectProxy::EmptyResponseCallback()); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + session_manager_proxy_ = bus->GetObjectProxy( + login_manager::kSessionManagerServiceName, + dbus::ObjectPath(login_manager::kSessionManagerServicePath)); + blocking_method_caller_.reset( + new BlockingMethodCaller(bus, session_manager_proxy_)); + + // Signals emitted on Chromium's interface. Many of these ought to be + // method calls instead. + session_manager_proxy_->ConnectToSignal( + chromium::kChromiumInterface, + chromium::kOwnerKeySetSignal, + base::Bind(&SessionManagerClientImpl::OwnerKeySetReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + session_manager_proxy_->ConnectToSignal( + chromium::kChromiumInterface, + chromium::kPropertyChangeCompleteSignal, + base::Bind(&SessionManagerClientImpl::PropertyChangeCompleteReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + session_manager_proxy_->ConnectToSignal( + chromium::kChromiumInterface, + chromium::kLockScreenSignal, + base::Bind(&SessionManagerClientImpl::ScreenLockReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + session_manager_proxy_->ConnectToSignal( + chromium::kChromiumInterface, + chromium::kUnlockScreenSignal, + base::Bind(&SessionManagerClientImpl::ScreenUnlockReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + session_manager_proxy_->ConnectToSignal( + chromium::kChromiumInterface, + chromium::kLivenessRequestedSignal, + base::Bind(&SessionManagerClientImpl::LivenessRequestedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + // Signals emitted on the session manager's interface. + session_manager_proxy_->ConnectToSignal( + login_manager::kSessionManagerInterface, + login_manager::kScreenIsLockedSignal, + base::Bind(&SessionManagerClientImpl::ScreenIsLockedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + session_manager_proxy_->ConnectToSignal( + login_manager::kSessionManagerInterface, + login_manager::kScreenIsUnlockedSignal, + base::Bind(&SessionManagerClientImpl::ScreenIsUnlockedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + } + private: // Makes a method call to the session manager with no arguments and no // response. @@ -513,7 +519,7 @@ class SessionManagerClientImpl : public SessionManagerClient { } dbus::ObjectProxy* session_manager_proxy_; - BlockingMethodCaller blocking_method_caller_; + scoped_ptr<BlockingMethodCaller> blocking_method_caller_; ObserverList<Observer> observers_; // Note: This should remain the last member so it'll be destroyed and @@ -527,7 +533,11 @@ class SessionManagerClientImpl : public SessionManagerClient { // which does nothing. class SessionManagerClientStubImpl : public SessionManagerClient { public: - SessionManagerClientStubImpl() { + SessionManagerClientStubImpl() {} + virtual ~SessionManagerClientStubImpl() {} + + // SessionManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE { // Make sure that there are no keys left over from a previous browser run. base::FilePath user_policy_key_dir; if (PathService::Get(chromeos::DIR_USER_POLICY_KEYS, @@ -539,9 +549,7 @@ class SessionManagerClientStubImpl : public SessionManagerClient { false); } } - virtual ~SessionManagerClientStubImpl() {} - // SessionManagerClient overrides. virtual void AddObserver(Observer* observer) OVERRIDE { observers_.AddObserver(observer); } @@ -664,10 +672,9 @@ SessionManagerClient::~SessionManagerClient() { } SessionManagerClient* SessionManagerClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new SessionManagerClientImpl(bus); + return new SessionManagerClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new SessionManagerClientStubImpl(); } diff --git a/chromeos/dbus/session_manager_client.h b/chromeos/dbus/session_manager_client.h index 45b9b14..f09a041 100644 --- a/chromeos/dbus/session_manager_client.h +++ b/chromeos/dbus/session_manager_client.h @@ -11,16 +11,13 @@ #include "base/callback.h" #include "base/observer_list.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" -namespace dbus { -class Bus; -} // namespace dbus - namespace chromeos { // SessionManagerClient is used to communicate with the session manager. -class CHROMEOS_EXPORT SessionManagerClient { +class CHROMEOS_EXPORT SessionManagerClient : public DBusClient { public: // Interface for observing changes from the session manager. class Observer { @@ -173,8 +170,7 @@ class CHROMEOS_EXPORT SessionManagerClient { const std::vector<std::string>& flags) = 0; // Creates the instance. - static SessionManagerClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static SessionManagerClient* Create(DBusClientImplementationType type); virtual ~SessionManagerClient(); diff --git a/chromeos/dbus/shill_device_client.cc b/chromeos/dbus/shill_device_client.cc index ccab2b9..420f586 100644 --- a/chromeos/dbus/shill_device_client.cc +++ b/chromeos/dbus/shill_device_client.cc @@ -24,8 +24,8 @@ namespace { // The ShillDeviceClient implementation. class ShillDeviceClientImpl : public ShillDeviceClient { public: - explicit ShillDeviceClientImpl(dbus::Bus* bus) - : bus_(bus) { + explicit ShillDeviceClientImpl() + : bus_(NULL) { } virtual ~ShillDeviceClientImpl() { @@ -196,6 +196,11 @@ class ShillDeviceClientImpl : public ShillDeviceClient { return NULL; } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + bus_ = bus; + } + private: typedef std::map<std::string, ShillClientHelper*> HelperMap; @@ -231,10 +236,9 @@ ShillDeviceClient::~ShillDeviceClient() {} // static ShillDeviceClient* ShillDeviceClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new ShillDeviceClientImpl(bus); + return new ShillDeviceClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new ShillDeviceClientStub(); } diff --git a/chromeos/dbus/shill_device_client.h b/chromeos/dbus/shill_device_client.h index 2047059..4600e37 100644 --- a/chromeos/dbus/shill_device_client.h +++ b/chromeos/dbus/shill_device_client.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/shill_client_helper.h" @@ -22,7 +23,6 @@ class DictionaryValue; namespace dbus { -class Bus; class ObjectPath; } // namespace dbus @@ -34,7 +34,7 @@ class ShillPropertyChangedObserver; // ShillDeviceClient is used to communicate with the Shill Device service. // All methods should be called from the origin thread which initializes the // DBusThreadManager instance. -class CHROMEOS_EXPORT ShillDeviceClient { +class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient { public: typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; @@ -62,8 +62,7 @@ class CHROMEOS_EXPORT ShillDeviceClient { // Factory function, creates a new instance which is owned by the caller. // For normal usage, access the singleton via DBusThreadManager::Get(). - static ShillDeviceClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static ShillDeviceClient* Create(DBusClientImplementationType type); // Adds a property changed |observer| for the device at |device_path|. virtual void AddPropertyChangedObserver( @@ -160,6 +159,8 @@ class CHROMEOS_EXPORT ShillDeviceClient { virtual TestInterface* GetTestInterface() = 0; protected: + friend class ShillDeviceClientTest; + // Create() should be used instead. ShillDeviceClient(); diff --git a/chromeos/dbus/shill_device_client_stub.cc b/chromeos/dbus/shill_device_client_stub.cc index f7f39da..a32febd 100644 --- a/chromeos/dbus/shill_device_client_stub.cc +++ b/chromeos/dbus/shill_device_client_stub.cc @@ -30,7 +30,6 @@ void ErrorFunction(const std::string& error_name, } // namespace ShillDeviceClientStub::ShillDeviceClientStub() : weak_ptr_factory_(this) { - SetDefaultProperties(); } ShillDeviceClientStub::~ShillDeviceClientStub() { @@ -40,6 +39,10 @@ ShillDeviceClientStub::~ShillDeviceClientStub() { // ShillDeviceClient overrides. +void ShillDeviceClientStub::Init(dbus::Bus* bus) { + SetDefaultProperties(); +} + void ShillDeviceClientStub::AddPropertyChangedObserver( const dbus::ObjectPath& device_path, ShillPropertyChangedObserver* observer){ diff --git a/chromeos/dbus/shill_device_client_stub.h b/chromeos/dbus/shill_device_client_stub.h index 8038cc7..fe2ca8c 100644 --- a/chromeos/dbus/shill_device_client_stub.h +++ b/chromeos/dbus/shill_device_client_stub.h @@ -20,7 +20,8 @@ class ShillDeviceClientStub : public ShillDeviceClient, ShillDeviceClientStub(); virtual ~ShillDeviceClientStub(); - // ShillDeviceClient overrides. + // ShillDeviceClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( const dbus::ObjectPath& device_path, ShillPropertyChangedObserver* observer) OVERRIDE; diff --git a/chromeos/dbus/shill_device_client_unittest.cc b/chromeos/dbus/shill_device_client_unittest.cc index 4149b17..52e50a9 100644 --- a/chromeos/dbus/shill_device_client_unittest.cc +++ b/chromeos/dbus/shill_device_client_unittest.cc @@ -59,8 +59,8 @@ class ShillDeviceClientTest : public ShillClientUnittestBase { virtual void SetUp() { ShillClientUnittestBase::SetUp(); // Create a client with the mock bus. - client_.reset(ShillDeviceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, - mock_bus_.get())); + client_.reset(ShillDeviceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); + client_->Init(mock_bus_.get()); // Run the message loop to run the signal connection result callback. message_loop_.RunUntilIdle(); } diff --git a/chromeos/dbus/shill_ipconfig_client.cc b/chromeos/dbus/shill_ipconfig_client.cc index 2171590..6c6c750 100644 --- a/chromeos/dbus/shill_ipconfig_client.cc +++ b/chromeos/dbus/shill_ipconfig_client.cc @@ -24,7 +24,7 @@ namespace { // The ShillIPConfigClient implementation. class ShillIPConfigClientImpl : public ShillIPConfigClient { public: - explicit ShillIPConfigClientImpl(dbus::Bus* bus); + ShillIPConfigClientImpl(); //////////////////////////////////// // ShillIPConfigClient overrides. @@ -55,6 +55,11 @@ class ShillIPConfigClientImpl : public ShillIPConfigClient { virtual void Remove(const dbus::ObjectPath& ipconfig_path, const VoidDBusMethodCallback& callback) OVERRIDE; + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + bus_ = bus; + } + private: typedef std::map<std::string, ShillClientHelper*> HelperMap; @@ -80,8 +85,8 @@ class ShillIPConfigClientImpl : public ShillIPConfigClient { DISALLOW_COPY_AND_ASSIGN(ShillIPConfigClientImpl); }; -ShillIPConfigClientImpl::ShillIPConfigClientImpl(dbus::Bus* bus) - : bus_(bus), +ShillIPConfigClientImpl::ShillIPConfigClientImpl() + : bus_(NULL), helpers_deleter_(&helpers_) { } @@ -178,10 +183,9 @@ ShillIPConfigClient::~ShillIPConfigClient() {} // static ShillIPConfigClient* ShillIPConfigClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new ShillIPConfigClientImpl(bus); + return new ShillIPConfigClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new ShillIPConfigClientStub(); } diff --git a/chromeos/dbus/shill_ipconfig_client.h b/chromeos/dbus/shill_ipconfig_client.h index b311c56..df6db23 100644 --- a/chromeos/dbus/shill_ipconfig_client.h +++ b/chromeos/dbus/shill_ipconfig_client.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/shill_client_helper.h" @@ -22,7 +23,6 @@ class DictionaryValue; namespace dbus { -class Bus; class ObjectPath; } // namespace dbus @@ -34,7 +34,7 @@ class ShillPropertyChangedObserver; // ShillIPConfigClient is used to communicate with the Shill IPConfig // service. All methods should be called from the origin thread which // initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT ShillIPConfigClient { +class CHROMEOS_EXPORT ShillIPConfigClient : public DBusClient { public: typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; @@ -42,8 +42,7 @@ class CHROMEOS_EXPORT ShillIPConfigClient { // Factory function, creates a new instance which is owned by the caller. // For normal usage, access the singleton via DBusThreadManager::Get(). - static ShillIPConfigClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static ShillIPConfigClient* Create(DBusClientImplementationType type); // Adds a property changed |observer| for the ipconfig at |ipconfig_path|. virtual void AddPropertyChangedObserver( @@ -93,6 +92,8 @@ class CHROMEOS_EXPORT ShillIPConfigClient { const VoidDBusMethodCallback& callback) = 0; protected: + friend class ShillIPConfigClientTest; + // Create() should be used instead. ShillIPConfigClient(); diff --git a/chromeos/dbus/shill_ipconfig_client_stub.cc b/chromeos/dbus/shill_ipconfig_client_stub.cc index ccccfd4..a29d479 100644 --- a/chromeos/dbus/shill_ipconfig_client_stub.cc +++ b/chromeos/dbus/shill_ipconfig_client_stub.cc @@ -24,6 +24,9 @@ ShillIPConfigClientStub::ShillIPConfigClientStub() : weak_ptr_factory_(this) { ShillIPConfigClientStub::~ShillIPConfigClientStub() { } +void ShillIPConfigClientStub::Init(dbus::Bus* bus) { +} + void ShillIPConfigClientStub::AddPropertyChangedObserver( const dbus::ObjectPath& ipconfig_path, ShillPropertyChangedObserver* observer) { diff --git a/chromeos/dbus/shill_ipconfig_client_stub.h b/chromeos/dbus/shill_ipconfig_client_stub.h index bc77486..1122d77 100644 --- a/chromeos/dbus/shill_ipconfig_client_stub.h +++ b/chromeos/dbus/shill_ipconfig_client_stub.h @@ -18,7 +18,8 @@ class ShillIPConfigClientStub : public ShillIPConfigClient { ShillIPConfigClientStub(); virtual ~ShillIPConfigClientStub(); - // ShillIPConfigClient overrides: + // ShillIPConfigClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( const dbus::ObjectPath& ipconfig_path, ShillPropertyChangedObserver* observer) OVERRIDE; diff --git a/chromeos/dbus/shill_ipconfig_client_unittest.cc b/chromeos/dbus/shill_ipconfig_client_unittest.cc index 424935f..8ea537e 100644 --- a/chromeos/dbus/shill_ipconfig_client_unittest.cc +++ b/chromeos/dbus/shill_ipconfig_client_unittest.cc @@ -33,8 +33,8 @@ class ShillIPConfigClientTest : public ShillClientUnittestBase { virtual void SetUp() { ShillClientUnittestBase::SetUp(); // Create a client with the mock bus. - client_.reset(ShillIPConfigClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, - mock_bus_.get())); + client_.reset(ShillIPConfigClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); + client_->Init(mock_bus_.get()); // Run the message loop to run the signal connection result callback. message_loop_.RunUntilIdle(); } diff --git a/chromeos/dbus/shill_manager_client.cc b/chromeos/dbus/shill_manager_client.cc index fca8ba0..70f2095 100644 --- a/chromeos/dbus/shill_manager_client.cc +++ b/chromeos/dbus/shill_manager_client.cc @@ -24,37 +24,31 @@ namespace { // The ShillManagerClient implementation. class ShillManagerClientImpl : public ShillManagerClient { public: - explicit ShillManagerClientImpl(dbus::Bus* bus) - : proxy_(bus->GetObjectProxy( - flimflam::kFlimflamServiceName, - dbus::ObjectPath(flimflam::kFlimflamServicePath))), - helper_(bus, proxy_) { - helper_.MonitorPropertyChanged(flimflam::kFlimflamManagerInterface); - } + ShillManagerClientImpl() : proxy_(NULL) {} //////////////////////////////////// // ShillManagerClient overrides. virtual void AddPropertyChangedObserver( ShillPropertyChangedObserver* observer) OVERRIDE { - helper_.AddPropertyChangedObserver(observer); + helper_->AddPropertyChangedObserver(observer); } virtual void RemovePropertyChangedObserver( ShillPropertyChangedObserver* observer) OVERRIDE { - helper_.RemovePropertyChangedObserver(observer); + helper_->RemovePropertyChangedObserver(observer); } virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE { dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, flimflam::kGetPropertiesFunction); - helper_.CallDictionaryValueMethod(&method_call, callback); + helper_->CallDictionaryValueMethod(&method_call, callback); } virtual void GetNetworksForGeolocation( const DictionaryValueCallback& callback) OVERRIDE { dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, shill::kGetNetworksForGeolocation); - helper_.CallDictionaryValueMethod(&method_call, callback); + helper_->CallDictionaryValueMethod(&method_call, callback); } virtual void SetProperty(const std::string& name, @@ -66,7 +60,7 @@ class ShillManagerClientImpl : public ShillManagerClient { dbus::MessageWriter writer(&method_call); writer.AppendString(name); ShillClientHelper::AppendValueDataAsVariant(&writer, value); - helper_.CallVoidMethodWithErrorCallback(&method_call, + helper_->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -78,7 +72,7 @@ class ShillManagerClientImpl : public ShillManagerClient { flimflam::kRequestScanFunction); dbus::MessageWriter writer(&method_call); writer.AppendString(type); - helper_.CallVoidMethodWithErrorCallback(&method_call, + helper_->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -91,7 +85,7 @@ class ShillManagerClientImpl : public ShillManagerClient { flimflam::kEnableTechnologyFunction); dbus::MessageWriter writer(&method_call); writer.AppendString(type); - helper_.CallVoidMethodWithErrorCallback(&method_call, + helper_->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -104,7 +98,7 @@ class ShillManagerClientImpl : public ShillManagerClient { flimflam::kDisableTechnologyFunction); dbus::MessageWriter writer(&method_call); writer.AppendString(type); - helper_.CallVoidMethodWithErrorCallback(&method_call, + helper_->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -117,7 +111,7 @@ class ShillManagerClientImpl : public ShillManagerClient { flimflam::kConfigureServiceFunction); dbus::MessageWriter writer(&method_call); ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties); - helper_.CallObjectPathMethodWithErrorCallback(&method_call, + helper_->CallObjectPathMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -132,7 +126,7 @@ class ShillManagerClientImpl : public ShillManagerClient { dbus::MessageWriter writer(&method_call); writer.AppendObjectPath(dbus::ObjectPath(profile_path)); ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties); - helper_.CallObjectPathMethodWithErrorCallback(&method_call, + helper_->CallObjectPathMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -145,7 +139,7 @@ class ShillManagerClientImpl : public ShillManagerClient { flimflam::kGetServiceFunction); dbus::MessageWriter writer(&method_call); ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties); - helper_.CallObjectPathMethodWithErrorCallback(&method_call, + helper_->CallObjectPathMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -163,7 +157,7 @@ class ShillManagerClientImpl : public ShillManagerClient { writer.AppendString(properties.device_serial); writer.AppendString(properties.device_ssid); writer.AppendString(properties.device_bssid); - helper_.CallBooleanMethodWithErrorCallback( + helper_->CallBooleanMethodWithErrorCallback( &method_call, callback, error_callback); } @@ -183,7 +177,7 @@ class ShillManagerClientImpl : public ShillManagerClient { writer.AppendString(properties.device_ssid); writer.AppendString(properties.device_bssid); writer.AppendObjectPath(dbus::ObjectPath(service_path)); - helper_.CallStringMethodWithErrorCallback( + helper_->CallStringMethodWithErrorCallback( &method_call, callback, error_callback); } @@ -203,7 +197,7 @@ class ShillManagerClientImpl : public ShillManagerClient { writer.AppendString(properties.device_ssid); writer.AppendString(properties.device_bssid); writer.AppendString(data); - helper_.CallStringMethodWithErrorCallback( + helper_->CallStringMethodWithErrorCallback( &method_call, callback, error_callback); } @@ -212,7 +206,7 @@ class ShillManagerClientImpl : public ShillManagerClient { const ErrorCallback& error_callback) OVERRIDE { dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, shill::kConnectToBestServicesFunction); - helper_.CallVoidMethodWithErrorCallback(&method_call, + helper_->CallVoidMethodWithErrorCallback(&method_call, callback, error_callback); } @@ -221,9 +215,18 @@ class ShillManagerClientImpl : public ShillManagerClient { return NULL; } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + proxy_ = + bus->GetObjectProxy(flimflam::kFlimflamServiceName, + dbus::ObjectPath(flimflam::kFlimflamServicePath)); + helper_.reset(new ShillClientHelper(bus, proxy_)); + helper_->MonitorPropertyChanged(flimflam::kFlimflamManagerInterface); + } + private: dbus::ObjectProxy* proxy_; - ShillClientHelper helper_; + scoped_ptr<ShillClientHelper> helper_; DISALLOW_COPY_AND_ASSIGN(ShillManagerClientImpl); }; @@ -236,10 +239,9 @@ ShillManagerClient::~ShillManagerClient() {} // static ShillManagerClient* ShillManagerClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new ShillManagerClientImpl(bus); + return new ShillManagerClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new ShillManagerClientStub(); } diff --git a/chromeos/dbus/shill_manager_client.h b/chromeos/dbus/shill_manager_client.h index ce06815..c9307ca 100644 --- a/chromeos/dbus/shill_manager_client.h +++ b/chromeos/dbus/shill_manager_client.h @@ -9,13 +9,13 @@ #include "base/basictypes.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/shill_client_helper.h" namespace dbus { -class Bus; class ObjectPath; } // namespace dbus @@ -27,7 +27,7 @@ class ShillPropertyChangedObserver; // ShillManagerClient is used to communicate with the Shill Manager // service. All methods should be called from the origin thread which // initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT ShillManagerClient { +class CHROMEOS_EXPORT ShillManagerClient : public DBusClient { public: typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; @@ -109,8 +109,7 @@ class CHROMEOS_EXPORT ShillManagerClient { // Factory function, creates a new instance which is owned by the caller. // For normal usage, access the singleton via DBusThreadManager::Get(). - static ShillManagerClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static ShillManagerClient* Create(DBusClientImplementationType type); // Adds a property changed |observer|. virtual void AddPropertyChangedObserver( @@ -207,6 +206,8 @@ class CHROMEOS_EXPORT ShillManagerClient { virtual TestInterface* GetTestInterface() = 0; protected: + friend class ShillManagerClientTest; + // Create() should be used instead. ShillManagerClient(); diff --git a/chromeos/dbus/shill_manager_client_stub.cc b/chromeos/dbus/shill_manager_client_stub.cc index b601eb2..0614874 100644 --- a/chromeos/dbus/shill_manager_client_stub.cc +++ b/chromeos/dbus/shill_manager_client_stub.cc @@ -78,13 +78,16 @@ void AppendServicesForType( ShillManagerClientStub::ShillManagerClientStub() : weak_ptr_factory_(this) { - SetDefaultProperties(); } ShillManagerClientStub::~ShillManagerClientStub() {} // ShillManagerClient overrides. +void ShillManagerClientStub::Init(dbus::Bus* bus) { + SetDefaultProperties(); +} + void ShillManagerClientStub::AddPropertyChangedObserver( ShillPropertyChangedObserver* observer) { observer_list_.AddObserver(observer); diff --git a/chromeos/dbus/shill_manager_client_stub.h b/chromeos/dbus/shill_manager_client_stub.h index 678922f..f6edc15 100644 --- a/chromeos/dbus/shill_manager_client_stub.h +++ b/chromeos/dbus/shill_manager_client_stub.h @@ -22,7 +22,8 @@ class ShillManagerClientStub : public ShillManagerClient, ShillManagerClientStub(); virtual ~ShillManagerClientStub(); - // ShillManagerClient overrides. + // ShillManagerClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( ShillPropertyChangedObserver* observer) OVERRIDE; virtual void RemovePropertyChangedObserver( diff --git a/chromeos/dbus/shill_manager_client_unittest.cc b/chromeos/dbus/shill_manager_client_unittest.cc index e2feccf..107458d 100644 --- a/chromeos/dbus/shill_manager_client_unittest.cc +++ b/chromeos/dbus/shill_manager_client_unittest.cc @@ -60,8 +60,8 @@ class ShillManagerClientTest : public ShillClientUnittestBase { virtual void SetUp() { ShillClientUnittestBase::SetUp(); // Create a client with the mock bus. - client_.reset(ShillManagerClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, - mock_bus_.get())); + client_.reset(ShillManagerClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); + client_->Init(mock_bus_.get()); // Run the message loop to run the signal connection result callback. message_loop_.RunUntilIdle(); } diff --git a/chromeos/dbus/shill_profile_client.cc b/chromeos/dbus/shill_profile_client.cc index 696be7f..c0f675d 100644 --- a/chromeos/dbus/shill_profile_client.cc +++ b/chromeos/dbus/shill_profile_client.cc @@ -23,9 +23,8 @@ namespace { class ShillProfileClientImpl : public ShillProfileClient { public: - explicit ShillProfileClientImpl(dbus::Bus* bus); + ShillProfileClientImpl(); - // ShillProfileClient overrides. virtual void AddPropertyChangedObserver( const dbus::ObjectPath& profile_path, ShillPropertyChangedObserver* observer) OVERRIDE { @@ -37,6 +36,7 @@ class ShillProfileClientImpl : public ShillProfileClient { ShillPropertyChangedObserver* observer) OVERRIDE { GetHelper(profile_path)->RemovePropertyChangedObserver(observer); } + virtual void GetProperties( const dbus::ObjectPath& profile_path, const DictionaryValueCallbackWithoutStatus& callback, @@ -54,6 +54,11 @@ class ShillProfileClientImpl : public ShillProfileClient { return NULL; } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + bus_ = bus; + } + private: typedef std::map<std::string, ShillClientHelper*> HelperMap; @@ -67,8 +72,8 @@ class ShillProfileClientImpl : public ShillProfileClient { DISALLOW_COPY_AND_ASSIGN(ShillProfileClientImpl); }; -ShillProfileClientImpl::ShillProfileClientImpl(dbus::Bus* bus) - : bus_(bus), +ShillProfileClientImpl::ShillProfileClientImpl() + : bus_(NULL), helpers_deleter_(&helpers_) { } @@ -131,10 +136,9 @@ ShillProfileClient::~ShillProfileClient() {} // static ShillProfileClient* ShillProfileClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new ShillProfileClientImpl(bus); + return new ShillProfileClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new ShillProfileClientStub(); } diff --git a/chromeos/dbus/shill_profile_client.h b/chromeos/dbus/shill_profile_client.h index bf81afb..1529120 100644 --- a/chromeos/dbus/shill_profile_client.h +++ b/chromeos/dbus/shill_profile_client.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/shill_client_helper.h" @@ -22,7 +23,6 @@ class DictionaryValue; namespace dbus { -class Bus; class ObjectPath; } // namespace dbus @@ -34,7 +34,7 @@ class ShillPropertyChangedObserver; // ShillProfileClient is used to communicate with the Shill Profile // service. All methods should be called from the origin thread which // initializes the DBusThreadManager instance. -class CHROMEOS_EXPORT ShillProfileClient { +class CHROMEOS_EXPORT ShillProfileClient : public DBusClient { public: typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; typedef ShillClientHelper::DictionaryValueCallbackWithoutStatus @@ -75,8 +75,7 @@ class CHROMEOS_EXPORT ShillProfileClient { // Factory function, creates a new instance which is owned by the caller. // For normal usage, access the singleton via DBusThreadManager::Get(). - static ShillProfileClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static ShillProfileClient* Create(DBusClientImplementationType type); // Adds a property changed |observer| for the profile at |profile_path|. virtual void AddPropertyChangedObserver( @@ -113,6 +112,8 @@ class CHROMEOS_EXPORT ShillProfileClient { virtual TestInterface* GetTestInterface() = 0; protected: + friend class ShillProfileClientTest; + // Create() should be used instead. ShillProfileClient(); diff --git a/chromeos/dbus/shill_profile_client_stub.cc b/chromeos/dbus/shill_profile_client_stub.cc index ef3e74c..cfa97b7 100644 --- a/chromeos/dbus/shill_profile_client_stub.cc +++ b/chromeos/dbus/shill_profile_client_stub.cc @@ -40,13 +40,16 @@ void PassDictionary( const char ShillProfileClientStub::kSharedProfilePath[] = "/profile/default"; ShillProfileClientStub::ShillProfileClientStub() { - AddProfile(kSharedProfilePath, std::string()); } ShillProfileClientStub::~ShillProfileClientStub() { STLDeleteValues(&profiles_); } +void ShillProfileClientStub::Init(dbus::Bus* bus) { + AddProfile(kSharedProfilePath, std::string()); +} + void ShillProfileClientStub::AddPropertyChangedObserver( const dbus::ObjectPath& profile_path, ShillPropertyChangedObserver* observer) { diff --git a/chromeos/dbus/shill_profile_client_stub.h b/chromeos/dbus/shill_profile_client_stub.h index 98d8347..63a8912 100644 --- a/chromeos/dbus/shill_profile_client_stub.h +++ b/chromeos/dbus/shill_profile_client_stub.h @@ -21,7 +21,8 @@ class ShillProfileClientStub : public ShillProfileClient, ShillProfileClientStub(); virtual ~ShillProfileClientStub(); - // ShillProfileClient overrides. + // ShillProfileClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( const dbus::ObjectPath& profile_path, ShillPropertyChangedObserver* observer) OVERRIDE; diff --git a/chromeos/dbus/shill_profile_client_unittest.cc b/chromeos/dbus/shill_profile_client_unittest.cc index d95b62b..3352e2d 100644 --- a/chromeos/dbus/shill_profile_client_unittest.cc +++ b/chromeos/dbus/shill_profile_client_unittest.cc @@ -41,8 +41,8 @@ class ShillProfileClientTest : public ShillClientUnittestBase { virtual void SetUp() { ShillClientUnittestBase::SetUp(); // Create a client with the mock bus. - client_.reset(ShillProfileClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, - mock_bus_.get())); + client_.reset(ShillProfileClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); + client_->Init(mock_bus_.get()); // Run the message loop to run the signal connection result callback. message_loop_.RunUntilIdle(); } diff --git a/chromeos/dbus/shill_service_client.cc b/chromeos/dbus/shill_service_client.cc index 1c42142..f058117 100644 --- a/chromeos/dbus/shill_service_client.cc +++ b/chromeos/dbus/shill_service_client.cc @@ -52,13 +52,11 @@ void OnGetDictionaryError( // The ShillServiceClient implementation. class ShillServiceClientImpl : public ShillServiceClient { public: - explicit ShillServiceClientImpl(dbus::Bus* bus) - : bus_(bus), + explicit ShillServiceClientImpl() + : bus_(NULL), helpers_deleter_(&helpers_) { } - ///////////////////////////////////// - // ShillServiceClient overrides. virtual void AddPropertyChangedObserver( const dbus::ObjectPath& service_path, ShillPropertyChangedObserver* observer) OVERRIDE { @@ -219,6 +217,11 @@ class ShillServiceClientImpl : public ShillServiceClient { return NULL; } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + bus_ = bus; + } + private: typedef std::map<std::string, ShillClientHelper*> HelperMap; @@ -252,10 +255,9 @@ ShillServiceClient::~ShillServiceClient() {} // static ShillServiceClient* ShillServiceClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new ShillServiceClientImpl(bus); + return new ShillServiceClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new ShillServiceClientStub(); } diff --git a/chromeos/dbus/shill_service_client.h b/chromeos/dbus/shill_service_client.h index 0ee87a0..6280f2c 100644 --- a/chromeos/dbus/shill_service_client.h +++ b/chromeos/dbus/shill_service_client.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include "chromeos/dbus/shill_client_helper.h" @@ -22,7 +23,6 @@ class DictionaryValue; namespace dbus { -class Bus; class ObjectPath; } // namespace dbus @@ -33,7 +33,7 @@ namespace chromeos { // service. // All methods should be called from the origin thread which initializes the // DBusThreadManager instance. -class CHROMEOS_EXPORT ShillServiceClient { +class CHROMEOS_EXPORT ShillServiceClient : public DBusClient { public: typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; @@ -85,8 +85,7 @@ class CHROMEOS_EXPORT ShillServiceClient { // Factory function, creates a new instance which is owned by the caller. // For normal usage, access the singleton via DBusThreadManager::Get(). - static ShillServiceClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static ShillServiceClient* Create(DBusClientImplementationType type); // Adds a property changed |observer| to the service at |service_path|. virtual void AddPropertyChangedObserver( @@ -184,6 +183,8 @@ class CHROMEOS_EXPORT ShillServiceClient { virtual TestInterface* GetTestInterface() = 0; protected: + friend class ShillServiceClientTest; + // Create() should be used instead. ShillServiceClient(); diff --git a/chromeos/dbus/shill_service_client_stub.cc b/chromeos/dbus/shill_service_client_stub.cc index 19dc65e..d7c28da 100644 --- a/chromeos/dbus/shill_service_client_stub.cc +++ b/chromeos/dbus/shill_service_client_stub.cc @@ -66,6 +66,9 @@ bool ShillServiceClientStub::IsStubPortalledWifiEnabled( // ShillServiceClient overrides. +void ShillServiceClientStub::Init(dbus::Bus* bus) { +} + void ShillServiceClientStub::AddPropertyChangedObserver( const dbus::ObjectPath& service_path, ShillPropertyChangedObserver* observer) { diff --git a/chromeos/dbus/shill_service_client_stub.h b/chromeos/dbus/shill_service_client_stub.h index 824aa2a..4cd2964 100644 --- a/chromeos/dbus/shill_service_client_stub.h +++ b/chromeos/dbus/shill_service_client_stub.h @@ -29,7 +29,8 @@ class ShillServiceClientStub : public ShillServiceClient, CHROMEOS_EXPORT static bool IsStubPortalledWifiEnabled( const std::string& path); - // ShillServiceClient overrides. + // ShillServiceClient overrides + virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void AddPropertyChangedObserver( const dbus::ObjectPath& service_path, ShillPropertyChangedObserver* observer) OVERRIDE; diff --git a/chromeos/dbus/shill_service_client_unittest.cc b/chromeos/dbus/shill_service_client_unittest.cc index 3d5649f..4267a45 100644 --- a/chromeos/dbus/shill_service_client_unittest.cc +++ b/chromeos/dbus/shill_service_client_unittest.cc @@ -33,8 +33,8 @@ class ShillServiceClientTest : public ShillClientUnittestBase { virtual void SetUp() { ShillClientUnittestBase::SetUp(); // Create a client with the mock bus. - client_.reset(ShillServiceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION, - mock_bus_.get())); + client_.reset(ShillServiceClient::Create(REAL_DBUS_CLIENT_IMPLEMENTATION)); + client_->Init(mock_bus_.get()); // Run the message loop to run the signal connection result callback. message_loop_.RunUntilIdle(); } diff --git a/chromeos/dbus/sms_client.cc b/chromeos/dbus/sms_client.cc index ee6fb04..cd867a5 100644 --- a/chromeos/dbus/sms_client.cc +++ b/chromeos/dbus/sms_client.cc @@ -31,7 +31,8 @@ namespace { // DBusThreadManager instance. class SMSClientImpl : public SMSClient { public: - explicit SMSClientImpl(dbus::Bus* bus) : bus_(bus), weak_ptr_factory_(this) {} + SMSClientImpl() : bus_(NULL), weak_ptr_factory_(this) {} + virtual ~SMSClientImpl() {} // Calls GetAll method. |callback| is called after the method call succeeds. @@ -49,6 +50,11 @@ class SMSClientImpl : public SMSClient { callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + bus_ = bus; + } + private: // Handles responses of GetAll method calls. void OnGetAll(const GetAllCallback& callback, dbus::Response* response) { @@ -84,6 +90,8 @@ class SMSClientStubImpl : public SMSClient { SMSClientStubImpl() : weak_ptr_factory_(this) {} virtual ~SMSClientStubImpl() {} + virtual void Init(dbus::Bus* bus) OVERRIDE {} + virtual void GetAll(const std::string& service_name, const dbus::ObjectPath& object_path, const GetAllCallback& callback) OVERRIDE { @@ -131,10 +139,9 @@ SMSClient::~SMSClient() {} // static -SMSClient* SMSClient::Create(DBusClientImplementationType type, - dbus::Bus* bus) { +SMSClient* SMSClient::Create(DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { - return new SMSClientImpl(bus); + return new SMSClientImpl(); } DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new SMSClientStubImpl(); diff --git a/chromeos/dbus/sms_client.h b/chromeos/dbus/sms_client.h index f405bad..44cfa89 100644 --- a/chromeos/dbus/sms_client.h +++ b/chromeos/dbus/sms_client.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" namespace base { @@ -17,7 +18,6 @@ class DictionaryValue; } namespace dbus { -class Bus; class ObjectPath; } @@ -27,7 +27,7 @@ namespace chromeos { // org.freedesktop.ModemManager1.SMS service. All methods should be // called from the origin thread (UI thread) which initializes the // DBusThreadManager instance. -class CHROMEOS_EXPORT SMSClient { +class CHROMEOS_EXPORT SMSClient : public DBusClient { public: typedef base::Callback<void(const base::DictionaryValue& sms)> GetAllCallback; @@ -35,8 +35,7 @@ class CHROMEOS_EXPORT SMSClient { // Factory function, creates a new instance and returns ownership. // For normal usage, access the singleton via DBusThreadManager::Get(). - static SMSClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static SMSClient* Create(DBusClientImplementationType type); // Calls GetAll method. |callback| is called after the method call succeeds. virtual void GetAll(const std::string& service_name, diff --git a/chromeos/dbus/system_clock_client.cc b/chromeos/dbus/system_clock_client.cc index b9a094e..6775c64 100644 --- a/chromeos/dbus/system_clock_client.cc +++ b/chromeos/dbus/system_clock_client.cc @@ -17,27 +17,12 @@ namespace chromeos { // The SystemClockClient implementation used in production. class SystemClockClientImpl : public SystemClockClient { public: - explicit SystemClockClientImpl(dbus::Bus* bus) - : system_clock_proxy_(NULL), - weak_ptr_factory_(this) { - system_clock_proxy_ = bus->GetObjectProxy( - system_clock::kSystemClockServiceName, - dbus::ObjectPath(system_clock::kSystemClockServicePath)); - - // Monitor the D-Bus signal for TimeUpdated changes. - system_clock_proxy_->ConnectToSignal( - system_clock::kSystemClockInterface, - system_clock::kSystemClockUpdated, - base::Bind(&SystemClockClientImpl::TimeUpdatedReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&SystemClockClientImpl::TimeUpdatedConnected, - weak_ptr_factory_.GetWeakPtr())); - } + SystemClockClientImpl() + : system_clock_proxy_(NULL), weak_ptr_factory_(this) {} virtual ~SystemClockClientImpl() { } - // SystemClockClient overrides: virtual void AddObserver(Observer* observer) OVERRIDE { observers_.AddObserver(observer); } @@ -50,6 +35,22 @@ class SystemClockClientImpl : public SystemClockClient { return observers_.HasObserver(observer); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + system_clock_proxy_ = bus->GetObjectProxy( + system_clock::kSystemClockServiceName, + dbus::ObjectPath(system_clock::kSystemClockServicePath)); + + // Monitor the D-Bus signal for TimeUpdated changes. + system_clock_proxy_->ConnectToSignal( + system_clock::kSystemClockInterface, + system_clock::kSystemClockUpdated, + base::Bind(&SystemClockClientImpl::TimeUpdatedReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SystemClockClientImpl::TimeUpdatedConnected, + weak_ptr_factory_.GetWeakPtr())); + } + private: // Called when a TimeUpdated signal is received. void TimeUpdatedReceived(dbus::Signal* signal) { @@ -84,10 +85,9 @@ SystemClockClient::~SystemClockClient() { // static SystemClockClient* SystemClockClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { - return new SystemClockClientImpl(bus); + return new SystemClockClientImpl(); } DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new FakeSystemClockClient(); diff --git a/chromeos/dbus/system_clock_client.h b/chromeos/dbus/system_clock_client.h index 38158da..ece1e2d 100644 --- a/chromeos/dbus/system_clock_client.h +++ b/chromeos/dbus/system_clock_client.h @@ -7,16 +7,13 @@ #include "base/observer_list.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" -namespace dbus { -class Bus; -} // namespace - namespace chromeos { // SystemClockClient is used to communicate with the system clock. -class CHROMEOS_EXPORT SystemClockClient { +class CHROMEOS_EXPORT SystemClockClient : public DBusClient { public: // Interface for observing changes from the system clock. class Observer { @@ -36,8 +33,7 @@ class CHROMEOS_EXPORT SystemClockClient { virtual bool HasObserver(Observer* observer) = 0; // Creates the instance. - static SystemClockClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static SystemClockClient* Create(DBusClientImplementationType type); protected: // Create() should be used instead. diff --git a/chromeos/dbus/update_engine_client.cc b/chromeos/dbus/update_engine_client.cc index fca89aa..659d7a4 100644 --- a/chromeos/dbus/update_engine_client.cc +++ b/chromeos/dbus/update_engine_client.cc @@ -59,31 +59,8 @@ bool IsValidChannel(const std::string& channel) { // The UpdateEngineClient implementation used in production. class UpdateEngineClientImpl : public UpdateEngineClient { public: - explicit UpdateEngineClientImpl(dbus::Bus* bus) - : update_engine_proxy_(NULL), - last_status_(), - weak_ptr_factory_(this) { - update_engine_proxy_ = bus->GetObjectProxy( - update_engine::kUpdateEngineServiceName, - dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); - - // Monitor the D-Bus signal for brightness changes. Only the power - // manager knows the actual brightness level. We don't cache the - // brightness level in Chrome as it will make things less reliable. - update_engine_proxy_->ConnectToSignal( - update_engine::kUpdateEngineInterface, - update_engine::kStatusUpdate, - base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&UpdateEngineClientImpl::StatusUpdateConnected, - weak_ptr_factory_.GetWeakPtr())); - - // Get update engine status for the initial status. Update engine won't - // send StatusUpdate signal unless there is a status change. If chrome - // crashes after UPDATE_STATUS_UPDATED_NEED_REBOOT status is set, - // restarted chrome would not get this status. See crbug.com/154104. - GetUpdateEngineStatus(); - } + UpdateEngineClientImpl() + : update_engine_proxy_(NULL), last_status_(), weak_ptr_factory_(this) {} virtual ~UpdateEngineClientImpl() { } @@ -178,6 +155,30 @@ class UpdateEngineClientImpl : public UpdateEngineClient { callback)); } + protected: + virtual void Init(dbus::Bus* bus) OVERRIDE { + update_engine_proxy_ = bus->GetObjectProxy( + update_engine::kUpdateEngineServiceName, + dbus::ObjectPath(update_engine::kUpdateEngineServicePath)); + + // Monitor the D-Bus signal for brightness changes. Only the power + // manager knows the actual brightness level. We don't cache the + // brightness level in Chrome as it will make things less reliable. + update_engine_proxy_->ConnectToSignal( + update_engine::kUpdateEngineInterface, + update_engine::kStatusUpdate, + base::Bind(&UpdateEngineClientImpl::StatusUpdateReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&UpdateEngineClientImpl::StatusUpdateConnected, + weak_ptr_factory_.GetWeakPtr())); + + // Get update engine status for the initial status. Update engine won't + // send StatusUpdate signal unless there is a status change. If chrome + // crashes after UPDATE_STATUS_UPDATED_NEED_REBOOT status is set, + // restarted chrome would not get this status. See crbug.com/154104. + GetUpdateEngineStatus(); + } + private: void GetUpdateEngineStatus() { dbus::MethodCall method_call( @@ -320,6 +321,7 @@ class UpdateEngineClientImpl : public UpdateEngineClient { // which does nothing. class UpdateEngineClientStubImpl : public UpdateEngineClient { // UpdateEngineClient implementation: + virtual void Init(dbus::Bus* bus) OVERRIDE {} virtual void AddObserver(Observer* observer) OVERRIDE {} virtual void RemoveObserver(Observer* observer) OVERRIDE {} virtual bool HasObserver(Observer* observer) OVERRIDE { return false; } @@ -358,10 +360,9 @@ UpdateEngineClient::EmptyUpdateCheckCallback() { // static UpdateEngineClient* UpdateEngineClient::Create( - DBusClientImplementationType type, - dbus::Bus* bus) { + DBusClientImplementationType type) { if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) - return new UpdateEngineClientImpl(bus); + return new UpdateEngineClientImpl(); DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); return new UpdateEngineClientStubImpl(); } diff --git a/chromeos/dbus/update_engine_client.h b/chromeos/dbus/update_engine_client.h index 00120cb..2923c6b 100644 --- a/chromeos/dbus/update_engine_client.h +++ b/chromeos/dbus/update_engine_client.h @@ -8,18 +8,15 @@ #include "base/callback.h" #include "base/observer_list.h" #include "chromeos/chromeos_export.h" +#include "chromeos/dbus/dbus_client.h" #include "chromeos/dbus/dbus_client_implementation_type.h" #include <string> -namespace dbus { -class Bus; -} - namespace chromeos { // UpdateEngineClient is used to communicate with the update engine. -class CHROMEOS_EXPORT UpdateEngineClient { +class CHROMEOS_EXPORT UpdateEngineClient : public DBusClient { public: // Edges for state machine // IDLE->CHECKING_FOR_UPDATE @@ -123,8 +120,7 @@ class CHROMEOS_EXPORT UpdateEngineClient { static UpdateCheckCallback EmptyUpdateCheckCallback(); // Creates the instance. - static UpdateEngineClient* Create(DBusClientImplementationType type, - dbus::Bus* bus); + static UpdateEngineClient* Create(DBusClientImplementationType type); protected: // Create() should be used instead. |