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

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

Issue 11415094: Split UserCloudPolicyManager implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bring back ProxyPolicyProvider, fix local_state policy provider, fix Joao's fine CloudPolicyTest. Created 8 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/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/command_line.h"
Joao da Silva 2012/11/21 17:06:34 nit: not used
Mattias Nissler (ping if slow) 2012/11/22 20:51:59 Done.
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
Joao da Silva 2012/11/21 17:06:34 nit: not used
Mattias Nissler (ping if slow) 2012/11/22 20:51:59 Done.
16 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/policy/proto/cloud_policy.pb.h" 17 #include "chrome/browser/policy/proto/cloud_policy.pb.h"
18 #include "chrome/browser/policy/proto/device_management_local.pb.h" 18 #include "chrome/browser/policy/proto/device_management_local.pb.h"
19 #include "chrome/browser/policy/user_policy_disk_cache.h" 19 #include "chrome/browser/policy/user_policy_disk_cache.h"
20 #include "chrome/browser/policy/user_policy_token_cache.h" 20 #include "chrome/browser/policy/user_policy_token_cache.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
23 #include "chromeos/dbus/dbus_thread_manager.h" 23 #include "chromeos/dbus/dbus_thread_manager.h"
Joao da Silva 2012/11/21 17:06:34 nit: not used
Mattias Nissler (ping if slow) 2012/11/22 20:51:59 Done.
24 #include "chromeos/dbus/session_manager_client.h" 24 #include "chromeos/dbus/session_manager_client.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "google_apis/gaia/gaia_auth_util.h" 26 #include "google_apis/gaia/gaia_auth_util.h"
27 27
28 namespace em = enterprise_management; 28 namespace em = enterprise_management;
29 29
30 namespace policy { 30 namespace policy {
31 31
32 namespace { 32 namespace {
33 // Subdirectory in the user's profile for storing user policies. 33 // Subdirectory in the user's profile for storing user policies.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 176
177 void UserCloudPolicyStoreChromeOS::Load() { 177 void UserCloudPolicyStoreChromeOS::Load() {
178 // Cancel all pending requests. 178 // Cancel all pending requests.
179 weak_factory_.InvalidateWeakPtrs(); 179 weak_factory_.InvalidateWeakPtrs();
180 session_manager_client_->RetrieveUserPolicy( 180 session_manager_client_->RetrieveUserPolicy(
181 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved, 181 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyRetrieved,
182 weak_factory_.GetWeakPtr())); 182 weak_factory_.GetWeakPtr()));
183 } 183 }
184 184
185 void UserCloudPolicyStoreChromeOS::RemoveStoredPolicy() {
186 // This should never be called on ChromeOS since it is not possible to sign
187 // out of a Profile. The underlying policy store is only removed if the
188 // Profile itself is deleted.
189 NOTREACHED();
190 }
191
192 void UserCloudPolicyStoreChromeOS::OnPolicyRetrieved( 185 void UserCloudPolicyStoreChromeOS::OnPolicyRetrieved(
193 const std::string& policy_blob) { 186 const std::string& policy_blob) {
194 if (policy_blob.empty()) { 187 if (policy_blob.empty()) {
195 // Policy fetch failed. Try legacy caches if we haven't done that already. 188 // Policy fetch failed. Try legacy caches if we haven't done that already.
196 if (!legacy_caches_loaded_ && legacy_loader_.get()) { 189 if (!legacy_caches_loaded_ && legacy_loader_.get()) {
197 legacy_caches_loaded_ = true; 190 legacy_caches_loaded_ = true;
198 legacy_loader_->Load( 191 legacy_loader_->Load(
199 base::Bind(&UserCloudPolicyStoreChromeOS::OnLegacyLoadFinished, 192 base::Bind(&UserCloudPolicyStoreChromeOS::OnLegacyLoadFinished,
200 weak_factory_.GetWeakPtr())); 193 weak_factory_.GetWeakPtr()));
201 } else { 194 } else {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // Tell the rest of the world that the policy load completed. 344 // Tell the rest of the world that the policy load completed.
352 NotifyStoreLoaded(); 345 NotifyStoreLoaded();
353 } 346 }
354 347
355 // static 348 // static
356 void UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir(const FilePath& dir) { 349 void UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir(const FilePath& dir) {
357 if (file_util::PathExists(dir) && !file_util::Delete(dir, true)) 350 if (file_util::PathExists(dir) && !file_util::Delete(dir, true))
358 LOG(ERROR) << "Failed to remove cache dir " << dir.value(); 351 LOG(ERROR) << "Failed to remove cache dir " << dir.value();
359 } 352 }
360 353
361 // static
362 scoped_ptr<CloudPolicyStore> CloudPolicyStore::CreateUserPolicyStore(
363 Profile* profile, bool force_immediate_policy_load) {
364 // On ChromeOS, callers should never try to load policy synchronously
365 // (profile initialization is always asynchronous).
366 DCHECK(!force_immediate_policy_load);
367 FilePath profile_dir;
368 CHECK(PathService::Get(chrome::DIR_USER_DATA, &profile_dir));
369 CommandLine* command_line = CommandLine::ForCurrentProcess();
370 const FilePath policy_dir =
371 profile_dir
372 .Append(command_line->GetSwitchValuePath(switches::kLoginProfile))
373 .Append(kPolicyDir);
374 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile);
375 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile);
376
377 return scoped_ptr<CloudPolicyStore>(new UserCloudPolicyStoreChromeOS(
378 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
379 token_cache_file, policy_cache_file));
380 }
381
382 } // namespace policy 354 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698