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