Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: chrome/browser/chromeos/dbus/bluetooth_device_client.cc

Issue 9363045: Revert 121920 - dbus: add ObjectPath type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h" 5 #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" 12 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h"
13 #include "chrome/browser/chromeos/system/runtime_environment.h" 13 #include "chrome/browser/chromeos/system/runtime_environment.h"
14 #include "dbus/bus.h" 14 #include "dbus/bus.h"
15 #include "dbus/message.h" 15 #include "dbus/message.h"
16 #include "dbus/object_path.h"
17 #include "dbus/object_proxy.h" 16 #include "dbus/object_proxy.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h" 17 #include "third_party/cros_system_api/dbus/service_constants.h"
19 18
20 namespace chromeos { 19 namespace chromeos {
21 20
22 // The BluetoothDeviceClient implementation used in production. 21 // The BluetoothDeviceClient implementation used in production.
23 class BluetoothDeviceClientImpl: public BluetoothDeviceClient, 22 class BluetoothDeviceClientImpl: public BluetoothDeviceClient,
24 private BluetoothAdapterClient::Observer { 23 private BluetoothAdapterClient::Observer {
25 public: 24 public:
26 BluetoothDeviceClientImpl(dbus::Bus* bus, 25 BluetoothDeviceClientImpl(dbus::Bus* bus,
(...skipping 20 matching lines...) Expand all
47 // BluetoothDeviceClient override. 46 // BluetoothDeviceClient override.
48 virtual void RemoveObserver(BluetoothDeviceClient::Observer* observer) 47 virtual void RemoveObserver(BluetoothDeviceClient::Observer* observer)
49 OVERRIDE { 48 OVERRIDE {
50 VLOG(1) << "RemoveObserver"; 49 VLOG(1) << "RemoveObserver";
51 DCHECK(observer); 50 DCHECK(observer);
52 observers_.RemoveObserver(observer); 51 observers_.RemoveObserver(observer);
53 } 52 }
54 53
55 private: 54 private:
56 // BluetoothAdapterClient::Observer override. 55 // BluetoothAdapterClient::Observer override.
57 virtual void DeviceCreated(const dbus::ObjectPath& adapter_path, 56 virtual void DeviceCreated(const std::string& adapter_path,
58 const dbus::ObjectPath& object_path) OVERRIDE { 57 const std::string& object_path) OVERRIDE {
59 VLOG(1) << "DeviceCreated: " << object_path.value(); 58 VLOG(1) << "DeviceCreated: " << object_path;
60 } 59 }
61 60
62 // BluetoothAdapterClient::Observer override. 61 // BluetoothAdapterClient::Observer override.
63 virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path, 62 virtual void DeviceRemoved(const std::string& adapter_path,
64 const dbus::ObjectPath& object_path) OVERRIDE { 63 const std::string& object_path) OVERRIDE {
65 VLOG(1) << "DeviceRemoved: " << object_path.value(); 64 VLOG(1) << "DeviceRemoved: " << object_path;
66 RemoveObjectProxyForPath(object_path); 65 RemoveObjectProxyForPath(object_path);
67 } 66 }
68 67
69 // Ensures that we have a dbus object proxy for a device with dbus 68 // Ensures that we have a dbus object proxy for a device with dbus
70 // object path |object_path|, and if not, creates it stores it in 69 // object path |object_path|, and if not, creates it stores it in
71 // our |proxy_map_| map. 70 // our |proxy_map_| map.
72 dbus::ObjectProxy* GetObjectProxyForPath( 71 dbus::ObjectProxy* GetObjectProxyForPath(const std::string& object_path) {
73 const dbus::ObjectPath& object_path) { 72 VLOG(1) << "GetObjectProxyForPath: " << object_path;
74 VLOG(1) << "GetObjectProxyForPath: " << object_path.value();
75 73
76 ProxyMap::iterator it = proxy_map_.find(object_path); 74 ProxyMap::iterator it = proxy_map_.find(object_path);
77 if (it != proxy_map_.end()) 75 if (it != proxy_map_.end())
78 return it->second; 76 return it->second;
79 77
80 DCHECK(bus_); 78 DCHECK(bus_);
81 dbus::ObjectProxy* device_proxy = bus_->GetObjectProxy( 79 dbus::ObjectProxy* device_proxy = bus_->GetObjectProxy(
82 bluetooth_device::kBluetoothDeviceServiceName, object_path); 80 bluetooth_device::kBluetoothDeviceServiceName, object_path);
83 81
84 proxy_map_[object_path] = device_proxy; 82 proxy_map_[object_path] = device_proxy;
85 83
86 return device_proxy; 84 return device_proxy;
87 } 85 }
88 86
89 // Removes the dbus object proxy for the device with dbus object path 87 // Removes the dbus object proxy for the device with dbus object path
90 // |object_path| from our |proxy_map_| map. 88 // |object_path| from our |proxy_map_| map.
91 void RemoveObjectProxyForPath(const dbus::ObjectPath& object_path) { 89 void RemoveObjectProxyForPath(const std::string& object_path) {
92 VLOG(1) << "RemoveObjectProxyForPath: " << object_path.value(); 90 VLOG(1) << "RemoveObjectProxyForPath: " << object_path;
93 proxy_map_.erase(object_path); 91 proxy_map_.erase(object_path);
94 } 92 }
95 93
96 // Weak pointer factory for generating 'this' pointers that might live longer 94 // Weak pointer factory for generating 'this' pointers that might live longer
97 // than we do. 95 // than we do.
98 base::WeakPtrFactory<BluetoothDeviceClientImpl> weak_ptr_factory_; 96 base::WeakPtrFactory<BluetoothDeviceClientImpl> weak_ptr_factory_;
99 97
100 dbus::Bus* bus_; 98 dbus::Bus* bus_;
101 99
102 // We maintain a collection of dbus object proxies, one for each device. 100 // We maintain a collection of dbus object proxies, one for each device.
103 typedef std::map<const dbus::ObjectPath, dbus::ObjectProxy*> ProxyMap; 101 typedef std::map<const std::string, dbus::ObjectProxy*> ProxyMap;
104 ProxyMap proxy_map_; 102 ProxyMap proxy_map_;
105 103
106 // List of observers interested in event notifications from us. 104 // List of observers interested in event notifications from us.
107 ObserverList<BluetoothDeviceClient::Observer> observers_; 105 ObserverList<BluetoothDeviceClient::Observer> observers_;
108 106
109 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); 107 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl);
110 }; 108 };
111 109
112 // The BluetoothDeviceClient implementation used on Linux desktop, which does 110 // The BluetoothDeviceClient implementation used on Linux desktop, which does
113 // nothing. 111 // nothing.
(...skipping 20 matching lines...) Expand all
134 dbus::Bus* bus, 132 dbus::Bus* bus,
135 BluetoothAdapterClient* adapter_client) { 133 BluetoothAdapterClient* adapter_client) {
136 if (system::runtime_environment::IsRunningOnChromeOS()) { 134 if (system::runtime_environment::IsRunningOnChromeOS()) {
137 return new BluetoothDeviceClientImpl(bus, adapter_client); 135 return new BluetoothDeviceClientImpl(bus, adapter_client);
138 } else { 136 } else {
139 return new BluetoothDeviceClientStubImpl(); 137 return new BluetoothDeviceClientStubImpl();
140 } 138 }
141 } 139 }
142 140
143 } // namespace chromeos 141 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/bluetooth_adapter_client.cc ('k') | chrome/browser/chromeos/dbus/bluetooth_manager_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698