| 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/session_manager_client.h" | 5 #include "chromeos/dbus/session_manager_client.h" |
| 6 | 6 |
| 7 #include <map> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" |
| 14 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/threading/worker_pool.h" |
| 17 #include "chromeos/chromeos_paths.h" |
| 18 #include "chromeos/dbus/cryptohome_client.h" |
| 10 #include "dbus/bus.h" | 19 #include "dbus/bus.h" |
| 11 #include "dbus/message.h" | 20 #include "dbus/message.h" |
| 12 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 13 #include "dbus/object_proxy.h" | 22 #include "dbus/object_proxy.h" |
| 14 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 15 | 24 |
| 16 namespace chromeos { | 25 namespace chromeos { |
| 17 | 26 |
| 18 // The SessionManagerClient implementation used in production. | 27 // The SessionManagerClient implementation used in production. |
| 19 class SessionManagerClientImpl : public SessionManagerClient { | 28 class SessionManagerClientImpl : public SessionManagerClient { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 login_manager::kSessionManagerUnlockScreen); | 181 login_manager::kSessionManagerUnlockScreen); |
| 173 } | 182 } |
| 174 | 183 |
| 175 virtual void NotifyLockScreenDismissed() OVERRIDE { | 184 virtual void NotifyLockScreenDismissed() OVERRIDE { |
| 176 SimpleMethodCallToSessionManager( | 185 SimpleMethodCallToSessionManager( |
| 177 login_manager::kSessionManagerHandleLockScreenDismissed); | 186 login_manager::kSessionManagerHandleLockScreenDismissed); |
| 178 } | 187 } |
| 179 | 188 |
| 180 virtual void RetrieveDevicePolicy( | 189 virtual void RetrieveDevicePolicy( |
| 181 const RetrievePolicyCallback& callback) OVERRIDE { | 190 const RetrievePolicyCallback& callback) OVERRIDE { |
| 182 CallRetrievePolicy(login_manager::kSessionManagerRetrievePolicy, | 191 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 183 callback); | 192 login_manager::kSessionManagerRetrievePolicy); |
| 193 session_manager_proxy_->CallMethod( |
| 194 &method_call, |
| 195 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 196 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, |
| 197 weak_ptr_factory_.GetWeakPtr(), |
| 198 login_manager::kSessionManagerRetrievePolicy, |
| 199 callback)); |
| 184 } | 200 } |
| 185 | 201 |
| 186 virtual void RetrieveUserPolicy( | 202 virtual void RetrievePolicyForUser( |
| 203 const std::string& username, |
| 187 const RetrievePolicyCallback& callback) OVERRIDE { | 204 const RetrievePolicyCallback& callback) OVERRIDE { |
| 188 CallRetrievePolicy(login_manager::kSessionManagerRetrieveUserPolicy, | 205 CallRetrievePolicyByUsername( |
| 189 callback); | 206 login_manager::kSessionManagerRetrievePolicyForUser, |
| 207 username, |
| 208 callback); |
| 190 } | 209 } |
| 191 | 210 |
| 192 virtual void RetrieveDeviceLocalAccountPolicy( | 211 virtual void RetrieveDeviceLocalAccountPolicy( |
| 193 const std::string& account_name, | 212 const std::string& account_name, |
| 194 const RetrievePolicyCallback& callback) OVERRIDE { | 213 const RetrievePolicyCallback& callback) OVERRIDE { |
| 195 dbus::MethodCall method_call( | 214 CallRetrievePolicyByUsername( |
| 196 login_manager::kSessionManagerInterface, | 215 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, |
| 197 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy); | 216 account_name, |
| 198 dbus::MessageWriter writer(&method_call); | 217 callback); |
| 199 writer.AppendString(account_name); | |
| 200 session_manager_proxy_->CallMethod( | |
| 201 &method_call, | |
| 202 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 203 base::Bind( | |
| 204 &SessionManagerClientImpl::OnRetrievePolicy, | |
| 205 weak_ptr_factory_.GetWeakPtr(), | |
| 206 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, | |
| 207 callback)); | |
| 208 } | 218 } |
| 209 | 219 |
| 210 virtual void StoreDevicePolicy(const std::string& policy_blob, | 220 virtual void StoreDevicePolicy(const std::string& policy_blob, |
| 211 const StorePolicyCallback& callback) OVERRIDE { | 221 const StorePolicyCallback& callback) OVERRIDE { |
| 212 CallStorePolicy(login_manager::kSessionManagerStorePolicy, | 222 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 213 policy_blob, callback); | 223 login_manager::kSessionManagerStorePolicy); |
| 224 dbus::MessageWriter writer(&method_call); |
| 225 // static_cast does not work due to signedness. |
| 226 writer.AppendArrayOfBytes( |
| 227 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size()); |
| 228 session_manager_proxy_->CallMethod( |
| 229 &method_call, |
| 230 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 231 base::Bind(&SessionManagerClientImpl::OnStorePolicy, |
| 232 weak_ptr_factory_.GetWeakPtr(), |
| 233 login_manager::kSessionManagerStorePolicy, |
| 234 callback)); |
| 214 } | 235 } |
| 215 | 236 |
| 216 virtual void StoreUserPolicy(const std::string& policy_blob, | 237 virtual void StorePolicyForUser( |
| 217 const StorePolicyCallback& callback) OVERRIDE { | 238 const std::string& username, |
| 218 CallStorePolicy(login_manager::kSessionManagerStoreUserPolicy, | 239 const std::string& policy_blob, |
| 219 policy_blob, callback); | 240 const std::string& ignored_policy_key, |
| 241 const StorePolicyCallback& callback) OVERRIDE { |
| 242 CallStorePolicyByUsername(login_manager::kSessionManagerStorePolicyForUser, |
| 243 username, |
| 244 policy_blob, |
| 245 callback); |
| 220 } | 246 } |
| 221 | 247 |
| 222 virtual void StoreDeviceLocalAccountPolicy( | 248 virtual void StoreDeviceLocalAccountPolicy( |
| 223 const std::string& account_name, | 249 const std::string& account_name, |
| 224 const std::string& policy_blob, | 250 const std::string& policy_blob, |
| 225 const StorePolicyCallback& callback) OVERRIDE { | 251 const StorePolicyCallback& callback) OVERRIDE { |
| 226 dbus::MethodCall method_call( | 252 CallStorePolicyByUsername( |
| 227 login_manager::kSessionManagerInterface, | 253 login_manager::kSessionManagerStoreDeviceLocalAccountPolicy, |
| 228 login_manager::kSessionManagerStoreDeviceLocalAccountPolicy); | 254 account_name, |
| 229 dbus::MessageWriter writer(&method_call); | 255 policy_blob, |
| 230 writer.AppendString(account_name); | 256 callback); |
| 231 // static_cast does not work due to signedness. | |
| 232 writer.AppendArrayOfBytes( | |
| 233 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size()); | |
| 234 session_manager_proxy_->CallMethod( | |
| 235 &method_call, | |
| 236 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 237 base::Bind( | |
| 238 &SessionManagerClientImpl::OnStorePolicy, | |
| 239 weak_ptr_factory_.GetWeakPtr(), | |
| 240 login_manager::kSessionManagerStoreDeviceLocalAccountPolicy, | |
| 241 callback)); | |
| 242 } | 257 } |
| 243 | 258 |
| 244 private: | 259 private: |
| 245 // Makes a method call to the session manager with no arguments and no | 260 // Makes a method call to the session manager with no arguments and no |
| 246 // response. | 261 // response. |
| 247 void SimpleMethodCallToSessionManager(const std::string& method_name) { | 262 void SimpleMethodCallToSessionManager(const std::string& method_name) { |
| 248 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 263 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 249 method_name); | 264 method_name); |
| 250 session_manager_proxy_->CallMethod( | 265 session_manager_proxy_->CallMethod( |
| 251 &method_call, | 266 &method_call, |
| 252 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 267 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 253 dbus::ObjectProxy::EmptyResponseCallback()); | 268 dbus::ObjectProxy::EmptyResponseCallback()); |
| 254 } | 269 } |
| 255 | 270 |
| 256 // Helper for Retrieve{User,Device}Policy. | 271 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. |
| 257 virtual void CallRetrievePolicy(const std::string& method_name, | 272 void CallRetrievePolicyByUsername(const std::string& method_name, |
| 258 const RetrievePolicyCallback& callback) { | 273 const std::string& username, |
| 274 const RetrievePolicyCallback& callback) { |
| 259 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 275 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 260 method_name); | 276 method_name); |
| 277 dbus::MessageWriter writer(&method_call); |
| 278 writer.AppendString(username); |
| 261 session_manager_proxy_->CallMethod( | 279 session_manager_proxy_->CallMethod( |
| 262 &method_call, | 280 &method_call, |
| 263 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 281 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 264 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, | 282 base::Bind( |
| 265 weak_ptr_factory_.GetWeakPtr(), | 283 &SessionManagerClientImpl::OnRetrievePolicy, |
| 266 method_name, | 284 weak_ptr_factory_.GetWeakPtr(), |
| 267 callback)); | 285 method_name, |
| 286 callback)); |
| 268 } | 287 } |
| 269 | 288 |
| 270 // Helper for Store{User,Device}Policy. | 289 void CallStorePolicyByUsername(const std::string& method_name, |
| 271 virtual void CallStorePolicy(const std::string& method_name, | 290 const std::string& username, |
| 272 const std::string& policy_blob, | 291 const std::string& policy_blob, |
| 273 const StorePolicyCallback& callback) { | 292 const StorePolicyCallback& callback) { |
| 274 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 293 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 275 method_name); | 294 method_name); |
| 276 dbus::MessageWriter writer(&method_call); | 295 dbus::MessageWriter writer(&method_call); |
| 296 writer.AppendString(username); |
| 277 // static_cast does not work due to signedness. | 297 // static_cast does not work due to signedness. |
| 278 writer.AppendArrayOfBytes( | 298 writer.AppendArrayOfBytes( |
| 279 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size()); | 299 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size()); |
| 280 session_manager_proxy_->CallMethod( | 300 session_manager_proxy_->CallMethod( |
| 281 &method_call, | 301 &method_call, |
| 282 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 302 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 283 base::Bind(&SessionManagerClientImpl::OnStorePolicy, | 303 base::Bind( |
| 284 weak_ptr_factory_.GetWeakPtr(), | 304 &SessionManagerClientImpl::OnStorePolicy, |
| 285 method_name, | 305 weak_ptr_factory_.GetWeakPtr(), |
| 286 callback)); | 306 method_name, |
| 307 callback)); |
| 287 } | 308 } |
| 288 | 309 |
| 289 // Called when kSessionManagerRestartJob method is complete. | 310 // Called when kSessionManagerRestartJob method is complete. |
| 290 void OnRestartJob(dbus::Response* response) { | 311 void OnRestartJob(dbus::Response* response) { |
| 291 LOG_IF(ERROR, !response) | 312 LOG_IF(ERROR, !response) |
| 292 << "Failed to call " | 313 << "Failed to call " |
| 293 << login_manager::kSessionManagerRestartJob; | 314 << login_manager::kSessionManagerRestartJob; |
| 294 } | 315 } |
| 295 | 316 |
| 296 // Called when kSessionManagerStartSession method is complete. | 317 // Called when kSessionManagerStartSession method is complete. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 308 } | 329 } |
| 309 | 330 |
| 310 // Called when kSessionManagerStopSession method is complete. | 331 // Called when kSessionManagerStopSession method is complete. |
| 311 void OnDeviceWipe(dbus::Response* response) { | 332 void OnDeviceWipe(dbus::Response* response) { |
| 312 LOG_IF(ERROR, !response) | 333 LOG_IF(ERROR, !response) |
| 313 << "Failed to call " | 334 << "Failed to call " |
| 314 << login_manager::kSessionManagerStartDeviceWipe; | 335 << login_manager::kSessionManagerStartDeviceWipe; |
| 315 } | 336 } |
| 316 | 337 |
| 317 // Called when kSessionManagerRetrievePolicy or | 338 // Called when kSessionManagerRetrievePolicy or |
| 318 // kSessionManagerRetrieveUserPolicy method is complete. | 339 // kSessionManagerRetrievePolicyForUser method is complete. |
| 319 void OnRetrievePolicy(const std::string& method_name, | 340 void OnRetrievePolicy(const std::string& method_name, |
| 320 const RetrievePolicyCallback& callback, | 341 const RetrievePolicyCallback& callback, |
| 321 dbus::Response* response) { | 342 dbus::Response* response) { |
| 322 if (!response) { | 343 if (!response) { |
| 323 LOG(ERROR) << "Failed to call " << method_name; | 344 LOG(ERROR) << "Failed to call " << method_name; |
| 324 callback.Run(""); | 345 callback.Run(""); |
| 325 return; | 346 return; |
| 326 } | 347 } |
| 327 dbus::MessageReader reader(response); | 348 dbus::MessageReader reader(response); |
| 328 uint8* values = NULL; | 349 uint8* values = NULL; |
| 329 size_t length = 0; | 350 size_t length = 0; |
| 330 if (!reader.PopArrayOfBytes(&values, &length)) { | 351 if (!reader.PopArrayOfBytes(&values, &length)) { |
| 331 LOG(ERROR) << "Invalid response: " << response->ToString(); | 352 LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 332 callback.Run(""); | 353 callback.Run(""); |
| 333 return; | 354 return; |
| 334 } | 355 } |
| 335 // static_cast does not work due to signedness. | 356 // static_cast does not work due to signedness. |
| 336 std::string serialized_proto(reinterpret_cast<char*>(values), length); | 357 std::string serialized_proto(reinterpret_cast<char*>(values), length); |
| 337 callback.Run(serialized_proto); | 358 callback.Run(serialized_proto); |
| 338 } | 359 } |
| 339 | 360 |
| 340 // Called when kSessionManagerStorePolicy or kSessionManagerStoreUserPolicy | 361 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser |
| 341 // method is complete. | 362 // method is complete. |
| 342 void OnStorePolicy(const std::string& method_name, | 363 void OnStorePolicy(const std::string& method_name, |
| 343 const StorePolicyCallback& callback, | 364 const StorePolicyCallback& callback, |
| 344 dbus::Response* response) { | 365 dbus::Response* response) { |
| 345 bool success = false; | 366 bool success = false; |
| 346 if (!response) { | 367 if (!response) { |
| 347 LOG(ERROR) << "Failed to call " << method_name; | 368 LOG(ERROR) << "Failed to call " << method_name; |
| 348 } else { | 369 } else { |
| 349 dbus::MessageReader reader(response); | 370 dbus::MessageReader reader(response); |
| 350 if (!reader.PopBool(&success)) | 371 if (!reader.PopBool(&success)) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // invalidate its weak pointers before any other members are destroyed. | 433 // invalidate its weak pointers before any other members are destroyed. |
| 413 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; | 434 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; |
| 414 | 435 |
| 415 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); | 436 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); |
| 416 }; | 437 }; |
| 417 | 438 |
| 418 // The SessionManagerClient implementation used on Linux desktop, | 439 // The SessionManagerClient implementation used on Linux desktop, |
| 419 // which does nothing. | 440 // which does nothing. |
| 420 class SessionManagerClientStubImpl : public SessionManagerClient { | 441 class SessionManagerClientStubImpl : public SessionManagerClient { |
| 421 public: | 442 public: |
| 422 SessionManagerClientStubImpl() {} | 443 SessionManagerClientStubImpl() { |
| 444 // Make sure that there are no keys left over from a previous browser run. |
| 445 base::FilePath user_policy_key_dir; |
| 446 if (PathService::Get(chromeos::DIR_USER_POLICY_KEYS, |
| 447 &user_policy_key_dir)) { |
| 448 base::WorkerPool::PostTask( |
| 449 FROM_HERE, |
| 450 base::Bind(base::IgnoreResult(&file_util::Delete), |
| 451 user_policy_key_dir, true), |
| 452 false); |
| 453 } |
| 454 } |
| 423 virtual ~SessionManagerClientStubImpl() {} | 455 virtual ~SessionManagerClientStubImpl() {} |
| 424 | 456 |
| 425 // SessionManagerClient overrides. | 457 // SessionManagerClient overrides. |
| 426 virtual void AddObserver(Observer* observer) OVERRIDE { | 458 virtual void AddObserver(Observer* observer) OVERRIDE { |
| 427 observers_.AddObserver(observer); | 459 observers_.AddObserver(observer); |
| 428 } | 460 } |
| 429 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 461 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 430 observers_.RemoveObserver(observer); | 462 observers_.RemoveObserver(observer); |
| 431 } | 463 } |
| 432 virtual bool HasObserver(Observer* observer) OVERRIDE { | 464 virtual bool HasObserver(Observer* observer) OVERRIDE { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 448 virtual void RequestUnlockScreen() OVERRIDE { | 480 virtual void RequestUnlockScreen() OVERRIDE { |
| 449 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); | 481 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); |
| 450 } | 482 } |
| 451 virtual void NotifyLockScreenDismissed() OVERRIDE { | 483 virtual void NotifyLockScreenDismissed() OVERRIDE { |
| 452 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); | 484 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); |
| 453 } | 485 } |
| 454 virtual void RetrieveDevicePolicy( | 486 virtual void RetrieveDevicePolicy( |
| 455 const RetrievePolicyCallback& callback) OVERRIDE { | 487 const RetrievePolicyCallback& callback) OVERRIDE { |
| 456 callback.Run(device_policy_); | 488 callback.Run(device_policy_); |
| 457 } | 489 } |
| 458 virtual void RetrieveUserPolicy( | 490 virtual void RetrievePolicyForUser( |
| 491 const std::string& username, |
| 459 const RetrievePolicyCallback& callback) OVERRIDE { | 492 const RetrievePolicyCallback& callback) OVERRIDE { |
| 460 callback.Run(user_policy_); | 493 callback.Run(user_policies_[username]); |
| 461 } | 494 } |
| 462 virtual void RetrieveDeviceLocalAccountPolicy( | 495 virtual void RetrieveDeviceLocalAccountPolicy( |
| 463 const std::string& account_name, | 496 const std::string& account_name, |
| 464 const RetrievePolicyCallback& callback) OVERRIDE { | 497 const RetrievePolicyCallback& callback) OVERRIDE { |
| 465 callback.Run(""); | 498 callback.Run(user_policies_[account_name]); |
| 466 } | 499 } |
| 467 virtual void StoreDevicePolicy(const std::string& policy_blob, | 500 virtual void StoreDevicePolicy(const std::string& policy_blob, |
| 468 const StorePolicyCallback& callback) OVERRIDE { | 501 const StorePolicyCallback& callback) OVERRIDE { |
| 469 device_policy_ = policy_blob; | 502 device_policy_ = policy_blob; |
| 470 callback.Run(true); | 503 callback.Run(true); |
| 471 } | 504 } |
| 472 virtual void StoreUserPolicy(const std::string& policy_blob, | 505 virtual void StorePolicyForUser( |
| 473 const StorePolicyCallback& callback) OVERRIDE { | 506 const std::string& username, |
| 474 user_policy_ = policy_blob; | 507 const std::string& policy_blob, |
| 475 callback.Run(true); | 508 const std::string& policy_key, |
| 509 const StorePolicyCallback& callback) OVERRIDE { |
| 510 if (policy_key.empty()) { |
| 511 user_policies_[username] = policy_blob; |
| 512 callback.Run(true); |
| 513 return; |
| 514 } |
| 515 // The session manager writes the user policy key to a well-known |
| 516 // location. Do the same with the stub impl, so that user policy works and |
| 517 // can be tested on desktop builds. |
| 518 // TODO(joaodasilva): parse the PolicyFetchResponse in |policy_blob| to get |
| 519 // the policy key directly, after moving the policy protobufs to a top-level |
| 520 // directory. The |policy_key| argument to this method can then be removed. |
| 521 // http://crbug.com/240269 |
| 522 base::FilePath key_path; |
| 523 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &key_path)) { |
| 524 callback.Run(false); |
| 525 return; |
| 526 } |
| 527 const std::string sanitized = |
| 528 CryptohomeClient::GetStubSanitizedUsername(username); |
| 529 key_path = key_path.AppendASCII(sanitized).AppendASCII("policy.pub"); |
| 530 // Assume that the key write is successful. |
| 531 user_policies_[username] = policy_blob; |
| 532 base::WorkerPool::PostTaskAndReply( |
| 533 FROM_HERE, |
| 534 base::Bind(&SessionManagerClientStubImpl::StoreFileInBackground, |
| 535 key_path, policy_key), |
| 536 base::Bind(callback, true), |
| 537 false); |
| 476 } | 538 } |
| 477 virtual void StoreDeviceLocalAccountPolicy( | 539 virtual void StoreDeviceLocalAccountPolicy( |
| 478 const std::string& account_name, | 540 const std::string& account_name, |
| 479 const std::string& policy_blob, | 541 const std::string& policy_blob, |
| 480 const StorePolicyCallback& callback) OVERRIDE { | 542 const StorePolicyCallback& callback) OVERRIDE { |
| 543 user_policies_[account_name] = policy_blob; |
| 481 callback.Run(true); | 544 callback.Run(true); |
| 482 } | 545 } |
| 483 | 546 |
| 547 static void StoreFileInBackground(const base::FilePath& path, |
| 548 const std::string& data) { |
| 549 const int size = static_cast<int>(data.size()); |
| 550 if (!file_util::CreateDirectory(path.DirName()) || |
| 551 file_util::WriteFile(path, data.data(), size) != size) { |
| 552 LOG(WARNING) << "Failed to write policy key to " << path.value(); |
| 553 } |
| 554 } |
| 555 |
| 484 private: | 556 private: |
| 485 ObserverList<Observer> observers_; | 557 ObserverList<Observer> observers_; |
| 486 std::string device_policy_; | 558 std::string device_policy_; |
| 487 std::string user_policy_; | 559 std::map<std::string, std::string> user_policies_; |
| 488 | 560 |
| 489 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientStubImpl); | 561 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientStubImpl); |
| 490 }; | 562 }; |
| 491 | 563 |
| 492 SessionManagerClient::SessionManagerClient() { | 564 SessionManagerClient::SessionManagerClient() { |
| 493 } | 565 } |
| 494 | 566 |
| 495 SessionManagerClient::~SessionManagerClient() { | 567 SessionManagerClient::~SessionManagerClient() { |
| 496 } | 568 } |
| 497 | 569 |
| 498 SessionManagerClient* SessionManagerClient::Create( | 570 SessionManagerClient* SessionManagerClient::Create( |
| 499 DBusClientImplementationType type, | 571 DBusClientImplementationType type, |
| 500 dbus::Bus* bus) { | 572 dbus::Bus* bus) { |
| 501 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 573 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 502 return new SessionManagerClientImpl(bus); | 574 return new SessionManagerClientImpl(bus); |
| 503 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 575 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 504 return new SessionManagerClientStubImpl(); | 576 return new SessionManagerClientStubImpl(); |
| 505 } | 577 } |
| 506 | 578 |
| 507 } // namespace chromeos | 579 } // namespace chromeos |
| OLD | NEW |