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 "chromeos/dbus/shill_profile_client.h" | 5 #include "chromeos/dbus/shill_profile_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/values.h" | 10 #include "base/values.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_path.h" | 13 #include "dbus/object_path.h" |
14 #include "dbus/values_util.h" | 14 #include "dbus/values_util.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 chromeos { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // The ShillProfileClient implementation. | 21 // The ShillProfileClient implementation. |
22 class ShillProfileClientImpl : public ShillProfileClient { | 22 class ShillProfileClientImpl : public ShillProfileClient { |
23 public: | 23 public: |
24 explicit ShillProfileClientImpl(dbus::Bus* bus); | 24 explicit ShillProfileClientImpl(dbus::Bus* bus); |
25 | 25 |
26 // ShillProfileClient overrides: | 26 ///////////////////////////////////// |
27 // ShillProfileClient overrides. | |
27 virtual void SetPropertyChangedHandler( | 28 virtual void SetPropertyChangedHandler( |
28 const dbus::ObjectPath& profile_path, | 29 const dbus::ObjectPath& profile_path, |
29 const PropertyChangedHandler& handler) OVERRIDE; | 30 const PropertyChangedHandler& handler) OVERRIDE; |
30 virtual void ResetPropertyChangedHandler( | 31 virtual void ResetPropertyChangedHandler( |
31 const dbus::ObjectPath& profile_path) OVERRIDE; | 32 const dbus::ObjectPath& profile_path) OVERRIDE; |
32 virtual void GetProperties(const dbus::ObjectPath& profile_path, | 33 |
hashimoto
2012/09/24 02:28:56
nit: Remove this line.
| |
33 const DictionaryValueCallback& callback) OVERRIDE; | 34 virtual void GetProperties( |
35 const dbus::ObjectPath& profile_path, | |
36 const DictionaryValueCallbackWithoutStatus& callback, | |
37 const ErrorCallback& error_callback) OVERRIDE; | |
34 virtual void GetEntry(const dbus::ObjectPath& profile_path, | 38 virtual void GetEntry(const dbus::ObjectPath& profile_path, |
35 const std::string& entry_path, | 39 const std::string& entry_path, |
36 const DictionaryValueCallback& callback) OVERRIDE; | 40 const DictionaryValueCallbackWithoutStatus& callback, |
41 const ErrorCallback& error_callback) OVERRIDE; | |
37 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, | 42 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, |
38 const std::string& entry_path, | 43 const std::string& entry_path, |
39 const VoidDBusMethodCallback& callback) OVERRIDE; | 44 const base::Closure& callback, |
45 const ErrorCallback& error_callback) OVERRIDE; | |
40 | 46 |
41 private: | 47 private: |
42 typedef std::map<std::string, ShillClientHelper*> HelperMap; | 48 typedef std::map<std::string, ShillClientHelper*> HelperMap; |
43 | 49 |
44 // Returns the corresponding ShillClientHelper for the profile. | 50 // Returns the corresponding ShillClientHelper for the profile. |
45 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path); | 51 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path); |
46 | 52 |
47 dbus::Bus* bus_; | 53 dbus::Bus* bus_; |
48 HelperMap helpers_; | 54 HelperMap helpers_; |
49 STLValueDeleter<HelperMap> helpers_deleter_; | 55 STLValueDeleter<HelperMap> helpers_deleter_; |
(...skipping 27 matching lines...) Expand all Loading... | |
77 GetHelper(profile_path)->SetPropertyChangedHandler(handler); | 83 GetHelper(profile_path)->SetPropertyChangedHandler(handler); |
78 } | 84 } |
79 | 85 |
80 void ShillProfileClientImpl::ResetPropertyChangedHandler( | 86 void ShillProfileClientImpl::ResetPropertyChangedHandler( |
81 const dbus::ObjectPath& profile_path) { | 87 const dbus::ObjectPath& profile_path) { |
82 GetHelper(profile_path)->ResetPropertyChangedHandler(); | 88 GetHelper(profile_path)->ResetPropertyChangedHandler(); |
83 } | 89 } |
84 | 90 |
85 void ShillProfileClientImpl::GetProperties( | 91 void ShillProfileClientImpl::GetProperties( |
86 const dbus::ObjectPath& profile_path, | 92 const dbus::ObjectPath& profile_path, |
87 const DictionaryValueCallback& callback) { | 93 const DictionaryValueCallbackWithoutStatus& callback, |
94 const ErrorCallback& error_callback) { | |
88 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, | 95 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, |
89 flimflam::kGetPropertiesFunction); | 96 flimflam::kGetPropertiesFunction); |
90 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); | 97 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback( |
98 &method_call, callback, error_callback); | |
91 } | 99 } |
92 | 100 |
93 void ShillProfileClientImpl::GetEntry( | 101 void ShillProfileClientImpl::GetEntry( |
94 const dbus::ObjectPath& profile_path, | 102 const dbus::ObjectPath& profile_path, |
95 const std::string& entry_path, | 103 const std::string& entry_path, |
96 const DictionaryValueCallback& callback) { | 104 const DictionaryValueCallbackWithoutStatus& callback, |
105 const ErrorCallback& error_callback) { | |
97 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, | 106 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, |
98 flimflam::kGetEntryFunction); | 107 flimflam::kGetEntryFunction); |
99 dbus::MessageWriter writer(&method_call); | 108 dbus::MessageWriter writer(&method_call); |
100 writer.AppendString(entry_path); | 109 writer.AppendString(entry_path); |
101 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); | 110 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback( |
111 &method_call, callback, error_callback); | |
102 } | 112 } |
103 | 113 |
104 void ShillProfileClientImpl::DeleteEntry( | 114 void ShillProfileClientImpl::DeleteEntry( |
105 const dbus::ObjectPath& profile_path, | 115 const dbus::ObjectPath& profile_path, |
106 const std::string& entry_path, | 116 const std::string& entry_path, |
107 const VoidDBusMethodCallback& callback) { | 117 const base::Closure& callback, |
118 const ErrorCallback& error_callback) { | |
108 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, | 119 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, |
109 flimflam::kDeleteEntryFunction); | 120 flimflam::kDeleteEntryFunction); |
110 dbus::MessageWriter writer(&method_call); | 121 dbus::MessageWriter writer(&method_call); |
111 writer.AppendString(entry_path); | 122 writer.AppendString(entry_path); |
112 GetHelper(profile_path)->CallVoidMethod(&method_call, callback); | 123 GetHelper(profile_path)->CallVoidMethodWithErrorCallback( |
124 &method_call, callback, error_callback); | |
113 } | 125 } |
114 | 126 |
115 // A stub implementation of ShillProfileClient. | 127 // A stub implementation of ShillProfileClient. |
116 class ShillProfileClientStubImpl : public ShillProfileClient { | 128 class ShillProfileClientStubImpl : public ShillProfileClient { |
117 public: | 129 public: |
118 ShillProfileClientStubImpl() : weak_ptr_factory_(this) {} | 130 ShillProfileClientStubImpl() : weak_ptr_factory_(this) {} |
119 | 131 |
120 virtual ~ShillProfileClientStubImpl() {} | 132 virtual ~ShillProfileClientStubImpl() {} |
121 | 133 |
122 // ShillProfileClient override. | 134 // ShillProfileClient override. |
123 virtual void SetPropertyChangedHandler( | 135 virtual void SetPropertyChangedHandler( |
124 const dbus::ObjectPath& profile_path, | 136 const dbus::ObjectPath& profile_path, |
125 const PropertyChangedHandler& handler) OVERRIDE {} | 137 const PropertyChangedHandler& handler) OVERRIDE {} |
126 | 138 |
127 // ShillProfileClient override. | 139 // ShillProfileClient override. |
128 virtual void ResetPropertyChangedHandler( | 140 virtual void ResetPropertyChangedHandler( |
129 const dbus::ObjectPath& profile_path) OVERRIDE {} | 141 const dbus::ObjectPath& profile_path) OVERRIDE {} |
130 | 142 |
131 // ShillProfileClient override. | 143 virtual void GetProperties( |
132 virtual void GetProperties(const dbus::ObjectPath& profile_path, | 144 const dbus::ObjectPath& profile_path, |
133 const DictionaryValueCallback& callback) OVERRIDE { | 145 const DictionaryValueCallbackWithoutStatus& callback, |
146 const ErrorCallback& error_callback) OVERRIDE { | |
134 MessageLoop::current()->PostTask( | 147 MessageLoop::current()->PostTask( |
135 FROM_HERE, | 148 FROM_HERE, |
136 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, | 149 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, |
137 weak_ptr_factory_.GetWeakPtr(), | 150 weak_ptr_factory_.GetWeakPtr(), |
138 callback)); | 151 callback)); |
139 } | 152 } |
140 | 153 |
141 // ShillProfileClient override. | 154 // ShillProfileClient override. |
142 virtual void GetEntry(const dbus::ObjectPath& profile_path, | 155 virtual void GetEntry(const dbus::ObjectPath& profile_path, |
143 const std::string& entry_path, | 156 const std::string& entry_path, |
144 const DictionaryValueCallback& callback) OVERRIDE { | 157 const DictionaryValueCallbackWithoutStatus& callback, |
158 const ErrorCallback& error_callback) OVERRIDE { | |
145 MessageLoop::current()->PostTask( | 159 MessageLoop::current()->PostTask( |
146 FROM_HERE, | 160 FROM_HERE, |
147 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, | 161 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, |
148 weak_ptr_factory_.GetWeakPtr(), | 162 weak_ptr_factory_.GetWeakPtr(), |
149 callback)); | 163 callback)); |
150 } | 164 } |
151 | 165 |
152 // ShillProfileClient override. | 166 // ShillProfileClient override. |
153 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, | 167 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, |
154 const std::string& entry_path, | 168 const std::string& entry_path, |
155 const VoidDBusMethodCallback& callback) OVERRIDE { | 169 const base::Closure& callback, |
156 MessageLoop::current()->PostTask(FROM_HERE, | 170 const ErrorCallback& error_callback) OVERRIDE { |
157 base::Bind(callback, | 171 MessageLoop::current()->PostTask(FROM_HERE, callback); |
158 DBUS_METHOD_CALL_SUCCESS)); | |
159 } | 172 } |
160 | 173 |
161 private: | 174 private: |
162 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { | 175 void PassEmptyDictionaryValue( |
176 const DictionaryValueCallbackWithoutStatus& callback) const { | |
163 base::DictionaryValue dictionary; | 177 base::DictionaryValue dictionary; |
164 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); | 178 callback.Run(dictionary); |
165 } | 179 } |
166 | 180 |
167 // Note: This should remain the last member so it'll be destroyed and | 181 // Note: This should remain the last member so it'll be destroyed and |
168 // invalidate its weak pointers before any other members are destroyed. | 182 // invalidate its weak pointers before any other members are destroyed. |
169 base::WeakPtrFactory<ShillProfileClientStubImpl> weak_ptr_factory_; | 183 base::WeakPtrFactory<ShillProfileClientStubImpl> weak_ptr_factory_; |
170 | 184 |
171 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientStubImpl); | 185 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientStubImpl); |
172 }; | 186 }; |
173 | 187 |
174 } // namespace | 188 } // namespace |
175 | 189 |
176 ShillProfileClient::ShillProfileClient() {} | 190 ShillProfileClient::ShillProfileClient() {} |
177 | 191 |
178 ShillProfileClient::~ShillProfileClient() {} | 192 ShillProfileClient::~ShillProfileClient() {} |
179 | 193 |
180 // static | 194 // static |
181 ShillProfileClient* ShillProfileClient::Create( | 195 ShillProfileClient* ShillProfileClient::Create( |
182 DBusClientImplementationType type, | 196 DBusClientImplementationType type, |
183 dbus::Bus* bus) { | 197 dbus::Bus* bus) { |
184 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 198 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
185 return new ShillProfileClientImpl(bus); | 199 return new ShillProfileClientImpl(bus); |
186 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 200 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
187 return new ShillProfileClientStubImpl(); | 201 return new ShillProfileClientStubImpl(); |
188 } | 202 } |
189 | 203 |
190 } // namespace chromeos | 204 } // namespace chromeos |
OLD | NEW |