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

Side by Side Diff: chrome/browser/chromeos/dbus/session_manager_client.cc

Issue 9961014: Add calls to store/retrieve user policy to SessionManagerClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser tests. Created 8 years, 8 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 | Annotate | Revision Log
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 "chrome/browser/chromeos/dbus/session_manager_client.h" 5 #include "chrome/browser/chromeos/dbus/session_manager_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "dbus/bus.h" 10 #include "dbus/bus.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 dbus::MessageWriter writer(&method_call); 127 dbus::MessageWriter writer(&method_call);
128 writer.AppendString(""); // Unique ID is deprecated 128 writer.AppendString(""); // Unique ID is deprecated
129 session_manager_proxy_->CallMethod( 129 session_manager_proxy_->CallMethod(
130 &method_call, 130 &method_call,
131 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 131 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
132 base::Bind(&SessionManagerClientImpl::OnStopSession, 132 base::Bind(&SessionManagerClientImpl::OnStopSession,
133 weak_ptr_factory_.GetWeakPtr())); 133 weak_ptr_factory_.GetWeakPtr()));
134 } 134 }
135 135
136 // SessionManagerClient override. 136 // SessionManagerClient override.
137 virtual void RetrievePolicy(RetrievePolicyCallback callback) OVERRIDE { 137 virtual void RetrieveDevicePolicy(RetrievePolicyCallback callback) OVERRIDE {
138 CallRetrievePolicy(login_manager::kSessionManagerRetrievePolicy,
139 callback);
140 }
141
142 // SessionManagerClient override.
143 virtual void RetrieveUserPolicy(RetrievePolicyCallback callback) OVERRIDE {
144 CallRetrievePolicy(login_manager::kSessionManagerRetrieveUserPolicy,
145 callback);
146 }
147
148 // SessionManagerClient override.
149 virtual void StoreDevicePolicy(const std::string& policy_blob,
150 StorePolicyCallback callback) OVERRIDE {
151 CallStorePolicy(login_manager::kSessionManagerStorePolicy,
152 policy_blob, callback);
153 }
154
155 // SessionManagerClient override.
156 virtual void StoreUserPolicy(const std::string& policy_blob,
157 StorePolicyCallback callback) OVERRIDE {
158 CallStorePolicy(login_manager::kSessionManagerStoreUserPolicy,
159 policy_blob, callback);
160 }
161
162 private:
163 // Helper for Retrieve{User,Device}Policy.
164 virtual void CallRetrievePolicy(const char* method_name,
165 RetrievePolicyCallback callback) {
138 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 166 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
139 login_manager::kSessionManagerRetrievePolicy); 167 method_name);
140 session_manager_proxy_->CallMethod( 168 session_manager_proxy_->CallMethod(
141 &method_call, 169 &method_call,
142 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 170 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
143 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, 171 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy,
144 weak_ptr_factory_.GetWeakPtr(), 172 weak_ptr_factory_.GetWeakPtr(),
173 method_name,
145 callback)); 174 callback));
146 } 175 }
147 176
148 // SessionManagerClient override. 177 // Helper for Store{User,Device}Policy.
149 virtual void StorePolicy(const std::string& policy_blob, 178 virtual void CallStorePolicy(const char* method_name,
satorux1 2012/04/04 19:41:15 Please use const std::string&. we rarely use const
Mattias Nissler (ping if slow) 2012/04/05 09:29:14 Done.
150 StorePolicyCallback callback) OVERRIDE { 179 const std::string& policy_blob,
180 StorePolicyCallback callback) {
151 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, 181 dbus::MethodCall method_call(login_manager::kSessionManagerInterface,
152 login_manager::kSessionManagerStorePolicy); 182 method_name);
153 dbus::MessageWriter writer(&method_call); 183 dbus::MessageWriter writer(&method_call);
154 // static_cast does not work due to signedness. 184 // static_cast does not work due to signedness.
155 writer.AppendArrayOfBytes( 185 writer.AppendArrayOfBytes(
156 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size()); 186 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size());
157 session_manager_proxy_->CallMethod( 187 session_manager_proxy_->CallMethod(
158 &method_call, 188 &method_call,
159 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 189 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
160 base::Bind(&SessionManagerClientImpl::OnStorePolicy, 190 base::Bind(&SessionManagerClientImpl::OnStorePolicy,
161 weak_ptr_factory_.GetWeakPtr(), 191 weak_ptr_factory_.GetWeakPtr(),
192 method_name,
162 callback)); 193 callback));
163 } 194 }
164 195
165 private:
166 // Called when kSessionManagerEmitLoginPromptReady method is complete. 196 // Called when kSessionManagerEmitLoginPromptReady method is complete.
167 void OnEmitLoginPromptReady(dbus::Response* response) { 197 void OnEmitLoginPromptReady(dbus::Response* response) {
168 LOG_IF(ERROR, !response) 198 LOG_IF(ERROR, !response)
169 << "Failed to call " 199 << "Failed to call "
170 << login_manager::kSessionManagerEmitLoginPromptReady; 200 << login_manager::kSessionManagerEmitLoginPromptReady;
171 } 201 }
172 202
173 // Called when kSessionManagerEmitLoginPromptVisible method is complete. 203 // Called when kSessionManagerEmitLoginPromptVisible method is complete.
174 void OnEmitLoginPromptVisible(dbus::Response* response) { 204 void OnEmitLoginPromptVisible(dbus::Response* response) {
175 LOG_IF(ERROR, !response) 205 LOG_IF(ERROR, !response)
(...skipping 22 matching lines...) Expand all
198 << login_manager::kSessionManagerStartSession; 228 << login_manager::kSessionManagerStartSession;
199 } 229 }
200 230
201 // Called when kSessionManagerStopSession method is complete. 231 // Called when kSessionManagerStopSession method is complete.
202 void OnStopSession(dbus::Response* response) { 232 void OnStopSession(dbus::Response* response) {
203 LOG_IF(ERROR, !response) 233 LOG_IF(ERROR, !response)
204 << "Failed to call " 234 << "Failed to call "
205 << login_manager::kSessionManagerStopSession; 235 << login_manager::kSessionManagerStopSession;
206 } 236 }
207 237
208 // Called when kSessionManagerRetrievePolicy method is complete. 238 // Called when kSessionManagerRetrievePolicy or
209 void OnRetrievePolicy(RetrievePolicyCallback callback, 239 // kSessionManagerRetrieveUserPolicy method is complete.
240 void OnRetrievePolicy(const char* method_name,
241 RetrievePolicyCallback callback,
210 dbus::Response* response) { 242 dbus::Response* response) {
211 if (!response) { 243 if (!response) {
212 LOG(ERROR) << "Failed to call " 244 LOG(ERROR) << "Failed to call " << method_name;
213 << login_manager::kSessionManagerRetrievePolicy;
214 callback.Run(""); 245 callback.Run("");
215 return; 246 return;
216 } 247 }
217 dbus::MessageReader reader(response); 248 dbus::MessageReader reader(response);
218 uint8* values = NULL; 249 uint8* values = NULL;
219 size_t length = 0; 250 size_t length = 0;
220 if (!reader.PopArrayOfBytes(&values, &length)) { 251 if (!reader.PopArrayOfBytes(&values, &length)) {
221 LOG(ERROR) << "Invalid response: " << response->ToString(); 252 LOG(ERROR) << "Invalid response: " << response->ToString();
222 callback.Run(""); 253 callback.Run("");
223 return; 254 return;
224 } 255 }
225 // static_cast does not work due to signedness. 256 // static_cast does not work due to signedness.
226 std::string serialized_proto(reinterpret_cast<char*>(values), length); 257 std::string serialized_proto(reinterpret_cast<char*>(values), length);
227 callback.Run(serialized_proto); 258 callback.Run(serialized_proto);
228 } 259 }
229 260
230 // Called when kSessionManagerStorePolicy method is complete. 261 // Called when kSessionManagerStorePolicy or kSessionManagerStoreUserPolicy
231 void OnStorePolicy(StorePolicyCallback callback, dbus::Response* response) { 262 // method is complete.
263 void OnStorePolicy(const char* method_name,
264 StorePolicyCallback callback,
265 dbus::Response* response) {
266 bool success = false;
232 if (!response) { 267 if (!response) {
233 LOG(ERROR) << "Failed to call " 268 LOG(ERROR) << "Failed to call " << method_name;
234 << login_manager::kSessionManagerStorePolicy; 269 } else {
235 return; 270 dbus::MessageReader reader(response);
236 } 271 if (!reader.PopBool(&success))
237 dbus::MessageReader reader(response); 272 LOG(ERROR) << "Invalid response: " << response->ToString();
238 bool success = false;
239 if (!reader.PopBool(&success)) {
240 LOG(ERROR) << "Invalid response: " << response->ToString();
241 return;
242 } 273 }
243 callback.Run(success); 274 callback.Run(success);
244 } 275 }
245 276
246 // Called when the owner key set signal is received. 277 // Called when the owner key set signal is received.
247 void OwnerKeySetReceived(dbus::Signal* signal) { 278 void OwnerKeySetReceived(dbus::Signal* signal) {
248 dbus::MessageReader reader(signal); 279 dbus::MessageReader reader(signal);
249 std::string result_string; 280 std::string result_string;
250 if (!reader.PopString(&result_string)) { 281 if (!reader.PopString(&result_string)) {
251 LOG(ERROR) << "Invalid signal: " << signal->ToString(); 282 LOG(ERROR) << "Invalid signal: " << signal->ToString();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 class SessionManagerClientStubImpl : public SessionManagerClient { 317 class SessionManagerClientStubImpl : public SessionManagerClient {
287 // SessionManagerClient overrides. 318 // SessionManagerClient overrides.
288 virtual void AddObserver(Observer* observer) OVERRIDE {} 319 virtual void AddObserver(Observer* observer) OVERRIDE {}
289 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 320 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
290 virtual void EmitLoginPromptReady() OVERRIDE {} 321 virtual void EmitLoginPromptReady() OVERRIDE {}
291 virtual void EmitLoginPromptVisible() OVERRIDE {} 322 virtual void EmitLoginPromptVisible() OVERRIDE {}
292 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {} 323 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {}
293 virtual void RestartEntd() OVERRIDE {} 324 virtual void RestartEntd() OVERRIDE {}
294 virtual void StartSession(const std::string& user_email) OVERRIDE {} 325 virtual void StartSession(const std::string& user_email) OVERRIDE {}
295 virtual void StopSession() OVERRIDE {} 326 virtual void StopSession() OVERRIDE {}
296 virtual void RetrievePolicy(RetrievePolicyCallback callback) OVERRIDE { 327 virtual void RetrieveDevicePolicy(RetrievePolicyCallback callback) OVERRIDE {
297 callback.Run(""); 328 callback.Run("");
298 } 329 }
299 virtual void StorePolicy(const std::string& policy_blob, 330 virtual void RetrieveUserPolicy(RetrievePolicyCallback callback) OVERRIDE {
300 StorePolicyCallback callback) OVERRIDE { 331 callback.Run("");
332 }
333 virtual void StoreDevicePolicy(const std::string& policy_blob,
334 StorePolicyCallback callback) OVERRIDE {
301 callback.Run(true); 335 callback.Run(true);
302 } 336 }
303 337 virtual void StoreUserPolicy(const std::string& policy_blob,
338 StorePolicyCallback callback) OVERRIDE {
339 callback.Run(true);
340 }
304 }; 341 };
305 342
306 SessionManagerClient::SessionManagerClient() { 343 SessionManagerClient::SessionManagerClient() {
307 } 344 }
308 345
309 SessionManagerClient::~SessionManagerClient() { 346 SessionManagerClient::~SessionManagerClient() {
310 } 347 }
311 348
312 SessionManagerClient* SessionManagerClient::Create( 349 SessionManagerClient* SessionManagerClient::Create(
313 DBusClientImplementationType type, 350 DBusClientImplementationType type,
314 dbus::Bus* bus) { 351 dbus::Bus* bus) {
315 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 352 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
316 return new SessionManagerClientImpl(bus); 353 return new SessionManagerClientImpl(bus);
317 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 354 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
318 return new SessionManagerClientStubImpl(); 355 return new SessionManagerClientStubImpl();
319 } 356 }
320 357
321 } // namespace chromeos 358 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698