| 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/dbus/bluetooth_agent_service_provider.h" | 5 #include "chrome/browser/chromeos/dbus/bluetooth_agent_service_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // The BluetoothAgentServiceProvider implementation used in production. | 31 // The BluetoothAgentServiceProvider implementation used in production. |
| 32 class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider { | 32 class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider { |
| 33 public: | 33 public: |
| 34 BluetoothAgentServiceProviderImpl(dbus::Bus* bus, | 34 BluetoothAgentServiceProviderImpl(dbus::Bus* bus, |
| 35 const dbus::ObjectPath& object_path, | 35 const dbus::ObjectPath& object_path, |
| 36 Delegate* delegate) | 36 Delegate* delegate) |
| 37 : weak_ptr_factory_(this), | 37 : weak_ptr_factory_(this), |
| 38 origin_thread_id_(base::PlatformThread::CurrentId()), | 38 origin_thread_id_(base::PlatformThread::CurrentId()), |
| 39 bus_(bus), | 39 bus_(bus), |
| 40 delegate_(delegate) { | 40 delegate_(delegate), |
| 41 object_path_(object_path) { |
| 41 DVLOG(1) << "Creating BluetoothAdapterClientImpl for " | 42 DVLOG(1) << "Creating BluetoothAdapterClientImpl for " |
| 42 << object_path.value(); | 43 << object_path.value(); |
| 43 | 44 |
| 44 exported_object_ = bus_->GetExportedObject(object_path); | 45 exported_object_ = bus_->GetExportedObject(object_path_); |
| 45 | 46 |
| 46 exported_object_->ExportMethod( | 47 exported_object_->ExportMethod( |
| 47 bluetooth_agent::kBluetoothAgentInterface, | 48 bluetooth_agent::kBluetoothAgentInterface, |
| 48 bluetooth_agent::kRelease, | 49 bluetooth_agent::kRelease, |
| 49 base::Bind(&BluetoothAgentServiceProviderImpl::Release, | 50 base::Bind(&BluetoothAgentServiceProviderImpl::Release, |
| 50 weak_ptr_factory_.GetWeakPtr()), | 51 weak_ptr_factory_.GetWeakPtr()), |
| 51 base::Bind(&BluetoothAgentServiceProviderImpl::ReleaseExported, | 52 base::Bind(&BluetoothAgentServiceProviderImpl::ReleaseExported, |
| 52 weak_ptr_factory_.GetWeakPtr())); | 53 weak_ptr_factory_.GetWeakPtr())); |
| 53 | 54 |
| 54 exported_object_->ExportMethod( | 55 exported_object_->ExportMethod( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 exported_object_->ExportMethod( | 113 exported_object_->ExportMethod( |
| 113 bluetooth_agent::kBluetoothAgentInterface, | 114 bluetooth_agent::kBluetoothAgentInterface, |
| 114 bluetooth_agent::kCancel, | 115 bluetooth_agent::kCancel, |
| 115 base::Bind(&BluetoothAgentServiceProviderImpl::Cancel, | 116 base::Bind(&BluetoothAgentServiceProviderImpl::Cancel, |
| 116 weak_ptr_factory_.GetWeakPtr()), | 117 weak_ptr_factory_.GetWeakPtr()), |
| 117 base::Bind(&BluetoothAgentServiceProviderImpl::CancelExported, | 118 base::Bind(&BluetoothAgentServiceProviderImpl::CancelExported, |
| 118 weak_ptr_factory_.GetWeakPtr())); | 119 weak_ptr_factory_.GetWeakPtr())); |
| 119 } | 120 } |
| 120 | 121 |
| 121 virtual ~BluetoothAgentServiceProviderImpl() { | 122 virtual ~BluetoothAgentServiceProviderImpl() { |
| 123 // Unregister the object path so we can reuse with a new agent. |
| 124 bus_->UnregisterExportedObject(object_path_); |
| 122 } | 125 } |
| 123 | 126 |
| 124 private: | 127 private: |
| 125 // Returns true if the current thread is on the origin thread. | 128 // Returns true if the current thread is on the origin thread. |
| 126 bool OnOriginThread() { | 129 bool OnOriginThread() { |
| 127 return base::PlatformThread::CurrentId() == origin_thread_id_; | 130 return base::PlatformThread::CurrentId() == origin_thread_id_; |
| 128 } | 131 } |
| 129 | 132 |
| 130 // Called by dbus:: when the agent is unregistered from the Bluetooth | 133 // Called by dbus:: when the agent is unregistered from the Bluetooth |
| 131 // daemon, generally at the end of a pairing request. | 134 // daemon, generally at the end of a pairing request. |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 518 |
| 516 // D-Bus bus object is exported on, not owned by this object and must | 519 // D-Bus bus object is exported on, not owned by this object and must |
| 517 // outlive it. | 520 // outlive it. |
| 518 dbus::Bus* bus_; | 521 dbus::Bus* bus_; |
| 519 | 522 |
| 520 // All incoming method calls are passed on to the Delegate and a callback | 523 // All incoming method calls are passed on to the Delegate and a callback |
| 521 // passed to generate the reply. |delegate_| is generally the object that | 524 // passed to generate the reply. |delegate_| is generally the object that |
| 522 // owns this one, and must outlive it. | 525 // owns this one, and must outlive it. |
| 523 Delegate* delegate_; | 526 Delegate* delegate_; |
| 524 | 527 |
| 528 // D-Bus object path of object we are exporting, kept so we can unregister |
| 529 // again in our destructor. |
| 530 dbus::ObjectPath object_path_; |
| 531 |
| 525 // D-Bus object we are exporting, owned by this object. | 532 // D-Bus object we are exporting, owned by this object. |
| 526 scoped_refptr<dbus::ExportedObject> exported_object_; | 533 scoped_refptr<dbus::ExportedObject> exported_object_; |
| 527 | 534 |
| 528 DISALLOW_COPY_AND_ASSIGN(BluetoothAgentServiceProviderImpl); | 535 DISALLOW_COPY_AND_ASSIGN(BluetoothAgentServiceProviderImpl); |
| 529 }; | 536 }; |
| 530 | 537 |
| 531 // The BluetoothAgentServiceProvider implementation used on Linux desktop, | 538 // The BluetoothAgentServiceProvider implementation used on Linux desktop, |
| 532 // which does nothing. | 539 // which does nothing. |
| 533 class BluetoothAgentServiceProviderStubImpl | 540 class BluetoothAgentServiceProviderStubImpl |
| 534 : public BluetoothAgentServiceProvider { | 541 : public BluetoothAgentServiceProvider { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 552 const dbus::ObjectPath& object_path, | 559 const dbus::ObjectPath& object_path, |
| 553 Delegate* delegate) { | 560 Delegate* delegate) { |
| 554 if (system::runtime_environment::IsRunningOnChromeOS()) { | 561 if (system::runtime_environment::IsRunningOnChromeOS()) { |
| 555 return new BluetoothAgentServiceProviderImpl(bus, object_path, delegate); | 562 return new BluetoothAgentServiceProviderImpl(bus, object_path, delegate); |
| 556 } else { | 563 } else { |
| 557 return new BluetoothAgentServiceProviderStubImpl(delegate); | 564 return new BluetoothAgentServiceProviderStubImpl(delegate); |
| 558 } | 565 } |
| 559 } | 566 } |
| 560 | 567 |
| 561 } // namespace chromeos | 568 } // namespace chromeos |
| OLD | NEW |