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

Side by Side Diff: chrome/browser/policy/user_cloud_policy_store_chromeos.cc

Issue 10823212: Relanding this as this did not fix the chromiumos breakage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/policy/user_cloud_policy_store_chromeos.h" 5 #include "chrome/browser/policy/user_cloud_policy_store_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/path_service.h"
14 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
15 #include "chrome/browser/policy/proto/cloud_policy.pb.h" 17 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
16 #include "chrome/browser/policy/proto/device_management_local.pb.h" 18 #include "chrome/browser/policy/proto/device_management_local.pb.h"
17 #include "chrome/browser/policy/user_policy_disk_cache.h" 19 #include "chrome/browser/policy/user_policy_disk_cache.h"
18 #include "chrome/browser/policy/user_policy_token_cache.h" 20 #include "chrome/browser/policy/user_policy_token_cache.h"
19 #include "chrome/common/net/gaia/gaia_auth_util.h" 21 #include "chrome/common/net/gaia/gaia_auth_util.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chromeos/dbus/dbus_thread_manager.h"
20 #include "chromeos/dbus/session_manager_client.h" 25 #include "chromeos/dbus/session_manager_client.h"
21 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
22 27
23 namespace em = enterprise_management; 28 namespace em = enterprise_management;
24 29
25 namespace policy { 30 namespace policy {
26 31
27 // Decodes a CloudPolicySettings object into a policy map. The implementation is 32 namespace {
28 // generated code in policy/cloud_policy_generated.cc. 33 // Subdirectory in the user's profile for storing user policies.
29 void DecodePolicy(const em::CloudPolicySettings& policy, 34 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management");
30 PolicyMap* policies); 35 // File in the above directory for stroing user policy dmtokens.
36 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token");
37 // File in the above directory for storing user policy data.
38 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
39 } // namespace
40
31 41
32 // Helper class for loading legacy policy caches. 42 // Helper class for loading legacy policy caches.
33 class LegacyPolicyCacheLoader : public UserPolicyTokenCache::Delegate, 43 class LegacyPolicyCacheLoader : public UserPolicyTokenCache::Delegate,
34 public UserPolicyDiskCache::Delegate { 44 public UserPolicyDiskCache::Delegate {
35 public: 45 public:
36 typedef base::Callback<void(const std::string&, 46 typedef base::Callback<void(const std::string&,
37 const std::string&, 47 const std::string&,
38 CloudPolicyStore::Status, 48 CloudPolicyStore::Status,
39 scoped_ptr<em::PolicyFetchResponse>)> Callback; 49 scoped_ptr<em::PolicyFetchResponse>)> Callback;
40 50
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 legacy_loader_(new LegacyPolicyCacheLoader(legacy_token_cache_file, 161 legacy_loader_(new LegacyPolicyCacheLoader(legacy_token_cache_file,
152 legacy_policy_cache_file)), 162 legacy_policy_cache_file)),
153 legacy_caches_loaded_(false) {} 163 legacy_caches_loaded_(false) {}
154 164
155 UserCloudPolicyStoreChromeOS::~UserCloudPolicyStoreChromeOS() {} 165 UserCloudPolicyStoreChromeOS::~UserCloudPolicyStoreChromeOS() {}
156 166
157 void UserCloudPolicyStoreChromeOS::Store( 167 void UserCloudPolicyStoreChromeOS::Store(
158 const em::PolicyFetchResponse& policy) { 168 const em::PolicyFetchResponse& policy) {
159 // Cancel all pending requests. 169 // Cancel all pending requests.
160 weak_factory_.InvalidateWeakPtrs(); 170 weak_factory_.InvalidateWeakPtrs();
161 Validate(scoped_ptr<em::PolicyFetchResponse>( 171 Validate(
162 new em::PolicyFetchResponse(policy)), 172 scoped_ptr<em::PolicyFetchResponse>(new em::PolicyFetchResponse(policy)),
163 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, 173 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated,
164 weak_factory_.GetWeakPtr())); 174 weak_factory_.GetWeakPtr()));
165 } 175 }
166 176
167 void UserCloudPolicyStoreChromeOS::Load() { 177 void UserCloudPolicyStoreChromeOS::Load() {
168 // Cancel all pending requests. 178 // Cancel all pending requests.
169 weak_factory_.InvalidateWeakPtrs(); 179 weak_factory_.InvalidateWeakPtrs();
170 session_manager_client_->RetrieveUserPolicy( 180 session_manager_client_->RetrieveUserPolicy(
171 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, 181 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved,
172 weak_factory_.GetWeakPtr())); 182 weak_factory_.GetWeakPtr()));
173 } 183 }
174 184
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (!success) { 265 if (!success) {
256 status_ = STATUS_STORE_ERROR; 266 status_ = STATUS_STORE_ERROR;
257 NotifyStoreError(); 267 NotifyStoreError();
258 } else { 268 } else {
259 // TODO(mnissler): Once we do signature verifications, we'll have to reload 269 // TODO(mnissler): Once we do signature verifications, we'll have to reload
260 // the key at this point to account for key rotations. 270 // the key at this point to account for key rotations.
261 Load(); 271 Load();
262 } 272 }
263 } 273 }
264 274
265 void UserCloudPolicyStoreChromeOS::InstallPolicy(
266 scoped_ptr<em::PolicyData> policy_data,
267 scoped_ptr<em::CloudPolicySettings> payload) {
268 // Decode the payload.
269 policy_map_.Clear();
270 DecodePolicy(*payload, &policy_map_);
271 policy_ = policy_data.Pass();
272 }
273
274 void UserCloudPolicyStoreChromeOS::Validate( 275 void UserCloudPolicyStoreChromeOS::Validate(
275 scoped_ptr<em::PolicyFetchResponse> policy, 276 scoped_ptr<em::PolicyFetchResponse> policy,
276 const UserCloudPolicyValidator::CompletionCallback& callback) { 277 const UserCloudPolicyValidator::CompletionCallback& callback) {
277 // Configure the validator. 278 // Configure the validator.
278 UserCloudPolicyValidator* validator = 279 scoped_ptr<UserCloudPolicyValidator> validator =
279 UserCloudPolicyValidator::Create(policy.Pass(), callback); 280 CreateValidator(policy.Pass(), callback);
280 validator->ValidateUsername( 281 validator->ValidateUsername(
281 chromeos::UserManager::Get()->GetLoggedInUser().email()); 282 chromeos::UserManager::Get()->GetLoggedInUser().email());
282 validator->ValidatePolicyType(dm_protocol::kChromeUserPolicyType);
283 validator->ValidateAgainstCurrentPolicy(policy_.get());
284 validator->ValidatePayload();
285 283
286 // TODO(mnissler): Do a signature check here as well. The key is stored by 284 // TODO(mnissler): Do a signature check here as well. The key is stored by
287 // session_manager in the root-owned cryptohome area, which is currently 285 // session_manager in the root-owned cryptohome area, which is currently
288 // inaccessible to Chrome though. 286 // inaccessible to Chrome though.
289 287
290 // Start validation. 288 // Start validation. The Validator will free itself once validation is
291 validator->StartValidation(); 289 // complete.
290 validator.release()->StartValidation();
292 } 291 }
293 292
294 void UserCloudPolicyStoreChromeOS::OnLegacyLoadFinished( 293 void UserCloudPolicyStoreChromeOS::OnLegacyLoadFinished(
295 const std::string& dm_token, 294 const std::string& dm_token,
296 const std::string& device_id, 295 const std::string& device_id,
297 Status status, 296 Status status,
298 scoped_ptr<em::PolicyFetchResponse> policy) { 297 scoped_ptr<em::PolicyFetchResponse> policy) {
299 status_ = status; 298 status_ = status;
300 if (policy.get()) { 299 if (policy.get()) {
301 Validate(policy.Pass(), 300 Validate(policy.Pass(),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // Tell the rest of the world that the policy load completed. 344 // Tell the rest of the world that the policy load completed.
346 NotifyStoreLoaded(); 345 NotifyStoreLoaded();
347 } 346 }
348 347
349 // static 348 // static
350 void UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir(const FilePath& dir) { 349 void UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir(const FilePath& dir) {
351 if (file_util::PathExists(dir) && !file_util::Delete(dir, true)) 350 if (file_util::PathExists(dir) && !file_util::Delete(dir, true))
352 LOG(ERROR) << "Failed to remove cache dir " << dir.value(); 351 LOG(ERROR) << "Failed to remove cache dir " << dir.value();
353 } 352 }
354 353
354 // static
355 scoped_ptr<CloudPolicyStore> CloudPolicyStore::CreateUserPolicyStore(
356 Profile* profile) {
357 FilePath profile_dir;
358 CHECK(PathService::Get(chrome::DIR_USER_DATA, &profile_dir));
359 CommandLine* command_line = CommandLine::ForCurrentProcess();
360 const FilePath policy_dir =
361 profile_dir
362 .Append(command_line->GetSwitchValuePath(switches::kLoginProfile))
363 .Append(kPolicyDir);
364 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile);
365 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile);
366
367 return scoped_ptr<CloudPolicyStore>(new UserCloudPolicyStoreChromeOS(
368 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
369 token_cache_file, policy_cache_file));
370 }
371
355 } // namespace policy 372 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_cloud_policy_store_chromeos.h ('k') | chrome/browser/policy/user_cloud_policy_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698