OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/bluetooth/bluetooth_private_api.h" | 5 #include "extensions/browser/api/bluetooth/bluetooth_private_api.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "components/device_event_log/device_event_log.h" |
15 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
16 #include "device/bluetooth/bluetooth_adapter_factory.h" | 17 #include "device/bluetooth/bluetooth_adapter_factory.h" |
17 #include "device/bluetooth/bluetooth_common.h" | 18 #include "device/bluetooth/bluetooth_common.h" |
18 #include "device/bluetooth/bluetooth_discovery_session.h" | 19 #include "device/bluetooth/bluetooth_discovery_session.h" |
19 #include "extensions/browser/api/bluetooth/bluetooth_api.h" | 20 #include "extensions/browser/api/bluetooth/bluetooth_api.h" |
20 #include "extensions/browser/api/bluetooth/bluetooth_api_pairing_delegate.h" | 21 #include "extensions/browser/api/bluetooth/bluetooth_api_pairing_delegate.h" |
21 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" | 22 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" |
22 #include "extensions/common/api/bluetooth_private.h" | 23 #include "extensions/common/api/bluetooth_private.h" |
23 | 24 |
24 namespace bt_private = extensions::api::bluetooth_private; | 25 namespace bt_private = extensions::api::bluetooth_private; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 156 } |
156 | 157 |
157 const bt_private::NewAdapterState& new_state = params->adapter_state; | 158 const bt_private::NewAdapterState& new_state = params->adapter_state; |
158 | 159 |
159 // These properties are not owned. | 160 // These properties are not owned. |
160 std::string* name = new_state.name.get(); | 161 std::string* name = new_state.name.get(); |
161 bool* powered = new_state.powered.get(); | 162 bool* powered = new_state.powered.get(); |
162 bool* discoverable = new_state.discoverable.get(); | 163 bool* discoverable = new_state.discoverable.get(); |
163 | 164 |
164 if (name && adapter->GetName() != *name) { | 165 if (name && adapter->GetName() != *name) { |
| 166 BLUETOOTH_LOG(USER) << "SetAdapterState: name=" << *name; |
165 pending_properties_.insert(kNameProperty); | 167 pending_properties_.insert(kNameProperty); |
166 adapter->SetName(*name, CreatePropertySetCallback(kNameProperty), | 168 adapter->SetName(*name, CreatePropertySetCallback(kNameProperty), |
167 CreatePropertyErrorCallback(kNameProperty)); | 169 CreatePropertyErrorCallback(kNameProperty)); |
168 } | 170 } |
169 | 171 |
170 if (powered && adapter->IsPowered() != *powered) { | 172 if (powered && adapter->IsPowered() != *powered) { |
| 173 BLUETOOTH_LOG(USER) << "SetAdapterState: powerd=" << *powered; |
171 pending_properties_.insert(kPoweredProperty); | 174 pending_properties_.insert(kPoweredProperty); |
172 adapter->SetPowered(*powered, CreatePropertySetCallback(kPoweredProperty), | 175 adapter->SetPowered(*powered, CreatePropertySetCallback(kPoweredProperty), |
173 CreatePropertyErrorCallback(kPoweredProperty)); | 176 CreatePropertyErrorCallback(kPoweredProperty)); |
174 } | 177 } |
175 | 178 |
176 if (discoverable && adapter->IsDiscoverable() != *discoverable) { | 179 if (discoverable && adapter->IsDiscoverable() != *discoverable) { |
| 180 BLUETOOTH_LOG(USER) << "SetAdapterState: discoverable=" << *discoverable; |
177 pending_properties_.insert(kDiscoverableProperty); | 181 pending_properties_.insert(kDiscoverableProperty); |
178 adapter->SetDiscoverable( | 182 adapter->SetDiscoverable( |
179 *discoverable, CreatePropertySetCallback(kDiscoverableProperty), | 183 *discoverable, CreatePropertySetCallback(kDiscoverableProperty), |
180 CreatePropertyErrorCallback(kDiscoverableProperty)); | 184 CreatePropertyErrorCallback(kDiscoverableProperty)); |
181 } | 185 } |
182 | 186 |
183 parsed_ = true; | 187 parsed_ = true; |
184 | 188 |
185 if (pending_properties_.empty()) | 189 if (pending_properties_.empty()) |
186 SendResponse(true); | 190 SendResponse(true); |
187 return true; | 191 return true; |
188 } | 192 } |
189 | 193 |
190 base::Closure | 194 base::Closure |
191 BluetoothPrivateSetAdapterStateFunction::CreatePropertySetCallback( | 195 BluetoothPrivateSetAdapterStateFunction::CreatePropertySetCallback( |
192 const std::string& property_name) { | 196 const std::string& property_name) { |
| 197 BLUETOOTH_LOG(DEBUG) << "Set property succeeded: " << property_name; |
193 return base::Bind( | 198 return base::Bind( |
194 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet, this, | 199 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet, this, |
195 property_name); | 200 property_name); |
196 } | 201 } |
197 | 202 |
198 base::Closure | 203 base::Closure |
199 BluetoothPrivateSetAdapterStateFunction::CreatePropertyErrorCallback( | 204 BluetoothPrivateSetAdapterStateFunction::CreatePropertyErrorCallback( |
200 const std::string& property_name) { | 205 const std::string& property_name) { |
| 206 BLUETOOTH_LOG(DEBUG) << "Set property failed: " << property_name; |
201 return base::Bind( | 207 return base::Bind( |
202 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertyError, this, | 208 &BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertyError, this, |
203 property_name); | 209 property_name); |
204 } | 210 } |
205 | 211 |
206 void BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet( | 212 void BluetoothPrivateSetAdapterStateFunction::OnAdapterPropertySet( |
207 const std::string& property) { | 213 const std::string& property) { |
208 DCHECK(pending_properties_.find(property) != pending_properties_.end()); | 214 DCHECK(pending_properties_.find(property) != pending_properties_.end()); |
209 DCHECK(failed_properties_.find(property) == failed_properties_.end()); | 215 DCHECK(failed_properties_.find(property) == failed_properties_.end()); |
210 | 216 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 device::BluetoothDevice::ConnectErrorCode error) { | 602 device::BluetoothDevice::ConnectErrorCode error) { |
597 SetError(kPairingFailed); | 603 SetError(kPairingFailed); |
598 SendResponse(false); | 604 SendResponse(false); |
599 } | 605 } |
600 | 606 |
601 //////////////////////////////////////////////////////////////////////////////// | 607 //////////////////////////////////////////////////////////////////////////////// |
602 | 608 |
603 } // namespace api | 609 } // namespace api |
604 | 610 |
605 } // namespace extensions | 611 } // namespace extensions |
OLD | NEW |