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