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

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: Fix bad merge Created 8 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
« no previous file with comments | « chromeos/dbus/shill_profile_client.h ('k') | chromeos/dbus/shill_profile_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 19 matching lines...) Expand all
30 const dbus::ObjectPath& profile_path, 30 const dbus::ObjectPath& profile_path,
31 ShillPropertyChangedObserver* observer) OVERRIDE { 31 ShillPropertyChangedObserver* observer) OVERRIDE {
32 GetHelper(profile_path)->AddPropertyChangedObserver(observer); 32 GetHelper(profile_path)->AddPropertyChangedObserver(observer);
33 } 33 }
34 34
35 virtual void RemovePropertyChangedObserver( 35 virtual void RemovePropertyChangedObserver(
36 const dbus::ObjectPath& profile_path, 36 const dbus::ObjectPath& profile_path,
37 ShillPropertyChangedObserver* observer) OVERRIDE { 37 ShillPropertyChangedObserver* observer) OVERRIDE {
38 GetHelper(profile_path)->RemovePropertyChangedObserver(observer); 38 GetHelper(profile_path)->RemovePropertyChangedObserver(observer);
39 } 39 }
40 virtual void GetProperties(const dbus::ObjectPath& profile_path, 40 virtual void GetProperties(
41 const DictionaryValueCallback& callback) OVERRIDE; 41 const dbus::ObjectPath& profile_path,
42 const DictionaryValueCallbackWithoutStatus& callback,
43 const ErrorCallback& error_callback) OVERRIDE;
42 virtual void GetEntry(const dbus::ObjectPath& profile_path, 44 virtual void GetEntry(const dbus::ObjectPath& profile_path,
43 const std::string& entry_path, 45 const std::string& entry_path,
44 const DictionaryValueCallback& callback) OVERRIDE; 46 const DictionaryValueCallbackWithoutStatus& callback,
47 const ErrorCallback& error_callback) OVERRIDE;
45 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, 48 virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
46 const std::string& entry_path, 49 const std::string& entry_path,
47 const VoidDBusMethodCallback& callback) OVERRIDE; 50 const base::Closure& callback,
51 const ErrorCallback& error_callback) OVERRIDE;
48 52
49 private: 53 private:
50 typedef std::map<std::string, ShillClientHelper*> HelperMap; 54 typedef std::map<std::string, ShillClientHelper*> HelperMap;
51 55
52 // Returns the corresponding ShillClientHelper for the profile. 56 // Returns the corresponding ShillClientHelper for the profile.
53 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path); 57 ShillClientHelper* GetHelper(const dbus::ObjectPath& profile_path);
54 58
55 dbus::Bus* bus_; 59 dbus::Bus* bus_;
56 HelperMap helpers_; 60 HelperMap helpers_;
57 STLValueDeleter<HelperMap> helpers_deleter_; 61 STLValueDeleter<HelperMap> helpers_deleter_;
(...skipping 16 matching lines...) Expand all
74 dbus::ObjectProxy* object_proxy = 78 dbus::ObjectProxy* object_proxy =
75 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, profile_path); 79 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, profile_path);
76 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy); 80 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy);
77 helper->MonitorPropertyChanged(flimflam::kFlimflamProfileInterface); 81 helper->MonitorPropertyChanged(flimflam::kFlimflamProfileInterface);
78 helpers_.insert(HelperMap::value_type(profile_path.value(), helper)); 82 helpers_.insert(HelperMap::value_type(profile_path.value(), helper));
79 return helper; 83 return helper;
80 } 84 }
81 85
82 void ShillProfileClientImpl::GetProperties( 86 void ShillProfileClientImpl::GetProperties(
83 const dbus::ObjectPath& profile_path, 87 const dbus::ObjectPath& profile_path,
84 const DictionaryValueCallback& callback) { 88 const DictionaryValueCallbackWithoutStatus& callback,
89 const ErrorCallback& error_callback) {
85 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 90 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
86 flimflam::kGetPropertiesFunction); 91 flimflam::kGetPropertiesFunction);
87 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); 92 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback(
93 &method_call, callback, error_callback);
88 } 94 }
89 95
90 void ShillProfileClientImpl::GetEntry( 96 void ShillProfileClientImpl::GetEntry(
91 const dbus::ObjectPath& profile_path, 97 const dbus::ObjectPath& profile_path,
92 const std::string& entry_path, 98 const std::string& entry_path,
93 const DictionaryValueCallback& callback) { 99 const DictionaryValueCallbackWithoutStatus& callback,
100 const ErrorCallback& error_callback) {
94 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 101 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
95 flimflam::kGetEntryFunction); 102 flimflam::kGetEntryFunction);
96 dbus::MessageWriter writer(&method_call); 103 dbus::MessageWriter writer(&method_call);
97 writer.AppendString(entry_path); 104 writer.AppendString(entry_path);
98 GetHelper(profile_path)->CallDictionaryValueMethod(&method_call, callback); 105 GetHelper(profile_path)->CallDictionaryValueMethodWithErrorCallback(
106 &method_call, callback, error_callback);
99 } 107 }
100 108
101 void ShillProfileClientImpl::DeleteEntry( 109 void ShillProfileClientImpl::DeleteEntry(
102 const dbus::ObjectPath& profile_path, 110 const dbus::ObjectPath& profile_path,
103 const std::string& entry_path, 111 const std::string& entry_path,
104 const VoidDBusMethodCallback& callback) { 112 const base::Closure& callback,
113 const ErrorCallback& error_callback) {
105 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface, 114 dbus::MethodCall method_call(flimflam::kFlimflamProfileInterface,
106 flimflam::kDeleteEntryFunction); 115 flimflam::kDeleteEntryFunction);
107 dbus::MessageWriter writer(&method_call); 116 dbus::MessageWriter writer(&method_call);
108 writer.AppendString(entry_path); 117 writer.AppendString(entry_path);
109 GetHelper(profile_path)->CallVoidMethod(&method_call, callback); 118 GetHelper(profile_path)->CallVoidMethodWithErrorCallback(
119 &method_call, callback, error_callback);
110 } 120 }
111 121
112 // A stub implementation of ShillProfileClient. 122 // A stub implementation of ShillProfileClient.
113 class ShillProfileClientStubImpl : public ShillProfileClient { 123 class ShillProfileClientStubImpl : public ShillProfileClient {
114 public: 124 public:
115 ShillProfileClientStubImpl() : weak_ptr_factory_(this) {} 125 ShillProfileClientStubImpl() : weak_ptr_factory_(this) {}
116 126
117 virtual ~ShillProfileClientStubImpl() {} 127 virtual ~ShillProfileClientStubImpl() {}
118 128
119 ////////////////////////////////////// 129 //////////////////////////////////////
120 // ShillProfileClient overrides. 130 // ShillProfileClient overrides.
121 virtual void AddPropertyChangedObserver( 131 virtual void AddPropertyChangedObserver(
122 const dbus::ObjectPath& profile_path, 132 const dbus::ObjectPath& profile_path,
123 ShillPropertyChangedObserver* observer) OVERRIDE {} 133 ShillPropertyChangedObserver* observer) OVERRIDE {}
124 134
125 virtual void RemovePropertyChangedObserver( 135 virtual void RemovePropertyChangedObserver(
126 const dbus::ObjectPath& profile_path, 136 const dbus::ObjectPath& profile_path,
127 ShillPropertyChangedObserver* observer) OVERRIDE {} 137 ShillPropertyChangedObserver* observer) OVERRIDE {}
128 138
129 // ShillProfileClient override. 139 virtual void GetProperties(
130 virtual void GetProperties(const dbus::ObjectPath& profile_path, 140 const dbus::ObjectPath& profile_path,
131 const DictionaryValueCallback& callback) OVERRIDE { 141 const DictionaryValueCallbackWithoutStatus& callback,
142 const ErrorCallback& error_callback) OVERRIDE {
132 MessageLoop::current()->PostTask( 143 MessageLoop::current()->PostTask(
133 FROM_HERE, 144 FROM_HERE,
134 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, 145 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue,
135 weak_ptr_factory_.GetWeakPtr(), 146 weak_ptr_factory_.GetWeakPtr(),
136 callback)); 147 callback));
137 } 148 }
138 149
139 virtual void GetEntry(const dbus::ObjectPath& profile_path, 150 virtual void GetEntry(const dbus::ObjectPath& profile_path,
140 const std::string& entry_path, 151 const std::string& entry_path,
141 const DictionaryValueCallback& callback) OVERRIDE { 152 const DictionaryValueCallbackWithoutStatus& callback,
153 const ErrorCallback& error_callback) OVERRIDE {
142 MessageLoop::current()->PostTask( 154 MessageLoop::current()->PostTask(
143 FROM_HERE, 155 FROM_HERE,
144 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue, 156 base::Bind(&ShillProfileClientStubImpl::PassEmptyDictionaryValue,
145 weak_ptr_factory_.GetWeakPtr(), 157 weak_ptr_factory_.GetWeakPtr(),
146 callback)); 158 callback));
147 } 159 }
148 160
149 virtual void DeleteEntry(const dbus::ObjectPath& profile_path, 161 virtual void DeleteEntry(const dbus::ObjectPath& profile_path,
150 const std::string& entry_path, 162 const std::string& entry_path,
151 const VoidDBusMethodCallback& callback) OVERRIDE { 163 const base::Closure& callback,
152 MessageLoop::current()->PostTask(FROM_HERE, 164 const ErrorCallback& error_callback) OVERRIDE {
153 base::Bind(callback, 165 MessageLoop::current()->PostTask(FROM_HERE, callback);
154 DBUS_METHOD_CALL_SUCCESS));
155 } 166 }
156 167
157 private: 168 private:
158 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { 169 void PassEmptyDictionaryValue(
170 const DictionaryValueCallbackWithoutStatus& callback) const {
159 base::DictionaryValue dictionary; 171 base::DictionaryValue dictionary;
160 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); 172 callback.Run(dictionary);
161 } 173 }
162 174
163 // Note: This should remain the last member so it'll be destroyed and 175 // Note: This should remain the last member so it'll be destroyed and
164 // invalidate its weak pointers before any other members are destroyed. 176 // invalidate its weak pointers before any other members are destroyed.
165 base::WeakPtrFactory<ShillProfileClientStubImpl> weak_ptr_factory_; 177 base::WeakPtrFactory<ShillProfileClientStubImpl> weak_ptr_factory_;
166 178
167 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientStubImpl); 179 DISALLOW_COPY_AND_ASSIGN(ShillProfileClientStubImpl);
168 }; 180 };
169 181
170 } // namespace 182 } // namespace
171 183
172 ShillProfileClient::ShillProfileClient() {} 184 ShillProfileClient::ShillProfileClient() {}
173 185
174 ShillProfileClient::~ShillProfileClient() {} 186 ShillProfileClient::~ShillProfileClient() {}
175 187
176 // static 188 // static
177 ShillProfileClient* ShillProfileClient::Create( 189 ShillProfileClient* ShillProfileClient::Create(
178 DBusClientImplementationType type, 190 DBusClientImplementationType type,
179 dbus::Bus* bus) { 191 dbus::Bus* bus) {
180 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 192 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
181 return new ShillProfileClientImpl(bus); 193 return new ShillProfileClientImpl(bus);
182 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 194 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
183 return new ShillProfileClientStubImpl(); 195 return new ShillProfileClientStubImpl();
184 } 196 }
185 197
186 } // namespace chromeos 198 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/shill_profile_client.h ('k') | chromeos/dbus/shill_profile_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698