Chromium Code Reviews| 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 "chrome/browser/policy/cloud/user_cloud_policy_store.h" | 5 #include "chrome/browser/policy/cloud/user_cloud_policy_store.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace | 94 } // namespace |
| 95 | 95 |
| 96 UserCloudPolicyStore::UserCloudPolicyStore( | 96 UserCloudPolicyStore::UserCloudPolicyStore( |
| 97 Profile* profile, | 97 Profile* profile, |
| 98 const base::FilePath& path, | 98 const base::FilePath& path, |
| 99 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 99 scoped_refptr<base::SequencedTaskRunner> background_task_runner) |
| 100 : UserCloudPolicyStoreBase(background_task_runner), | 100 : UserCloudPolicyStoreBase(background_task_runner), |
| 101 weak_factory_(this), | 101 weak_factory_(this), |
| 102 profile_(profile), | 102 profile_(profile), |
|
Joao da Silva
2013/11/04 09:58:32
This can now be removed, please do it.
pneubeck (no reviews)
2013/11/04 10:59:46
Done.
| |
| 103 backing_file_path_(path) {} | 103 backing_file_path_(path) {} |
| 104 | 104 |
| 105 UserCloudPolicyStore::~UserCloudPolicyStore() {} | 105 UserCloudPolicyStore::~UserCloudPolicyStore() {} |
| 106 | 106 |
| 107 // static | 107 // static |
| 108 scoped_ptr<UserCloudPolicyStore> UserCloudPolicyStore::Create( | 108 scoped_ptr<UserCloudPolicyStore> UserCloudPolicyStore::Create( |
| 109 Profile* profile, | 109 Profile* profile, |
| 110 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 110 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
| 111 base::FilePath path = | 111 base::FilePath path = |
| 112 profile->GetPath().Append(kPolicyDir).Append(kPolicyCacheFile); | 112 profile->GetPath().Append(kPolicyDir).Append(kPolicyCacheFile); |
| 113 return make_scoped_ptr( | 113 return make_scoped_ptr( |
| 114 new UserCloudPolicyStore(profile, path, background_task_runner)); | 114 new UserCloudPolicyStore(profile, path, background_task_runner)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void UserCloudPolicyStore::SetSigninUsername(const std::string& username) { | |
| 118 signin_username_ = username; | |
| 119 } | |
| 120 | |
| 117 void UserCloudPolicyStore::LoadImmediately() { | 121 void UserCloudPolicyStore::LoadImmediately() { |
| 118 DVLOG(1) << "Initiating immediate policy load from disk"; | 122 DVLOG(1) << "Initiating immediate policy load from disk"; |
| 119 // Cancel any pending Load/Store/Validate operations. | 123 // Cancel any pending Load/Store/Validate operations. |
| 120 weak_factory_.InvalidateWeakPtrs(); | 124 weak_factory_.InvalidateWeakPtrs(); |
| 121 // Load the policy from disk... | 125 // Load the policy from disk... |
| 122 PolicyLoadResult result = LoadPolicyFromDisk(backing_file_path_); | 126 PolicyLoadResult result = LoadPolicyFromDisk(backing_file_path_); |
| 123 // ...and install it, reporting success/failure to any observers. | 127 // ...and install it, reporting success/failure to any observers. |
| 124 PolicyLoaded(false, result); | 128 PolicyLoaded(false, result); |
| 125 } | 129 } |
| 126 | 130 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 } | 214 } |
| 211 | 215 |
| 212 void UserCloudPolicyStore::Validate( | 216 void UserCloudPolicyStore::Validate( |
| 213 scoped_ptr<em::PolicyFetchResponse> policy, | 217 scoped_ptr<em::PolicyFetchResponse> policy, |
| 214 bool validate_in_background, | 218 bool validate_in_background, |
| 215 const UserCloudPolicyValidator::CompletionCallback& callback) { | 219 const UserCloudPolicyValidator::CompletionCallback& callback) { |
| 216 // Configure the validator. | 220 // Configure the validator. |
| 217 scoped_ptr<UserCloudPolicyValidator> validator = CreateValidator( | 221 scoped_ptr<UserCloudPolicyValidator> validator = CreateValidator( |
| 218 policy.Pass(), | 222 policy.Pass(), |
| 219 CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); | 223 CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); |
| 220 SigninManager* signin = SigninManagerFactory::GetForProfileIfExists(profile_); | |
| 221 if (signin) { | |
| 222 std::string username = signin->GetAuthenticatedUsername(); | |
| 223 if (username.empty()) | |
| 224 username = signin->GetUsernameForAuthInProgress(); | |
| 225 | 224 |
| 226 // Validate the username if the user is signed in (or in the process of | 225 // Validate the username if the user is signed in. |
| 227 // signing in). | 226 if (!signin_username_.empty()) |
| 228 if (!username.empty()) | 227 validator->ValidateUsername(signin_username_); |
| 229 validator->ValidateUsername(username); | |
| 230 } | |
| 231 | 228 |
| 232 if (validate_in_background) { | 229 if (validate_in_background) { |
| 233 // Start validation in the background. The Validator will free itself once | 230 // Start validation in the background. The Validator will free itself once |
| 234 // validation is complete. | 231 // validation is complete. |
| 235 validator.release()->StartValidation(callback); | 232 validator.release()->StartValidation(callback); |
| 236 } else { | 233 } else { |
| 237 // Run validation immediately and invoke the callback with the results. | 234 // Run validation immediately and invoke the callback with the results. |
| 238 validator->RunValidation(); | 235 validator->RunValidation(); |
| 239 callback.Run(validator.get()); | 236 callback.Run(validator.get()); |
| 240 } | 237 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 255 background_task_runner()->PostTask( | 252 background_task_runner()->PostTask( |
| 256 FROM_HERE, | 253 FROM_HERE, |
| 257 base::Bind(&StorePolicyToDiskOnBackgroundThread, | 254 base::Bind(&StorePolicyToDiskOnBackgroundThread, |
| 258 backing_file_path_, *validator->policy())); | 255 backing_file_path_, *validator->policy())); |
| 259 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass()); | 256 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass()); |
| 260 status_ = STATUS_OK; | 257 status_ = STATUS_OK; |
| 261 NotifyStoreLoaded(); | 258 NotifyStoreLoaded(); |
| 262 } | 259 } |
| 263 | 260 |
| 264 } // namespace policy | 261 } // namespace policy |
| OLD | NEW |