diff options
47 files changed, 470 insertions, 333 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc index 2679274..65c53f5 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc +++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc @@ -49,40 +49,40 @@ class BluetoothAdapterImpl : public BluetoothAdapter, virtual void StartDiscovery() { VLOG(1) << id_ << ": StartDiscovery"; DCHECK(bluetooth_adapter_client_); - bluetooth_adapter_client_->StartDiscovery(id_); + bluetooth_adapter_client_->StartDiscovery(dbus::ObjectPath(id_)); } virtual void StopDiscovery() { VLOG(1) << id_ << ": StopDiscovery"; DCHECK(bluetooth_adapter_client_); - bluetooth_adapter_client_->StopDiscovery(id_); + bluetooth_adapter_client_->StopDiscovery(dbus::ObjectPath(id_)); } // BluetoothAdapterClient::Observer override. - virtual void DiscoveringPropertyChanged(const std::string& object_path, + virtual void DiscoveringPropertyChanged(const dbus::ObjectPath& object_path, bool discovering) { - VLOG(1) << id_ << ": object_path = " << object_path << ", Discovering = " - << discovering; - if (object_path != id_) { + VLOG(1) << id_ << ": object_path = " << object_path.value() + << ", Discovering = " << discovering; + if (object_path.value() != id_) { return; } if (discovering) { FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, - DiscoveryStarted(object_path)); + DiscoveryStarted(object_path.value())); } else { FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, - DiscoveryEnded(object_path)); + DiscoveryEnded(object_path.value())); } } // BluetoothAdapterClient::Observer override. - virtual void DeviceFound(const std::string& object_path, + virtual void DeviceFound(const dbus::ObjectPath& object_path, const std::string& address, const base::DictionaryValue& device_properties) { - VLOG(1) << id_ << ": object_path = " << object_path << ", Device found: " - << address << " (with " << device_properties.size() - << " properties)"; - if (object_path != id_) { + VLOG(1) << id_ << ": object_path = " << object_path.value() + << ", Device found: " << address << " (with " + << device_properties.size() << " properties)"; + if (object_path.value() != id_) { return; } // TODO(vlaviano): later, we will want to persist the device. @@ -90,18 +90,18 @@ class BluetoothAdapterImpl : public BluetoothAdapter, BluetoothDevice::Create(device_properties)); if (device.get() != NULL) { FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, - DeviceFound(object_path, device.get())); + DeviceFound(object_path.value(), device.get())); } else { LOG(WARNING) << "Could not create BluetoothDevice from properties."; } } // BluetoothAdapterClient::Observer override. - virtual void DeviceDisappeared(const std::string& object_path, + virtual void DeviceDisappeared(const dbus::ObjectPath& object_path, const std::string& address) { - VLOG(1) << id_ << ": object_path = " << object_path + VLOG(1) << id_ << ": object_path = " << object_path.value() << ", Device disappeared: " << address; - if (object_path != id_) { + if (object_path.value() != id_) { return; } // For now, we don't propagate this event to our observers. diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_manager.cc b/chrome/browser/chromeos/bluetooth/bluetooth_manager.cc index 3161885..ef362f0 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_manager.cc +++ b/chrome/browser/chromeos/bluetooth/bluetooth_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,6 +10,7 @@ #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" +#include "dbus/object_path.h" namespace chromeos { @@ -50,9 +51,10 @@ class BluetoothManagerImpl : public BluetoothManager, } // BluetoothManagerClient::Observer override. - virtual void AdapterRemoved(const std::string& adapter) { - VLOG(1) << "AdapterRemoved: " << adapter; - if (default_adapter_.get() == NULL || default_adapter_->Id() != adapter) { + virtual void AdapterRemoved(const dbus::ObjectPath& adapter) { + VLOG(1) << "AdapterRemoved: " << adapter.value(); + if (default_adapter_.get() == NULL + || default_adapter_->Id() != adapter.value()) { return; } // The default adapter was removed. @@ -62,8 +64,8 @@ class BluetoothManagerImpl : public BluetoothManager, } // BluetoothManagerClient::Observer override. - virtual void DefaultAdapterChanged(const std::string& adapter) { - VLOG(1) << "DefaultAdapterChanged: " << adapter; + virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter) { + VLOG(1) << "DefaultAdapterChanged: " << adapter.value(); OnNewDefaultAdapter(adapter); } @@ -73,12 +75,13 @@ class BluetoothManagerImpl : public BluetoothManager, } // We have updated info about the default adapter. - void OnNewDefaultAdapter(const std::string& adapter) { - VLOG(1) << "OnNewDefaultAdapter: " << adapter; - if (default_adapter_.get() != NULL && default_adapter_->Id() == adapter) { + void OnNewDefaultAdapter(const dbus::ObjectPath& adapter) { + VLOG(1) << "OnNewDefaultAdapter: " << adapter.value(); + if (default_adapter_.get() != NULL + && default_adapter_->Id() == adapter.value()) { return; } - default_adapter_.reset(BluetoothAdapter::Create(adapter)); + default_adapter_.reset(BluetoothAdapter::Create(adapter.value())); DCHECK(default_adapter_.get()); FOR_EACH_OBSERVER(BluetoothManager::Observer, observers_, DefaultAdapterChanged(default_adapter_.get())); @@ -86,12 +89,12 @@ class BluetoothManagerImpl : public BluetoothManager, // Called by bluetooth_manager_client when our DefaultAdapter request is // complete - void OnDefaultAdapter(const std::string& adapter, bool success) { + void OnDefaultAdapter(const dbus::ObjectPath& adapter, bool success) { if (!success) { LOG(ERROR) << "OnDefaultAdapter: failed."; return; } - VLOG(1) << "OnDefaultAdapter: " << adapter; + VLOG(1) << "OnDefaultAdapter: " << adapter.value(); OnNewDefaultAdapter(adapter); } diff --git a/chrome/browser/chromeos/dbus/bluetooth_adapter_client.cc b/chrome/browser/chromeos/dbus/bluetooth_adapter_client.cc index 54b772d..bb62d53 100644 --- a/chrome/browser/chromeos/dbus/bluetooth_adapter_client.cc +++ b/chrome/browser/chromeos/dbus/bluetooth_adapter_client.cc @@ -13,6 +13,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -142,11 +143,11 @@ bool PopArrayOfDictEntries(dbus::MessageReader* reader, break; } case dbus::Message::OBJECT_PATH: { - std::string value; + dbus::ObjectPath value; if (!variant_reader.PopObjectPath(&value)) { return false; } - dictionary->SetString(key, value); + dictionary->SetString(key, value.value()); break; } case dbus::Message::ARRAY: { @@ -208,8 +209,8 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient, } // BluetoothAdapterClient override. - virtual void StartDiscovery(const std::string& object_path) { - VLOG(1) << "StartDiscovery: " << object_path; + virtual void StartDiscovery(const dbus::ObjectPath& object_path) { + VLOG(1) << "StartDiscovery: " << object_path.value(); dbus::MethodCall method_call( bluetooth_adapter::kBluetoothAdapterInterface, @@ -225,8 +226,8 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient, } // BluetoothAdapterClient override. - virtual void StopDiscovery(const std::string& object_path) { - VLOG(1) << "StopDiscovery: " << object_path; + virtual void StopDiscovery(const dbus::ObjectPath& object_path) { + VLOG(1) << "StopDiscovery: " << object_path.value(); dbus::MethodCall method_call( bluetooth_adapter::kBluetoothAdapterInterface, @@ -243,21 +244,22 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient, private: // BluetoothManagerClient::Observer override. - virtual void AdapterAdded(const std::string& object_path) OVERRIDE { - VLOG(1) << "AdapterAdded: " << object_path; + virtual void AdapterAdded(const dbus::ObjectPath& object_path) OVERRIDE { + VLOG(1) << "AdapterAdded: " << object_path.value(); } // BluetoothManagerClient::Observer override. - virtual void AdapterRemoved(const std::string& object_path) OVERRIDE { - VLOG(1) << "AdapterRemoved: " << object_path; + virtual void AdapterRemoved(const dbus::ObjectPath& object_path) OVERRIDE { + VLOG(1) << "AdapterRemoved: " << object_path.value(); RemoveObjectProxyForPath(object_path); } // Ensures that we have a dbus object proxy for an adapter with dbus // object path |object_path|, and if not, creates it and stores it in // our |proxy_map_| map. - dbus::ObjectProxy* GetObjectProxyForPath(const std::string& object_path) { - VLOG(1) << "GetObjectProxyForPath: " << object_path; + dbus::ObjectProxy* GetObjectProxyForPath( + const dbus::ObjectPath& object_path) { + VLOG(1) << "GetObjectProxyForPath: " << object_path.value(); ProxyMap::iterator it = proxy_map_.find(object_path); if (it != proxy_map_.end()) @@ -314,126 +316,129 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient, // Removes the dbus object proxy for the adapter with dbus object path // |object_path| from our |proxy_map_| map. - void RemoveObjectProxyForPath(const std::string& object_path) { - VLOG(1) << "RemoveObjectProxyForPath: " << object_path; + void RemoveObjectProxyForPath(const dbus::ObjectPath& object_path) { + VLOG(1) << "RemoveObjectProxyForPath: " << object_path.value(); proxy_map_.erase(object_path); } // Called by dbus:: when a DeviceCreated signal is received. - void DeviceCreatedReceived(const std::string& object_path, + void DeviceCreatedReceived(const dbus::ObjectPath& object_path, dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); - std::string device_path; + dbus::ObjectPath device_path; if (!reader.PopObjectPath(&device_path)) { - LOG(ERROR) << object_path - << ": DeviceCreated signal has incorrect parameters: " - << signal->ToString(); + LOG(ERROR) << object_path.value() + << ": DeviceCreated signal has incorrect parameters: " + << signal->ToString(); return; } - VLOG(1) << object_path << ": Device created: " << device_path; + VLOG(1) << object_path.value() << ": Device created: " + << device_path.value(); FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, DeviceCreated(object_path, device_path)); } // Called by dbus:: when the DeviceCreated signal is initially connected. - void DeviceCreatedConnected(const std::string& object_path, + void DeviceCreatedConnected(const dbus::ObjectPath& object_path, const std::string& interface_name, const std::string& signal_name, bool success) { - LOG_IF(WARNING, !success) << object_path - << ": Failed to connect to DeviceCreated signal."; + LOG_IF(WARNING, !success) << object_path.value() + << ": Failed to connect to DeviceCreated signal."; } // Called by dbus:: when a DeviceRemoved signal is received. - void DeviceRemovedReceived(const std::string& object_path, + void DeviceRemovedReceived(const dbus::ObjectPath& object_path, dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); - std::string device_path; + dbus::ObjectPath device_path; if (!reader.PopObjectPath(&device_path)) { - LOG(ERROR) << object_path - << ": DeviceRemoved signal has incorrect parameters: " - << signal->ToString(); + LOG(ERROR) << object_path.value() + << ": DeviceRemoved signal has incorrect parameters: " + << signal->ToString(); return; } - VLOG(1) << object_path << ": Device removed: " << device_path; + VLOG(1) << object_path.value() << ": Device removed: " + << device_path.value(); FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, DeviceRemoved(object_path, device_path)); } // Called by dbus:: when the DeviceRemoved signal is initially connected. - void DeviceRemovedConnected(const std::string& object_path, + void DeviceRemovedConnected(const dbus::ObjectPath& object_path, const std::string& interface_name, const std::string& signal_name, bool success) { - LOG_IF(WARNING, !success) << object_path - << ": Failed to connect to DeviceRemoved signal."; + LOG_IF(WARNING, !success) << object_path.value() + << ": Failed to connect to DeviceRemoved signal."; } // Called by dbus:: when a PropertyChanged signal is received. - void PropertyChangedReceived(const std::string& object_path, + void PropertyChangedReceived(const dbus::ObjectPath& object_path, dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); std::string property_name; if (!reader.PopString(&property_name)) { - LOG(ERROR) << object_path - << ": PropertyChanged signal has incorrect parameters: " - << signal->ToString(); + LOG(ERROR) << object_path.value() + << ": PropertyChanged signal has incorrect parameters: " + << signal->ToString(); return; } if (property_name != bluetooth_adapter::kDiscoveringProperty) { - VLOG(1) << object_path << ": PropertyChanged: " << property_name; + VLOG(1) << object_path.value() << ": PropertyChanged: " << property_name; // We don't care. return; } bool discovering = false; if (!reader.PopVariantOfBool(&discovering)) { - LOG(ERROR) << object_path - << ": PropertyChanged signal has incorrect parameters: " - << signal->ToString(); + LOG(ERROR) << object_path.value() + << ": PropertyChanged signal has incorrect parameters: " + << signal->ToString(); return; } - VLOG(1) << object_path << ": PropertyChanged: Discovering = " - << discovering; + VLOG(1) << object_path.value() << ": PropertyChanged: Discovering = " + << discovering; FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, DiscoveringPropertyChanged(object_path, discovering)); } // Called by dbus:: when the PropertyChanged signal is initially connected. - void PropertyChangedConnected(const std::string& object_path, + void PropertyChangedConnected(const dbus::ObjectPath& object_path, const std::string& interface_name, const std::string& signal_name, bool success) { - LOG_IF(WARNING, !success) << object_path + LOG_IF(WARNING, !success) + << object_path.value() << ": Failed to connect to PropertyChanged signal."; } // Called by dbus:: when a DeviceFound signal is received. - void DeviceFoundReceived(const std::string& object_path, + void DeviceFoundReceived(const dbus::ObjectPath& object_path, dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); std::string address; if (!reader.PopString(&address)) { - LOG(ERROR) << object_path - << ": DeviceFound signal has incorrect parameters: " - << signal->ToString(); + LOG(ERROR) << object_path.value() + << ": DeviceFound signal has incorrect parameters: " + << signal->ToString(); return; } - VLOG(1) << object_path << ": Device found: " << address; + VLOG(1) << object_path.value() << ": Device found: " << address; DictionaryValue device_properties; if (!PopArrayOfDictEntries(&reader, signal, &device_properties)) { - LOG(ERROR) << object_path - << ": DeviceFound signal has incorrect parameters: " - << signal->ToString(); + LOG(ERROR) << object_path.value() + << ": DeviceFound signal has incorrect parameters: " + << signal->ToString(); return; } @@ -442,52 +447,55 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient, } // Called by dbus:: when the DeviceFound signal is initially connected. - void DeviceFoundConnected(const std::string& object_path, + void DeviceFoundConnected(const dbus::ObjectPath& object_path, const std::string& interface_name, const std::string& signal_name, bool success) { - LOG_IF(WARNING, !success) << object_path - << ": Failed to connect to DeviceFound signal."; + LOG_IF(WARNING, !success) << object_path.value() + << ": Failed to connect to DeviceFound signal."; } // Called by dbus:: when a DeviceDisappeared signal is received. - void DeviceDisappearedReceived(const std::string& object_path, + void DeviceDisappearedReceived(const dbus::ObjectPath& object_path, dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); std::string address; if (!reader.PopString(&address)) { - LOG(ERROR) << object_path - << ": DeviceDisappeared signal has incorrect parameters: " - << signal->ToString(); + LOG(ERROR) << object_path.value() + << ": DeviceDisappeared signal has incorrect parameters: " + << signal->ToString(); return; } - VLOG(1) << object_path << ": Device disappeared: " << address; + VLOG(1) << object_path.value() << ": Device disappeared: " << address; FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, DeviceDisappeared(object_path, address)); } // Called by dbus:: when the DeviceDisappeared signal is initially connected. - void DeviceDisappearedConnected(const std::string& object_path, + void DeviceDisappearedConnected(const dbus::ObjectPath& object_path, const std::string& interface_name, const std::string& signal_name, bool success) { - LOG_IF(WARNING, !success) << object_path + LOG_IF(WARNING, !success) + << object_path.value() << ": Failed to connect to DeviceDisappeared signal."; } // Called when a response for StartDiscovery() is received. - void OnStartDiscovery(const std::string& object_path, + void OnStartDiscovery(const dbus::ObjectPath& object_path, dbus::Response* response) { - VLOG(1) << "OnStartDiscovery: " << object_path; - LOG_IF(WARNING, !response) << object_path << ": OnStartDiscovery: failed."; + VLOG(1) << "OnStartDiscovery: " << object_path.value(); + LOG_IF(WARNING, !response) << object_path.value() + << ": OnStartDiscovery: failed."; } // Called when a response for StopDiscovery() is received. - void OnStopDiscovery(const std::string& object_path, + void OnStopDiscovery(const dbus::ObjectPath& object_path, dbus::Response* response) { - VLOG(1) << "OnStopDiscovery: " << object_path; - LOG_IF(WARNING, !response) << object_path << ": OnStopDiscovery: failed."; + VLOG(1) << "OnStopDiscovery: " << object_path.value(); + LOG_IF(WARNING, !response) << object_path.value() + << ": OnStopDiscovery: failed."; } // Weak pointer factory for generating 'this' pointers that might live longer @@ -497,7 +505,7 @@ class BluetoothAdapterClientImpl: public BluetoothAdapterClient, dbus::Bus* bus_; // We maintain a collection of dbus object proxies, one for each adapter. - typedef std::map<const std::string, dbus::ObjectProxy*> ProxyMap; + typedef std::map<const dbus::ObjectPath, dbus::ObjectProxy*> ProxyMap; ProxyMap proxy_map_; // List of observers interested in event notifications from us. @@ -521,13 +529,13 @@ class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient { } // BluetoothAdapterClient override. - virtual void StartDiscovery(const std::string& object_path) { - VLOG(1) << "StartDiscovery: " << object_path; + virtual void StartDiscovery(const dbus::ObjectPath& object_path) { + VLOG(1) << "StartDiscovery: " << object_path.value(); } // BluetoothAdapterClient override. - virtual void StopDiscovery(const std::string& object_path) { - VLOG(1) << "StopDiscovery: " << object_path; + virtual void StopDiscovery(const dbus::ObjectPath& object_path) { + VLOG(1) << "StopDiscovery: " << object_path.value(); } }; diff --git a/chrome/browser/chromeos/dbus/bluetooth_adapter_client.h b/chrome/browser/chromeos/dbus/bluetooth_adapter_client.h index e740100..2e7e0f0 100644 --- a/chrome/browser/chromeos/dbus/bluetooth_adapter_client.h +++ b/chrome/browser/chromeos/dbus/bluetooth_adapter_client.h @@ -11,6 +11,7 @@ #include "base/callback.h" #include "base/observer_list.h" #include "base/values.h" +#include "dbus/object_path.h" namespace dbus { class Bus; @@ -30,25 +31,25 @@ class BluetoothAdapterClient { virtual ~Observer() {} // Called when a new known device has been created. - virtual void DeviceCreated(const std::string& object_path, - const std::string& device_path) {} + virtual void DeviceCreated(const dbus::ObjectPath& object_path, + const dbus::ObjectPath& device_path) {} // Called when a previously known device is removed. - virtual void DeviceRemoved(const std::string& object_path, - const std::string& device_path) {} + virtual void DeviceRemoved(const dbus::ObjectPath& object_path, + const dbus::ObjectPath& device_path) {} // Called when the adapter's Discovering property changes. - virtual void DiscoveringPropertyChanged(const std::string& object_path, + virtual void DiscoveringPropertyChanged(const dbus::ObjectPath& object_path, bool discovering) {} // Called when a new remote device has been discovered. // |device_properties| should be copied if needed. - virtual void DeviceFound(const std::string& object_path, + virtual void DeviceFound(const dbus::ObjectPath& object_path, const std::string& address, const DictionaryValue& device_properties) {} // Called when a previously discovered device is no longer visible. - virtual void DeviceDisappeared(const std::string& object_path, + virtual void DeviceDisappeared(const dbus::ObjectPath& object_path, const std::string& address) {} }; @@ -60,11 +61,11 @@ class BluetoothAdapterClient { virtual void RemoveObserver(Observer* observer) = 0; // Starts a device discovery on the adapter with object path |object_path|. - virtual void StartDiscovery(const std::string& object_path) = 0; + virtual void StartDiscovery(const dbus::ObjectPath& object_path) = 0; // Cancels any previous device discovery on the adapter with object path // |object_path|. - virtual void StopDiscovery(const std::string& object_path) = 0; + virtual void StopDiscovery(const dbus::ObjectPath& object_path) = 0; // Creates the instance. static BluetoothAdapterClient* Create(dbus::Bus* bus, diff --git a/chrome/browser/chromeos/dbus/bluetooth_device_client.cc b/chrome/browser/chromeos/dbus/bluetooth_device_client.cc index 6069681..78121fc 100644 --- a/chrome/browser/chromeos/dbus/bluetooth_device_client.cc +++ b/chrome/browser/chromeos/dbus/bluetooth_device_client.cc @@ -13,6 +13,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -53,23 +54,24 @@ class BluetoothDeviceClientImpl: public BluetoothDeviceClient, private: // BluetoothAdapterClient::Observer override. - virtual void DeviceCreated(const std::string& adapter_path, - const std::string& object_path) OVERRIDE { - VLOG(1) << "DeviceCreated: " << object_path; + virtual void DeviceCreated(const dbus::ObjectPath& adapter_path, + const dbus::ObjectPath& object_path) OVERRIDE { + VLOG(1) << "DeviceCreated: " << object_path.value(); } // BluetoothAdapterClient::Observer override. - virtual void DeviceRemoved(const std::string& adapter_path, - const std::string& object_path) OVERRIDE { - VLOG(1) << "DeviceRemoved: " << object_path; + virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path, + const dbus::ObjectPath& object_path) OVERRIDE { + VLOG(1) << "DeviceRemoved: " << object_path.value(); RemoveObjectProxyForPath(object_path); } // Ensures that we have a dbus object proxy for a device with dbus // object path |object_path|, and if not, creates it stores it in // our |proxy_map_| map. - dbus::ObjectProxy* GetObjectProxyForPath(const std::string& object_path) { - VLOG(1) << "GetObjectProxyForPath: " << object_path; + dbus::ObjectProxy* GetObjectProxyForPath( + const dbus::ObjectPath& object_path) { + VLOG(1) << "GetObjectProxyForPath: " << object_path.value(); ProxyMap::iterator it = proxy_map_.find(object_path); if (it != proxy_map_.end()) @@ -86,8 +88,8 @@ class BluetoothDeviceClientImpl: public BluetoothDeviceClient, // Removes the dbus object proxy for the device with dbus object path // |object_path| from our |proxy_map_| map. - void RemoveObjectProxyForPath(const std::string& object_path) { - VLOG(1) << "RemoveObjectProxyForPath: " << object_path; + void RemoveObjectProxyForPath(const dbus::ObjectPath& object_path) { + VLOG(1) << "RemoveObjectProxyForPath: " << object_path.value(); proxy_map_.erase(object_path); } @@ -98,7 +100,7 @@ class BluetoothDeviceClientImpl: public BluetoothDeviceClient, dbus::Bus* bus_; // We maintain a collection of dbus object proxies, one for each device. - typedef std::map<const std::string, dbus::ObjectProxy*> ProxyMap; + typedef std::map<const dbus::ObjectPath, dbus::ObjectProxy*> ProxyMap; ProxyMap proxy_map_; // List of observers interested in event notifications from us. diff --git a/chrome/browser/chromeos/dbus/bluetooth_manager_client.cc b/chrome/browser/chromeos/dbus/bluetooth_manager_client.cc index 12f1e8a..f65fa84 100644 --- a/chrome/browser/chromeos/dbus/bluetooth_manager_client.cc +++ b/chrome/browser/chromeos/dbus/bluetooth_manager_client.cc @@ -9,6 +9,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -26,7 +27,7 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient { bluetooth_manager_proxy_ = bus->GetObjectProxy( bluetooth_manager::kBluetoothManagerServiceName, - bluetooth_manager::kBluetoothManagerServicePath); + dbus::ObjectPath(bluetooth_manager::kBluetoothManagerServicePath)); bluetooth_manager_proxy_->ConnectToSignal( bluetooth_manager::kBluetoothManagerInterface, @@ -91,13 +92,13 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient { void AdapterAddedReceived(dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); - std::string object_path; + dbus::ObjectPath object_path; if (!reader.PopObjectPath(&object_path)) { LOG(ERROR) << "AdapterAdded signal has incorrect parameters: " - << signal->ToString(); + << signal->ToString(); return; } - VLOG(1) << "Adapter added: " << object_path; + VLOG(1) << "Adapter added: " << object_path.value(); FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(object_path)); } @@ -112,13 +113,13 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient { void AdapterRemovedReceived(dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); - std::string object_path; + dbus::ObjectPath object_path; if (!reader.PopObjectPath(&object_path)) { LOG(ERROR) << "AdapterRemoved signal has incorrect parameters: " - << signal->ToString(); + << signal->ToString(); return; } - VLOG(1) << "Adapter removed: " << object_path; + VLOG(1) << "Adapter removed: " << object_path.value(); FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(object_path)); } @@ -133,14 +134,14 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient { void DefaultAdapterChangedReceived(dbus::Signal* signal) { DCHECK(signal); dbus::MessageReader reader(signal); - std::string adapter; - if (!reader.PopObjectPath(&adapter)) { + dbus::ObjectPath object_path; + if (!reader.PopObjectPath(&object_path)) { LOG(ERROR) << "DefaultAdapterChanged signal has incorrect parameters: " - << signal->ToString(); + << signal->ToString(); return; } - VLOG(1) << "Default adapter changed: " << adapter; - FOR_EACH_OBSERVER(Observer, observers_, DefaultAdapterChanged(adapter)); + VLOG(1) << "Default adapter changed: " << object_path.value(); + FOR_EACH_OBSERVER(Observer, observers_, DefaultAdapterChanged(object_path)); } // Called by dbus:: when the DefaultAdapterChanged signal is initially @@ -157,15 +158,15 @@ class BluetoothManagerClientImpl : public BluetoothManagerClient { dbus::Response* response) { // Parse response. bool success = false; - std::string adapter; + dbus::ObjectPath adapter; if (response != NULL) { dbus::MessageReader reader(response); if (!reader.PopObjectPath(&adapter)) { LOG(ERROR) << "DefaultAdapter response has incorrect parameters: " - << response->ToString(); + << response->ToString(); } else { success = true; - LOG(INFO) << "OnDefaultAdapter: " << adapter; + LOG(INFO) << "OnDefaultAdapter: " << adapter.value(); } } else { LOG(ERROR) << "Failed to get default adapter."; diff --git a/chrome/browser/chromeos/dbus/bluetooth_manager_client.h b/chrome/browser/chromeos/dbus/bluetooth_manager_client.h index 394f9c9..a74f925 100644 --- a/chrome/browser/chromeos/dbus/bluetooth_manager_client.h +++ b/chrome/browser/chromeos/dbus/bluetooth_manager_client.h @@ -10,6 +10,7 @@ #include "base/callback.h" #include "base/observer_list.h" +#include "dbus/object_path.h" namespace dbus { class Bus; @@ -28,16 +29,16 @@ class BluetoothManagerClient { // Called when a local bluetooth adapter is added. // |object_path| is the dbus object path of the adapter. - virtual void AdapterAdded(const std::string& object_path) {} + virtual void AdapterAdded(const dbus::ObjectPath& object_path) {} // Called when a local bluetooth adapter is removed. // |object_path| is the dbus object path of the adapter. - virtual void AdapterRemoved(const std::string& object_path) {} + virtual void AdapterRemoved(const dbus::ObjectPath& object_path) {} // Called when the default local bluetooth adapter changes. - // |adapter| is the dbus object path of the new default adapter. + // |object_path| is the dbus object path of the new default adapter. // Not called if all adapters are removed. - virtual void DefaultAdapterChanged(const std::string& adapter) {} + virtual void DefaultAdapterChanged(const dbus::ObjectPath& object_path) {} }; virtual ~BluetoothManagerClient(); @@ -47,9 +48,9 @@ class BluetoothManagerClient { virtual void RemoveObserver(Observer* observer) = 0; // The DefaultAdapterCallback receives two arguments: - // std::string adapter - the unique identifier of the default adapter + // dbus::ObjectPath object_path - the path of the new default adapter // bool success - whether or not the request succeeded - typedef base::Callback<void(const std::string&, bool)> + typedef base::Callback<void(const dbus::ObjectPath&, bool)> DefaultAdapterCallback; // Retrieves the dbus object path for the default adapter. diff --git a/chrome/browser/chromeos/dbus/cros_dbus_service.cc b/chrome/browser/chromeos/dbus/cros_dbus_service.cc index bb1bdcb..5f912ed 100644 --- a/chrome/browser/chromeos/dbus/cros_dbus_service.cc +++ b/chrome/browser/chromeos/dbus/cros_dbus_service.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -11,6 +11,7 @@ #include "content/public/browser/browser_thread.h" #include "dbus/bus.h" #include "dbus/exported_object.h" +#include "dbus/object_path.h" #include "third_party/cros_system_api/dbus/service_constants.h" namespace chromeos { @@ -40,7 +41,7 @@ class CrosDBusServiceImpl : public CrosDBusService { exported_object_ = bus_->GetExportedObject( kLibCrosServiceName, - kLibCrosServicePath); + dbus::ObjectPath(kLibCrosServicePath)); for (size_t i = 0; i < service_providers_.size(); ++i) service_providers_[i]->Start(exported_object_); diff --git a/chrome/browser/chromeos/dbus/cros_dbus_service_unittest.cc b/chrome/browser/chromeos/dbus/cros_dbus_service_unittest.cc index 649f678..3dc6359 100644 --- a/chrome/browser/chromeos/dbus/cros_dbus_service_unittest.cc +++ b/chrome/browser/chromeos/dbus/cros_dbus_service_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -11,6 +11,7 @@ #include "dbus/mock_bus.h" #include "dbus/mock_exported_object.h" #include "dbus/mock_object_proxy.h" +#include "dbus/object_path.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -48,12 +49,12 @@ class CrosDBusServiceTest : public testing::Test { mock_exported_object_ = new dbus::MockExportedObject(mock_bus_.get(), kLibCrosServiceName, - kLibCrosServicePath); + dbus::ObjectPath(kLibCrosServicePath)); // |mock_bus_|'s GetExportedObject() will return mock_exported_object_| // for the given service name and the object path. EXPECT_CALL(*mock_bus_, GetExportedObject( - kLibCrosServiceName, kLibCrosServicePath)) + kLibCrosServiceName, dbus::ObjectPath(kLibCrosServicePath))) .WillOnce(Return(mock_exported_object_.get())); // Create a mock proxy resolution service. diff --git a/chrome/browser/chromeos/dbus/cros_disks_client.cc b/chrome/browser/chromeos/dbus/cros_disks_client.cc index 63e63df..210a71d 100644 --- a/chrome/browser/chromeos/dbus/cros_disks_client.cc +++ b/chrome/browser/chromeos/dbus/cros_disks_client.cc @@ -9,6 +9,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -105,8 +106,9 @@ bool MaybePopArrayOfStrings(dbus::MessageReader* reader, class CrosDisksClientImpl : public CrosDisksClient { public: explicit CrosDisksClientImpl(dbus::Bus* bus) - : proxy_(bus->GetObjectProxy(cros_disks::kCrosDisksServiceName, - cros_disks::kCrosDisksServicePath)), + : proxy_(bus->GetObjectProxy( + cros_disks::kCrosDisksServiceName, + dbus::ObjectPath(cros_disks::kCrosDisksServicePath))), weak_ptr_factory_(this) { } diff --git a/chrome/browser/chromeos/dbus/image_burner_client.cc b/chrome/browser/chromeos/dbus/image_burner_client.cc index 813ed47..49ea93f 100644 --- a/chrome/browser/chromeos/dbus/image_burner_client.cc +++ b/chrome/browser/chromeos/dbus/image_burner_client.cc @@ -9,6 +9,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -22,8 +23,9 @@ class ImageBurnerClientImpl : public ImageBurnerClient { explicit ImageBurnerClientImpl(dbus::Bus* bus) : proxy_(NULL), weak_ptr_factory_(this) { - proxy_ = bus->GetObjectProxy(imageburn::kImageBurnServiceName, - imageburn::kImageBurnServicePath); + proxy_ = bus->GetObjectProxy( + imageburn::kImageBurnServiceName, + dbus::ObjectPath(imageburn::kImageBurnServicePath)); proxy_->ConnectToSignal( imageburn::kImageBurnServiceInterface, imageburn::kSignalBurnFinishedName, diff --git a/chrome/browser/chromeos/dbus/mock_bluetooth_adapter_client.h b/chrome/browser/chromeos/dbus/mock_bluetooth_adapter_client.h index 6cd0de9..47c1c9d 100644 --- a/chrome/browser/chromeos/dbus/mock_bluetooth_adapter_client.h +++ b/chrome/browser/chromeos/dbus/mock_bluetooth_adapter_client.h @@ -19,8 +19,8 @@ class MockBluetoothAdapterClient : public BluetoothAdapterClient { MOCK_METHOD1(AddObserver, void(Observer*)); MOCK_METHOD1(RemoveObserver, void(Observer*)); - MOCK_METHOD1(StartDiscovery, void(const std::string&)); - MOCK_METHOD1(StopDiscovery, void(const std::string&)); + MOCK_METHOD1(StartDiscovery, void(const dbus::ObjectPath&)); + MOCK_METHOD1(StopDiscovery, void(const dbus::ObjectPath&)); }; } // namespace chromeos diff --git a/chrome/browser/chromeos/dbus/power_manager_client.cc b/chrome/browser/chromeos/dbus/power_manager_client.cc index 1391dbfc..54e7ab7 100644 --- a/chrome/browser/chromeos/dbus/power_manager_client.cc +++ b/chrome/browser/chromeos/dbus/power_manager_client.cc @@ -18,6 +18,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -63,7 +64,7 @@ class PowerManagerClientImpl : public PowerManagerClient { weak_ptr_factory_(this) { power_manager_proxy_ = bus->GetObjectProxy( power_manager::kPowerManagerServiceName, - power_manager::kPowerManagerServicePath); + dbus::ObjectPath(power_manager::kPowerManagerServicePath)); // Monitor the D-Bus signal for brightness changes. Only the power // manager knows the actual brightness level. We don't cache the diff --git a/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc b/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc index 9cbbdf5..e7f3f9fb 100644 --- a/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc +++ b/chrome/browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. // @@ -22,6 +22,7 @@ #include "dbus/mock_bus.h" #include "dbus/mock_exported_object.h" #include "dbus/mock_object_proxy.h" +#include "dbus/object_path.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -80,7 +81,7 @@ class ProxyResolutionServiceProviderTest : public testing::Test { mock_exported_object_ = new dbus::MockExportedObject(mock_bus_.get(), kLibCrosServiceName, - kLibCrosServicePath); + dbus::ObjectPath(kLibCrosServicePath)); // |mock_exported_object_|'s ExportMethod() will use // |MockExportedObject(). @@ -102,7 +103,7 @@ class ProxyResolutionServiceProviderTest : public testing::Test { mock_object_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(), kLibCrosServiceName, - kLibCrosServicePath); + dbus::ObjectPath(kLibCrosServicePath)); // |mock_object_proxy_|'s CallMethodAndBlock() will use // MockCallMethodAndBlock() to return responses. EXPECT_CALL(*mock_object_proxy_, diff --git a/chrome/browser/chromeos/dbus/sensors_client.cc b/chrome/browser/chromeos/dbus/sensors_client.cc index ff0dd8d..f8c03f4 100644 --- a/chrome/browser/chromeos/dbus/sensors_client.cc +++ b/chrome/browser/chromeos/dbus/sensors_client.cc @@ -11,6 +11,7 @@ #include "content/public/browser/sensors_provider.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" using content::BrowserThread; @@ -31,8 +32,9 @@ class SensorsClientImpl : public SensorsClient { explicit SensorsClientImpl(dbus::Bus* bus) : sensors_proxy_(NULL), weak_ptr_factory_(this) { - sensors_proxy_ = bus->GetObjectProxy(chromeos::kSensorsServiceName, - chromeos::kSensorsServicePath); + sensors_proxy_ = bus->GetObjectProxy( + chromeos::kSensorsServiceName, + dbus::ObjectPath(chromeos::kSensorsServicePath)); sensors_proxy_->ConnectToSignal( chromeos::kSensorsServiceInterface, chromeos::kScreenOrientationChanged, diff --git a/chrome/browser/chromeos/dbus/session_manager_client.cc b/chrome/browser/chromeos/dbus/session_manager_client.cc index b2643c7..a4b3579 100644 --- a/chrome/browser/chromeos/dbus/session_manager_client.cc +++ b/chrome/browser/chromeos/dbus/session_manager_client.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,6 +10,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -23,7 +24,7 @@ class SessionManagerClientImpl : public SessionManagerClient { weak_ptr_factory_(this) { session_manager_proxy_ = bus->GetObjectProxy( login_manager::kSessionManagerServiceName, - login_manager::kSessionManagerServicePath); + dbus::ObjectPath(login_manager::kSessionManagerServicePath)); // Monitor the D-Bus signal for owner key changes. session_manager_proxy_->ConnectToSignal( diff --git a/chrome/browser/chromeos/dbus/speech_synthesizer_client.cc b/chrome/browser/chromeos/dbus/speech_synthesizer_client.cc index 745b4ba..5c474c8 100644 --- a/chrome/browser/chromeos/dbus/speech_synthesizer_client.cc +++ b/chrome/browser/chromeos/dbus/speech_synthesizer_client.cc @@ -9,6 +9,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -32,7 +33,7 @@ class SpeechSynthesizerClientImpl : public SpeechSynthesizerClient { weak_ptr_factory_(this) { proxy_ = bus->GetObjectProxy( speech_synthesis::kSpeechSynthesizerServiceName, - speech_synthesis::kSpeechSynthesizerServicePath); + dbus::ObjectPath(speech_synthesis::kSpeechSynthesizerServicePath)); } virtual ~SpeechSynthesizerClientImpl() {} diff --git a/chrome/browser/chromeos/dbus/update_engine_client.cc b/chrome/browser/chromeos/dbus/update_engine_client.cc index ed5cecb..9352375 100644 --- a/chrome/browser/chromeos/dbus/update_engine_client.cc +++ b/chrome/browser/chromeos/dbus/update_engine_client.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,6 +10,7 @@ #include "chrome/browser/chromeos/system/runtime_environment.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "third_party/cros_system_api/dbus/service_constants.h" @@ -54,7 +55,7 @@ class UpdateEngineClientImpl : public UpdateEngineClient { last_status_() { update_engine_proxy_ = bus->GetObjectProxy( update_engine::kUpdateEngineServiceName, - update_engine::kUpdateEngineServicePath); + 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 diff --git a/chrome/browser/password_manager/native_backend_kwallet_x.cc b/chrome/browser/password_manager/native_backend_kwallet_x.cc index d74898d..787ed5b 100644 --- a/chrome/browser/password_manager/native_backend_kwallet_x.cc +++ b/chrome/browser/password_manager/native_backend_kwallet_x.cc @@ -15,6 +15,7 @@ #include "content/public/browser/browser_thread.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "grit/chromium_strings.h" #include "ui/base/l10n/l10n_util.h" @@ -103,7 +104,8 @@ void NativeBackendKWallet::InitOnDBThread(scoped_refptr<dbus::Bus> optional_bus, session_bus_ = new dbus::Bus(options); } kwallet_proxy_ = - session_bus_->GetObjectProxy(kKWalletServiceName, kKWalletPath); + session_bus_->GetObjectProxy(kKWalletServiceName, + dbus::ObjectPath(kKWalletPath)); // kwalletd may not be running. If we get a temporary failure initializing it, // try to start it and then try again. (Note the short-circuit evaluation.) const InitResult result = InitWallet(); @@ -118,7 +120,8 @@ bool NativeBackendKWallet::StartKWalletd() { // Sadly kwalletd doesn't use DBus activation, so we have to make a call to // klauncher to start it. dbus::ObjectProxy* klauncher = - session_bus_->GetObjectProxy(kKLauncherServiceName, kKLauncherPath); + session_bus_->GetObjectProxy(kKLauncherServiceName, + dbus::ObjectPath(kKLauncherPath)); dbus::MethodCall method_call(kKLauncherInterface, "start_service_by_desktop_name"); diff --git a/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc b/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc index a091be5..dbdcd20 100644 --- a/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc +++ b/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc @@ -20,6 +20,7 @@ #include "dbus/message.h" #include "dbus/mock_bus.h" #include "dbus/mock_object_proxy.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -225,7 +226,7 @@ void NativeBackendKWalletTest::SetUp() { mock_klauncher_proxy_ = new dbus::MockObjectProxy(mock_session_bus_.get(), "org.kde.klauncher", - "/KLauncher"); + dbus::ObjectPath("/KLauncher")); EXPECT_CALL(*mock_klauncher_proxy_, CallMethodAndBlock(_, _)) .WillRepeatedly(Invoke(this, @@ -234,7 +235,7 @@ void NativeBackendKWalletTest::SetUp() { mock_kwallet_proxy_ = new dbus::MockObjectProxy(mock_session_bus_.get(), "org.kde.kwalletd", - "/modules/kwalletd"); + dbus::ObjectPath("/modules/kwalletd")); EXPECT_CALL(*mock_kwallet_proxy_, CallMethodAndBlock(_, _)) .WillRepeatedly(Invoke(this, @@ -242,11 +243,11 @@ void NativeBackendKWalletTest::SetUp() { EXPECT_CALL(*mock_session_bus_, GetObjectProxy( "org.kde.klauncher", - "/KLauncher")) + dbus::ObjectPath("/KLauncher"))) .WillRepeatedly(Return(mock_klauncher_proxy_.get())); EXPECT_CALL(*mock_session_bus_, GetObjectProxy( "org.kde.kwalletd", - "/modules/kwalletd")) + dbus::ObjectPath("/modules/kwalletd"))) .WillRepeatedly(Return(mock_kwallet_proxy_.get())); EXPECT_CALL(*mock_session_bus_, diff --git a/content/browser/geolocation/wifi_data_provider_linux.cc b/content/browser/geolocation/wifi_data_provider_linux.cc index 178260a..a1f5237 100644 --- a/content/browser/geolocation/wifi_data_provider_linux.cc +++ b/content/browser/geolocation/wifi_data_provider_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -13,6 +13,7 @@ #include "base/utf_string_conversions.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" namespace { @@ -56,12 +57,12 @@ class NetworkManagerWlanApi : public WifiDataProviderCommon::WlanApiInterface { private: // Enumerates the list of available network adapter devices known to // NetworkManager. Return true on success. - bool GetAdapterDeviceList(std::vector<std::string>* device_paths); + bool GetAdapterDeviceList(std::vector<dbus::ObjectPath>* device_paths); // Given the NetworkManager path to a wireless adapater, dumps the wifi scan // results and appends them to |data|. Returns false if a fatal error is // encountered such that the data set could not be populated. - bool GetAccessPointsForAdapter(const std::string& adapter_path, + bool GetAccessPointsForAdapter(const dbus::ObjectPath& adapter_path, WifiData::AccessPointDataSet* data); // Internal method used by |GetAccessPointsForAdapter|, given a wifi access @@ -110,9 +111,9 @@ bool NetworkManagerWlanApi::InitWithBus(dbus::Bus* bus) { // system_bus_ will own all object proxies created from the bus. network_manager_proxy_ = system_bus_->GetObjectProxy(kNetworkManagerServiceName, - kNetworkManagerPath); + dbus::ObjectPath(kNetworkManagerPath)); // Validate the proxy object by checking we can enumerate devices. - std::vector<std::string> adapter_paths; + std::vector<dbus::ObjectPath> adapter_paths; const bool success = GetAdapterDeviceList(&adapter_paths); VLOG(1) << "Init() result: " << success; return success; @@ -120,7 +121,7 @@ bool NetworkManagerWlanApi::InitWithBus(dbus::Bus* bus) { bool NetworkManagerWlanApi::GetAccessPointData( WifiData::AccessPointDataSet* data) { - std::vector<std::string> device_paths; + std::vector<dbus::ObjectPath> device_paths; if (!GetAdapterDeviceList(&device_paths)) { LOG(WARNING) << "Could not enumerate access points"; return false; @@ -130,8 +131,8 @@ bool NetworkManagerWlanApi::GetAccessPointData( // Iterate the devices, getting APs for each wireless adapter found for (size_t i = 0; i < device_paths.size(); ++i) { - const std::string& device_path = device_paths[i]; - VLOG(1) << "Checking device: " << device_path; + const dbus::ObjectPath& device_path = device_paths[i]; + VLOG(1) << "Checking device: " << device_path.value(); dbus::ObjectProxy* device_proxy = system_bus_->GetObjectProxy(kNetworkManagerServiceName, @@ -146,7 +147,8 @@ bool NetworkManagerWlanApi::GetAccessPointData( &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); if (!response.get()) { - LOG(WARNING) << "Failed to get the device type for " << device_path; + LOG(WARNING) << "Failed to get the device type for " + << device_path.value(); continue; // Check the next device. } dbus::MessageReader reader(response.get()); @@ -170,7 +172,7 @@ bool NetworkManagerWlanApi::GetAccessPointData( } bool NetworkManagerWlanApi::GetAdapterDeviceList( - std::vector<std::string>* device_paths) { + std::vector<dbus::ObjectPath>* device_paths) { dbus::MethodCall method_call(kNetworkManagerInterface, "GetDevices"); scoped_ptr<dbus::Response> response( network_manager_proxy_->CallMethodAndBlock( @@ -191,7 +193,7 @@ bool NetworkManagerWlanApi::GetAdapterDeviceList( bool NetworkManagerWlanApi::GetAccessPointsForAdapter( - const std::string& adapter_path, WifiData::AccessPointDataSet* data) { + const dbus::ObjectPath& adapter_path, WifiData::AccessPointDataSet* data) { // Create a proxy object for this wifi adapter, and ask it to do a scan // (or at least, dump its scan results). dbus::ObjectProxy* device_proxy = @@ -205,23 +207,24 @@ bool NetworkManagerWlanApi::GetAccessPointsForAdapter( &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); if (!response.get()) { - LOG(WARNING) << "Failed to get access points data for " << adapter_path; + LOG(WARNING) << "Failed to get access points data for " + << adapter_path.value(); return false; } dbus::MessageReader reader(response.get()); - std::vector<std::string> access_point_paths; + std::vector<dbus::ObjectPath> access_point_paths; if (!reader.PopArrayOfObjectPaths(&access_point_paths)) { - LOG(WARNING) << "Unexpected response for " << adapter_path << ": " + LOG(WARNING) << "Unexpected response for " << adapter_path.value() << ": " << response->ToString(); return false; } - VLOG(1) << "Wireless adapter " << adapter_path << " found " + VLOG(1) << "Wireless adapter " << adapter_path.value() << " found " << access_point_paths.size() << " access points."; for (size_t i = 0; i < access_point_paths.size(); ++i) { - const std::string& access_point_path = access_point_paths[i]; - VLOG(1) << "Checking access point: " << access_point_path; + const dbus::ObjectPath& access_point_path = access_point_paths[i]; + VLOG(1) << "Checking access point: " << access_point_path.value(); dbus::ObjectProxy* access_point_proxy = system_bus_->GetObjectProxy(kNetworkManagerServiceName, @@ -237,15 +240,15 @@ bool NetworkManagerWlanApi::GetAccessPointsForAdapter( dbus::MessageReader reader(response.get()); dbus::MessageReader variant_reader(response.get()); if (!reader.PopVariant(&variant_reader)) { - LOG(WARNING) << "Unexpected response for " << access_point_path << ": " - << response->ToString(); + LOG(WARNING) << "Unexpected response for " << access_point_path.value() + << ": " << response->ToString(); continue; } uint8* ssid_bytes = NULL; size_t ssid_length = 0; if (!variant_reader.PopArrayOfBytes(&ssid_bytes, &ssid_length)) { - LOG(WARNING) << "Unexpected response for " << access_point_path << ": " - << response->ToString(); + LOG(WARNING) << "Unexpected response for " << access_point_path.value() + << ": " << response->ToString(); continue; } std::string ssid(ssid_bytes, ssid_bytes + ssid_length); @@ -260,8 +263,8 @@ bool NetworkManagerWlanApi::GetAccessPointsForAdapter( dbus::MessageReader reader(response.get()); std::string mac; if (!reader.PopVariantOfString(&mac)) { - LOG(WARNING) << "Unexpected response for " << access_point_path << ": " - << response->ToString(); + LOG(WARNING) << "Unexpected response for " << access_point_path.value() + << ": " << response->ToString(); continue; } @@ -284,8 +287,8 @@ bool NetworkManagerWlanApi::GetAccessPointsForAdapter( dbus::MessageReader reader(response.get()); uint8 strength = 0; if (!reader.PopVariantOfByte(&strength)) { - LOG(WARNING) << "Unexpected response for " << access_point_path << ": " - << response->ToString(); + LOG(WARNING) << "Unexpected response for " << access_point_path.value() + << ": " << response->ToString(); continue; } // Convert strength as a percentage into dBs. @@ -300,8 +303,8 @@ bool NetworkManagerWlanApi::GetAccessPointsForAdapter( dbus::MessageReader reader(response.get()); uint32 frequency = 0; if (!reader.PopVariantOfUint32(&frequency)) { - LOG(WARNING) << "Unexpected response for " << access_point_path << ": " - << response->ToString(); + LOG(WARNING) << "Unexpected response for " << access_point_path.value() + << ": " << response->ToString(); continue; } @@ -309,7 +312,7 @@ bool NetworkManagerWlanApi::GetAccessPointsForAdapter( access_point_data.channel = frquency_in_khz_to_channel(frequency * 1000); } - VLOG(1) << "Access point data of " << access_point_path << ": " + VLOG(1) << "Access point data of " << access_point_path.value() << ": " << "SSID: " << access_point_data.ssid << ", " << "MAC: " << access_point_data.mac_address << ", " << "Strength: " << access_point_data.radio_signal_strength << ", " diff --git a/content/browser/geolocation/wifi_data_provider_linux_unittest.cc b/content/browser/geolocation/wifi_data_provider_linux_unittest.cc index e5a39b9..94c56f2 100644 --- a/content/browser/geolocation/wifi_data_provider_linux_unittest.cc +++ b/content/browser/geolocation/wifi_data_provider_linux_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -11,6 +11,7 @@ #include "dbus/message.h" #include "dbus/mock_bus.h" #include "dbus/mock_object_proxy.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -29,9 +30,10 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test { // Create a mock proxy that behaves as NetworkManager. mock_network_manager_proxy_ = - new dbus::MockObjectProxy(mock_bus_.get(), - "org.freedesktop.NetworkManager", - "/org/freedesktop/NetworkManager"); + new dbus::MockObjectProxy( + mock_bus_.get(), + "org.freedesktop.NetworkManager", + dbus::ObjectPath("/org/freedesktop/NetworkManager")); // Set an expectation so mock_network_manager_proxy_'s // CallMethodAndBlock() will use CreateNetowrkManagerProxyResponse() // to return responses. @@ -44,9 +46,10 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test { // Create a mock proxy that behaves as NetworkManager/Devices/0. mock_device_proxy_ = - new dbus::MockObjectProxy(mock_bus_.get(), - "org.freedesktop.NetworkManager", - "/org/freedesktop/NetworkManager/Devices/0"); + new dbus::MockObjectProxy( + mock_bus_.get(), + "org.freedesktop.NetworkManager", + dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")); EXPECT_CALL(*mock_device_proxy_, CallMethodAndBlock(_, _)) .WillRepeatedly(Invoke( @@ -58,7 +61,7 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test { new dbus::MockObjectProxy( mock_bus_.get(), "org.freedesktop.NetworkManager", - "/org/freedesktop/NetworkManager/AccessPoint/0"); + dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); EXPECT_CALL(*mock_access_point_proxy_, CallMethodAndBlock(_, _)) .WillRepeatedly(Invoke( @@ -71,18 +74,18 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test { // mock_network_manager_proxy_. EXPECT_CALL(*mock_bus_, GetObjectProxy( "org.freedesktop.NetworkManager", - "/org/freedesktop/NetworkManager")) + dbus::ObjectPath("/org/freedesktop/NetworkManager"))) .WillOnce(Return(mock_network_manager_proxy_.get())); // Likewise, set an expectation for mock_device_proxy_. EXPECT_CALL(*mock_bus_, GetObjectProxy( "org.freedesktop.NetworkManager", - "/org/freedesktop/NetworkManager/Devices/0")) + dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0"))) .WillOnce(Return(mock_device_proxy_.get())) .WillOnce(Return(mock_device_proxy_.get())); // Likewise, set an expectation for mock_access_point_proxy_. EXPECT_CALL(*mock_bus_, GetObjectProxy( "org.freedesktop.NetworkManager", - "/org/freedesktop/NetworkManager/AccessPoint/0")) + dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0"))) .WillOnce(Return(mock_access_point_proxy_.get())); // ShutdownAndBlock() should be called. @@ -115,8 +118,9 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test { if (method_call->GetInterface() == "org.freedesktop.NetworkManager" && method_call->GetMember() == "GetDevices") { // The list of devices is asked. Return the object path. - std::vector<std::string> object_paths; - object_paths.push_back("/org/freedesktop/NetworkManager/Devices/0"); + std::vector<dbus::ObjectPath> object_paths; + object_paths.push_back( + dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")); dbus::Response* response = dbus::Response::CreateEmpty(); dbus::MessageWriter writer(response); @@ -152,8 +156,9 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test { // The list of access points is asked. Return the object path. dbus::Response* response = dbus::Response::CreateEmpty(); dbus::MessageWriter writer(response); - std::vector<std::string> object_paths; - object_paths.push_back("/org/freedesktop/NetworkManager/AccessPoint/0"); + std::vector<dbus::ObjectPath> object_paths; + object_paths.push_back( + dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0")); writer.AppendArrayOfObjectPaths(object_paths); return response; } diff --git a/content/browser/power_save_blocker_linux.cc b/content/browser/power_save_blocker_linux.cc index 5a5b29e..f08150a 100644 --- a/content/browser/power_save_blocker_linux.cc +++ b/content/browser/power_save_blocker_linux.cc @@ -20,6 +20,7 @@ #include "content/public/browser/browser_thread.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" using content::BrowserThread; @@ -136,7 +137,7 @@ class KDEPowerSaveBlocker: public DBusPowerSaveBlocker::Delegate { scoped_refptr<dbus::ObjectProxy> object_proxy = DBusPowerSaveBlocker::GetInstance()->bus()->GetObjectProxy( "org.freedesktop.PowerManagement", - "/org/freedesktop/PowerManagement/Inhibit"); + dbus::ObjectPath("/org/freedesktop/PowerManagement/Inhibit")); dbus::MethodCall method_call("org.freedesktop.PowerManagement.Inhibit", "Inhibit"); dbus::MessageWriter message_writer(&method_call); @@ -284,7 +285,7 @@ class GnomePowerSaveBlocker: public DBusPowerSaveBlocker::Delegate { scoped_refptr<dbus::ObjectProxy> object_proxy = DBusPowerSaveBlocker::GetInstance()->bus()->GetObjectProxy( "org.gnome.SessionManager", - "/org/gnome/SessionManager"); + dbus::ObjectPath("/org/gnome/SessionManager")); dbus::MethodCall method_call("org.gnome.SessionManager", "Inhibit"); dbus::MessageWriter message_writer(&method_call); base::Callback<void(dbus::Response*)> bus_callback; diff --git a/dbus/bus.cc b/dbus/bus.cc index 0c6a421..3b2f059 100644 --- a/dbus/bus.cc +++ b/dbus/bus.cc @@ -16,6 +16,7 @@ #include "base/threading/thread_restrictions.h" #include "base/time.h" #include "dbus/exported_object.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "dbus/scoped_dbus_error.h" @@ -207,18 +208,19 @@ Bus::~Bus() { } ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, - const std::string& object_path) { + const ObjectPath& object_path) { return GetObjectProxyWithOptions(service_name, object_path, ObjectProxy::DEFAULT_OPTIONS); } ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, - const std::string& object_path, + const dbus::ObjectPath& object_path, int options) { AssertOnOriginThread(); // Check if we already have the requested object proxy. - const ObjectProxyTable::key_type key(service_name + object_path, options); + const ObjectProxyTable::key_type key(service_name + object_path.value(), + options); ObjectProxyTable::iterator iter = object_proxy_table_.find(key); if (iter != object_proxy_table_.end()) { return iter->second; @@ -232,11 +234,11 @@ ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, } ExportedObject* Bus::GetExportedObject(const std::string& service_name, - const std::string& object_path) { + const ObjectPath& object_path) { AssertOnOriginThread(); // Check if we already have the requested exported object. - const std::string key = service_name + object_path; + const std::string key = service_name + object_path.value(); ExportedObjectTable::iterator iter = exported_object_table_.find(key); if (iter != exported_object_table_.end()) { return iter->second; @@ -521,7 +523,7 @@ void Bus::RemoveMatch(const std::string& match_rule, DBusError* error) { match_rules_added_.erase(match_rule); } -bool Bus::TryRegisterObjectPath(const std::string& object_path, +bool Bus::TryRegisterObjectPath(const ObjectPath& object_path, const DBusObjectPathVTable* vtable, void* user_data, DBusError* error) { @@ -530,13 +532,13 @@ bool Bus::TryRegisterObjectPath(const std::string& object_path, if (registered_object_paths_.find(object_path) != registered_object_paths_.end()) { - LOG(ERROR) << "Object path already registered: " << object_path; + LOG(ERROR) << "Object path already registered: " << object_path.value(); return false; } const bool success = dbus_connection_try_register_object_path( connection_, - object_path.c_str(), + object_path.value().c_str(), vtable, user_data, error); @@ -545,20 +547,20 @@ bool Bus::TryRegisterObjectPath(const std::string& object_path, return success; } -void Bus::UnregisterObjectPath(const std::string& object_path) { +void Bus::UnregisterObjectPath(const ObjectPath& object_path) { DCHECK(connection_); AssertOnDBusThread(); if (registered_object_paths_.find(object_path) == registered_object_paths_.end()) { LOG(ERROR) << "Requested to unregister an unknown object path: " - << object_path; + << object_path.value(); return; } const bool success = dbus_connection_unregister_object_path( connection_, - object_path.c_str()); + object_path.value().c_str()); CHECK(success) << "Unable to allocate memory"; registered_object_paths_.erase(object_path); } @@ -17,6 +17,7 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/platform_thread.h" #include "base/tracked_objects.h" +#include "dbus/object_path.h" class MessageLoop; @@ -112,7 +113,7 @@ class ObjectProxy; // } // // void OnExported(const std::string& interface_name, -// const std::string& object_path, +// const ObjectPath& object_path, // bool success) { // // success is true if the method was exported successfully. // } @@ -194,13 +195,13 @@ class Bus : public base::RefCountedThreadSafe<Bus> { // // Must be called in the origin thread. virtual ObjectProxy* GetObjectProxy(const std::string& service_name, - const std::string& object_path); + const ObjectPath& object_path); // Same as above, but also takes a bitfield of ObjectProxy::Options. // See object_proxy.h for available options. virtual ObjectProxy* GetObjectProxyWithOptions( const std::string& service_name, - const std::string& object_path, + const ObjectPath& object_path, int options); // Gets the exported object for the given service name and the object @@ -219,7 +220,7 @@ class Bus : public base::RefCountedThreadSafe<Bus> { // // Must be called in the origin thread. virtual ExportedObject* GetExportedObject(const std::string& service_name, - const std::string& object_path); + const ObjectPath& object_path); // Shuts down the bus and blocks until it's done. More specifically, this // function does the following: @@ -353,7 +354,7 @@ class Bus : public base::RefCountedThreadSafe<Bus> { // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html // // BLOCKING CALL. - virtual bool TryRegisterObjectPath(const std::string& object_path, + virtual bool TryRegisterObjectPath(const ObjectPath& object_path, const DBusObjectPathVTable* vtable, void* user_data, DBusError* error); @@ -361,7 +362,7 @@ class Bus : public base::RefCountedThreadSafe<Bus> { // Unregister the object path. // // BLOCKING CALL. - virtual void UnregisterObjectPath(const std::string& object_path); + virtual void UnregisterObjectPath(const ObjectPath& object_path); // Posts the task to the message loop of the thread that created the bus. virtual void PostTaskToOriginThread( @@ -461,7 +462,7 @@ class Bus : public base::RefCountedThreadSafe<Bus> { // The following sets are used to check if rules/object_paths/filters // are properly cleaned up before destruction of the bus object. std::set<std::string> match_rules_added_; - std::set<std::string> registered_object_paths_; + std::set<ObjectPath> registered_object_paths_; std::set<std::pair<DBusHandleMessageFunction, void*> > filter_functions_added_; diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc index c21044b..c66a05b 100644 --- a/dbus/bus_unittest.cc +++ b/dbus/bus_unittest.cc @@ -9,6 +9,7 @@ #include "base/memory/ref_counted.h" #include "base/threading/thread.h" #include "dbus/exported_object.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "testing/gtest/include/gtest/gtest.h" @@ -30,20 +31,21 @@ TEST(BusTest, GetObjectProxy) { dbus::ObjectProxy* object_proxy1 = bus->GetObjectProxy("org.chromium.TestService", - "/org/chromium/TestObject"); + dbus::ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy1); // This should return the same object. dbus::ObjectProxy* object_proxy2 = bus->GetObjectProxy("org.chromium.TestService", - "/org/chromium/TestObject"); + dbus::ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy2); EXPECT_EQ(object_proxy1, object_proxy2); // This should not. dbus::ObjectProxy* object_proxy3 = - bus->GetObjectProxy("org.chromium.TestService", - "/org/chromium/DifferentTestObject"); + bus->GetObjectProxy( + "org.chromium.TestService", + dbus::ObjectPath("/org/chromium/DifferentTestObject")); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); @@ -57,7 +59,7 @@ TEST(BusTest, GetObjectProxyIgnoreUnknownService) { dbus::ObjectProxy* object_proxy1 = bus->GetObjectProxyWithOptions( "org.chromium.TestService", - "/org/chromium/TestObject", + dbus::ObjectPath("/org/chromium/TestObject"), dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); ASSERT_TRUE(object_proxy1); @@ -65,7 +67,7 @@ TEST(BusTest, GetObjectProxyIgnoreUnknownService) { dbus::ObjectProxy* object_proxy2 = bus->GetObjectProxyWithOptions( "org.chromium.TestService", - "/org/chromium/TestObject", + dbus::ObjectPath("/org/chromium/TestObject"), dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); ASSERT_TRUE(object_proxy2); EXPECT_EQ(object_proxy1, object_proxy2); @@ -74,7 +76,7 @@ TEST(BusTest, GetObjectProxyIgnoreUnknownService) { dbus::ObjectProxy* object_proxy3 = bus->GetObjectProxyWithOptions( "org.chromium.TestService", - "/org/chromium/DifferentTestObject", + dbus::ObjectPath("/org/chromium/DifferentTestObject"), dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); @@ -88,20 +90,21 @@ TEST(BusTest, GetExportedObject) { dbus::ExportedObject* object_proxy1 = bus->GetExportedObject("org.chromium.TestService", - "/org/chromium/TestObject"); + dbus::ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy1); // This should return the same object. dbus::ExportedObject* object_proxy2 = bus->GetExportedObject("org.chromium.TestService", - "/org/chromium/TestObject"); + dbus::ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(object_proxy2); EXPECT_EQ(object_proxy1, object_proxy2); // This should not. dbus::ExportedObject* object_proxy3 = - bus->GetExportedObject("org.chromium.TestService", - "/org/chromium/DifferentTestObject"); + bus->GetExportedObject( + "org.chromium.TestService", + dbus::ObjectPath("/org/chromium/DifferentTestObject")); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); diff --git a/dbus/dbus.gyp b/dbus/dbus.gyp index 2dc8fee..8a3cb22 100644 --- a/dbus/dbus.gyp +++ b/dbus/dbus.gyp @@ -25,6 +25,8 @@ 'exported_object.h', 'message.cc', 'message.h', + 'object_path.cc', + 'object_path.h', 'object_proxy.cc', 'object_proxy.h', 'scoped_dbus_error.h', diff --git a/dbus/end_to_end_async_unittest.cc b/dbus/end_to_end_async_unittest.cc index 150ed29..9a88b42 100644 --- a/dbus/end_to_end_async_unittest.cc +++ b/dbus/end_to_end_async_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -15,6 +15,7 @@ #include "base/threading/thread_restrictions.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" @@ -51,8 +52,9 @@ class EndToEndAsyncTest : public testing::Test { bus_options.dbus_thread_message_loop_proxy = dbus_thread_->message_loop_proxy(); bus_ = new dbus::Bus(bus_options); - object_proxy_ = bus_->GetObjectProxy("org.chromium.TestService", - "/org/chromium/TestObject"); + object_proxy_ = bus_->GetObjectProxy( + "org.chromium.TestService", + dbus::ObjectPath("/org/chromium/TestObject")); ASSERT_TRUE(bus_->HasDBusThread()); // Connect to the "Test" signal of "org.chromium.TestInterface" from diff --git a/dbus/end_to_end_sync_unittest.cc b/dbus/end_to_end_sync_unittest.cc index c338809..26a9011 100644 --- a/dbus/end_to_end_sync_unittest.cc +++ b/dbus/end_to_end_sync_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -6,6 +6,7 @@ #include "base/memory/scoped_ptr.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" @@ -31,8 +32,9 @@ class EndToEndSyncTest : public testing::Test { client_bus_options.bus_type = dbus::Bus::SESSION; client_bus_options.connection_type = dbus::Bus::PRIVATE; client_bus_ = new dbus::Bus(client_bus_options); - object_proxy_ = client_bus_->GetObjectProxy("org.chromium.TestService", - "/org/chromium/TestObject"); + object_proxy_ = client_bus_->GetObjectProxy( + "org.chromium.TestService", + dbus::ObjectPath("/org/chromium/TestObject")); ASSERT_FALSE(client_bus_->HasDBusThread()); } diff --git a/dbus/exported_object.cc b/dbus/exported_object.cc index de25168..730c98b 100644 --- a/dbus/exported_object.cc +++ b/dbus/exported_object.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -13,6 +13,7 @@ #include "base/time.h" #include "dbus/bus.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/scoped_dbus_error.h" namespace dbus { @@ -35,7 +36,7 @@ std::string GetAbsoluteMethodName( ExportedObject::ExportedObject(Bus* bus, const std::string& service_name, - const std::string& object_path) + const ObjectPath& object_path) : bus_(bus), service_name_(service_name), object_path_(object_path), @@ -175,8 +176,8 @@ bool ExportedObject::Register() { this, error.get()); if (!success) { - LOG(ERROR) << "Failed to register the object: " << object_path_ << ": " - << (error.is_set() ? error.message() : ""); + LOG(ERROR) << "Failed to register the object: " << object_path_.value() + << ": " << (error.is_set() ? error.message() : ""); return false; } diff --git a/dbus/exported_object.h b/dbus/exported_object.h index 7ac2f88..24db66e 100644 --- a/dbus/exported_object.h +++ b/dbus/exported_object.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -17,6 +17,7 @@ #include "base/synchronization/waitable_event.h" #include "base/threading/platform_thread.h" #include "base/time.h" +#include "dbus/object_path.h" namespace dbus { @@ -36,7 +37,7 @@ class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> { // constructor. ExportedObject(Bus* bus, const std::string& service_name, - const std::string& object_path); + const ObjectPath& object_path); // Called to send a response from an exported method. Response* is the // response message. Callers should pass a NULL Response* in the event @@ -157,7 +158,7 @@ class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> { scoped_refptr<Bus> bus_; std::string service_name_; - std::string object_path_; + ObjectPath object_path_; bool object_is_registered_; // The method table where keys are absolute method names (i.e. interface diff --git a/dbus/message.cc b/dbus/message.cc index 4a94b54..486538a 100644 --- a/dbus/message.cc +++ b/dbus/message.cc @@ -10,6 +10,7 @@ #include "base/format_macros.h" #include "base/logging.h" #include "base/stringprintf.h" +#include "dbus/object_path.h" #include "third_party/protobuf/src/google/protobuf/message_lite.h" namespace { @@ -157,10 +158,10 @@ std::string Message::ToStringInternal(const std::string& indent, break; } case OBJECT_PATH: { - std::string value; + ObjectPath value; if (!reader->PopObjectPath(&value)) return kBrokenMessage; - output += indent + "object_path \"" + value + "\"\n"; + output += indent + "object_path \"" + value.value() + "\"\n"; break; } case ARRAY: { @@ -224,7 +225,7 @@ std::string Message::ToString() { std::string headers; AppendStringHeader("message_type", GetMessageTypeAsString(), &headers); AppendStringHeader("destination", GetDestination(), &headers); - AppendStringHeader("path", GetPath(), &headers); + AppendStringHeader("path", GetPath().value(), &headers); AppendStringHeader("interface", GetInterface(), &headers); AppendStringHeader("member", GetMember(), &headers); AppendStringHeader("error_name", GetErrorName(), &headers); @@ -244,9 +245,9 @@ void Message::SetDestination(const std::string& destination) { CHECK(success) << "Unable to allocate memory"; } -void Message::SetPath(const std::string& path) { +void Message::SetPath(const ObjectPath& path) { const bool success = dbus_message_set_path(raw_message_, - path.c_str()); + path.value().c_str()); CHECK(success) << "Unable to allocate memory"; } @@ -287,9 +288,9 @@ std::string Message::GetDestination() { return destination ? destination : ""; } -std::string Message::GetPath() { +ObjectPath Message::GetPath() { const char* path = dbus_message_get_path(raw_message_); - return path ? path : ""; + return ObjectPath(path ? path : ""); } std::string Message::GetInterface() { @@ -490,8 +491,8 @@ void MessageWriter::AppendString(const std::string& value) { // bool AppendStringWithErrorChecking(). } -void MessageWriter::AppendObjectPath(const std::string& value) { - const char* pointer = value.c_str(); +void MessageWriter::AppendObjectPath(const ObjectPath& value) { + const char* pointer = value.value().c_str(); AppendBasic(DBUS_TYPE_OBJECT_PATH, &pointer); } @@ -587,7 +588,7 @@ void MessageWriter::AppendArrayOfStrings( } void MessageWriter::AppendArrayOfObjectPaths( - const std::vector<std::string>& object_paths) { + const std::vector<ObjectPath>& object_paths) { DCHECK(!container_is_open_); MessageWriter array_writer(message_); OpenArray("o", &array_writer); @@ -652,8 +653,8 @@ void MessageWriter::AppendVariantOfString(const std::string& value) { AppendVariantOfBasic(DBUS_TYPE_STRING, &pointer); } -void MessageWriter::AppendVariantOfObjectPath(const std::string& value) { - const char* pointer = value.c_str(); +void MessageWriter::AppendVariantOfObjectPath(const ObjectPath& value) { + const char* pointer = value.value().c_str(); AppendVariantOfBasic(DBUS_TYPE_OBJECT_PATH, &pointer); } @@ -746,11 +747,11 @@ bool MessageReader::PopString(std::string* value) { return success; } -bool MessageReader::PopObjectPath(std::string* value) { +bool MessageReader::PopObjectPath(ObjectPath* value) { char* tmp_value = NULL; const bool success = PopBasic(DBUS_TYPE_OBJECT_PATH, &tmp_value); if (success) - value->assign(tmp_value); + *value = ObjectPath(tmp_value); return success; } @@ -805,12 +806,12 @@ bool MessageReader::PopArrayOfStrings( } bool MessageReader::PopArrayOfObjectPaths( - std::vector<std::string> *object_paths) { + std::vector<ObjectPath> *object_paths) { MessageReader array_reader(message_); if (!PopArray(&array_reader)) return false; while (array_reader.HasMoreData()) { - std::string object_path; + ObjectPath object_path; if (!array_reader.PopObjectPath(&object_path)) return false; object_paths->push_back(object_path); @@ -882,11 +883,11 @@ bool MessageReader::PopVariantOfString(std::string* value) { return success; } -bool MessageReader::PopVariantOfObjectPath(std::string* value) { +bool MessageReader::PopVariantOfObjectPath(ObjectPath* value) { char* tmp_value = NULL; const bool success = PopVariantOfBasic(DBUS_TYPE_OBJECT_PATH, &tmp_value); if (success) - value->assign(tmp_value); + *value = ObjectPath(tmp_value); return success; } diff --git a/dbus/message.h b/dbus/message.h index 54227a0..4683abe 100644 --- a/dbus/message.h +++ b/dbus/message.h @@ -11,6 +11,7 @@ #include <dbus/dbus.h> #include "base/basictypes.h" +#include "dbus/object_path.h" namespace google { namespace protobuf { @@ -80,7 +81,7 @@ class Message { // Sets the destination, the path, the interface, the member, etc. void SetDestination(const std::string& destination); - void SetPath(const std::string& path); + void SetPath(const ObjectPath& path); void SetInterface(const std::string& interface); void SetMember(const std::string& member); void SetErrorName(const std::string& error_name); @@ -92,7 +93,7 @@ class Message { // Gets the destination, the path, the interface, the member, etc. // If not set, an empty string is returned. std::string GetDestination(); - std::string GetPath(); + ObjectPath GetPath(); std::string GetInterface(); std::string GetMember(); std::string GetErrorName(); @@ -265,7 +266,7 @@ class MessageWriter { void AppendUint64(uint64 value); void AppendDouble(double value); void AppendString(const std::string& value); - void AppendObjectPath(const std::string& value); + void AppendObjectPath(const ObjectPath& value); // Opens an array. The array contents can be added to the array with // |sub_writer|. The client code must close the array with @@ -302,7 +303,7 @@ class MessageWriter { // Appends the array of object paths. Arrays of object paths are often // used when exchanging object paths, hence it's worth having a // specialized function. - void AppendArrayOfObjectPaths(const std::vector<std::string>& object_paths); + void AppendArrayOfObjectPaths(const std::vector<ObjectPath>& object_paths); // Appends the protocol buffer as an array of bytes. The buffer is serialized // into an array of bytes before communication, since protocol buffers are not @@ -326,7 +327,7 @@ class MessageWriter { void AppendVariantOfUint64(uint64 value); void AppendVariantOfDouble(double value); void AppendVariantOfString(const std::string& value); - void AppendVariantOfObjectPath(const std::string& value); + void AppendVariantOfObjectPath(const ObjectPath& value); private: // Helper function used to implement AppendByte etc. @@ -374,7 +375,7 @@ class MessageReader { bool PopUint64(uint64* value); bool PopDouble(double* value); bool PopString(std::string* value); - bool PopObjectPath(std::string* value); + bool PopObjectPath(ObjectPath* value); // Sets up the given message reader to read an array at the current // iterator position. @@ -409,7 +410,7 @@ class MessageReader { // Arrays of object paths are often used to communicate with D-Bus // services like NetworkManager, hence it's worth having a specialized // function. - bool PopArrayOfObjectPaths(std::vector<std::string>* object_paths); + bool PopArrayOfObjectPaths(std::vector<ObjectPath>* object_paths); // Gets the array of bytes at the current iterator position. It then parses // this binary blob into the protocol buffer supplied. @@ -436,7 +437,7 @@ class MessageReader { bool PopVariantOfUint64(uint64* value); bool PopVariantOfDouble(double* value); bool PopVariantOfString(std::string* value); - bool PopVariantOfObjectPath(std::string* value); + bool PopVariantOfObjectPath(ObjectPath* value); // Get the data type of the value at the current iterator // position. INVALID_DATA will be returned if the iterator points to the diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc index 1e6d668..a40ba0aa 100644 --- a/dbus/message_unittest.cc +++ b/dbus/message_unittest.cc @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" +#include "dbus/object_path.h" #include "dbus/test_proto.pb.h" #include "testing/gtest/include/gtest/gtest.h" @@ -50,7 +51,7 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { writer.AppendUint64(7); writer.AppendDouble(8.0); writer.AppendString("string"); - writer.AppendObjectPath("/object/path"); + writer.AppendObjectPath(dbus::ObjectPath("/object/path")); uint8 byte_value = 0; bool bool_value = false; @@ -62,7 +63,7 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { uint64 uint64_value = 0; double double_value = 0; std::string string_value; - std::string object_path_value; + dbus::ObjectPath object_path_value; dbus::MessageReader reader(message.get()); ASSERT_TRUE(reader.HasMoreData()); @@ -90,7 +91,7 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { EXPECT_EQ(7U, uint64_value); EXPECT_DOUBLE_EQ(8.0, double_value); EXPECT_EQ("string", string_value); - EXPECT_EQ("/object/path", object_path_value); + EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); } // Check all variant types can be properly written and read. @@ -109,7 +110,7 @@ TEST(MessageTest, AppendAndPopVariantDataTypes) { writer.AppendVariantOfUint64(7); writer.AppendVariantOfDouble(8.0); writer.AppendVariantOfString("string"); - writer.AppendVariantOfObjectPath("/object/path"); + writer.AppendVariantOfObjectPath(dbus::ObjectPath("/object/path")); uint8 byte_value = 0; bool bool_value = false; @@ -121,7 +122,7 @@ TEST(MessageTest, AppendAndPopVariantDataTypes) { uint64 uint64_value = 0; double double_value = 0; std::string string_value; - std::string object_path_value; + dbus::ObjectPath object_path_value; dbus::MessageReader reader(message.get()); ASSERT_TRUE(reader.HasMoreData()); @@ -149,7 +150,7 @@ TEST(MessageTest, AppendAndPopVariantDataTypes) { EXPECT_EQ(7U, uint64_value); EXPECT_DOUBLE_EQ(8.0, double_value); EXPECT_EQ("string", string_value); - EXPECT_EQ("/object/path", object_path_value); + EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); } TEST(MessageTest, ArrayOfBytes) { @@ -211,20 +212,20 @@ TEST(MessageTest, ArrayOfStrings) { TEST(MessageTest, ArrayOfObjectPaths) { scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); dbus::MessageWriter writer(message.get()); - std::vector<std::string> object_paths; - object_paths.push_back("/object/path/1"); - object_paths.push_back("/object/path/2"); - object_paths.push_back("/object/path/3"); + std::vector<dbus::ObjectPath> object_paths; + object_paths.push_back(dbus::ObjectPath("/object/path/1")); + object_paths.push_back(dbus::ObjectPath("/object/path/2")); + object_paths.push_back(dbus::ObjectPath("/object/path/3")); writer.AppendArrayOfObjectPaths(object_paths); dbus::MessageReader reader(message.get()); - std::vector<std::string> output_object_paths; + std::vector<dbus::ObjectPath> output_object_paths; ASSERT_TRUE(reader.PopArrayOfObjectPaths(&output_object_paths)); ASSERT_FALSE(reader.HasMoreData()); ASSERT_EQ(3U, output_object_paths.size()); - EXPECT_EQ("/object/path/1", output_object_paths[0]); - EXPECT_EQ("/object/path/2", output_object_paths[1]); - EXPECT_EQ("/object/path/3", output_object_paths[2]); + EXPECT_EQ(dbus::ObjectPath("/object/path/1"), output_object_paths[0]); + EXPECT_EQ(dbus::ObjectPath("/object/path/2"), output_object_paths[1]); + EXPECT_EQ(dbus::ObjectPath("/object/path/3"), output_object_paths[2]); } TEST(MessageTest, ProtoBuf) { @@ -408,7 +409,7 @@ TEST(MessageTest, MethodCall) { EXPECT_EQ(dbus::Message::MESSAGE_METHOD_CALL, method_call.GetMessageType()); EXPECT_EQ("MESSAGE_METHOD_CALL", method_call.GetMessageTypeAsString()); method_call.SetDestination("com.example.Service"); - method_call.SetPath("/com/example/Object"); + method_call.SetPath(dbus::ObjectPath("/com/example/Object")); dbus::MessageWriter writer(&method_call); writer.AppendString("payload"); @@ -440,7 +441,7 @@ TEST(MessageTest, Signal) { EXPECT_TRUE(signal.raw_message() != NULL); EXPECT_EQ(dbus::Message::MESSAGE_SIGNAL, signal.GetMessageType()); EXPECT_EQ("MESSAGE_SIGNAL", signal.GetMessageTypeAsString()); - signal.SetPath("/com/example/Object"); + signal.SetPath(dbus::ObjectPath("/com/example/Object")); dbus::MessageWriter writer(&signal); writer.AppendString("payload"); @@ -513,7 +514,7 @@ TEST(MessageTest, GetAndSetHeaders) { scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); EXPECT_EQ("", message->GetDestination()); - EXPECT_EQ("", message->GetPath()); + EXPECT_EQ(dbus::ObjectPath(""), message->GetPath()); EXPECT_EQ("", message->GetInterface()); EXPECT_EQ("", message->GetMember()); EXPECT_EQ("", message->GetErrorName()); @@ -522,7 +523,7 @@ TEST(MessageTest, GetAndSetHeaders) { EXPECT_EQ(0U, message->GetReplySerial()); message->SetDestination("org.chromium.destination"); - message->SetPath("/org/chromium/path"); + message->SetPath(dbus::ObjectPath("/org/chromium/path")); message->SetInterface("org.chromium.interface"); message->SetMember("member"); message->SetErrorName("org.chromium.error"); @@ -531,7 +532,7 @@ TEST(MessageTest, GetAndSetHeaders) { message->SetReplySerial(456); EXPECT_EQ("org.chromium.destination", message->GetDestination()); - EXPECT_EQ("/org/chromium/path", message->GetPath()); + EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); EXPECT_EQ("org.chromium.interface", message->GetInterface()); EXPECT_EQ("member", message->GetMember()); EXPECT_EQ("org.chromium.error", message->GetErrorName()); diff --git a/dbus/mock_bus.h b/dbus/mock_bus.h index 31c1349..463790a 100644 --- a/dbus/mock_bus.h +++ b/dbus/mock_bus.h @@ -7,6 +7,7 @@ #pragma once #include "dbus/bus.h" +#include "dbus/object_path.h" #include "testing/gmock/include/gmock/gmock.h" namespace dbus { @@ -20,14 +21,14 @@ class MockBus : public Bus { virtual ~MockBus(); MOCK_METHOD2(GetObjectProxy, ObjectProxy*(const std::string& service_name, - const std::string& object_path)); + const ObjectPath& object_path)); MOCK_METHOD3(GetObjectProxyWithOptions, ObjectProxy*(const std::string& service_name, - const std::string& object_path, + const ObjectPath& object_path, int options)); MOCK_METHOD2(GetExportedObject, ExportedObject*( const std::string& service_name, - const std::string& object_path)); + const ObjectPath& object_path)); MOCK_METHOD0(ShutdownAndBlock, void()); MOCK_METHOD0(ShutdownOnDBusThreadAndBlock, void()); MOCK_METHOD0(Connect, bool()); @@ -50,11 +51,11 @@ class MockBus : public Bus { DBusError* error)); MOCK_METHOD2(RemoveMatch, void(const std::string& match_rule, DBusError* error)); - MOCK_METHOD4(TryRegisterObjectPath, bool(const std::string& object_path, + MOCK_METHOD4(TryRegisterObjectPath, bool(const ObjectPath& object_path, const DBusObjectPathVTable* vtable, void* user_data, DBusError* error)); - MOCK_METHOD1(UnregisterObjectPath, void(const std::string& object_path)); + MOCK_METHOD1(UnregisterObjectPath, void(const ObjectPath& object_path)); MOCK_METHOD2(PostTaskToOriginThread, void( const tracked_objects::Location& from_here, const base::Closure& task)); diff --git a/dbus/mock_exported_object.cc b/dbus/mock_exported_object.cc index 0fd4f2e..f49cd3d 100644 --- a/dbus/mock_exported_object.cc +++ b/dbus/mock_exported_object.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -8,7 +8,7 @@ namespace dbus { MockExportedObject::MockExportedObject(Bus* bus, const std::string& service_name, - const std::string& object_path) + const ObjectPath& object_path) : ExportedObject(bus, service_name, object_path) { } diff --git a/dbus/mock_exported_object.h b/dbus/mock_exported_object.h index 17a36d0..7deb111 100644 --- a/dbus/mock_exported_object.h +++ b/dbus/mock_exported_object.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -9,6 +9,7 @@ #include <string> #include "dbus/exported_object.h" +#include "dbus/object_path.h" #include "testing/gmock/include/gmock/gmock.h" namespace dbus { @@ -18,7 +19,7 @@ class MockExportedObject : public ExportedObject { public: MockExportedObject(Bus* bus, const std::string& service_name, - const std::string& object_path); + const ObjectPath& object_path); virtual ~MockExportedObject(); MOCK_METHOD3(ExportMethodAndBlock, diff --git a/dbus/mock_object_proxy.cc b/dbus/mock_object_proxy.cc index a7186bb..7e26f01 100644 --- a/dbus/mock_object_proxy.cc +++ b/dbus/mock_object_proxy.cc @@ -8,7 +8,7 @@ namespace dbus { MockObjectProxy::MockObjectProxy(Bus* bus, const std::string& service_name, - const std::string& object_path) + const ObjectPath& object_path) : ObjectProxy(bus, service_name, object_path, DEFAULT_OPTIONS) { } diff --git a/dbus/mock_object_proxy.h b/dbus/mock_object_proxy.h index b5d4477..a8a5791 100644 --- a/dbus/mock_object_proxy.h +++ b/dbus/mock_object_proxy.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -8,6 +8,7 @@ #include <string> +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "testing/gmock/include/gmock/gmock.h" @@ -18,7 +19,7 @@ class MockObjectProxy : public ObjectProxy { public: MockObjectProxy(Bus* bus, const std::string& service_name, - const std::string& object_path); + const ObjectPath& object_path); virtual ~MockObjectProxy(); MOCK_METHOD2(CallMethodAndBlock, Response*(MethodCall* method_call, diff --git a/dbus/mock_unittest.cc b/dbus/mock_unittest.cc index 022b03d..cf644df 100644 --- a/dbus/mock_unittest.cc +++ b/dbus/mock_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -11,6 +11,7 @@ #include "dbus/mock_bus.h" #include "dbus/mock_object_proxy.h" #include "dbus/mock_exported_object.h" +#include "dbus/object_path.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -31,9 +32,10 @@ class MockTest : public testing::Test { mock_bus_ = new dbus::MockBus(options); // Create a mock proxy. - mock_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(), - "org.chromium.TestService", - "/org/chromium/TestObject"); + mock_proxy_ = new dbus::MockObjectProxy( + mock_bus_.get(), + "org.chromium.TestService", + dbus::ObjectPath("/org/chromium/TestObject")); // Set an expectation so mock_proxy's CallMethodAndBlock() will use // CreateMockProxyResponse() to return responses. @@ -49,8 +51,9 @@ class MockTest : public testing::Test { // Set an expectation so mock_bus's GetObjectProxy() for the given // service name and the object path will return mock_proxy_. - EXPECT_CALL(*mock_bus_, GetObjectProxy("org.chromium.TestService", - "/org/chromium/TestObject")) + EXPECT_CALL(*mock_bus_, GetObjectProxy( + "org.chromium.TestService", + dbus::ObjectPath("/org/chromium/TestObject"))) .WillOnce(Return(mock_proxy_.get())); // ShutdownAndBlock() will be called in TearDown(). @@ -130,7 +133,7 @@ TEST_F(MockTest, CallMethodAndBlock) { // Get an object proxy from the mock bus. dbus::ObjectProxy* proxy = mock_bus_->GetObjectProxy( "org.chromium.TestService", - "/org/chromium/TestObject"); + dbus::ObjectPath("/org/chromium/TestObject")); // Create a method call. dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); @@ -159,7 +162,7 @@ TEST_F(MockTest, CallMethod) { // Get an object proxy from the mock bus. dbus::ObjectProxy* proxy = mock_bus_->GetObjectProxy( "org.chromium.TestService", - "/org/chromium/TestObject"); + dbus::ObjectPath("/org/chromium/TestObject")); // Create a method call. dbus::MethodCall method_call("org.chromium.TestInterface", "Echo"); diff --git a/dbus/object_path.cc b/dbus/object_path.cc new file mode 100644 index 0000000..2dda466 --- /dev/null +++ b/dbus/object_path.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2012 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. + +#include "dbus/object_path.h" + +namespace dbus { + +bool ObjectPath::operator<(const ObjectPath& that) const { + return value_ < that.value_; +} + +bool ObjectPath::operator==(const ObjectPath& that) const { + return value_ == that.value_; +} + +bool ObjectPath::operator!=(const ObjectPath& that) const { + return value_ != that.value_; +} + +} // namespace dbus diff --git a/dbus/object_path.h b/dbus/object_path.h new file mode 100644 index 0000000..59071da --- /dev/null +++ b/dbus/object_path.h @@ -0,0 +1,46 @@ +// Copyright (c) 2012 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 DBUS_OBJECT_PATH_H_ +#define DBUS_OBJECT_PATH_H_ +#pragma once + +#include <string> + +namespace dbus { + +// ObjectPath is a type used to distinguish D-Bus object paths from simple +// strings, especially since normal practice is that these should be only +// initialized from static constants or obtained from remote objects and no +// assumptions about their value made. +class ObjectPath { + public: + // Permit initialization without a value for passing to + // dbus::MessageReader::PopObjectPath to fill in and from std::string + // objects. + // + // The compiler synthesised copy constructor and assignment operator are + // sufficient for our needs, as is implicit initialization of a std::string + // from a string constant. + ObjectPath() {} + explicit ObjectPath(const std::string& value) : value_(value) {} + + // Retrieves value as a std::string. + const std::string& value() const { return value_; } + + // Permit sufficient comparison to allow an ObjectPath to be used as a + // key in a std::map. + bool operator<(const ObjectPath&) const; + + // Permit testing for equality, required for mocks to work and useful for + // observers. + bool operator==(const ObjectPath&) const; + bool operator!=(const ObjectPath&) const; + private: + std::string value_; +}; + +} // namespace dbus + +#endif // DBUS_OBJECT_PATH_H_ diff --git a/dbus/object_proxy.cc b/dbus/object_proxy.cc index 58d679c..32f6a60 100644 --- a/dbus/object_proxy.cc +++ b/dbus/object_proxy.cc @@ -13,6 +13,7 @@ #include "base/threading/thread.h" #include "base/threading/thread_restrictions.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "dbus/scoped_dbus_error.h" @@ -42,7 +43,7 @@ namespace dbus { ObjectProxy::ObjectProxy(Bus* bus, const std::string& service_name, - const std::string& object_path, + const ObjectPath& object_path, int options) : bus_(bus), service_name_(service_name), diff --git a/dbus/object_proxy.h b/dbus/object_proxy.h index 3da4e9b..3a9fab1 100644 --- a/dbus/object_proxy.h +++ b/dbus/object_proxy.h @@ -16,6 +16,7 @@ #include "base/memory/ref_counted.h" #include "base/string_piece.h" #include "base/time.h" +#include "dbus/object_path.h" namespace dbus { @@ -35,7 +36,7 @@ class ObjectProxy : public base::RefCountedThreadSafe<ObjectProxy> { // Bus::GetObjectProxyWithOptions() instead of this constructor. ObjectProxy(Bus* bus, const std::string& service_name, - const std::string& object_path, + const ObjectPath& object_path, int options); // Options to be OR-ed together when calling Bus::GetObjectProxyWithOptions(). @@ -196,7 +197,7 @@ class ObjectProxy : public base::RefCountedThreadSafe<ObjectProxy> { scoped_refptr<Bus> bus_; std::string service_name_; - std::string object_path_; + ObjectPath object_path_; // True if the message filter was added. bool filter_added_; diff --git a/dbus/test_service.cc b/dbus/test_service.cc index 714c09b..6454bb5 100644 --- a/dbus/test_service.cc +++ b/dbus/test_service.cc @@ -10,6 +10,7 @@ #include "dbus/bus.h" #include "dbus/exported_object.h" #include "dbus/message.h" +#include "dbus/object_path.h" namespace dbus { @@ -96,7 +97,7 @@ void TestService::SendTestSignalFromRootInternal(const std::string& message) { // Use "/" just like dbus-send does. ExportedObject* root_object = bus_->GetExportedObject("org.chromium.TestService", - "/"); + dbus::ObjectPath("/")); root_object->SendSignal(&signal); } @@ -125,7 +126,7 @@ void TestService::Run(MessageLoop* message_loop) { exported_object_ = bus_->GetExportedObject( "org.chromium.TestService", - "/org/chromium/TestObject"); + dbus::ObjectPath("/org/chromium/TestObject")); int num_methods = 0; exported_object_->ExportMethod( diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc index edc77b9..ff3c3c0 100644 --- a/net/base/network_change_notifier_linux.cc +++ b/net/base/network_change_notifier_linux.cc @@ -137,8 +137,8 @@ void NetworkManagerApi::Init() { // Ignore ServiceUnknown errors to avoid log spam: http://crbug.com/109696. dbus::ObjectProxy* proxy = system_bus_->GetObjectProxyWithOptions( - kNetworkManagerServiceName, kNetworkManagerPath, - dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); + kNetworkManagerServiceName, dbus::ObjectPath(kNetworkManagerPath), + dbus::ObjectProxy::IGNORE_SERVICE_UNKNOWN_ERRORS); // Get the initial state asynchronously. dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get"); diff --git a/net/base/network_change_notifier_linux_unittest.cc b/net/base/network_change_notifier_linux_unittest.cc index ecd48a5..d8513ce 100644 --- a/net/base/network_change_notifier_linux_unittest.cc +++ b/net/base/network_change_notifier_linux_unittest.cc @@ -10,6 +10,7 @@ #include "dbus/mock_bus.h" #include "dbus/mock_object_proxy.h" #include "dbus/message.h" +#include "dbus/object_path.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -41,9 +42,10 @@ class NetworkChangeNotifierLinuxTest : public testing::Test { options.bus_type = dbus::Bus::SYSTEM; mock_bus_ = new dbus::MockBus(options); - mock_object_proxy_ = new dbus::MockObjectProxy(mock_bus_.get(), - "service_name", - "service_path"); + mock_object_proxy_ = new dbus::MockObjectProxy( + mock_bus_.get(), + "service_name", + dbus::ObjectPath("service_path")); EXPECT_CALL(*mock_bus_, GetObjectProxyWithOptions(_, _, _)) .WillOnce(Return(mock_object_proxy_.get())); |