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" |
| 11 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 11 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| 12 #include "chrome/browser/policy/proto/cloud/device_management_local.pb.h" | 12 #include "chrome/browser/policy/proto/cloud/device_management_local.pb.h" |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/browser/signin/signin_manager.h" | 13 #include "chrome/browser/signin/signin_manager.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "policy/policy_constants.h" | 15 #include "policy/policy_constants.h" |
| 17 #include "policy/proto/cloud_policy.pb.h" | 16 #include "policy/proto/cloud_policy.pb.h" |
| 18 | 17 |
| 19 namespace em = enterprise_management; | 18 namespace em = enterprise_management; |
| 20 | 19 |
| 21 namespace policy { | 20 namespace policy { |
| 22 | 21 |
| 23 enum PolicyLoadStatus { | 22 enum PolicyLoadStatus { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 86 |
| 88 int size = data.size(); | 87 int size = data.size(); |
| 89 if (file_util::WriteFile(path, data.c_str(), size) != size) { | 88 if (file_util::WriteFile(path, data.c_str(), size) != size) { |
| 90 DLOG(WARNING) << "Failed to write " << path.value(); | 89 DLOG(WARNING) << "Failed to write " << path.value(); |
| 91 } | 90 } |
| 92 } | 91 } |
| 93 | 92 |
| 94 } // namespace | 93 } // namespace |
| 95 | 94 |
| 96 UserCloudPolicyStore::UserCloudPolicyStore( | 95 UserCloudPolicyStore::UserCloudPolicyStore( |
| 97 Profile* profile, | 96 content::BrowserContext* context, |
| 98 const base::FilePath& path, | 97 const base::FilePath& path, |
| 99 scoped_refptr<base::SequencedTaskRunner> background_task_runner) | 98 scoped_refptr<base::SequencedTaskRunner> background_task_runner) |
| 100 : UserCloudPolicyStoreBase(background_task_runner), | 99 : UserCloudPolicyStoreBase(background_task_runner), |
| 101 weak_factory_(this), | 100 weak_factory_(this), |
| 102 profile_(profile), | 101 context_(context), |
| 103 backing_file_path_(path) {} | 102 backing_file_path_(path) {} |
| 104 | 103 |
| 105 UserCloudPolicyStore::~UserCloudPolicyStore() {} | 104 UserCloudPolicyStore::~UserCloudPolicyStore() {} |
| 106 | 105 |
| 107 // static | 106 // static |
| 108 scoped_ptr<UserCloudPolicyStore> UserCloudPolicyStore::Create( | 107 scoped_ptr<UserCloudPolicyStore> UserCloudPolicyStore::Create( |
| 109 Profile* profile, | 108 content::BrowserContext* context, |
| 110 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { | 109 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { |
| 111 base::FilePath path = | 110 base::FilePath path = |
| 112 profile->GetPath().Append(kPolicyDir).Append(kPolicyCacheFile); | 111 context->GetPath().Append(kPolicyDir).Append(kPolicyCacheFile); |
| 113 return make_scoped_ptr( | 112 return make_scoped_ptr( |
| 114 new UserCloudPolicyStore(profile, path, background_task_runner)); | 113 new UserCloudPolicyStore(context, path, background_task_runner)); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void UserCloudPolicyStore::LoadImmediately() { | 116 void UserCloudPolicyStore::LoadImmediately() { |
| 118 DVLOG(1) << "Initiating immediate policy load from disk"; | 117 DVLOG(1) << "Initiating immediate policy load from disk"; |
| 119 // Cancel any pending Load/Store/Validate operations. | 118 // Cancel any pending Load/Store/Validate operations. |
| 120 weak_factory_.InvalidateWeakPtrs(); | 119 weak_factory_.InvalidateWeakPtrs(); |
| 121 // Load the policy from disk... | 120 // Load the policy from disk... |
| 122 PolicyLoadResult result = LoadPolicyFromDisk(backing_file_path_); | 121 PolicyLoadResult result = LoadPolicyFromDisk(backing_file_path_); |
| 123 // ...and install it, reporting success/failure to any observers. | 122 // ...and install it, reporting success/failure to any observers. |
| 124 PolicyLoaded(false, result); | 123 PolicyLoaded(false, result); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 } | 209 } |
| 211 | 210 |
| 212 void UserCloudPolicyStore::Validate( | 211 void UserCloudPolicyStore::Validate( |
| 213 scoped_ptr<em::PolicyFetchResponse> policy, | 212 scoped_ptr<em::PolicyFetchResponse> policy, |
| 214 bool validate_in_background, | 213 bool validate_in_background, |
| 215 const UserCloudPolicyValidator::CompletionCallback& callback) { | 214 const UserCloudPolicyValidator::CompletionCallback& callback) { |
| 216 // Configure the validator. | 215 // Configure the validator. |
| 217 scoped_ptr<UserCloudPolicyValidator> validator = CreateValidator( | 216 scoped_ptr<UserCloudPolicyValidator> validator = CreateValidator( |
| 218 policy.Pass(), | 217 policy.Pass(), |
| 219 CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); | 218 CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); |
| 220 SigninManager* signin = SigninManagerFactory::GetForProfileIfExists(profile_); | 219 SigninManager* signin = |
| 220 SigninManagerFactory::GetForBrowserContextIfExists(context_); | |
|
Joao da Silva
2013/11/04 10:02:55
This renaming (and the changes to signin_manager_*
| |
| 221 if (signin) { | 221 if (signin) { |
| 222 std::string username = signin->GetAuthenticatedUsername(); | 222 std::string username = signin->GetAuthenticatedUsername(); |
| 223 if (username.empty()) | 223 if (username.empty()) |
| 224 username = signin->GetUsernameForAuthInProgress(); | 224 username = signin->GetUsernameForAuthInProgress(); |
| 225 | 225 |
| 226 // Validate the username if the user is signed in (or in the process of | 226 // Validate the username if the user is signed in (or in the process of |
| 227 // signing in). | 227 // signing in). |
| 228 if (!username.empty()) | 228 if (!username.empty()) |
| 229 validator->ValidateUsername(username); | 229 validator->ValidateUsername(username); |
| 230 } | 230 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 255 background_task_runner()->PostTask( | 255 background_task_runner()->PostTask( |
| 256 FROM_HERE, | 256 FROM_HERE, |
| 257 base::Bind(&StorePolicyToDiskOnBackgroundThread, | 257 base::Bind(&StorePolicyToDiskOnBackgroundThread, |
| 258 backing_file_path_, *validator->policy())); | 258 backing_file_path_, *validator->policy())); |
| 259 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass()); | 259 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass()); |
| 260 status_ = STATUS_OK; | 260 status_ = STATUS_OK; |
| 261 NotifyStoreLoaded(); | 261 NotifyStoreLoaded(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace policy | 264 } // namespace policy |
| OLD | NEW |