Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Side by Side Diff: device/bluetooth/dbus/bluetooth_input_client.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
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 "chromeos/dbus/bluetooth_input_client.h" 5 #include "device/bluetooth/dbus/bluetooth_input_client.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "dbus/bus.h" 11 #include "dbus/bus.h"
12 #include "dbus/message.h" 12 #include "dbus/message.h"
13 #include "dbus/object_manager.h" 13 #include "dbus/object_manager.h"
14 #include "dbus/object_proxy.h" 14 #include "dbus/object_proxy.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 16
17 namespace chromeos { 17 namespace bluez {
18 18
19 BluetoothInputClient::Properties::Properties( 19 BluetoothInputClient::Properties::Properties(
20 dbus::ObjectProxy* object_proxy, 20 dbus::ObjectProxy* object_proxy,
21 const std::string& interface_name, 21 const std::string& interface_name,
22 const PropertyChangedCallback& callback) 22 const PropertyChangedCallback& callback)
23 : dbus::PropertySet(object_proxy, interface_name, callback) { 23 : dbus::PropertySet(object_proxy, interface_name, callback) {
24 RegisterProperty(bluetooth_input::kReconnectModeProperty, &reconnect_mode); 24 RegisterProperty(bluetooth_input::kReconnectModeProperty, &reconnect_mode);
25 } 25 }
26 26
27 BluetoothInputClient::Properties::~Properties() { 27 BluetoothInputClient::Properties::~Properties() {}
28 }
29
30 28
31 // The BluetoothInputClient implementation used in production. 29 // The BluetoothInputClient implementation used in production.
32 class BluetoothInputClientImpl 30 class BluetoothInputClientImpl : public BluetoothInputClient,
33 : public BluetoothInputClient, 31 public dbus::ObjectManager::Interface {
34 public dbus::ObjectManager::Interface {
35 public: 32 public:
36 BluetoothInputClientImpl() : object_manager_(NULL), weak_ptr_factory_(this) {} 33 BluetoothInputClientImpl() : object_manager_(NULL), weak_ptr_factory_(this) {}
37 34
38 ~BluetoothInputClientImpl() override { 35 ~BluetoothInputClientImpl() override {
39 object_manager_->UnregisterInterface( 36 object_manager_->UnregisterInterface(
40 bluetooth_input::kBluetoothInputInterface); 37 bluetooth_input::kBluetoothInputInterface);
41 } 38 }
42 39
43 // BluetoothInputClient override. 40 // BluetoothInputClient override.
44 void AddObserver(BluetoothInputClient::Observer* observer) override { 41 void AddObserver(BluetoothInputClient::Observer* observer) override {
45 DCHECK(observer); 42 DCHECK(observer);
46 observers_.AddObserver(observer); 43 observers_.AddObserver(observer);
47 } 44 }
48 45
49 // BluetoothInputClient override. 46 // BluetoothInputClient override.
50 void RemoveObserver(BluetoothInputClient::Observer* observer) override { 47 void RemoveObserver(BluetoothInputClient::Observer* observer) override {
51 DCHECK(observer); 48 DCHECK(observer);
52 observers_.RemoveObserver(observer); 49 observers_.RemoveObserver(observer);
53 } 50 }
54 51
55 // dbus::ObjectManager::Interface override. 52 // dbus::ObjectManager::Interface override.
56 dbus::PropertySet* CreateProperties( 53 dbus::PropertySet* CreateProperties(
57 dbus::ObjectProxy* object_proxy, 54 dbus::ObjectProxy* object_proxy,
58 const dbus::ObjectPath& object_path, 55 const dbus::ObjectPath& object_path,
59 const std::string& interface_name) override { 56 const std::string& interface_name) override {
60 Properties* properties = new Properties( 57 Properties* properties =
61 object_proxy, 58 new Properties(object_proxy, interface_name,
62 interface_name, 59 base::Bind(&BluetoothInputClientImpl::OnPropertyChanged,
63 base::Bind(&BluetoothInputClientImpl::OnPropertyChanged, 60 weak_ptr_factory_.GetWeakPtr(), object_path));
64 weak_ptr_factory_.GetWeakPtr(),
65 object_path));
66 return static_cast<dbus::PropertySet*>(properties); 61 return static_cast<dbus::PropertySet*>(properties);
67 } 62 }
68 63
69 // BluetoothInputClient override. 64 // BluetoothInputClient override.
70 Properties* GetProperties(const dbus::ObjectPath& object_path) override { 65 Properties* GetProperties(const dbus::ObjectPath& object_path) override {
71 return static_cast<Properties*>( 66 return static_cast<Properties*>(object_manager_->GetProperties(
72 object_manager_->GetProperties( 67 object_path, bluetooth_input::kBluetoothInputInterface));
73 object_path,
74 bluetooth_input::kBluetoothInputInterface));
75 } 68 }
76 69
77 protected: 70 protected:
78 void Init(dbus::Bus* bus) override { 71 void Init(dbus::Bus* bus) override {
79 object_manager_ = bus->GetObjectManager( 72 object_manager_ = bus->GetObjectManager(
80 bluetooth_object_manager::kBluetoothObjectManagerServiceName, 73 bluetooth_object_manager::kBluetoothObjectManagerServiceName,
81 dbus::ObjectPath( 74 dbus::ObjectPath(
82 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); 75 bluetooth_object_manager::kBluetoothObjectManagerServicePath));
83 object_manager_->RegisterInterface( 76 object_manager_->RegisterInterface(
84 bluetooth_input::kBluetoothInputInterface, this); 77 bluetooth_input::kBluetoothInputInterface, this);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 110
118 // Weak pointer factory for generating 'this' pointers that might live longer 111 // Weak pointer factory for generating 'this' pointers that might live longer
119 // than we do. 112 // than we do.
120 // Note: This should remain the last member so it'll be destroyed and 113 // Note: This should remain the last member so it'll be destroyed and
121 // invalidate its weak pointers before any other members are destroyed. 114 // invalidate its weak pointers before any other members are destroyed.
122 base::WeakPtrFactory<BluetoothInputClientImpl> weak_ptr_factory_; 115 base::WeakPtrFactory<BluetoothInputClientImpl> weak_ptr_factory_;
123 116
124 DISALLOW_COPY_AND_ASSIGN(BluetoothInputClientImpl); 117 DISALLOW_COPY_AND_ASSIGN(BluetoothInputClientImpl);
125 }; 118 };
126 119
127 BluetoothInputClient::BluetoothInputClient() { 120 BluetoothInputClient::BluetoothInputClient() {}
128 }
129 121
130 BluetoothInputClient::~BluetoothInputClient() { 122 BluetoothInputClient::~BluetoothInputClient() {}
131 }
132 123
133 BluetoothInputClient* BluetoothInputClient::Create() { 124 BluetoothInputClient* BluetoothInputClient::Create() {
134 return new BluetoothInputClientImpl(); 125 return new BluetoothInputClientImpl();
135 } 126 }
136 127
137 } // namespace chromeos 128 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/bluetooth_input_client.h ('k') | device/bluetooth/dbus/bluetooth_le_advertisement_service_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698