| 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/dbus/bluetooth_agent_service_provider.h" | 5 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 11 #include "dbus/exported_object.h" | 12 #include "dbus/exported_object.h" |
| 12 #include "dbus/message.h" | 13 #include "dbus/message.h" |
| 13 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 14 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 14 #include "device/bluetooth/dbus/fake_bluetooth_agent_service_provider.h" | 15 #include "device/bluetooth/dbus/fake_bluetooth_agent_service_provider.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 17 |
| 17 namespace bluez { | 18 namespace bluez { |
| 18 | 19 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // Called by dbus:: when the Bluetooth daemon requires that the user | 197 // Called by dbus:: when the Bluetooth daemon requires that the user |
| 197 // enter a Passkey into the remote device so that it may be | 198 // enter a Passkey into the remote device so that it may be |
| 198 // authenticated. | 199 // authenticated. |
| 199 void DisplayPasskey(dbus::MethodCall* method_call, | 200 void DisplayPasskey(dbus::MethodCall* method_call, |
| 200 dbus::ExportedObject::ResponseSender response_sender) { | 201 dbus::ExportedObject::ResponseSender response_sender) { |
| 201 DCHECK(OnOriginThread()); | 202 DCHECK(OnOriginThread()); |
| 202 DCHECK(delegate_); | 203 DCHECK(delegate_); |
| 203 | 204 |
| 204 dbus::MessageReader reader(method_call); | 205 dbus::MessageReader reader(method_call); |
| 205 dbus::ObjectPath device_path; | 206 dbus::ObjectPath device_path; |
| 206 uint32 passkey; | 207 uint32_t passkey; |
| 207 uint16 entered; | 208 uint16_t entered; |
| 208 if (!reader.PopObjectPath(&device_path) || !reader.PopUint32(&passkey) || | 209 if (!reader.PopObjectPath(&device_path) || !reader.PopUint32(&passkey) || |
| 209 !reader.PopUint16(&entered)) { | 210 !reader.PopUint16(&entered)) { |
| 210 LOG(WARNING) << "DisplayPasskey called with incorrect paramters: " | 211 LOG(WARNING) << "DisplayPasskey called with incorrect paramters: " |
| 211 << method_call->ToString(); | 212 << method_call->ToString(); |
| 212 return; | 213 return; |
| 213 } | 214 } |
| 214 | 215 |
| 215 delegate_->DisplayPasskey(device_path, passkey, entered); | 216 delegate_->DisplayPasskey(device_path, passkey, entered); |
| 216 | 217 |
| 217 response_sender.Run(dbus::Response::FromMethodCall(method_call)); | 218 response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
| 218 } | 219 } |
| 219 | 220 |
| 220 // Called by dbus:: when the Bluetooth daemon requires that the user | 221 // Called by dbus:: when the Bluetooth daemon requires that the user |
| 221 // confirm that a Passkey is displayed on the screen of the remote | 222 // confirm that a Passkey is displayed on the screen of the remote |
| 222 // device so that it may be authenticated. | 223 // device so that it may be authenticated. |
| 223 void RequestConfirmation( | 224 void RequestConfirmation( |
| 224 dbus::MethodCall* method_call, | 225 dbus::MethodCall* method_call, |
| 225 dbus::ExportedObject::ResponseSender response_sender) { | 226 dbus::ExportedObject::ResponseSender response_sender) { |
| 226 DCHECK(OnOriginThread()); | 227 DCHECK(OnOriginThread()); |
| 227 DCHECK(delegate_); | 228 DCHECK(delegate_); |
| 228 | 229 |
| 229 dbus::MessageReader reader(method_call); | 230 dbus::MessageReader reader(method_call); |
| 230 dbus::ObjectPath device_path; | 231 dbus::ObjectPath device_path; |
| 231 uint32 passkey; | 232 uint32_t passkey; |
| 232 if (!reader.PopObjectPath(&device_path) || !reader.PopUint32(&passkey)) { | 233 if (!reader.PopObjectPath(&device_path) || !reader.PopUint32(&passkey)) { |
| 233 LOG(WARNING) << "RequestConfirmation called with incorrect paramters: " | 234 LOG(WARNING) << "RequestConfirmation called with incorrect paramters: " |
| 234 << method_call->ToString(); | 235 << method_call->ToString(); |
| 235 return; | 236 return; |
| 236 } | 237 } |
| 237 | 238 |
| 238 Delegate::ConfirmationCallback callback = base::Bind( | 239 Delegate::ConfirmationCallback callback = base::Bind( |
| 239 &BluetoothAgentServiceProviderImpl::OnConfirmation, | 240 &BluetoothAgentServiceProviderImpl::OnConfirmation, |
| 240 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender); | 241 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender); |
| 241 | 242 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 338 } |
| 338 default: | 339 default: |
| 339 NOTREACHED() << "Unexpected status code from delegate: " << status; | 340 NOTREACHED() << "Unexpected status code from delegate: " << status; |
| 340 } | 341 } |
| 341 } | 342 } |
| 342 | 343 |
| 343 // Called by the Delegate to response to a method requesting a Passkey. | 344 // Called by the Delegate to response to a method requesting a Passkey. |
| 344 void OnPasskey(dbus::MethodCall* method_call, | 345 void OnPasskey(dbus::MethodCall* method_call, |
| 345 dbus::ExportedObject::ResponseSender response_sender, | 346 dbus::ExportedObject::ResponseSender response_sender, |
| 346 Delegate::Status status, | 347 Delegate::Status status, |
| 347 uint32 passkey) { | 348 uint32_t passkey) { |
| 348 DCHECK(OnOriginThread()); | 349 DCHECK(OnOriginThread()); |
| 349 | 350 |
| 350 switch (status) { | 351 switch (status) { |
| 351 case Delegate::SUCCESS: { | 352 case Delegate::SUCCESS: { |
| 352 scoped_ptr<dbus::Response> response( | 353 scoped_ptr<dbus::Response> response( |
| 353 dbus::Response::FromMethodCall(method_call)); | 354 dbus::Response::FromMethodCall(method_call)); |
| 354 dbus::MessageWriter writer(response.get()); | 355 dbus::MessageWriter writer(response.get()); |
| 355 writer.AppendUint32(passkey); | 356 writer.AppendUint32(passkey); |
| 356 response_sender.Run(response.Pass()); | 357 response_sender.Run(response.Pass()); |
| 357 break; | 358 break; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 const dbus::ObjectPath& object_path, | 436 const dbus::ObjectPath& object_path, |
| 436 Delegate* delegate) { | 437 Delegate* delegate) { |
| 437 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { | 438 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { |
| 438 return new BluetoothAgentServiceProviderImpl(bus, object_path, delegate); | 439 return new BluetoothAgentServiceProviderImpl(bus, object_path, delegate); |
| 439 } else { | 440 } else { |
| 440 return new FakeBluetoothAgentServiceProvider(object_path, delegate); | 441 return new FakeBluetoothAgentServiceProvider(object_path, delegate); |
| 441 } | 442 } |
| 442 } | 443 } |
| 443 | 444 |
| 444 } // namespace bluez | 445 } // namespace bluez |
| OLD | NEW |