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_extension_function.h
" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h
" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 10 #include "content/public/browser/browser_thread.h" |
10 #include "device/bluetooth/bluetooth_adapter.h" | 11 #include "device/bluetooth/bluetooth_adapter.h" |
11 #include "device/bluetooth/bluetooth_adapter_factory.h" | 12 #include "device/bluetooth/bluetooth_adapter_factory.h" |
12 | 13 |
| 14 using content::BrowserThread; |
| 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 const char kPlatformNotSupported[] = | 18 const char kPlatformNotSupported[] = |
16 "This operation is not supported on your platform"; | 19 "This operation is not supported on your platform"; |
17 | 20 |
18 extensions::BluetoothEventRouter* GetEventRouter( | 21 extensions::BluetoothEventRouter* GetEventRouter( |
19 content::BrowserContext* context) { | 22 content::BrowserContext* context) { |
20 return extensions::BluetoothAPI::Get(context)->bluetooth_event_router(); | 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 24 return extensions::BluetoothAPI::Get(context)->event_router(); |
21 } | 25 } |
22 | 26 |
23 bool IsBluetoothSupported(content::BrowserContext* context) { | 27 bool IsBluetoothSupported(content::BrowserContext* context) { |
| 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
24 return GetEventRouter(context)->IsBluetoothSupported(); | 29 return GetEventRouter(context)->IsBluetoothSupported(); |
25 } | 30 } |
26 | 31 |
27 void GetAdapter(const device::BluetoothAdapterFactory::AdapterCallback callback, | 32 void GetAdapter(const device::BluetoothAdapterFactory::AdapterCallback callback, |
28 content::BrowserContext* context) { | 33 content::BrowserContext* context) { |
| 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
29 GetEventRouter(context)->GetAdapter(callback); | 35 GetEventRouter(context)->GetAdapter(callback); |
30 } | 36 } |
31 | 37 |
32 } // namespace | 38 } // namespace |
33 | 39 |
34 namespace extensions { | 40 namespace extensions { |
35 | |
36 namespace api { | 41 namespace api { |
37 | 42 |
38 BluetoothExtensionFunction::BluetoothExtensionFunction() { | 43 BluetoothExtensionFunction::BluetoothExtensionFunction() { |
39 } | 44 } |
40 | 45 |
41 BluetoothExtensionFunction::~BluetoothExtensionFunction() { | 46 BluetoothExtensionFunction::~BluetoothExtensionFunction() { |
42 } | 47 } |
43 | 48 |
44 bool BluetoothExtensionFunction::RunImpl() { | 49 bool BluetoothExtensionFunction::RunImpl() { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 51 |
45 if (!IsBluetoothSupported(browser_context())) { | 52 if (!IsBluetoothSupported(browser_context())) { |
46 SetError(kPlatformNotSupported); | 53 SetError(kPlatformNotSupported); |
47 return false; | 54 return false; |
48 } | 55 } |
49 GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this), | 56 GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this), |
50 browser_context()); | 57 browser_context()); |
51 | 58 |
52 return true; | 59 return true; |
53 } | 60 } |
54 | 61 |
55 void BluetoothExtensionFunction::RunOnAdapterReady( | 62 void BluetoothExtensionFunction::RunOnAdapterReady( |
56 scoped_refptr<device::BluetoothAdapter> adapter) { | 63 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
57 DoWork(adapter); | 65 DoWork(adapter); |
58 } | 66 } |
59 | 67 |
60 } // namespace api | 68 } // namespace api |
61 | |
62 } // namespace extensions | 69 } // namespace extensions |
OLD | NEW |