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

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

Issue 1124883004: Submission for C++ Readability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_chromeos.h" 5 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 return; 54 return;
55 55
56 LOG(WARNING) << "Failed to unregister pairing agent: " 56 LOG(WARNING) << "Failed to unregister pairing agent: "
57 << error_name << ": " << error_message; 57 << error_name << ": " << error_message;
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 namespace device { 62 namespace device {
63 63
64 // static 64 // static
omoikane 2015/05/22 23:55:27 These "// static" comments are often a maintenance
Marie Janssen 2015/06/18 21:08:35 This "// static" is convention in Chromium code.
65 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( 65 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
66 const InitCallback& init_callback) { 66 const InitCallback& init_callback) {
67 return chromeos::BluetoothAdapterChromeOS::CreateAdapter(); 67 return chromeos::BluetoothAdapterChromeOS::CreateAdapter();
68 } 68 }
69 69
70 } 70 }
omoikane 2015/05/22 23:55:27 End of namespace here should have "// namespace de
Marie Janssen 2015/06/18 21:08:35 Done.
71 71
72 namespace chromeos { 72 namespace chromeos {
73 73
74 // static 74 // static
75 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { 75 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() {
76 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); 76 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS();
77 return adapter->weak_ptr_factory_.GetWeakPtr(); 77 return adapter->weak_ptr_factory_.GetWeakPtr();
78 } 78 }
79 79
80 void BluetoothAdapterChromeOS::Shutdown() { 80 void BluetoothAdapterChromeOS::Shutdown() {
81 if (dbus_is_shutdown_) 81 if (dbus_is_shutdown_)
82 return; 82 return;
83 DCHECK(DBusThreadManager::IsInitialized()) 83 DCHECK(DBusThreadManager::IsInitialized())
84 << "Call BluetoothAdapterFactory::Shutdown() before " 84 << "Call BluetoothAdapterFactory::Shutdown() before "
85 "DBusThreadManager::Shutdown()."; 85 "DBusThreadManager::Shutdown().";
86 86
87 if (IsPresent()) 87 if (IsPresent())
88 RemoveAdapter(); // Also deletes devices_. 88 RemoveAdapter(); // Also deletes devices_.
89 DCHECK(devices_.empty()); 89 DCHECK(devices_.empty());
90 // profiles_ should be empty because all BluetoothSockets have been signaled 90 // profiles_ is empty because all BluetoothSockets have been notified
91 // that this adapter is disappearing. 91 // that this adapter is disappearing.
92 DCHECK(profiles_.empty()); 92 DCHECK(profiles_.empty());
93 93
94 for (auto& it : profile_queues_) 94 for (auto& it : profile_queues_)
95 delete it.second; 95 delete it.second;
96 profile_queues_.clear(); 96 profile_queues_.clear();
97 97
98 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); 98 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this);
99 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); 99 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this);
100 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); 100 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data, 317 scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data,
318 const CreateAdvertisementCallback& callback, 318 const CreateAdvertisementCallback& callback,
319 const CreateAdvertisementErrorCallback& error_callback) { 319 const CreateAdvertisementErrorCallback& error_callback) {
320 scoped_refptr<BluetoothAdvertisementChromeOS> advertisement( 320 scoped_refptr<BluetoothAdvertisementChromeOS> advertisement(
321 new BluetoothAdvertisementChromeOS(advertisement_data.Pass(), this)); 321 new BluetoothAdvertisementChromeOS(advertisement_data.Pass(), this));
322 advertisement->Register(base::Bind(callback, advertisement), error_callback); 322 advertisement->Register(base::Bind(callback, advertisement), error_callback);
323 } 323 }
324 324
325 void BluetoothAdapterChromeOS::RemovePairingDelegateInternal( 325 void BluetoothAdapterChromeOS::RemovePairingDelegateInternal(
326 BluetoothDevice::PairingDelegate* pairing_delegate) { 326 BluetoothDevice::PairingDelegate* pairing_delegate) {
327 // Before removing a pairing delegate make sure that there aren't any devices 327 // Check if any device is using the pairing delegate.
328 // currently using it; if there are, clear the pairing context which will 328 // If so, clear the pairing context which will make any responses no-ops.
329 // make any responses no-ops.
330 for (DevicesMap::iterator iter = devices_.begin(); 329 for (DevicesMap::iterator iter = devices_.begin();
331 iter != devices_.end(); ++iter) { 330 iter != devices_.end(); ++iter) {
332 BluetoothDeviceChromeOS* device_chromeos = 331 BluetoothDeviceChromeOS* device_chromeos =
333 static_cast<BluetoothDeviceChromeOS*>(iter->second); 332 static_cast<BluetoothDeviceChromeOS*>(iter->second);
334 333
335 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); 334 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing();
336 if (pairing && pairing->GetPairingDelegate() == pairing_delegate) 335 if (pairing && pairing->GetPairingDelegate() == pairing_delegate)
337 device_chromeos->EndPairing(); 336 device_chromeos->EndPairing();
338 } 337 }
339 } 338 }
(...skipping 16 matching lines...) Expand all
356 const std::string& property_name) { 355 const std::string& property_name) {
357 if (object_path != object_path_) 356 if (object_path != object_path_)
358 return; 357 return;
359 DCHECK(IsPresent()); 358 DCHECK(IsPresent());
360 359
361 BluetoothAdapterClient::Properties* properties = 360 BluetoothAdapterClient::Properties* properties =
362 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> 361 DBusThreadManager::Get()->GetBluetoothAdapterClient()->
363 GetProperties(object_path_); 362 GetProperties(object_path_);
364 363
365 if (property_name == properties->powered.name()) 364 if (property_name == properties->powered.name())
366 PoweredChanged(properties->powered.value()); 365 PoweredChanged(properties->powered.value());
omoikane 2015/05/22 23:55:27 These conditional blocks should be enclosed in bra
Marie Janssen 2015/06/18 21:08:35 Done.
367 else if (property_name == properties->discoverable.name()) 366 else if (property_name == properties->discoverable.name())
368 DiscoverableChanged(properties->discoverable.value()); 367 DiscoverableChanged(properties->discoverable.value());
369 else if (property_name == properties->discovering.name()) 368 else if (property_name == properties->discovering.name())
370 DiscoveringChanged(properties->discovering.value()); 369 DiscoveringChanged(properties->discovering.value());
371 } 370 }
372 371
373 void BluetoothAdapterChromeOS::DeviceAdded( 372 void BluetoothAdapterChromeOS::DeviceAdded(
374 const dbus::ObjectPath& object_path) { 373 const dbus::ObjectPath& object_path) {
375 DCHECK(DBusThreadManager::Get()); 374 DCHECK(DBusThreadManager::Get());
376 BluetoothDeviceClient::Properties* properties = 375 BluetoothDeviceClient::Properties* properties =
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 GetProperties(object_path); 421 GetProperties(object_path);
423 422
424 if (property_name == properties->bluetooth_class.name() || 423 if (property_name == properties->bluetooth_class.name() ||
425 property_name == properties->address.name() || 424 property_name == properties->address.name() ||
426 property_name == properties->alias.name() || 425 property_name == properties->alias.name() ||
427 property_name == properties->paired.name() || 426 property_name == properties->paired.name() ||
428 property_name == properties->trusted.name() || 427 property_name == properties->trusted.name() ||
429 property_name == properties->connected.name() || 428 property_name == properties->connected.name() ||
430 property_name == properties->uuids.name() || 429 property_name == properties->uuids.name() ||
431 property_name == properties->rssi.name()) 430 property_name == properties->rssi.name())
432 NotifyDeviceChanged(device_chromeos); 431 NotifyDeviceChanged(device_chromeos);
omoikane 2015/05/22 23:55:27 Body of this conditional should be enclosed in bra
Marie Janssen 2015/06/18 21:08:35 Done.
433 432
434 // When a device becomes paired, mark it as trusted so that the user does 433 // When a device becomes paired, mark it as trusted so that the user does
435 // not need to approve every incoming connection 434 // not need to approve every incoming connection
436 if (property_name == properties->paired.name() && 435 if (property_name == properties->paired.name() &&
437 properties->paired.value() && !properties->trusted.value()) 436 properties->paired.value() && !properties->trusted.value())
438 device_chromeos->SetTrusted(); 437 device_chromeos->SetTrusted();
439 438
440 // UMA connection counting 439 // UMA connection counting
441 if (property_name == properties->connected.name()) { 440 if (property_name == properties->connected.name()) {
442 // PlayStation joystick tries to reconnect after disconnection from USB. 441 // PlayStation joystick tries to reconnect after disconnection from USB.
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 805 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
807 AdapterDiscoverableChanged(this, discoverable)); 806 AdapterDiscoverableChanged(this, discoverable));
808 } 807 }
809 808
810 void BluetoothAdapterChromeOS::DiscoveringChanged( 809 void BluetoothAdapterChromeOS::DiscoveringChanged(
811 bool discovering) { 810 bool discovering) {
812 // If the adapter stopped discovery due to a reason other than a request by 811 // If the adapter stopped discovery due to a reason other than a request by
813 // us, reset the count to 0. 812 // us, reset the count to 0.
814 VLOG(1) << "Discovering changed: " << discovering; 813 VLOG(1) << "Discovering changed: " << discovering;
815 if (!discovering && !discovery_request_pending_ 814 if (!discovering && !discovery_request_pending_
816 && num_discovery_sessions_ > 0) { 815 && num_discovery_sessions_ > 0) {
omoikane 2015/05/22 23:55:27 "&&" usually appears at the end of the previous li
Marie Janssen 2015/06/18 21:08:35 Done.
817 VLOG(1) << "Marking sessions as inactive."; 816 VLOG(1) << "Marking sessions as inactive.";
818 num_discovery_sessions_ = 0; 817 num_discovery_sessions_ = 0;
819 MarkDiscoverySessionsAsInactive(); 818 MarkDiscoverySessionsAsInactive();
820 } 819 }
821 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 820 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
822 AdapterDiscoveringChanged(this, discovering)); 821 AdapterDiscoveringChanged(this, discovering));
823 } 822 }
824 823
825 void BluetoothAdapterChromeOS::PresentChanged(bool present) { 824 void BluetoothAdapterChromeOS::PresentChanged(bool present) {
826 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 825 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL)); 1123 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL));
1125 df->CopyFrom(*discovery_filter); 1124 df->CopyFrom(*discovery_filter);
1126 SetDiscoveryFilter( 1125 SetDiscoveryFilter(
1127 df.Pass(), 1126 df.Pass(),
1128 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter, 1127 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter,
1129 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), 1128 weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
1130 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, 1129 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError,
1131 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); 1130 weak_ptr_factory_.GetWeakPtr(), callback, error_callback));
1132 return; 1131 return;
1133 } else 1132 } else
1134 current_filter_.reset(); 1133 current_filter_.reset();
omoikane 2015/05/22 23:55:27 This conditional block should be enclosed in brace
Marie Janssen 2015/06/18 21:08:35 Done.
1135 1134
1136 // This is the first request to start device discovery. 1135 // This is the first request to start device discovery.
1137 discovery_request_pending_ = true; 1136 discovery_request_pending_ = true;
1138 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( 1137 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery(
1139 object_path_, 1138 object_path_,
1140 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, 1139 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery,
1141 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), 1140 weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
1142 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, 1141 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError,
1143 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); 1142 weak_ptr_factory_.GetWeakPtr(), callback, error_callback));
1144 } 1143 }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 1412
1414 // If the queued request resulted in a pending call, then let it 1413 // If the queued request resulted in a pending call, then let it
1415 // asynchonously process the remaining queued requests once the pending 1414 // asynchonously process the remaining queued requests once the pending
1416 // call returns. 1415 // call returns.
1417 if (discovery_request_pending_) 1416 if (discovery_request_pending_)
1418 return; 1417 return;
1419 } 1418 }
1420 } 1419 }
1421 1420
1422 } // namespace chromeos 1421 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698