Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / api / bluetooth / bluetooth_extension_function.cc
blob003a8393213f8e56c597358bc243908b1120f18a
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;
16 namespace {
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);
38 } // namespace
40 namespace extensions {
41 namespace api {
43 BluetoothExtensionFunction::BluetoothExtensionFunction() {
46 BluetoothExtensionFunction::~BluetoothExtensionFunction() {
49 bool BluetoothExtensionFunction::RunAsync() {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
52 if (!IsBluetoothSupported(browser_context())) {
53 SetError(kPlatformNotSupported);
54 return false;
56 GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this),
57 browser_context());
59 return true;
62 void BluetoothExtensionFunction::RunOnAdapterReady(
63 scoped_refptr<device::BluetoothAdapter> adapter) {
64 DCHECK_CURRENTLY_ON(BrowserThread::UI);
65 DoWork(adapter);
68 } // namespace api
69 } // namespace extensions