OLD | NEW |
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 "chromeos/dbus/bluetooth_manager_client.h" | 5 #include "chromeos/dbus/bluetooth_manager_client.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "chromeos/dbus/bluetooth_property.h" | 12 #include "chromeos/dbus/bluetooth_property.h" |
| 13 #include "chromeos/dbus/fake_old_bluetooth_manager_client.h" |
13 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
14 #include "dbus/message.h" | 15 #include "dbus/message.h" |
15 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
16 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 BluetoothManagerClient::Properties::Properties( | 22 BluetoothManagerClient::Properties::Properties( |
22 dbus::ObjectProxy* object_proxy, | 23 dbus::ObjectProxy* object_proxy, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 264 |
264 // Weak pointer factory for generating 'this' pointers that might live longer | 265 // Weak pointer factory for generating 'this' pointers that might live longer |
265 // than we do. | 266 // than we do. |
266 // Note: This should remain the last member so it'll be destroyed and | 267 // Note: This should remain the last member so it'll be destroyed and |
267 // invalidate its weak pointers before any other members are destroyed. | 268 // invalidate its weak pointers before any other members are destroyed. |
268 base::WeakPtrFactory<BluetoothManagerClientImpl> weak_ptr_factory_; | 269 base::WeakPtrFactory<BluetoothManagerClientImpl> weak_ptr_factory_; |
269 | 270 |
270 DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClientImpl); | 271 DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClientImpl); |
271 }; | 272 }; |
272 | 273 |
273 // The BluetoothManagerClient implementation used on Linux desktop, which does | |
274 // nothing. | |
275 class BluetoothManagerClientStubImpl : public BluetoothManagerClient { | |
276 public: | |
277 struct Properties : public BluetoothManagerClient::Properties { | |
278 explicit Properties(const PropertyChangedCallback& callback) | |
279 : BluetoothManagerClient::Properties(NULL, callback) { | |
280 } | |
281 | |
282 virtual ~Properties() { | |
283 } | |
284 | |
285 virtual void Get(dbus::PropertyBase* property, | |
286 dbus::PropertySet::GetCallback callback) OVERRIDE { | |
287 VLOG(1) << "Get " << property->name(); | |
288 callback.Run(false); | |
289 } | |
290 | |
291 virtual void GetAll() OVERRIDE { | |
292 VLOG(1) << "GetAll"; | |
293 } | |
294 | |
295 virtual void Set(dbus::PropertyBase* property, | |
296 dbus::PropertySet::SetCallback callback) OVERRIDE { | |
297 VLOG(1) << "Set " << property->name(); | |
298 callback.Run(false); | |
299 } | |
300 }; | |
301 | |
302 BluetoothManagerClientStubImpl() { | |
303 properties_.reset(new Properties(base::Bind( | |
304 &BluetoothManagerClientStubImpl::OnPropertyChanged, | |
305 base::Unretained(this)))); | |
306 | |
307 std::vector<dbus::ObjectPath> adapters; | |
308 adapters.push_back(dbus::ObjectPath("/fake/hci0")); | |
309 properties_->adapters.ReplaceValue(adapters); | |
310 } | |
311 | |
312 // BluetoothManagerClient override. | |
313 virtual void AddObserver(Observer* observer) OVERRIDE { | |
314 observers_.AddObserver(observer); | |
315 } | |
316 | |
317 // BluetoothManagerClient override. | |
318 virtual void RemoveObserver(Observer* observer) OVERRIDE { | |
319 observers_.RemoveObserver(observer); | |
320 } | |
321 | |
322 // BluetoothManagerClient override. | |
323 virtual Properties* GetProperties() OVERRIDE { | |
324 VLOG(1) << "GetProperties"; | |
325 return properties_.get(); | |
326 } | |
327 | |
328 // BluetoothManagerClient override. | |
329 virtual void DefaultAdapter(const AdapterCallback& callback) OVERRIDE { | |
330 VLOG(1) << "DefaultAdapter."; | |
331 callback.Run(dbus::ObjectPath("/fake/hci0"), true); | |
332 } | |
333 | |
334 // BluetoothManagerClient override. | |
335 virtual void FindAdapter(const std::string& address, | |
336 const AdapterCallback& callback) OVERRIDE { | |
337 VLOG(1) << "FindAdapter: " << address; | |
338 if (address == "hci0") | |
339 callback.Run(dbus::ObjectPath("/fake/hci0"), true); | |
340 else | |
341 callback.Run(dbus::ObjectPath(), false); | |
342 } | |
343 | |
344 private: | |
345 void OnPropertyChanged(const std::string& property_name) { | |
346 FOR_EACH_OBSERVER(BluetoothManagerClient::Observer, observers_, | |
347 ManagerPropertyChanged(property_name)); | |
348 } | |
349 | |
350 // List of observers interested in event notifications from us. | |
351 ObserverList<Observer> observers_; | |
352 | |
353 // Static properties we return. | |
354 scoped_ptr<Properties> properties_; | |
355 }; | |
356 | |
357 BluetoothManagerClient::BluetoothManagerClient() { | 274 BluetoothManagerClient::BluetoothManagerClient() { |
358 } | 275 } |
359 | 276 |
360 BluetoothManagerClient::~BluetoothManagerClient() { | 277 BluetoothManagerClient::~BluetoothManagerClient() { |
361 } | 278 } |
362 | 279 |
363 BluetoothManagerClient* BluetoothManagerClient::Create( | 280 BluetoothManagerClient* BluetoothManagerClient::Create( |
364 DBusClientImplementationType type, | 281 DBusClientImplementationType type, |
365 dbus::Bus* bus) { | 282 dbus::Bus* bus) { |
366 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 283 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
367 return new BluetoothManagerClientImpl(bus); | 284 return new BluetoothManagerClientImpl(bus); |
368 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 285 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
369 return new BluetoothManagerClientStubImpl(); | 286 return new FakeOldBluetoothManagerClient(); |
370 } | 287 } |
371 | 288 |
372 } // namespace chromeos | 289 } // namespace chromeos |
OLD | NEW |