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" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "device/bluetooth/bluetooth_adapter.h" | 11 #include "device/bluetooth/bluetooth_adapter.h" |
12 #include "device/bluetooth/bluetooth_adapter_factory.h" | 12 #include "device/bluetooth/bluetooth_adapter_factory.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const char kPlatformNotSupported[] = | 16 const char kPlatformNotSupported[] = |
17 "This operation is not supported on your platform"; | 17 "This operation is not supported on your platform"; |
18 | 18 |
19 scoped_refptr<device::BluetoothAdapter> GetAdapter(Profile* profile) { | 19 void RunCallbackOnAdapterReady( |
20 const device::BluetoothAdapterFactory::AdapterCallback callback, | |
21 Profile* profile) { | |
20 extensions::ExtensionBluetoothEventRouter* event_router = | 22 extensions::ExtensionBluetoothEventRouter* event_router = |
21 extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); | 23 extensions::BluetoothAPI::Get(profile)->bluetooth_event_router(); |
22 return event_router->GetAdapter(); | 24 event_router->RunCallbackOnAdapterReady(callback); |
23 } | 25 } |
24 | 26 |
25 } // namespace | 27 } // namespace |
26 | 28 |
27 namespace extensions { | 29 namespace extensions { |
28 | 30 |
29 namespace api { | 31 namespace api { |
30 | 32 |
31 BluetoothExtensionFunction::BluetoothExtensionFunction() { | 33 BluetoothExtensionFunction::BluetoothExtensionFunction() { |
32 } | 34 } |
33 | 35 |
34 BluetoothExtensionFunction::~BluetoothExtensionFunction() { | 36 BluetoothExtensionFunction::~BluetoothExtensionFunction() { |
35 } | 37 } |
36 | 38 |
37 bool BluetoothExtensionFunction::RunImpl() { | 39 bool BluetoothExtensionFunction::RunImpl() { |
38 scoped_refptr<device::BluetoothAdapter> adapter = GetAdapter(profile()); | 40 bool is_bluetooth_supported = |
39 if (!adapter) { | 41 device::BluetoothAdapterFactory::IsBluetoothSupported(); |
42 RunCallbackOnAdapterReady(base::Bind(&BluetoothExtensionFunction::DoWork, | |
bryeung
2013/01/08 22:24:27
why do we try this when is_bluetooth_supported ==
youngki
2013/01/09 15:12:03
!! You are right. Done.
| |
43 base::Unretained(this)), | |
44 profile()); | |
45 if (!is_bluetooth_supported) { | |
40 SetError(kPlatformNotSupported); | 46 SetError(kPlatformNotSupported); |
41 return false; | 47 return false; |
42 } | 48 } |
43 DoWork(adapter); | |
44 return true; | 49 return true; |
45 } | 50 } |
46 | 51 |
47 } // namespace api | 52 } // namespace api |
48 | 53 |
49 } // namespace extensions | 54 } // namespace extensions |
OLD | NEW |