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

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

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 "extensions/browser/api/bluetooth/bluetooth_event_router.h" 5 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return; 130 return;
131 } 131 }
132 132
133 // Check whether user pre set discovery filter by calling SetDiscoveryFilter 133 // Check whether user pre set discovery filter by calling SetDiscoveryFilter
134 // before. If the user has set a discovery filter then start a filtered 134 // before. If the user has set a discovery filter then start a filtered
135 // discovery session, otherwise start a regular session 135 // discovery session, otherwise start a regular session
136 PreSetFilterMap::iterator pre_set_iter = 136 PreSetFilterMap::iterator pre_set_iter =
137 pre_set_filter_map_.find(extension_id); 137 pre_set_filter_map_.find(extension_id);
138 if (pre_set_iter != pre_set_filter_map_.end()) { 138 if (pre_set_iter != pre_set_filter_map_.end()) {
139 adapter->StartDiscoverySessionWithFilter( 139 adapter->StartDiscoverySessionWithFilter(
140 scoped_ptr<device::BluetoothDiscoveryFilter>(pre_set_iter->second), 140 std::unique_ptr<device::BluetoothDiscoveryFilter>(pre_set_iter->second),
141 base::Bind(&BluetoothEventRouter::OnStartDiscoverySession, 141 base::Bind(&BluetoothEventRouter::OnStartDiscoverySession,
142 weak_ptr_factory_.GetWeakPtr(), extension_id, callback), 142 weak_ptr_factory_.GetWeakPtr(), extension_id, callback),
143 error_callback); 143 error_callback);
144 pre_set_filter_map_.erase(pre_set_iter); 144 pre_set_filter_map_.erase(pre_set_iter);
145 return; 145 return;
146 } 146 }
147 adapter->StartDiscoverySession( 147 adapter->StartDiscoverySession(
148 base::Bind(&BluetoothEventRouter::OnStartDiscoverySession, 148 base::Bind(&BluetoothEventRouter::OnStartDiscoverySession,
149 weak_ptr_factory_.GetWeakPtr(), extension_id, callback), 149 weak_ptr_factory_.GetWeakPtr(), extension_id, callback),
150 error_callback); 150 error_callback);
(...skipping 13 matching lines...) Expand all
164 if (iter == discovery_session_map_.end() || !iter->second->IsActive()) { 164 if (iter == discovery_session_map_.end() || !iter->second->IsActive()) {
165 DVLOG(1) << "No active discovery session exists for extension."; 165 DVLOG(1) << "No active discovery session exists for extension.";
166 error_callback.Run(); 166 error_callback.Run();
167 return; 167 return;
168 } 168 }
169 device::BluetoothDiscoverySession* session = iter->second; 169 device::BluetoothDiscoverySession* session = iter->second;
170 session->Stop(callback, error_callback); 170 session->Stop(callback, error_callback);
171 } 171 }
172 172
173 void BluetoothEventRouter::SetDiscoveryFilter( 173 void BluetoothEventRouter::SetDiscoveryFilter(
174 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter, 174 std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter,
175 device::BluetoothAdapter* adapter, 175 device::BluetoothAdapter* adapter,
176 const std::string& extension_id, 176 const std::string& extension_id,
177 const base::Closure& callback, 177 const base::Closure& callback,
178 const base::Closure& error_callback) { 178 const base::Closure& error_callback) {
179 DVLOG(1) << "SetDiscoveryFilter"; 179 DVLOG(1) << "SetDiscoveryFilter";
180 if (adapter != adapter_.get()) { 180 if (adapter != adapter_.get()) {
181 error_callback.Run(); 181 error_callback.Run();
182 return; 182 return;
183 } 183 }
184 184
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 num_event_listeners_--; 370 num_event_listeners_--;
371 MaybeReleaseAdapter(); 371 MaybeReleaseAdapter();
372 } 372 }
373 373
374 void BluetoothEventRouter::DispatchAdapterStateEvent() { 374 void BluetoothEventRouter::DispatchAdapterStateEvent() {
375 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 375 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
376 api::bluetooth::AdapterState state; 376 api::bluetooth::AdapterState state;
377 CHECK(adapter_.get()); 377 CHECK(adapter_.get());
378 PopulateAdapterState(*adapter_.get(), &state); 378 PopulateAdapterState(*adapter_.get(), &state);
379 379
380 scoped_ptr<base::ListValue> args = 380 std::unique_ptr<base::ListValue> args =
381 bluetooth::OnAdapterStateChanged::Create(state); 381 bluetooth::OnAdapterStateChanged::Create(state);
382 scoped_ptr<Event> event( 382 std::unique_ptr<Event> event(
383 new Event(events::BLUETOOTH_ON_ADAPTER_STATE_CHANGED, 383 new Event(events::BLUETOOTH_ON_ADAPTER_STATE_CHANGED,
384 bluetooth::OnAdapterStateChanged::kEventName, std::move(args))); 384 bluetooth::OnAdapterStateChanged::kEventName, std::move(args)));
385 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); 385 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event));
386 } 386 }
387 387
388 void BluetoothEventRouter::DispatchDeviceEvent( 388 void BluetoothEventRouter::DispatchDeviceEvent(
389 events::HistogramValue histogram_value, 389 events::HistogramValue histogram_value,
390 const std::string& event_name, 390 const std::string& event_name,
391 device::BluetoothDevice* device) { 391 device::BluetoothDevice* device) {
392 bluetooth::Device extension_device; 392 bluetooth::Device extension_device;
393 CHECK(device); 393 CHECK(device);
394 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); 394 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device);
395 395
396 scoped_ptr<base::ListValue> args = 396 std::unique_ptr<base::ListValue> args =
397 bluetooth::OnDeviceAdded::Create(extension_device); 397 bluetooth::OnDeviceAdded::Create(extension_device);
398 scoped_ptr<Event> event( 398 std::unique_ptr<Event> event(
399 new Event(histogram_value, event_name, std::move(args))); 399 new Event(histogram_value, event_name, std::move(args)));
400 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); 400 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event));
401 } 401 }
402 402
403 void BluetoothEventRouter::CleanUpForExtension( 403 void BluetoothEventRouter::CleanUpForExtension(
404 const std::string& extension_id) { 404 const std::string& extension_id) {
405 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 405 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
406 RemovePairingDelegate(extension_id); 406 RemovePairingDelegate(extension_id);
407 407
408 PreSetFilterMap::iterator pre_set_iter = 408 PreSetFilterMap::iterator pre_set_iter =
(...skipping 24 matching lines...) Expand all
433 discovery_session_map_.clear(); 433 discovery_session_map_.clear();
434 434
435 PairingDelegateMap::iterator pairing_iter = pairing_delegate_map_.begin(); 435 PairingDelegateMap::iterator pairing_iter = pairing_delegate_map_.begin();
436 while (pairing_iter != pairing_delegate_map_.end()) 436 while (pairing_iter != pairing_delegate_map_.end())
437 RemovePairingDelegate(pairing_iter++->first); 437 RemovePairingDelegate(pairing_iter++->first);
438 } 438 }
439 439
440 void BluetoothEventRouter::OnStartDiscoverySession( 440 void BluetoothEventRouter::OnStartDiscoverySession(
441 const std::string& extension_id, 441 const std::string& extension_id,
442 const base::Closure& callback, 442 const base::Closure& callback,
443 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 443 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) {
444 // Clean up any existing session instance for the extension. 444 // Clean up any existing session instance for the extension.
445 DiscoverySessionMap::iterator iter = 445 DiscoverySessionMap::iterator iter =
446 discovery_session_map_.find(extension_id); 446 discovery_session_map_.find(extension_id);
447 if (iter != discovery_session_map_.end()) 447 if (iter != discovery_session_map_.end())
448 delete iter->second; 448 delete iter->second;
449 discovery_session_map_[extension_id] = discovery_session.release(); 449 discovery_session_map_[extension_id] = discovery_session.release();
450 callback.Run(); 450 callback.Run();
451 } 451 }
452 452
453 void BluetoothEventRouter::OnSetDiscoveryFilter(const std::string& extension_id, 453 void BluetoothEventRouter::OnSetDiscoveryFilter(const std::string& extension_id,
(...skipping 13 matching lines...) Expand all
467 } 467 }
468 468
469 void BluetoothEventRouter::OnExtensionUnloaded( 469 void BluetoothEventRouter::OnExtensionUnloaded(
470 content::BrowserContext* browser_context, 470 content::BrowserContext* browser_context,
471 const Extension* extension, 471 const Extension* extension,
472 UnloadedExtensionInfo::Reason reason) { 472 UnloadedExtensionInfo::Reason reason) {
473 CleanUpForExtension(extension->id()); 473 CleanUpForExtension(extension->id());
474 } 474 }
475 475
476 } // namespace extensions 476 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698