Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_extension_function.cc

Issue 227493006: Revert 262175 "* Replace "read" method with onReceiveXxx events." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/public/browser/browser_thread.h"
11 #include "device/bluetooth/bluetooth_adapter.h" 10 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "device/bluetooth/bluetooth_adapter_factory.h" 11 #include "device/bluetooth/bluetooth_adapter_factory.h"
13 12
14 using content::BrowserThread;
15
16 namespace { 13 namespace {
17 14
18 const char kPlatformNotSupported[] = 15 const char kPlatformNotSupported[] =
19 "This operation is not supported on your platform"; 16 "This operation is not supported on your platform";
20 17
21 extensions::BluetoothEventRouter* GetEventRouter( 18 extensions::BluetoothEventRouter* GetEventRouter(
22 content::BrowserContext* context) { 19 content::BrowserContext* context) {
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 20 return extensions::BluetoothAPI::Get(context)->bluetooth_event_router();
24 return extensions::BluetoothAPI::Get(context)->event_router();
25 } 21 }
26 22
27 bool IsBluetoothSupported(content::BrowserContext* context) { 23 bool IsBluetoothSupported(content::BrowserContext* context) {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
29 return GetEventRouter(context)->IsBluetoothSupported(); 24 return GetEventRouter(context)->IsBluetoothSupported();
30 } 25 }
31 26
32 void GetAdapter(const device::BluetoothAdapterFactory::AdapterCallback callback, 27 void GetAdapter(const device::BluetoothAdapterFactory::AdapterCallback callback,
33 content::BrowserContext* context) { 28 content::BrowserContext* context) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 GetEventRouter(context)->GetAdapter(callback); 29 GetEventRouter(context)->GetAdapter(callback);
36 } 30 }
37 31
38 } // namespace 32 } // namespace
39 33
40 namespace extensions { 34 namespace extensions {
35
41 namespace api { 36 namespace api {
42 37
43 BluetoothExtensionFunction::BluetoothExtensionFunction() { 38 BluetoothExtensionFunction::BluetoothExtensionFunction() {
44 } 39 }
45 40
46 BluetoothExtensionFunction::~BluetoothExtensionFunction() { 41 BluetoothExtensionFunction::~BluetoothExtensionFunction() {
47 } 42 }
48 43
49 bool BluetoothExtensionFunction::RunImpl() { 44 bool BluetoothExtensionFunction::RunImpl() {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
51
52 if (!IsBluetoothSupported(browser_context())) { 45 if (!IsBluetoothSupported(browser_context())) {
53 SetError(kPlatformNotSupported); 46 SetError(kPlatformNotSupported);
54 return false; 47 return false;
55 } 48 }
56 GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this), 49 GetAdapter(base::Bind(&BluetoothExtensionFunction::RunOnAdapterReady, this),
57 browser_context()); 50 browser_context());
58 51
59 return true; 52 return true;
60 } 53 }
61 54
62 void BluetoothExtensionFunction::RunOnAdapterReady( 55 void BluetoothExtensionFunction::RunOnAdapterReady(
63 scoped_refptr<device::BluetoothAdapter> adapter) { 56 scoped_refptr<device::BluetoothAdapter> adapter) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 DoWork(adapter); 57 DoWork(adapter);
66 } 58 }
67 59
68 } // namespace api 60 } // namespace api
61
69 } // namespace extensions 62 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698