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 "extensions/browser/api/bluetooth/bluetooth_api.h" | 5 #include "extensions/browser/api/bluetooth/bluetooth_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "device/bluetooth/bluetooth_adapter.h" | 13 #include "device/bluetooth/bluetooth_adapter.h" |
14 #include "device/bluetooth/bluetooth_device.h" | 14 #include "device/bluetooth/bluetooth_device.h" |
15 #include "extensions/browser/api/bluetooth/bluetooth_api_utils.h" | 15 #include "extensions/browser/api/bluetooth/bluetooth_api_utils.h" |
16 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" | 16 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" |
17 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
18 #include "extensions/common/api/bluetooth.h" | 18 #include "extensions/common/api/bluetooth.h" |
19 | 19 |
20 using content::BrowserContext; | 20 using content::BrowserContext; |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 | 22 |
23 using device::BluetoothAdapter; | 23 using device::BluetoothAdapter; |
24 using device::BluetoothDevice; | 24 using device::BluetoothDevice; |
25 | 25 |
26 namespace bluetooth = extensions::core_api::bluetooth; | 26 namespace bluetooth = extensions::api::bluetooth; |
27 namespace GetDevice = extensions::core_api::bluetooth::GetDevice; | 27 namespace GetDevice = extensions::api::bluetooth::GetDevice; |
28 namespace GetDevices = extensions::core_api::bluetooth::GetDevices; | 28 namespace GetDevices = extensions::api::bluetooth::GetDevices; |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const char kInvalidDevice[] = "Invalid device"; | 32 const char kInvalidDevice[] = "Invalid device"; |
33 const char kStartDiscoveryFailed[] = "Starting discovery failed"; | 33 const char kStartDiscoveryFailed[] = "Starting discovery failed"; |
34 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; | 34 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; |
35 | 35 |
36 extensions::BluetoothEventRouter* GetEventRouter(BrowserContext* context) { | 36 extensions::BluetoothEventRouter* GetEventRouter(BrowserContext* context) { |
37 // Note: |context| is valid on UI thread only. | 37 // Note: |context| is valid on UI thread only. |
38 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 38 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (event_router()->IsBluetoothSupported()) | 89 if (event_router()->IsBluetoothSupported()) |
90 event_router()->OnListenerAdded(); | 90 event_router()->OnListenerAdded(); |
91 } | 91 } |
92 | 92 |
93 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { | 93 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { |
94 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 94 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
95 if (event_router()->IsBluetoothSupported()) | 95 if (event_router()->IsBluetoothSupported()) |
96 event_router()->OnListenerRemoved(); | 96 event_router()->OnListenerRemoved(); |
97 } | 97 } |
98 | 98 |
99 namespace core_api { | 99 namespace api { |
100 | 100 |
101 BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() {} | 101 BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() {} |
102 | 102 |
103 bool BluetoothGetAdapterStateFunction::DoWork( | 103 bool BluetoothGetAdapterStateFunction::DoWork( |
104 scoped_refptr<BluetoothAdapter> adapter) { | 104 scoped_refptr<BluetoothAdapter> adapter) { |
105 bluetooth::AdapterState state; | 105 bluetooth::AdapterState state; |
106 PopulateAdapterState(*adapter.get(), &state); | 106 PopulateAdapterState(*adapter.get(), &state); |
107 results_ = bluetooth::GetAdapterState::Results::Create(state); | 107 results_ = bluetooth::GetAdapterState::Results::Create(state); |
108 SendResponse(true); | 108 SendResponse(true); |
109 return true; | 109 return true; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 scoped_refptr<BluetoothAdapter> adapter) { | 192 scoped_refptr<BluetoothAdapter> adapter) { |
193 GetEventRouter(browser_context())->StopDiscoverySession( | 193 GetEventRouter(browser_context())->StopDiscoverySession( |
194 adapter.get(), | 194 adapter.get(), |
195 extension_id(), | 195 extension_id(), |
196 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 196 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
197 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 197 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
198 | 198 |
199 return true; | 199 return true; |
200 } | 200 } |
201 | 201 |
202 } // namespace core_api | 202 } // namespace api |
203 } // namespace extensions | 203 } // namespace extensions |
OLD | NEW |