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

Side by Side Diff: device/bluetooth/bluetooth_adapter.cc

Issue 2282763004: bluetooth: mac: Improve classic device discovery and update (Closed)
Patch Set: Address moar comments Created 4 years, 2 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 | « no previous file | device/bluetooth/bluetooth_adapter_mac.mm » ('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 "device/bluetooth/bluetooth_adapter.h" 5 #include "device/bluetooth/bluetooth_adapter.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) { 115 BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) {
116 return const_cast<BluetoothDevice *>( 116 return const_cast<BluetoothDevice *>(
117 const_cast<const BluetoothAdapter *>(this)->GetDevice(address)); 117 const_cast<const BluetoothAdapter *>(this)->GetDevice(address));
118 } 118 }
119 119
120 const BluetoothDevice* BluetoothAdapter::GetDevice( 120 const BluetoothDevice* BluetoothAdapter::GetDevice(
121 const std::string& address) const { 121 const std::string& address) const {
122 std::string canonicalized_address = 122 std::string canonicalized_address =
123 BluetoothDevice::CanonicalizeAddress(address); 123 BluetoothDevice::CanonicalizeAddress(address);
124 if (canonicalized_address.empty()) 124 if (canonicalized_address.empty())
125 return NULL; 125 return nullptr;
126 126
127 DevicesMap::const_iterator iter = devices_.find(canonicalized_address); 127 DevicesMap::const_iterator iter = devices_.find(canonicalized_address);
128 if (iter != devices_.end()) 128 if (iter != devices_.end())
129 return iter->second; 129 return iter->second;
130 130
131 return NULL; 131 return nullptr;
132 } 132 }
133 133
134 void BluetoothAdapter::AddPairingDelegate( 134 void BluetoothAdapter::AddPairingDelegate(
135 BluetoothDevice::PairingDelegate* pairing_delegate, 135 BluetoothDevice::PairingDelegate* pairing_delegate,
136 PairingDelegatePriority priority) { 136 PairingDelegatePriority priority) {
137 // Remove the delegate, if it already exists, before inserting to allow a 137 // Remove the delegate, if it already exists, before inserting to allow a
138 // change of priority. 138 // change of priority.
139 RemovePairingDelegate(pairing_delegate); 139 RemovePairingDelegate(pairing_delegate);
140 140
141 // Find the first point with a lower priority, or the end of the list. 141 // Find the first point with a lower priority, or the end of the list.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if (device->IsPaired() || device->IsConnected() || 376 if (device->IsPaired() || device->IsConnected() ||
377 device->IsGattConnected()) { 377 device->IsGattConnected()) {
378 ++it; 378 ++it;
379 continue; 379 continue;
380 } 380 }
381 381
382 base::Time last_update_time = device->GetLastUpdateTime(); 382 base::Time last_update_time = device->GetLastUpdateTime();
383 383
384 bool device_expired = 384 bool device_expired =
385 (base::Time::NowFromSystemTime() - last_update_time) > timeoutSec; 385 (base::Time::NowFromSystemTime() - last_update_time) > timeoutSec;
386 VLOG(1) << "device: " << device->GetAddress() 386 VLOG(3) << "device: " << device->GetAddress()
387 << ", last_update: " << last_update_time 387 << ", last_update: " << last_update_time
388 << ", exp: " << device_expired; 388 << ", exp: " << device_expired;
389 389
390 if (!device_expired) { 390 if (!device_expired) {
391 ++it; 391 ++it;
392 continue; 392 continue;
393 } 393 }
394
395 VLOG(1) << "Removing device: " << device->GetAddress();
394 DevicesMap::iterator next = it; 396 DevicesMap::iterator next = it;
395 next++; 397 next++;
396 std::unique_ptr<BluetoothDevice> removed_device = 398 std::unique_ptr<BluetoothDevice> removed_device =
397 devices_.take_and_erase(it); 399 devices_.take_and_erase(it);
398 it = next; 400 it = next;
399 401
400 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 402 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
401 DeviceRemoved(this, removed_device.get())); 403 DeviceRemoved(this, removed_device.get()));
402 } 404 }
403 } 405 }
(...skipping 12 matching lines...) Expand all
416 UMA_HISTOGRAM_ENUMERATION( 418 UMA_HISTOGRAM_ENUMERATION(
417 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), 419 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome),
418 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); 420 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT));
419 } 421 }
420 422
421 // static 423 // static
422 const base::TimeDelta BluetoothAdapter::timeoutSec = 424 const base::TimeDelta BluetoothAdapter::timeoutSec =
423 base::TimeDelta::FromSeconds(180); 425 base::TimeDelta::FromSeconds(180);
424 426
425 } // namespace device 427 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698