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

Side by Side Diff: extensions/browser/api/bluetooth/bluetooth_api.cc

Issue 2801403002: MD Settings: Bluetooth: Fix adapter state and discovery (Closed)
Patch Set: Use CHECK instead of early exit Created 3 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
« no previous file with comments | « extensions/browser/api/DEPS ('k') | extensions/browser/api/bluetooth/bluetooth_event_router.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "extensions/browser/api/bluetooth/bluetooth_api.h" 5 #include "extensions/browser/api/bluetooth/bluetooth_api.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "components/device_event_log/device_event_log.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "device/bluetooth/bluetooth_adapter.h" 16 #include "device/bluetooth/bluetooth_adapter.h"
16 #include "device/bluetooth/bluetooth_device.h" 17 #include "device/bluetooth/bluetooth_device.h"
17 #include "extensions/browser/api/bluetooth/bluetooth_api_utils.h" 18 #include "extensions/browser/api/bluetooth/bluetooth_api_utils.h"
18 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" 19 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h"
19 #include "extensions/browser/event_router.h" 20 #include "extensions/browser/event_router.h"
20 #include "extensions/common/api/bluetooth.h" 21 #include "extensions/common/api/bluetooth.h"
21 22
22 using content::BrowserContext; 23 using content::BrowserContext;
23 using content::BrowserThread; 24 using content::BrowserThread;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 // static 59 // static
59 BluetoothAPI* BluetoothAPI::Get(BrowserContext* context) { 60 BluetoothAPI* BluetoothAPI::Get(BrowserContext* context) {
60 DCHECK_CURRENTLY_ON(BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(BrowserThread::UI);
61 return GetFactoryInstance()->Get(context); 62 return GetFactoryInstance()->Get(context);
62 } 63 }
63 64
64 BluetoothAPI::BluetoothAPI(content::BrowserContext* context) 65 BluetoothAPI::BluetoothAPI(content::BrowserContext* context)
65 : browser_context_(context) { 66 : browser_context_(context) {
66 DCHECK_CURRENTLY_ON(BrowserThread::UI); 67 DCHECK_CURRENTLY_ON(BrowserThread::UI);
68 BLUETOOTH_LOG(EVENT) << "BluetoothAPI: " << browser_context_;
67 EventRouter* event_router = EventRouter::Get(browser_context_); 69 EventRouter* event_router = EventRouter::Get(browser_context_);
68 event_router->RegisterObserver(this, 70 event_router->RegisterObserver(this,
69 bluetooth::OnAdapterStateChanged::kEventName); 71 bluetooth::OnAdapterStateChanged::kEventName);
70 event_router->RegisterObserver(this, bluetooth::OnDeviceAdded::kEventName); 72 event_router->RegisterObserver(this, bluetooth::OnDeviceAdded::kEventName);
71 event_router->RegisterObserver(this, bluetooth::OnDeviceChanged::kEventName); 73 event_router->RegisterObserver(this, bluetooth::OnDeviceChanged::kEventName);
72 event_router->RegisterObserver(this, bluetooth::OnDeviceRemoved::kEventName); 74 event_router->RegisterObserver(this, bluetooth::OnDeviceRemoved::kEventName);
73 } 75 }
74 76
75 BluetoothAPI::~BluetoothAPI() {} 77 BluetoothAPI::~BluetoothAPI() {
78 BLUETOOTH_LOG(EVENT) << "~BluetoothAPI: " << browser_context_;
79 }
76 80
77 BluetoothEventRouter* BluetoothAPI::event_router() { 81 BluetoothEventRouter* BluetoothAPI::event_router() {
78 DCHECK_CURRENTLY_ON(BrowserThread::UI); 82 DCHECK_CURRENTLY_ON(BrowserThread::UI);
79 if (!event_router_) { 83 if (!event_router_) {
84 BLUETOOTH_LOG(EVENT) << "BluetoothAPI: Creating BluetoothEventRouter";
80 event_router_.reset(new BluetoothEventRouter(browser_context_)); 85 event_router_.reset(new BluetoothEventRouter(browser_context_));
81 } 86 }
82 return event_router_.get(); 87 return event_router_.get();
83 } 88 }
84 89
85 void BluetoothAPI::Shutdown() { 90 void BluetoothAPI::Shutdown() {
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); 91 DCHECK_CURRENTLY_ON(BrowserThread::UI);
92 BLUETOOTH_LOG(EVENT) << "BluetoothAPI: Shutdown";
87 EventRouter::Get(browser_context_)->UnregisterObserver(this); 93 EventRouter::Get(browser_context_)->UnregisterObserver(this);
88 } 94 }
89 95
90 void BluetoothAPI::OnListenerAdded(const EventListenerInfo& details) { 96 void BluetoothAPI::OnListenerAdded(const EventListenerInfo& details) {
91 DCHECK_CURRENTLY_ON(BrowserThread::UI); 97 DCHECK_CURRENTLY_ON(BrowserThread::UI);
92 if (event_router()->IsBluetoothSupported()) 98 if (event_router()->IsBluetoothSupported())
93 event_router()->OnListenerAdded(); 99 event_router()->OnListenerAdded(details);
94 } 100 }
95 101
96 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { 102 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) {
97 DCHECK_CURRENTLY_ON(BrowserThread::UI); 103 DCHECK_CURRENTLY_ON(BrowserThread::UI);
98 if (event_router()->IsBluetoothSupported()) 104 if (event_router()->IsBluetoothSupported())
99 event_router()->OnListenerRemoved(); 105 event_router()->OnListenerRemoved(details);
100 } 106 }
101 107
102 namespace api { 108 namespace api {
103 109
104 BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() {} 110 BluetoothGetAdapterStateFunction::~BluetoothGetAdapterStateFunction() {}
105 111
106 bool BluetoothGetAdapterStateFunction::DoWork( 112 bool BluetoothGetAdapterStateFunction::DoWork(
107 scoped_refptr<BluetoothAdapter> adapter) { 113 scoped_refptr<BluetoothAdapter> adapter) {
108 bluetooth::AdapterState state; 114 bluetooth::AdapterState state;
109 PopulateAdapterState(*adapter, &state); 115 PopulateAdapterState(*adapter, &state);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ->StopDiscoverySession( 203 ->StopDiscoverySession(
198 adapter.get(), GetExtensionId(), 204 adapter.get(), GetExtensionId(),
199 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), 205 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
200 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); 206 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
201 207
202 return true; 208 return true;
203 } 209 }
204 210
205 } // namespace api 211 } // namespace api
206 } // namespace extensions 212 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/DEPS ('k') | extensions/browser/api/bluetooth/bluetooth_event_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698