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

Side by Side Diff: chromeos/dbus/shill_profile_client.cc

Issue 10949030: This converts the Shill clients to allow propagation of shill errors (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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 (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 virtual void SetPropertyChangedHandler( 27 // ShillProfileClient overrides.
28 virtual void AddPropertyChangedObserver(
28 const dbus::ObjectPath& profile_path, 29 const dbus::ObjectPath& profile_path,
29 const PropertyChangedHandler& handler) OVERRIDE; 30 PropertyChangedObserver* observer) OVERRIDE {
30 virtual void ResetPropertyChangedHandler( 31 GetHelper(profile_path)->AddPropertyChangedObserver(observer);
31 const dbus::ObjectPath& profile_path) OVERRIDE; 32 }
32 virtual void GetProperties(const dbus::ObjectPath& profile_path, 33
33 const DictionaryValueCallback& callback) OVERRIDE; 34 virtual void RemovePropertyChangedObserver(
35 const dbus::ObjectPath& profile_path,
36 PropertyChangedObserver* observer) OVERRIDE {
37 GetHelper(profile_path)->RemovePropertyChangedObserver(observer);
38 }
39 virtual void GetProperties(
40 const dbus::ObjectPath& profile_path,
41 const DictionaryValueCallbackWithoutStatus& callback,
42 const ErrorCallback& error_callback) OVERRIDE;
34 virtual void GetEntry(const dbus::ObjectPath& profile_path, 43 virtual void GetEntry(const dbus::ObjectPath& profile_path,
35 const std::string& entry_path, 44 const std::string& entry_path,
36 const DictionaryValueCallback& callback) OVERRIDE; 45 const DictionaryValueCallbackWithoutStatus& callback,
46 const ErrorCallback& error_callback) OVERRIDE;
37 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, 47 virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
38 const std::string& entry_path, 48 const std::string& entry_path,
39 const VoidDBusMethodCallback& callback) OVERRIDE; 49 const base::Closure& callback,
50 const ErrorCallback& error_callback) OVERRIDE;
40 51
41 private: 52 private:
42 typedef std::map<std::string, ShillClientHelper*> HelperMap; 53 typedef std::map<std::string, ShillClientHelper*> HelperMap;
43 54
44 // Returns the corresponding ShillClientHelper for the profile. 55 // Returns the corresponding ShillClientHelper for the profile.
45 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path); 56 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path);
46 57
47 dbus::Bus* bus_; 58 dbus::Bus* bus_;
48 HelperMap helpers_; 59 HelperMap helpers_;
49 STLValueDeleter<HelperMap> helpers_deleter_; 60 STLValueDeleter<HelperMap> helpers_deleter_;
(...skipping 14 matching lines...) Expand all
64 75
65 // There is no helper for the profile, create it. 76 // There is no helper for the profile, create it.
66 dbus::ObjectProxy* object_proxy = 77 dbus::ObjectProxy* object_proxy =
67 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, profile_path); 78 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, profile_path);
68 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy); 79 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy);
69 helper->MonitorPropertyChanged(flimflam::kFlimflamProfileInterface); 80 helper->MonitorPropertyChanged(flimflam::kFlimflamProfileInterface);
70 helpers_.insert(HelperMap::value_type(profile_path.value(), helper)); 81 helpers_.insert(HelperMap::value_type(profile_path.value(), helper));
71 return helper; 82 return helper;
72 } 83 }
73 84
74 void ShillProfileClientImpl::SetPropertyChangedHandler(
75 const dbus::ObjectPath& profile_path,
76 const PropertyChangedHandler& handler) {
77 GetHelper(profile_path)->SetPropertyChangedHandler(handler);
78 }
79
80 void ShillProfileClientImpl::ResetPropertyChangedHandler(
81 const dbus::ObjectPath& profile_path) {
82 GetHelper(profile_path)->ResetPropertyChangedHandler();
83 }
84
85 void ShillProfileClientImpl::GetProperties( 85 void ShillProfileClientImpl::GetProperties(
86 const dbus::ObjectPath& profile_path, 86 const dbus::ObjectPath& profile_path,
87 const DictionaryValueCallback& callback) { 87 const DictionaryValueCallbackWithoutStatus& callback,
88 const ErrorCallback& error_callback) {
88 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 89 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
89 flimflam::kGetPropertiesFunction); 90 flimflam::kGetPropertiesFunction);
90 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); 91 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback(
92 &method_call, callback, error_callback);
91 } 93 }
92 94
93 void ShillProfileClientImpl::GetEntry( 95 void ShillProfileClientImpl::GetEntry(
94 const dbus::ObjectPath& profile_path, 96 const dbus::ObjectPath& profile_path,
95 const std::string& entry_path, 97 const std::string& entry_path,
96 const DictionaryValueCallback& callback) { 98 const DictionaryValueCallbackWithoutStatus& callback,
99 const ErrorCallback& error_callback) {
97 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 100 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
98 flimflam::kGetEntryFunction); 101 flimflam::kGetEntryFunction);
99 dbus::MessageWriter writer(&method_call); 102 dbus::MessageWriter writer(&method_call);
100 writer.AppendString(entry_path); 103 writer.AppendString(entry_path);
101 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); 104 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback(
105 &method_call, callback, error_callback);
102 } 106 }
103 107
104 void ShillProfileClientImpl::DeleteEntry( 108 void ShillProfileClientImpl::DeleteEntry(
105 const dbus::ObjectPath& profile_path, 109 const dbus::ObjectPath& profile_path,
106 const std::string& entry_path, 110 const std::string& entry_path,
107 const VoidDBusMethodCallback& callback) { 111 const base::Closure& callback,
112 const ErrorCallback& error_callback) {
108 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 113 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
109 flimflam::kDeleteEntryFunction); 114 flimflam::kDeleteEntryFunction);
110 dbus::MessageWriter writer(&method_call); 115 dbus::MessageWriter writer(&method_call);
111 writer.AppendString(entry_path); 116 writer.AppendString(entry_path);
112 GetHelper(profile_path)->CallVoidMethod(&method_call, callback); 117 GetHelper(profile_path)->CallVoidMethodWithErrorCallback(
118 &method_call, callback, error_callback);
113 } 119 }
114 120
115 // A stub implementation of ShillProfileClient. 121 // A stub implementation of ShillProfileClient.
116 class ShillProfileClientStubImpl : public ShillProfileClient { 122 class ShillProfileClientStubImpl : public ShillProfileClient {
117 public: 123 public:
118 ShillProfileClientStubImpl() : weak_ptr_factory_(this) {} 124 ShillProfileClientStubImpl() : weak_ptr_factory_(this) {}
119 125
120 virtual ~ShillProfileClientStubImpl() {} 126 virtual ~ShillProfileClientStubImpl() {}
121 127
122 // ShillProfileClient override. 128 //////////////////////////////////////
123 virtual void SetPropertyChangedHandler( 129 // ShillProfileClient overrides.
130 virtual void AddPropertyChangedObserver(
124 const dbus::ObjectPath& profile_path, 131 const dbus::ObjectPath& profile_path,
125 const PropertyChangedHandler& handler) OVERRIDE {} 132 PropertyChangedObserver* observer) OVERRIDE {}
126 133
127 // ShillProfileClient override. 134 virtual void RemovePropertyChangedObserver(
128 virtual void ResetPropertyChangedHandler( 135 const dbus::ObjectPath& profile_path,
129 const dbus::ObjectPath& profile_path) OVERRIDE {} 136 PropertyChangedObserver* observer) OVERRIDE {}
130 137
131 // ShillProfileClient override. 138 virtual void GetProperties(
132 virtual void GetProperties(const dbus::ObjectPath& profile_path, 139 const dbus::ObjectPath& profile_path,
133 const DictionaryValueCallback& callback) OVERRIDE { 140 const DictionaryValueCallbackWithoutStatus& callback,
141 const ErrorCallback& error_callback) OVERRIDE {
134 MessageLoop::current()->PostTask( 142 MessageLoop::current()->PostTask(
135 FROM_HERE, 143 FROM_HERE,
136 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, 144 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue,
137 weak_ptr_factory_.GetWeakPtr(), 145 weak_ptr_factory_.GetWeakPtr(),
138 callback)); 146 callback));
139 } 147 }
140 148
141 // ShillProfileClient override.
142 virtual void GetEntry(const dbus::ObjectPath& profile_path, 149 virtual void GetEntry(const dbus::ObjectPath& profile_path,
143 const std::string& entry_path, 150 const std::string& entry_path,
144 const DictionaryValueCallback& callback) OVERRIDE { 151 const DictionaryValueCallbackWithoutStatus& callback,
152 const ErrorCallback& error_callback) OVERRIDE {
145 MessageLoop::current()->PostTask( 153 MessageLoop::current()->PostTask(
146 FROM_HERE, 154 FROM_HERE,
147 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, 155 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue,
148 weak_ptr_factory_.GetWeakPtr(), 156 weak_ptr_factory_.GetWeakPtr(),
149 callback)); 157 callback));
150 } 158 }
151 159
152 // ShillProfileClient override.
153 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, 160 virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
154 const std::string& entry_path, 161 const std::string& entry_path,
155 const VoidDBusMethodCallback& callback) OVERRIDE { 162 const base::Closure& callback,
156 MessageLoop::current()->PostTask(FROM_HERE, 163 const ErrorCallback& error_callback) OVERRIDE {
157 base::Bind(callback, 164 MessageLoop::current()->PostTask(FROM_HERE, callback);
158 DBUS_METHOD_CALL_SUCCESS));
159 } 165 }
160 166
161 private: 167 private:
162 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { 168 void PassEmptyDictionaryValue(
169 const DictionaryValueCallbackWithoutStatus& callback) const {
163 base::DictionaryValue dictionary; 170 base::DictionaryValue dictionary;
164 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); 171 callback.Run(dictionary);
165 } 172 }
166 173
167 // Note: This should remain the last member so it'll be destroyed and 174 // Note: This should remain the last member so it'll be destroyed and
168 // invalidate its weak pointers before any other members are destroyed. 175 // invalidate its weak pointers before any other members are destroyed.
169 base::WeakPtrFactory<ShillProfileClientStubImpl> weak_ptr_factory_; 176 base::WeakPtrFactory<ShillProfileClientStubImpl> weak_ptr_factory_;
170 177
171 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientStubImpl); 178 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientStubImpl);
172 }; 179 };
173 180
174 } // namespace 181 } // namespace
175 182
176 ShillProfileClient::ShillProfileClient() {} 183 ShillProfileClient::ShillProfileClient() {}
177 184
178 ShillProfileClient::~ShillProfileClient() {} 185 ShillProfileClient::~ShillProfileClient() {}
179 186
180 // static 187 // static
181 ShillProfileClient* ShillProfileClient::Create( 188 ShillProfileClient* ShillProfileClient::Create(
182 DBusClientImplementationType type, 189 DBusClientImplementationType type,
183 dbus::Bus* bus) { 190 dbus::Bus* bus) {
184 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 191 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
185 return new ShillProfileClientImpl(bus); 192 return new ShillProfileClientImpl(bus);
186 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 193 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
187 return new ShillProfileClientStubImpl(); 194 return new ShillProfileClientStubImpl();
188 } 195 }
189 196
190 } // namespace chromeos 197 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698