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