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

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

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
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_api.h" 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h"
12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" 12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
13 #include "chrome/browser/extensions/api/bluetooth/bluetooth_socket_event_dispatc her.h" 13 #include "chrome/browser/extensions/api/bluetooth/bluetooth_socket_event_dispatc her.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/common/extensions/api/bluetooth.h" 15 #include "chrome/common/extensions/api/bluetooth.h"
16 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" 16 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "device/bluetooth/bluetooth_adapter.h" 18 #include "device/bluetooth/bluetooth_adapter.h"
19 #include "device/bluetooth/bluetooth_device.h" 19 #include "device/bluetooth/bluetooth_device.h"
20 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" 20 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
21 #include "device/bluetooth/bluetooth_profile.h" 21 #include "device/bluetooth/bluetooth_profile.h"
22 #include "device/bluetooth/bluetooth_service_record.h" 22 #include "device/bluetooth/bluetooth_service_record.h"
23 #include "device/bluetooth/bluetooth_socket.h" 23 #include "device/bluetooth/bluetooth_socket.h"
24 #include "extensions/browser/event_router.h" 24 #include "extensions/browser/event_router.h"
25 #include "extensions/browser/extension_system.h"
26 #include "extensions/common/permissions/permissions_data.h" 25 #include "extensions/common/permissions/permissions_data.h"
27 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
28 27
29 using content::BrowserContext; 28 using content::BrowserContext;
30 using content::BrowserThread; 29 using content::BrowserThread;
31 30
32 using device::BluetoothAdapter; 31 using device::BluetoothAdapter;
33 using device::BluetoothDevice; 32 using device::BluetoothDevice;
34 using device::BluetoothProfile; 33 using device::BluetoothProfile;
35 using device::BluetoothServiceRecord; 34 using device::BluetoothServiceRecord;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return GetFactoryInstance()->Get(context); 147 return GetFactoryInstance()->Get(context);
149 } 148 }
150 149
151 BluetoothAPI::ConnectionParams::ConnectionParams() {} 150 BluetoothAPI::ConnectionParams::ConnectionParams() {}
152 151
153 BluetoothAPI::ConnectionParams::~ConnectionParams() {} 152 BluetoothAPI::ConnectionParams::~ConnectionParams() {}
154 153
155 BluetoothAPI::BluetoothAPI(content::BrowserContext* context) 154 BluetoothAPI::BluetoothAPI(content::BrowserContext* context)
156 : browser_context_(context) { 155 : browser_context_(context) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
158 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( 157 EventRouter* event_router = EventRouter::Get(browser_context_);
159 this, bluetooth::OnAdapterStateChanged::kEventName); 158 event_router->RegisterObserver(this,
160 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( 159 bluetooth::OnAdapterStateChanged::kEventName);
161 this, bluetooth::OnDeviceAdded::kEventName); 160 event_router->RegisterObserver(this, bluetooth::OnDeviceAdded::kEventName);
162 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( 161 event_router->RegisterObserver(this, bluetooth::OnDeviceChanged::kEventName);
163 this, bluetooth::OnDeviceChanged::kEventName); 162 event_router->RegisterObserver(this, bluetooth::OnDeviceRemoved::kEventName);
164 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver(
165 this, bluetooth::OnDeviceRemoved::kEventName);
166 } 163 }
167 164
168 BluetoothAPI::~BluetoothAPI() {} 165 BluetoothAPI::~BluetoothAPI() {}
169 166
170 BluetoothEventRouter* BluetoothAPI::event_router() { 167 BluetoothEventRouter* BluetoothAPI::event_router() {
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
172 if (!event_router_) { 169 if (!event_router_) {
173 event_router_.reset(new BluetoothEventRouter(browser_context_)); 170 event_router_.reset(new BluetoothEventRouter(browser_context_));
174 } 171 }
175 return event_router_.get(); 172 return event_router_.get();
(...skipping 19 matching lines...) Expand all
195 BluetoothAPI::socket_event_dispatcher() { 192 BluetoothAPI::socket_event_dispatcher() {
196 if (!socket_event_dispatcher_) { 193 if (!socket_event_dispatcher_) {
197 socket_event_dispatcher_ = new api::BluetoothSocketEventDispatcher( 194 socket_event_dispatcher_ = new api::BluetoothSocketEventDispatcher(
198 browser_context_, socket_data()); 195 browser_context_, socket_data());
199 } 196 }
200 return socket_event_dispatcher_; 197 return socket_event_dispatcher_;
201 } 198 }
202 199
203 void BluetoothAPI::Shutdown() { 200 void BluetoothAPI::Shutdown() {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( 202 EventRouter::Get(browser_context_)->UnregisterObserver(this);
206 this);
207 } 203 }
208 204
209 void BluetoothAPI::OnListenerAdded(const EventListenerInfo& details) { 205 void BluetoothAPI::OnListenerAdded(const EventListenerInfo& details) {
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
211 if (event_router()->IsBluetoothSupported()) 207 if (event_router()->IsBluetoothSupported())
212 event_router()->OnListenerAdded(); 208 event_router()->OnListenerAdded();
213 } 209 }
214 210
215 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) { 211 void BluetoothAPI::OnListenerRemoved(const EventListenerInfo& details) {
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 api::bluetooth::Socket result_socket; 282 api::bluetooth::Socket result_socket;
287 bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device); 283 bluetooth::BluetoothDeviceToApiDevice(*device, &result_socket.device);
288 result_socket.uuid = params.uuid.canonical_value(); 284 result_socket.uuid = params.uuid.canonical_value();
289 result_socket.id = socket_id; 285 result_socket.id = socket_id;
290 286
291 scoped_ptr<base::ListValue> args = 287 scoped_ptr<base::ListValue> args =
292 bluetooth::OnConnection::Create(result_socket); 288 bluetooth::OnConnection::Create(result_socket);
293 scoped_ptr<Event> event( 289 scoped_ptr<Event> event(
294 new Event(bluetooth::OnConnection::kEventName, args.Pass())); 290 new Event(bluetooth::OnConnection::kEventName, args.Pass()));
295 291
296 EventRouter* router = ExtensionSystem::Get(context)->event_router(); 292 EventRouter* router = EventRouter::Get(context);
297 if (router) 293 if (router)
298 router->DispatchEventToExtension(params.extension_id, event.Pass()); 294 router->DispatchEventToExtension(params.extension_id, event.Pass());
299 } 295 }
300 296
301 namespace api { 297 namespace api {
302 298
303 BluetoothSocketApiFunction::BluetoothSocketApiFunction() {} 299 BluetoothSocketApiFunction::BluetoothSocketApiFunction() {}
304 300
305 BluetoothSocketApiFunction::~BluetoothSocketApiFunction() {} 301 BluetoothSocketApiFunction::~BluetoothSocketApiFunction() {}
306 302
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 adapter, 853 adapter,
858 extension_id(), 854 extension_id(),
859 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), 855 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
860 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); 856 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
861 857
862 return true; 858 return true;
863 } 859 }
864 860
865 } // namespace api 861 } // namespace api
866 } // namespace extensions 862 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698