OLD | NEW |
---|---|
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 "chrome/browser/chromeos/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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" | |
20 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" | |
21 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h" | |
22 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" | |
23 #include "chromeos/dbus/bluetooth_adapter_client.h" | 19 #include "chromeos/dbus/bluetooth_adapter_client.h" |
24 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 20 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
25 #include "chromeos/dbus/bluetooth_device_client.h" | 21 #include "chromeos/dbus/bluetooth_device_client.h" |
26 #include "chromeos/dbus/bluetooth_input_client.h" | 22 #include "chromeos/dbus/bluetooth_input_client.h" |
27 #include "chromeos/dbus/bluetooth_out_of_band_client.h" | 23 #include "chromeos/dbus/bluetooth_out_of_band_client.h" |
28 #include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" | |
29 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
30 #include "chromeos/dbus/introspectable_client.h" | 25 #include "chromeos/dbus/introspectable_client.h" |
31 #include "dbus/bus.h" | 26 #include "dbus/bus.h" |
32 #include "dbus/object_path.h" | 27 #include "dbus/object_path.h" |
28 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | |
29 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | |
30 #include "device/bluetooth/bluetooth_service_record.h" | |
31 #include "device/bluetooth/bluetooth_socket_chromeos.h" | |
32 #include "device/bluetooth/bluetooth_utils.h" | |
33 #include "third_party/cros_system_api/dbus/service_constants.h" | 33 #include "third_party/cros_system_api/dbus/service_constants.h" |
34 | 34 |
35 namespace chromeos { | 35 using chromeos::BluetoothDeviceClient; |
36 using chromeos::DBusThreadManager; | |
37 | |
38 namespace bluetooth { | |
keybuk
2012/10/12 00:13:18
namespace?
again pick either explicit chromeos::
youngki
2012/10/12 01:50:12
Done.
| |
36 | 39 |
37 BluetoothDeviceChromeOs::BluetoothDeviceChromeOs( | 40 BluetoothDeviceChromeOs::BluetoothDeviceChromeOs( |
38 BluetoothAdapterChromeOs* adapter) | 41 BluetoothAdapterChromeOs* adapter) |
39 : BluetoothDevice(), | 42 : BluetoothDevice(), |
40 adapter_(adapter), | 43 adapter_(adapter), |
41 pairing_delegate_(NULL), | 44 pairing_delegate_(NULL), |
42 connecting_applications_counter_(0), | 45 connecting_applications_counter_(0), |
43 weak_ptr_factory_(this) { | 46 weak_ptr_factory_(this) { |
44 } | 47 } |
45 | 48 |
(...skipping 21 matching lines...) Expand all Loading... | |
67 callback, | 70 callback, |
68 error_callback)); | 71 error_callback)); |
69 } | 72 } |
70 | 73 |
71 bool BluetoothDeviceChromeOs::ProvidesServiceWithUUID( | 74 bool BluetoothDeviceChromeOs::ProvidesServiceWithUUID( |
72 const std::string& uuid) const { | 75 const std::string& uuid) const { |
73 const BluetoothDevice::ServiceList& services = GetServices(); | 76 const BluetoothDevice::ServiceList& services = GetServices(); |
74 for (BluetoothDevice::ServiceList::const_iterator iter = services.begin(); | 77 for (BluetoothDevice::ServiceList::const_iterator iter = services.begin(); |
75 iter != services.end(); | 78 iter != services.end(); |
76 ++iter) { | 79 ++iter) { |
77 if (bluetooth_utils::CanonicalUuid(*iter) == uuid) | 80 if (utils::CanonicalUuid(*iter) == uuid) |
78 return true; | 81 return true; |
79 } | 82 } |
80 return false; | 83 return false; |
81 } | 84 } |
82 | 85 |
83 void BluetoothDeviceChromeOs::ProvidesServiceWithName( | 86 void BluetoothDeviceChromeOs::ProvidesServiceWithName( |
84 const std::string& name, | 87 const std::string& name, |
85 const ProvidesServiceCallback& callback) { | 88 const ProvidesServiceCallback& callback) { |
86 GetServiceRecords( | 89 GetServiceRecords( |
87 base::Bind(&BluetoothDeviceChromeOs::SearchServicesForNameCallback, | 90 base::Bind(&BluetoothDeviceChromeOs::SearchServicesForNameCallback, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // a given bluetooth device. | 137 // a given bluetooth device. |
135 DCHECK(agent_.get() == NULL); | 138 DCHECK(agent_.get() == NULL); |
136 | 139 |
137 std::string agent_path_basename; | 140 std::string agent_path_basename; |
138 ReplaceChars(address_, ":", "_", &agent_path_basename); | 141 ReplaceChars(address_, ":", "_", &agent_path_basename); |
139 dbus::ObjectPath agent_path("/org/chromium/bluetooth_agent/" + | 142 dbus::ObjectPath agent_path("/org/chromium/bluetooth_agent/" + |
140 agent_path_basename); | 143 agent_path_basename); |
141 | 144 |
142 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 145 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
143 if (system_bus) { | 146 if (system_bus) { |
144 agent_.reset(BluetoothAgentServiceProvider::Create(system_bus, | 147 agent_.reset(chromeos::BluetoothAgentServiceProvider::Create(system_bus, |
145 agent_path, | 148 agent_path, |
146 this)); | 149 this)); |
147 } else { | 150 } else { |
148 agent_.reset(NULL); | 151 agent_.reset(NULL); |
149 } | 152 } |
150 | 153 |
151 DVLOG(1) << "Pairing: " << address_; | 154 DVLOG(1) << "Pairing: " << address_; |
152 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 155 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
153 CreatePairedDevice( | 156 CreatePairedDevice( |
154 adapter_->object_path_, | 157 adapter_->object_path_, |
155 address_, | 158 address_, |
156 agent_path, | 159 agent_path, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 weak_ptr_factory_.GetWeakPtr(), | 255 weak_ptr_factory_.GetWeakPtr(), |
253 service_uuid, | 256 service_uuid, |
254 callback), | 257 callback), |
255 base::Bind( | 258 base::Bind( |
256 &BluetoothDeviceChromeOs::GetServiceRecordsForConnectErrorCallback, | 259 &BluetoothDeviceChromeOs::GetServiceRecordsForConnectErrorCallback, |
257 weak_ptr_factory_.GetWeakPtr(), | 260 weak_ptr_factory_.GetWeakPtr(), |
258 callback)); | 261 callback)); |
259 } | 262 } |
260 | 263 |
261 void BluetoothDeviceChromeOs::SetOutOfBandPairingData( | 264 void BluetoothDeviceChromeOs::SetOutOfBandPairingData( |
262 const chromeos::BluetoothOutOfBandPairingData& data, | 265 const bluetooth::BluetoothOutOfBandPairingData& data, |
263 const base::Closure& callback, | 266 const base::Closure& callback, |
264 const ErrorCallback& error_callback) { | 267 const ErrorCallback& error_callback) { |
265 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> | 268 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()-> |
266 AddRemoteData( | 269 AddRemoteData( |
267 object_path_, | 270 object_path_, |
268 address(), | 271 address(), |
269 data, | 272 data, |
270 base::Bind(&BluetoothDeviceChromeOs::OnRemoteDataCallback, | 273 base::Bind(&BluetoothDeviceChromeOs::OnRemoteDataCallback, |
271 weak_ptr_factory_.GetWeakPtr(), | 274 weak_ptr_factory_.GetWeakPtr(), |
272 callback, | 275 callback, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 LOG(WARNING) << "Failed to determine supported applications: " << address_; | 421 LOG(WARNING) << "Failed to determine supported applications: " << address_; |
419 error_callback.Run(); | 422 error_callback.Run(); |
420 return; | 423 return; |
421 } | 424 } |
422 | 425 |
423 // The introspection data for the device object may list one or more | 426 // The introspection data for the device object may list one or more |
424 // additional D-Bus interfaces that BlueZ supports for this particular | 427 // additional D-Bus interfaces that BlueZ supports for this particular |
425 // device. Send appropraite Connect calls for each of those interfaces | 428 // device. Send appropraite Connect calls for each of those interfaces |
426 // to connect all of the application protocols for this device. | 429 // to connect all of the application protocols for this device. |
427 std::vector<std::string> interfaces = | 430 std::vector<std::string> interfaces = |
428 IntrospectableClient::GetInterfacesFromIntrospectResult(xml_data); | 431 chromeos::IntrospectableClient::GetInterfacesFromIntrospectResult( |
432 xml_data); | |
429 | 433 |
430 DCHECK_EQ(0, connecting_applications_counter_); | 434 DCHECK_EQ(0, connecting_applications_counter_); |
431 connecting_applications_counter_ = 0; | 435 connecting_applications_counter_ = 0; |
432 for (std::vector<std::string>::iterator iter = interfaces.begin(); | 436 for (std::vector<std::string>::iterator iter = interfaces.begin(); |
433 iter != interfaces.end(); ++iter) { | 437 iter != interfaces.end(); ++iter) { |
434 if (*iter == bluetooth_input::kBluetoothInputInterface) { | 438 if (*iter == bluetooth_input::kBluetoothInputInterface) { |
435 connecting_applications_counter_++; | 439 connecting_applications_counter_++; |
436 // Supports Input interface. | 440 // Supports Input interface. |
437 DBusThreadManager::Get()->GetBluetoothInputClient()-> | 441 DBusThreadManager::Get()->GetBluetoothInputClient()-> |
438 Connect(object_path_, | 442 Connect(object_path_, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 pairing_delegate_->DismissDisplayOrConfirm(); | 679 pairing_delegate_->DismissDisplayOrConfirm(); |
676 } | 680 } |
677 | 681 |
678 | 682 |
679 // static | 683 // static |
680 BluetoothDeviceChromeOs* BluetoothDeviceChromeOs::Create( | 684 BluetoothDeviceChromeOs* BluetoothDeviceChromeOs::Create( |
681 BluetoothAdapterChromeOs* adapter) { | 685 BluetoothAdapterChromeOs* adapter) { |
682 return new BluetoothDeviceChromeOs(adapter); | 686 return new BluetoothDeviceChromeOs(adapter); |
683 } | 687 } |
684 | 688 |
685 } // namespace chromeos | 689 } // namespace bluetooth |
OLD | NEW |