OLD | NEW |
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_profile_chromeos.h" | 5 #include "device/bluetooth/bluetooth_profile_chromeos.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 DCHECK(object_path_.value().empty()); | 62 DCHECK(object_path_.value().empty()); |
63 DCHECK(profile_.get() == NULL); | 63 DCHECK(profile_.get() == NULL); |
64 | 64 |
65 if (adapter_.get()) { | 65 if (adapter_.get()) { |
66 adapter_->RemoveObserver(this); | 66 adapter_->RemoveObserver(this); |
67 adapter_ = NULL; | 67 adapter_ = NULL; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 void BluetoothProfileChromeOS::Init( | 71 void BluetoothProfileChromeOS::Init( |
72 const std::string& uuid, | 72 const device::BluetoothUUID& uuid, |
73 const device::BluetoothProfile::Options& options, | 73 const device::BluetoothProfile::Options& options, |
74 const ProfileCallback& callback) { | 74 const ProfileCallback& callback) { |
75 DCHECK(object_path_.value().empty()); | 75 DCHECK(object_path_.value().empty()); |
76 DCHECK(profile_.get() == NULL); | 76 DCHECK(profile_.get() == NULL); |
77 | 77 |
78 if (!BluetoothDevice::IsUUIDValid(uuid)) { | 78 if (!uuid.IsValid()) { |
79 callback.Run(NULL); | 79 callback.Run(NULL); |
80 return; | 80 return; |
81 } | 81 } |
82 | 82 |
83 uuid_ = uuid; | 83 uuid_ = uuid; |
84 | 84 |
85 options_.name = options.name; | 85 options_.name = options.name; |
86 options_.service = uuid; | 86 options_.service = uuid.canonical_value(); |
87 options_.channel = options.channel; | 87 options_.channel = options.channel; |
88 options_.psm = options.psm; | 88 options_.psm = options.psm; |
89 options_.require_authentication = options.require_authentication; | 89 options_.require_authentication = options.require_authentication; |
90 options_.require_authorization = options.require_authorization; | 90 options_.require_authorization = options.require_authorization; |
91 options_.auto_connect = options.auto_connect; | 91 options_.auto_connect = options.auto_connect; |
92 options_.version = options.version; | 92 options_.version = options.version; |
93 options_.features = options.features; | 93 options_.features = options.features; |
94 | 94 |
95 // The object path is relatively meaningless, but has to be unique, so we | 95 // The object path is relatively meaningless, but has to be unique, so we |
96 // use the UUID of the profile. | 96 // use the UUID of the profile. |
97 std::string uuid_path; | 97 std::string uuid_path; |
98 base::ReplaceChars(uuid, ":-", "_", &uuid_path); | 98 base::ReplaceChars(uuid.canonical_value(), ":-", "_", &uuid_path); |
99 | 99 |
100 object_path_ = dbus::ObjectPath("/org/chromium/bluetooth_profile/" + | 100 object_path_ = dbus::ObjectPath("/org/chromium/bluetooth_profile/" + |
101 uuid_path); | 101 uuid_path); |
102 | 102 |
103 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 103 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
104 profile_.reset(BluetoothProfileServiceProvider::Create( | 104 profile_.reset(BluetoothProfileServiceProvider::Create( |
105 system_bus, object_path_, this)); | 105 system_bus, object_path_, this)); |
106 DCHECK(profile_.get()); | 106 DCHECK(profile_.get()); |
107 | 107 |
108 // Now the profile object is registered we need an adapter to register it | 108 // Now the profile object is registered we need an adapter to register it |
(...skipping 27 matching lines...) Expand all Loading... |
136 | 136 |
137 void BluetoothProfileChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter, | 137 void BluetoothProfileChromeOS::AdapterPresentChanged(BluetoothAdapter* adapter, |
138 bool present) { | 138 bool present) { |
139 if (!present) | 139 if (!present) |
140 return; | 140 return; |
141 | 141 |
142 VLOG(1) << object_path_.value() << ": Register profile"; | 142 VLOG(1) << object_path_.value() << ": Register profile"; |
143 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> | 143 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> |
144 RegisterProfile( | 144 RegisterProfile( |
145 object_path_, | 145 object_path_, |
146 uuid_, | 146 uuid_.canonical_value(), |
147 options_, | 147 options_, |
148 base::Bind(&BluetoothProfileChromeOS::OnInternalRegisterProfile, | 148 base::Bind(&BluetoothProfileChromeOS::OnInternalRegisterProfile, |
149 weak_ptr_factory_.GetWeakPtr()), | 149 weak_ptr_factory_.GetWeakPtr()), |
150 base::Bind(&BluetoothProfileChromeOS::OnInternalRegisterProfileError, | 150 base::Bind(&BluetoothProfileChromeOS::OnInternalRegisterProfileError, |
151 weak_ptr_factory_.GetWeakPtr())); | 151 weak_ptr_factory_.GetWeakPtr())); |
152 } | 152 } |
153 | 153 |
154 void BluetoothProfileChromeOS::OnGetAdapter( | 154 void BluetoothProfileChromeOS::OnGetAdapter( |
155 const ProfileCallback& callback, | 155 const ProfileCallback& callback, |
156 scoped_refptr<device::BluetoothAdapter> adapter) { | 156 scoped_refptr<device::BluetoothAdapter> adapter) { |
157 DCHECK(!adapter_.get()); | 157 DCHECK(!adapter_.get()); |
158 adapter_ = adapter; | 158 adapter_ = adapter; |
159 adapter_->AddObserver(this); | 159 adapter_->AddObserver(this); |
160 | 160 |
161 VLOG(1) << object_path_.value() << ": Register profile"; | 161 VLOG(1) << object_path_.value() << ": Register profile"; |
162 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> | 162 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()-> |
163 RegisterProfile( | 163 RegisterProfile( |
164 object_path_, | 164 object_path_, |
165 uuid_, | 165 uuid_.canonical_value(), |
166 options_, | 166 options_, |
167 base::Bind(&BluetoothProfileChromeOS::OnRegisterProfile, | 167 base::Bind(&BluetoothProfileChromeOS::OnRegisterProfile, |
168 weak_ptr_factory_.GetWeakPtr(), | 168 weak_ptr_factory_.GetWeakPtr(), |
169 callback), | 169 callback), |
170 base::Bind(&BluetoothProfileChromeOS::OnRegisterProfileError, | 170 base::Bind(&BluetoothProfileChromeOS::OnRegisterProfileError, |
171 weak_ptr_factory_.GetWeakPtr(), | 171 weak_ptr_factory_.GetWeakPtr(), |
172 callback)); | 172 callback)); |
173 } | 173 } |
174 | 174 |
175 void BluetoothProfileChromeOS::Release() { | 175 void BluetoothProfileChromeOS::Release() { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> | 287 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())-> |
288 GetDeviceWithPath(device_path); | 288 GetDeviceWithPath(device_path); |
289 DCHECK(device); | 289 DCHECK(device); |
290 | 290 |
291 scoped_refptr<BluetoothSocket> socket(( | 291 scoped_refptr<BluetoothSocket> socket(( |
292 BluetoothSocketChromeOS::Create(fd.get()))); | 292 BluetoothSocketChromeOS::Create(fd.get()))); |
293 connection_callback_.Run(device, socket); | 293 connection_callback_.Run(device, socket); |
294 } | 294 } |
295 | 295 |
296 } // namespace chromeos | 296 } // namespace chromeos |
OLD | NEW |