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

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

Issue 13416005: Bluetooth: clean up BluetoothDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More win visible fixes Created 7 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 | Annotate | Revision Log
« no previous file with comments | « device/bluetooth/bluetooth_device_chromeos.h ('k') | device/bluetooth/bluetooth_device_mac.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 "device/bluetooth/bluetooth_device_chromeos.h" 5 #include "device/bluetooth/bluetooth_device_chromeos.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 void DoNothingServiceRecordList(const BluetoothDevice::ServiceRecordList&) {} 43 void DoNothingServiceRecordList(const BluetoothDevice::ServiceRecordList&) {}
44 44
45 } // namespace 45 } // namespace
46 46
47 namespace chromeos { 47 namespace chromeos {
48 48
49 BluetoothDeviceChromeOS::BluetoothDeviceChromeOS( 49 BluetoothDeviceChromeOS::BluetoothDeviceChromeOS(
50 BluetoothAdapterChromeOS* adapter) 50 BluetoothAdapterChromeOS* adapter)
51 : BluetoothDevice(), 51 : BluetoothDevice(),
52 adapter_(adapter), 52 adapter_(adapter),
53 bluetooth_class_(0),
54 paired_(false),
55 connected_(false),
56 connectable_(true),
57 connecting_(false),
53 pairing_delegate_(NULL), 58 pairing_delegate_(NULL),
54 connecting_applications_counter_(0), 59 connecting_applications_counter_(0),
55 connecting_calls_(0), 60 connecting_calls_(0),
56 service_records_loaded_(false), 61 service_records_loaded_(false),
57 weak_ptr_factory_(this) { 62 weak_ptr_factory_(this) {
58 } 63 }
59 64
60 BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() { 65 BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() {
61 } 66 }
62 67
63 bool BluetoothDeviceChromeOS::IsPaired() const { 68 uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const {
64 return !object_path_.value().empty(); 69 return bluetooth_class_;
65 } 70 }
66 71
67 const BluetoothDevice::ServiceList& 72 std::string BluetoothDeviceChromeOS::GetDeviceName() const {
73 return name_;
74 }
75
76 std::string BluetoothDeviceChromeOS::GetAddress() const {
77 return address_;
78 }
79
80 bool BluetoothDeviceChromeOS::IsPaired() const {
81 return paired_;
82 }
83
84 bool BluetoothDeviceChromeOS::IsConnected() const {
85 return connected_;
86 }
87
88 bool BluetoothDeviceChromeOS::IsConnectable() const {
89 return connectable_;
90 }
91
92 bool BluetoothDeviceChromeOS::IsConnecting() const {
93 return connecting_;
94 }
95
96 BluetoothDeviceChromeOS::ServiceList
68 BluetoothDeviceChromeOS::GetServices() const { 97 BluetoothDeviceChromeOS::GetServices() const {
69 return service_uuids_; 98 return service_uuids_;
70 } 99 }
71 100
72 void BluetoothDeviceChromeOS::GetServiceRecords( 101 void BluetoothDeviceChromeOS::GetServiceRecords(
73 const ServiceRecordsCallback& callback, 102 const ServiceRecordsCallback& callback,
74 const ErrorCallback& error_callback) { 103 const ErrorCallback& error_callback) {
75 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 104 DBusThreadManager::Get()->GetBluetoothDeviceClient()->
76 DiscoverServices( 105 DiscoverServices(
77 object_path_, 106 object_path_,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Set the decrement to be issued when either callback is called. 151 // Set the decrement to be issued when either callback is called.
123 base::Closure wrapped_callback = base::Bind( 152 base::Closure wrapped_callback = base::Bind(
124 &BluetoothDeviceChromeOS::OnConnectCallbackCalled, 153 &BluetoothDeviceChromeOS::OnConnectCallbackCalled,
125 weak_ptr_factory_.GetWeakPtr(), 154 weak_ptr_factory_.GetWeakPtr(),
126 callback); 155 callback);
127 ConnectErrorCallback wrapped_error_callback = base::Bind( 156 ConnectErrorCallback wrapped_error_callback = base::Bind(
128 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled, 157 &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled,
129 weak_ptr_factory_.GetWeakPtr(), 158 weak_ptr_factory_.GetWeakPtr(),
130 error_callback); 159 error_callback);
131 160
132 if (IsPaired() || IsBonded() || IsConnected()) { 161 if (IsPaired() || IsConnected()) {
133 // Connection to already paired or connected device. 162 // Connection to already paired or connected device.
134 ConnectApplications(wrapped_callback, wrapped_error_callback); 163 ConnectApplications(wrapped_callback, wrapped_error_callback);
135 164
136 } else if (!pairing_delegate) { 165 } else if (!pairing_delegate) {
137 // No pairing delegate supplied, initiate low-security connection only. 166 // No pairing delegate supplied, initiate low-security connection only.
138 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> 167 DBusThreadManager::Get()->GetBluetoothAdapterClient()->
139 CreateDevice(adapter_->object_path_, 168 CreateDevice(adapter_->object_path_,
140 address_, 169 address_,
141 base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice, 170 base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice,
142 weak_ptr_factory_.GetWeakPtr(), 171 weak_ptr_factory_.GetWeakPtr(),
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 callback)); 323 callback));
295 } 324 }
296 325
297 void BluetoothDeviceChromeOS::SetOutOfBandPairingData( 326 void BluetoothDeviceChromeOS::SetOutOfBandPairingData(
298 const BluetoothOutOfBandPairingData& data, 327 const BluetoothOutOfBandPairingData& data,
299 const base::Closure& callback, 328 const base::Closure& callback,
300 const ErrorCallback& error_callback) { 329 const ErrorCallback& error_callback) {
301 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> 330 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
302 AddRemoteData( 331 AddRemoteData(
303 object_path_, 332 object_path_,
304 address(), 333 address_,
305 data, 334 data,
306 base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback, 335 base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback,
307 weak_ptr_factory_.GetWeakPtr(), 336 weak_ptr_factory_.GetWeakPtr(),
308 callback, 337 callback,
309 error_callback)); 338 error_callback));
310 } 339 }
311 340
312 void BluetoothDeviceChromeOS::ClearOutOfBandPairingData( 341 void BluetoothDeviceChromeOS::ClearOutOfBandPairingData(
313 const base::Closure& callback, 342 const base::Closure& callback,
314 const ErrorCallback& error_callback) { 343 const ErrorCallback& error_callback) {
315 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> 344 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
316 RemoveRemoteData( 345 RemoveRemoteData(
317 object_path_, 346 object_path_,
318 address(), 347 address_,
319 base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback, 348 base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback,
320 weak_ptr_factory_.GetWeakPtr(), 349 weak_ptr_factory_.GetWeakPtr(),
321 callback, 350 callback,
322 error_callback)); 351 error_callback));
323 } 352 }
324 353
325 void BluetoothDeviceChromeOS::SetObjectPath( 354 void BluetoothDeviceChromeOS::SetObjectPath(
326 const dbus::ObjectPath& object_path) { 355 const dbus::ObjectPath& object_path) {
327 DCHECK(object_path_ == dbus::ObjectPath("")); 356 DCHECK(object_path_ == dbus::ObjectPath(""));
328 object_path_ = object_path; 357 object_path_ = object_path;
(...skipping 24 matching lines...) Expand all
353 } 382 }
354 383
355 if (update_state) { 384 if (update_state) {
356 // When the device reconnects and we don't have any service records for it, 385 // When the device reconnects and we don't have any service records for it,
357 // try to update the cache or fail silently. 386 // try to update the cache or fail silently.
358 if (!service_records_loaded_ && !connected_ && 387 if (!service_records_loaded_ && !connected_ &&
359 properties->connected.value()) 388 properties->connected.value())
360 GetServiceRecords(base::Bind(&DoNothingServiceRecordList), 389 GetServiceRecords(base::Bind(&DoNothingServiceRecordList),
361 base::Bind(&base::DoNothing)); 390 base::Bind(&base::DoNothing));
362 391
363 // BlueZ uses paired to mean link keys exchanged, whereas the Bluetooth 392 paired_ = properties->paired.value();
364 // spec refers to this as bonded. Use the spec name for our interface.
365 bonded_ = properties->paired.value();
366 connected_ = properties->connected.value(); 393 connected_ = properties->connected.value();
367 } 394 }
368 } 395 }
369 396
370 void BluetoothDeviceChromeOS::OnCreateDevice( 397 void BluetoothDeviceChromeOS::OnCreateDevice(
371 const base::Closure& callback, 398 const base::Closure& callback,
372 const ConnectErrorCallback& error_callback, 399 const ConnectErrorCallback& error_callback,
373 const dbus::ObjectPath& device_path) { 400 const dbus::ObjectPath& device_path) {
374 VLOG(1) << "Connection successful: " << device_path.value(); 401 VLOG(1) << "Connection successful: " << device_path.value();
375 if (object_path_.value().empty()) { 402 if (object_path_.value().empty()) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 // callback, so it is safe to delete the previous objects here. 474 // callback, so it is safe to delete the previous objects here.
448 service_records_.clear(); 475 service_records_.clear();
449 // TODO(deymo): Perhaps don't update the cache if the new SDP information is 476 // TODO(deymo): Perhaps don't update the cache if the new SDP information is
450 // empty and we had something before. Some devices only answer this 477 // empty and we had something before. Some devices only answer this
451 // information while paired, and this callback could be called in any order if 478 // information while paired, and this callback could be called in any order if
452 // several calls to GetServiceRecords are made while initial pairing with the 479 // several calls to GetServiceRecords are made while initial pairing with the
453 // device. This requires more investigation. 480 // device. This requires more investigation.
454 for (BluetoothDeviceClient::ServiceMap::const_iterator i = 481 for (BluetoothDeviceClient::ServiceMap::const_iterator i =
455 service_map.begin(); i != service_map.end(); ++i) { 482 service_map.begin(); i != service_map.end(); ++i) {
456 service_records_.push_back( 483 service_records_.push_back(
457 new BluetoothServiceRecordChromeOS(address(), i->second)); 484 new BluetoothServiceRecordChromeOS(address_, i->second));
458 } 485 }
459 service_records_loaded_ = true; 486 service_records_loaded_ = true;
460 487
461 callback.Run(service_records_); 488 callback.Run(service_records_);
462 } 489 }
463 490
464 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { 491 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) {
465 LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_; 492 LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_;
466 } 493 }
467 494
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 } 848 }
822 849
823 850
824 // static 851 // static
825 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( 852 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create(
826 BluetoothAdapterChromeOS* adapter) { 853 BluetoothAdapterChromeOS* adapter) {
827 return new BluetoothDeviceChromeOS(adapter); 854 return new BluetoothDeviceChromeOS(adapter);
828 } 855 }
829 856
830 } // namespace chromeos 857 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_chromeos.h ('k') | device/bluetooth/bluetooth_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698