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 "chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.h"
7 #include "base/memory/ref_counted.h"
8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.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"
12 #include "device/bluetooth/bluetooth_adapter_factory.h"
16 const char kPlatformNotSupported[] =
17 "This operation is not supported on your platform";
19 extensions::ExtensionBluetoothEventRouter* GetEventRouter(Profile* profile) {
20 return extensions::BluetoothAPI::Get(profile)->bluetooth_event_router();
23 bool IsBluetoothSupported(Profile* profile) {
24 return GetEventRouter(profile)->IsBluetoothSupported();
28 const device::BluetoothAdapterFactory::AdapterCallback callback,
30 GetEventRouter(profile)->GetAdapter(callback);
35 namespace extensions {
39 BluetoothExtensionFunction::BluetoothExtensionFunction() {
42 BluetoothExtensionFunction::~BluetoothExtensionFunction() {
45 bool BluetoothExtensionFunction::RunImpl() {
46 if (!IsBluetoothSupported(GetProfile())) {
47 SetError(kPlatformNotSupported);
50 GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this),
56 void BluetoothExtensionFunction::RunOnAdapterReady(
57 scoped_refptr<device::BluetoothAdapter> adapter) {
63 } // namespace extensions