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

Side by Side Diff: chrome/browser/policy/cloud/user_cloud_policy_store.cc

Issue 49783006: policy: Remove SigninManager from UserCloudPolicyStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 1 month 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/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
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,
98 const base::FilePath& path, 96 const base::FilePath& path,
99 scoped_refptr<base::SequencedTaskRunner> background_task_runner) 97 scoped_refptr<base::SequencedTaskRunner> background_task_runner)
100 : UserCloudPolicyStoreBase(background_task_runner), 98 : UserCloudPolicyStoreBase(background_task_runner),
101 weak_factory_(this), 99 weak_factory_(this),
102 profile_(profile),
103 backing_file_path_(path) {} 100 backing_file_path_(path) {}
104 101
105 UserCloudPolicyStore::~UserCloudPolicyStore() {} 102 UserCloudPolicyStore::~UserCloudPolicyStore() {}
106 103
107 // static 104 // static
108 scoped_ptr<UserCloudPolicyStore> UserCloudPolicyStore::Create( 105 scoped_ptr<UserCloudPolicyStore> UserCloudPolicyStore::Create(
109 Profile* profile, 106 const base::FilePath& profile_path,
110 scoped_refptr<base::SequencedTaskRunner> background_task_runner) { 107 scoped_refptr<base::SequencedTaskRunner> background_task_runner) {
111 base::FilePath path = 108 base::FilePath path =
112 profile->GetPath().Append(kPolicyDir).Append(kPolicyCacheFile); 109 profile_path.Append(kPolicyDir).Append(kPolicyCacheFile);
113 return make_scoped_ptr( 110 return make_scoped_ptr(
114 new UserCloudPolicyStore(profile, path, background_task_runner)); 111 new UserCloudPolicyStore(path, background_task_runner));
112 }
113
114 void UserCloudPolicyStore::SetSigninUsername(const std::string& username) {
115 signin_username_ = username;
115 } 116 }
116 117
117 void UserCloudPolicyStore::LoadImmediately() { 118 void UserCloudPolicyStore::LoadImmediately() {
118 DVLOG(1) << "Initiating immediate policy load from disk"; 119 DVLOG(1) << "Initiating immediate policy load from disk";
119 // Cancel any pending Load/Store/Validate operations. 120 // Cancel any pending Load/Store/Validate operations.
120 weak_factory_.InvalidateWeakPtrs(); 121 weak_factory_.InvalidateWeakPtrs();
121 // Load the policy from disk... 122 // Load the policy from disk...
122 PolicyLoadResult result = LoadPolicyFromDisk(backing_file_path_); 123 PolicyLoadResult result = LoadPolicyFromDisk(backing_file_path_);
123 // ...and install it, reporting success/failure to any observers. 124 // ...and install it, reporting success/failure to any observers.
124 PolicyLoaded(false, result); 125 PolicyLoaded(false, result);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 211 }
211 212
212 void UserCloudPolicyStore::Validate( 213 void UserCloudPolicyStore::Validate(
213 scoped_ptr<em::PolicyFetchResponse> policy, 214 scoped_ptr<em::PolicyFetchResponse> policy,
214 bool validate_in_background, 215 bool validate_in_background,
215 const UserCloudPolicyValidator::CompletionCallback& callback) { 216 const UserCloudPolicyValidator::CompletionCallback& callback) {
216 // Configure the validator. 217 // Configure the validator.
217 scoped_ptr<UserCloudPolicyValidator> validator = CreateValidator( 218 scoped_ptr<UserCloudPolicyValidator> validator = CreateValidator(
218 policy.Pass(), 219 policy.Pass(),
219 CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); 220 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 221
226 // Validate the username if the user is signed in (or in the process of 222 // Validate the username if the user is signed in.
227 // signing in). 223 if (!signin_username_.empty())
228 if (!username.empty()) 224 validator->ValidateUsername(signin_username_);
229 validator->ValidateUsername(username);
230 }
231 225
232 if (validate_in_background) { 226 if (validate_in_background) {
233 // Start validation in the background. The Validator will free itself once 227 // Start validation in the background. The Validator will free itself once
234 // validation is complete. 228 // validation is complete.
235 validator.release()->StartValidation(callback); 229 validator.release()->StartValidation(callback);
236 } else { 230 } else {
237 // Run validation immediately and invoke the callback with the results. 231 // Run validation immediately and invoke the callback with the results.
238 validator->RunValidation(); 232 validator->RunValidation();
239 callback.Run(validator.get()); 233 callback.Run(validator.get());
240 } 234 }
(...skipping 14 matching lines...) Expand all
255 background_task_runner()->PostTask( 249 background_task_runner()->PostTask(
256 FROM_HERE, 250 FROM_HERE,
257 base::Bind(&StorePolicyToDiskOnBackgroundThread, 251 base::Bind(&StorePolicyToDiskOnBackgroundThread,
258 backing_file_path_, *validator->policy())); 252 backing_file_path_, *validator->policy()));
259 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass()); 253 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass());
260 status_ = STATUS_OK; 254 status_ = STATUS_OK;
261 NotifyStoreLoaded(); 255 NotifyStoreLoaded();
262 } 256 }
263 257
264 } // namespace policy 258 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud/user_cloud_policy_store.h ('k') | chrome/browser/policy/cloud/user_cloud_policy_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698