OLD | NEW |
1 // Copyright (c) 2011 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/bluetooth/bluetooth_manager.h" | 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 10 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
11 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" | 11 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" |
12 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 12 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "dbus/object_path.h" |
13 | 14 |
14 namespace chromeos { | 15 namespace chromeos { |
15 | 16 |
16 static BluetoothManager* g_bluetooth_manager = NULL; | 17 static BluetoothManager* g_bluetooth_manager = NULL; |
17 | 18 |
18 class BluetoothManagerImpl : public BluetoothManager, | 19 class BluetoothManagerImpl : public BluetoothManager, |
19 public BluetoothManagerClient::Observer { | 20 public BluetoothManagerClient::Observer { |
20 public: | 21 public: |
21 BluetoothManagerImpl() : weak_ptr_factory_(this) { | 22 BluetoothManagerImpl() : weak_ptr_factory_(this) { |
22 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); | 23 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); |
(...skipping 20 matching lines...) Expand all Loading... |
43 DCHECK(observer); | 44 DCHECK(observer); |
44 observers_.RemoveObserver(observer); | 45 observers_.RemoveObserver(observer); |
45 } | 46 } |
46 | 47 |
47 virtual BluetoothAdapter* DefaultAdapter() { | 48 virtual BluetoothAdapter* DefaultAdapter() { |
48 VLOG(1) << "BluetoothManager::DefaultAdapter"; | 49 VLOG(1) << "BluetoothManager::DefaultAdapter"; |
49 return default_adapter_.get(); | 50 return default_adapter_.get(); |
50 } | 51 } |
51 | 52 |
52 // BluetoothManagerClient::Observer override. | 53 // BluetoothManagerClient::Observer override. |
53 virtual void AdapterRemoved(const std::string& adapter) { | 54 virtual void AdapterRemoved(const dbus::ObjectPath& adapter) { |
54 VLOG(1) << "AdapterRemoved: " << adapter; | 55 VLOG(1) << "AdapterRemoved: " << adapter.value(); |
55 if (default_adapter_.get() == NULL || default_adapter_->Id() != adapter) { | 56 if (default_adapter_.get() == NULL |
| 57 || default_adapter_->Id() != adapter.value()) { |
56 return; | 58 return; |
57 } | 59 } |
58 // The default adapter was removed. | 60 // The default adapter was removed. |
59 default_adapter_.reset(); | 61 default_adapter_.reset(); |
60 FOR_EACH_OBSERVER(BluetoothManager::Observer, observers_, | 62 FOR_EACH_OBSERVER(BluetoothManager::Observer, observers_, |
61 DefaultAdapterChanged(default_adapter_.get())); | 63 DefaultAdapterChanged(default_adapter_.get())); |
62 } | 64 } |
63 | 65 |
64 // BluetoothManagerClient::Observer override. | 66 // BluetoothManagerClient::Observer override. |
65 virtual void DefaultAdapterChanged(const std::string& adapter) { | 67 virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter) { |
66 VLOG(1) << "DefaultAdapterChanged: " << adapter; | 68 VLOG(1) << "DefaultAdapterChanged: " << adapter.value(); |
67 OnNewDefaultAdapter(adapter); | 69 OnNewDefaultAdapter(adapter); |
68 } | 70 } |
69 | 71 |
70 private: | 72 private: |
71 virtual ~BluetoothManagerImpl() { | 73 virtual ~BluetoothManagerImpl() { |
72 bluetooth_manager_client_->RemoveObserver(this); | 74 bluetooth_manager_client_->RemoveObserver(this); |
73 } | 75 } |
74 | 76 |
75 // We have updated info about the default adapter. | 77 // We have updated info about the default adapter. |
76 void OnNewDefaultAdapter(const std::string& adapter) { | 78 void OnNewDefaultAdapter(const dbus::ObjectPath& adapter) { |
77 VLOG(1) << "OnNewDefaultAdapter: " << adapter; | 79 VLOG(1) << "OnNewDefaultAdapter: " << adapter.value(); |
78 if (default_adapter_.get() != NULL && default_adapter_->Id() == adapter) { | 80 if (default_adapter_.get() != NULL |
| 81 && default_adapter_->Id() == adapter.value()) { |
79 return; | 82 return; |
80 } | 83 } |
81 default_adapter_.reset(BluetoothAdapter::Create(adapter)); | 84 default_adapter_.reset(BluetoothAdapter::Create(adapter.value())); |
82 DCHECK(default_adapter_.get()); | 85 DCHECK(default_adapter_.get()); |
83 FOR_EACH_OBSERVER(BluetoothManager::Observer, observers_, | 86 FOR_EACH_OBSERVER(BluetoothManager::Observer, observers_, |
84 DefaultAdapterChanged(default_adapter_.get())); | 87 DefaultAdapterChanged(default_adapter_.get())); |
85 } | 88 } |
86 | 89 |
87 // Called by bluetooth_manager_client when our DefaultAdapter request is | 90 // Called by bluetooth_manager_client when our DefaultAdapter request is |
88 // complete | 91 // complete |
89 void OnDefaultAdapter(const std::string& adapter, bool success) { | 92 void OnDefaultAdapter(const dbus::ObjectPath& adapter, bool success) { |
90 if (!success) { | 93 if (!success) { |
91 LOG(ERROR) << "OnDefaultAdapter: failed."; | 94 LOG(ERROR) << "OnDefaultAdapter: failed."; |
92 return; | 95 return; |
93 } | 96 } |
94 VLOG(1) << "OnDefaultAdapter: " << adapter; | 97 VLOG(1) << "OnDefaultAdapter: " << adapter.value(); |
95 OnNewDefaultAdapter(adapter); | 98 OnNewDefaultAdapter(adapter); |
96 } | 99 } |
97 | 100 |
98 base::WeakPtrFactory<BluetoothManagerImpl> weak_ptr_factory_; | 101 base::WeakPtrFactory<BluetoothManagerImpl> weak_ptr_factory_; |
99 | 102 |
100 // Owned by the dbus thread manager. Storing this is ok only because our | 103 // Owned by the dbus thread manager. Storing this is ok only because our |
101 // lifetime is a subset of the thread manager's lifetime. | 104 // lifetime is a subset of the thread manager's lifetime. |
102 BluetoothManagerClient* bluetooth_manager_client_; | 105 BluetoothManagerClient* bluetooth_manager_client_; |
103 | 106 |
104 ObserverList<BluetoothManager::Observer> observers_; | 107 ObserverList<BluetoothManager::Observer> observers_; |
(...skipping 26 matching lines...) Expand all Loading... |
131 g_bluetooth_manager = NULL; | 134 g_bluetooth_manager = NULL; |
132 } | 135 } |
133 } | 136 } |
134 | 137 |
135 // static | 138 // static |
136 BluetoothManager* BluetoothManager::GetInstance() { | 139 BluetoothManager* BluetoothManager::GetInstance() { |
137 return g_bluetooth_manager; | 140 return g_bluetooth_manager; |
138 } | 141 } |
139 | 142 |
140 } // namespace chromeos | 143 } // namespace chromeos |
OLD | NEW |