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
3 // found in the LICENSE file.
5 #include "extensions/browser/api/bluetooth/bluetooth_extension_function.h"
7 #include "base/memory/ref_counted.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_adapter_factory.h"
11 #include "extensions/browser/api/bluetooth/bluetooth_api.h"
12 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h"
14 using content::BrowserThread
;
18 const char kPlatformNotSupported
[] =
19 "This operation is not supported on your platform";
21 extensions::BluetoothEventRouter
* GetEventRouter(
22 content::BrowserContext
* context
) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
24 return extensions::BluetoothAPI::Get(context
)->event_router();
27 bool IsBluetoothSupported(content::BrowserContext
* context
) {
28 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
29 return GetEventRouter(context
)->IsBluetoothSupported();
32 void GetAdapter(const device::BluetoothAdapterFactory::AdapterCallback callback
,
33 content::BrowserContext
* context
) {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
35 GetEventRouter(context
)->GetAdapter(callback
);
40 namespace extensions
{
43 BluetoothExtensionFunction::BluetoothExtensionFunction() {
46 BluetoothExtensionFunction::~BluetoothExtensionFunction() {
49 bool BluetoothExtensionFunction::RunAsync() {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
52 if (!IsBluetoothSupported(browser_context())) {
53 SetError(kPlatformNotSupported
);
56 GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady
, this),
62 void BluetoothExtensionFunction::RunOnAdapterReady(
63 scoped_refptr
<device::BluetoothAdapter
> adapter
) {
64 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
69 } // namespace extensions