OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/dbus/nfc_device_client.h" | 5 #include "chromeos/dbus/nfc_device_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 weak_ptr_factory_(this) { | 42 weak_ptr_factory_(this) { |
43 DCHECK(adapter_client); | 43 DCHECK(adapter_client); |
44 } | 44 } |
45 | 45 |
46 virtual ~NfcDeviceClientImpl() { | 46 virtual ~NfcDeviceClientImpl() { |
47 DCHECK(adapter_client_); | 47 DCHECK(adapter_client_); |
48 adapter_client_->RemoveObserver(this); | 48 adapter_client_->RemoveObserver(this); |
49 } | 49 } |
50 | 50 |
51 // NfcDeviceClient override. | 51 // NfcDeviceClient override. |
52 virtual void AddObserver(NfcDeviceClient::Observer* observer) OVERRIDE { | 52 virtual void AddObserver(NfcDeviceClient::Observer* observer) override { |
53 DCHECK(observer); | 53 DCHECK(observer); |
54 observers_.AddObserver(observer); | 54 observers_.AddObserver(observer); |
55 } | 55 } |
56 | 56 |
57 // NfcDeviceClient override. | 57 // NfcDeviceClient override. |
58 virtual void RemoveObserver(NfcDeviceClient::Observer* observer) OVERRIDE { | 58 virtual void RemoveObserver(NfcDeviceClient::Observer* observer) override { |
59 DCHECK(observer); | 59 DCHECK(observer); |
60 observers_.RemoveObserver(observer); | 60 observers_.RemoveObserver(observer); |
61 } | 61 } |
62 | 62 |
63 // NfcDeviceClient override. | 63 // NfcDeviceClient override. |
64 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( | 64 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( |
65 const dbus::ObjectPath& adapter_path) OVERRIDE { | 65 const dbus::ObjectPath& adapter_path) override { |
66 DBusObjectMap* object_map = | 66 DBusObjectMap* object_map = |
67 adapters_to_object_maps_.GetObjectMap(adapter_path); | 67 adapters_to_object_maps_.GetObjectMap(adapter_path); |
68 if (!object_map) | 68 if (!object_map) |
69 return std::vector<dbus::ObjectPath>(); | 69 return std::vector<dbus::ObjectPath>(); |
70 return object_map->GetObjectPaths(); | 70 return object_map->GetObjectPaths(); |
71 } | 71 } |
72 | 72 |
73 // NfcDeviceClient override. | 73 // NfcDeviceClient override. |
74 virtual Properties* GetProperties( | 74 virtual Properties* GetProperties( |
75 const dbus::ObjectPath& object_path) OVERRIDE { | 75 const dbus::ObjectPath& object_path) override { |
76 return static_cast<Properties*>( | 76 return static_cast<Properties*>( |
77 adapters_to_object_maps_.FindObjectProperties(object_path)); | 77 adapters_to_object_maps_.FindObjectProperties(object_path)); |
78 } | 78 } |
79 | 79 |
80 // NfcDeviceClient override. | 80 // NfcDeviceClient override. |
81 virtual void Push( | 81 virtual void Push( |
82 const dbus::ObjectPath& object_path, | 82 const dbus::ObjectPath& object_path, |
83 const base::DictionaryValue& attributes, | 83 const base::DictionaryValue& attributes, |
84 const base::Closure& callback, | 84 const base::Closure& callback, |
85 const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE { | 85 const nfc_client_helpers::ErrorCallback& error_callback) override { |
86 dbus::ObjectProxy* object_proxy = | 86 dbus::ObjectProxy* object_proxy = |
87 adapters_to_object_maps_.FindObjectProxy(object_path); | 87 adapters_to_object_maps_.FindObjectProxy(object_path); |
88 if (!object_proxy) { | 88 if (!object_proxy) { |
89 std::string error_message = | 89 std::string error_message = |
90 base::StringPrintf( | 90 base::StringPrintf( |
91 "NFC device with object path \"%s\" does not exist.", | 91 "NFC device with object path \"%s\" does not exist.", |
92 object_path.value().c_str()); | 92 object_path.value().c_str()); |
93 LOG(ERROR) << error_message; | 93 LOG(ERROR) << error_message; |
94 error_callback.Run(nfc_client_helpers::kUnknownObjectError, | 94 error_callback.Run(nfc_client_helpers::kUnknownObjectError, |
95 error_message); | 95 error_message); |
(...skipping 17 matching lines...) Expand all Loading... |
113 | 113 |
114 object_proxy->CallMethodWithErrorCallback( | 114 object_proxy->CallMethodWithErrorCallback( |
115 &method_call, | 115 &method_call, |
116 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 116 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
117 base::Bind(&nfc_client_helpers::OnSuccess, callback), | 117 base::Bind(&nfc_client_helpers::OnSuccess, callback), |
118 base::Bind(&nfc_client_helpers::OnError, error_callback)); | 118 base::Bind(&nfc_client_helpers::OnError, error_callback)); |
119 } | 119 } |
120 | 120 |
121 protected: | 121 protected: |
122 // DBusClient override. | 122 // DBusClient override. |
123 virtual void Init(dbus::Bus* bus) OVERRIDE { | 123 virtual void Init(dbus::Bus* bus) override { |
124 VLOG(1) << "Creating NfcDeviceClientImpl"; | 124 VLOG(1) << "Creating NfcDeviceClientImpl"; |
125 DCHECK(bus); | 125 DCHECK(bus); |
126 bus_ = bus; | 126 bus_ = bus; |
127 DCHECK(adapter_client_); | 127 DCHECK(adapter_client_); |
128 adapter_client_->AddObserver(this); | 128 adapter_client_->AddObserver(this); |
129 } | 129 } |
130 | 130 |
131 private: | 131 private: |
132 // NfcAdapterClient::Observer override. | 132 // NfcAdapterClient::Observer override. |
133 virtual void AdapterAdded(const dbus::ObjectPath& object_path) OVERRIDE { | 133 virtual void AdapterAdded(const dbus::ObjectPath& object_path) override { |
134 VLOG(1) << "Adapter added. Creating map for device proxies belonging to " | 134 VLOG(1) << "Adapter added. Creating map for device proxies belonging to " |
135 << "adapter: " << object_path.value(); | 135 << "adapter: " << object_path.value(); |
136 adapters_to_object_maps_.CreateObjectMap( | 136 adapters_to_object_maps_.CreateObjectMap( |
137 object_path, nfc_device::kNfcDeviceServiceName, this, bus_); | 137 object_path, nfc_device::kNfcDeviceServiceName, this, bus_); |
138 } | 138 } |
139 | 139 |
140 // NfcAdapterClient::Observer override. | 140 // NfcAdapterClient::Observer override. |
141 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) OVERRIDE { | 141 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) override { |
142 // Neard doesn't send out property changed signals for the devices that | 142 // Neard doesn't send out property changed signals for the devices that |
143 // are removed when the adapter they belong to is removed. Clean up the | 143 // are removed when the adapter they belong to is removed. Clean up the |
144 // object proxies for devices that are managed by the removed adapter. | 144 // object proxies for devices that are managed by the removed adapter. |
145 // Note: DBusObjectMap guarantees that the Properties structure for the | 145 // Note: DBusObjectMap guarantees that the Properties structure for the |
146 // removed adapter will be valid before this method returns. | 146 // removed adapter will be valid before this method returns. |
147 VLOG(1) << "Adapter removed. Cleaning up device proxies belonging to " | 147 VLOG(1) << "Adapter removed. Cleaning up device proxies belonging to " |
148 << "adapter: " << object_path.value(); | 148 << "adapter: " << object_path.value(); |
149 adapters_to_object_maps_.RemoveObjectMap(object_path); | 149 adapters_to_object_maps_.RemoveObjectMap(object_path); |
150 } | 150 } |
151 | 151 |
152 // NfcAdapterClient::Observer override. | 152 // NfcAdapterClient::Observer override. |
153 virtual void AdapterPropertyChanged( | 153 virtual void AdapterPropertyChanged( |
154 const dbus::ObjectPath& object_path, | 154 const dbus::ObjectPath& object_path, |
155 const std::string& property_name) OVERRIDE { | 155 const std::string& property_name) override { |
156 DCHECK(adapter_client_); | 156 DCHECK(adapter_client_); |
157 NfcAdapterClient::Properties *adapter_properties = | 157 NfcAdapterClient::Properties *adapter_properties = |
158 adapter_client_->GetProperties(object_path); | 158 adapter_client_->GetProperties(object_path); |
159 DCHECK(adapter_properties); | 159 DCHECK(adapter_properties); |
160 | 160 |
161 // Ignore changes to properties other than "Devices". | 161 // Ignore changes to properties other than "Devices". |
162 if (property_name != adapter_properties->devices.name()) | 162 if (property_name != adapter_properties->devices.name()) |
163 return; | 163 return; |
164 | 164 |
165 // Update the known devices. | 165 // Update the known devices. |
166 VLOG(1) << "NFC devices changed."; | 166 VLOG(1) << "NFC devices changed."; |
167 const std::vector<dbus::ObjectPath>& received_devices = | 167 const std::vector<dbus::ObjectPath>& received_devices = |
168 adapter_properties->devices.value(); | 168 adapter_properties->devices.value(); |
169 DBusObjectMap* object_map = | 169 DBusObjectMap* object_map = |
170 adapters_to_object_maps_.GetObjectMap(object_path); | 170 adapters_to_object_maps_.GetObjectMap(object_path); |
171 DCHECK(object_map); | 171 DCHECK(object_map); |
172 object_map->UpdateObjects(received_devices); | 172 object_map->UpdateObjects(received_devices); |
173 } | 173 } |
174 | 174 |
175 // nfc_client_helpers::DBusObjectMap::Delegate override. | 175 // nfc_client_helpers::DBusObjectMap::Delegate override. |
176 virtual NfcPropertySet* CreateProperties( | 176 virtual NfcPropertySet* CreateProperties( |
177 dbus::ObjectProxy* object_proxy) OVERRIDE { | 177 dbus::ObjectProxy* object_proxy) override { |
178 return new Properties( | 178 return new Properties( |
179 object_proxy, | 179 object_proxy, |
180 base::Bind(&NfcDeviceClientImpl::OnPropertyChanged, | 180 base::Bind(&NfcDeviceClientImpl::OnPropertyChanged, |
181 weak_ptr_factory_.GetWeakPtr(), | 181 weak_ptr_factory_.GetWeakPtr(), |
182 object_proxy->object_path())); | 182 object_proxy->object_path())); |
183 } | 183 } |
184 | 184 |
185 // nfc_client_helpers::DBusObjectMap::Delegate override. | 185 // nfc_client_helpers::DBusObjectMap::Delegate override. |
186 virtual void ObjectAdded(const dbus::ObjectPath& object_path) OVERRIDE { | 186 virtual void ObjectAdded(const dbus::ObjectPath& object_path) override { |
187 FOR_EACH_OBSERVER(NfcDeviceClient::Observer, observers_, | 187 FOR_EACH_OBSERVER(NfcDeviceClient::Observer, observers_, |
188 DeviceAdded(object_path)); | 188 DeviceAdded(object_path)); |
189 } | 189 } |
190 | 190 |
191 virtual void ObjectRemoved(const dbus::ObjectPath& object_path) OVERRIDE { | 191 virtual void ObjectRemoved(const dbus::ObjectPath& object_path) override { |
192 FOR_EACH_OBSERVER(NfcDeviceClient::Observer, observers_, | 192 FOR_EACH_OBSERVER(NfcDeviceClient::Observer, observers_, |
193 DeviceRemoved(object_path)); | 193 DeviceRemoved(object_path)); |
194 } | 194 } |
195 | 195 |
196 // Called by NfcPropertySet when a property value is changed, either by | 196 // Called by NfcPropertySet when a property value is changed, either by |
197 // result of a signal or response to a GetAll() or Get() call. | 197 // result of a signal or response to a GetAll() or Get() call. |
198 void OnPropertyChanged(const dbus::ObjectPath& object_path, | 198 void OnPropertyChanged(const dbus::ObjectPath& object_path, |
199 const std::string& property_name) { | 199 const std::string& property_name) { |
200 VLOG(1) << "Device property changed; Path: " << object_path.value() | 200 VLOG(1) << "Device property changed; Path: " << object_path.value() |
201 << " Property: " << property_name; | 201 << " Property: " << property_name; |
(...skipping 29 matching lines...) Expand all Loading... |
231 } | 231 } |
232 | 232 |
233 NfcDeviceClient::~NfcDeviceClient() { | 233 NfcDeviceClient::~NfcDeviceClient() { |
234 } | 234 } |
235 | 235 |
236 NfcDeviceClient* NfcDeviceClient::Create(NfcAdapterClient* adapter_client) { | 236 NfcDeviceClient* NfcDeviceClient::Create(NfcAdapterClient* adapter_client) { |
237 return new NfcDeviceClientImpl(adapter_client); | 237 return new NfcDeviceClientImpl(adapter_client); |
238 } | 238 } |
239 | 239 |
240 } // namespace chromeos | 240 } // namespace chromeos |
OLD | NEW |