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: device/bluetooth/bluetooth_device_chromeos.cc

Issue 13416005: Bluetooth: clean up BluetoothDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make GetServices return a copy of the list 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
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::bluetooth_class() const {
64 return !object_path_.value().empty(); 69 return bluetooth_class_;
65 } 70 }
66 71
67 const BluetoothDevice::ServiceList& 72 std::string BluetoothDeviceChromeOS::name() const {
73 return name_;
74 }
75
76 std::string BluetoothDeviceChromeOS::address() 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 445 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

Powered by Google App Engine
This is Rietveld 408576698