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

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

Issue 10693022: Add support for loading user cloud policy on desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaked some comments after self-review. 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_manager.h" 5 #include "chrome/browser/policy/user_cloud_policy_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 store_(store.Pass()) { 49 store_(store.Pass()) {
50 store_->Load(); 50 store_->Load();
51 store_->AddObserver(this); 51 store_->AddObserver(this);
52 } 52 }
53 53
54 UserCloudPolicyManager::~UserCloudPolicyManager() { 54 UserCloudPolicyManager::~UserCloudPolicyManager() {
55 Shutdown(); 55 Shutdown();
56 store_->RemoveObserver(this); 56 store_->RemoveObserver(this);
57 } 57 }
58 58
59 #if defined(OS_CHROMEOS)
60 // static 59 // static
61 scoped_ptr<UserCloudPolicyManager> UserCloudPolicyManager::Create( 60 scoped_ptr<UserCloudPolicyManager> UserCloudPolicyManager::Create(
62 bool wait_for_policy_fetch) { 61 Profile* profile, bool wait_for_policy_fetch) {
Mattias Nissler (ping if slow) 2012/08/03 12:19:08 parameters on separate lines.
Andrew T Wilson (Slow) 2012/08/04 00:54:41 Done.
63 FilePath profile_dir; 62 scoped_ptr<CloudPolicyStore> store =
64 CHECK(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); 63 CloudPolicyStore::CreateUserPolicyStore(profile);
65 CommandLine* command_line = CommandLine::ForCurrentProcess();
66 const FilePath policy_dir =
67 profile_dir
68 .Append(command_line->GetSwitchValuePath(switches::kLoginProfile))
69 .Append(kPolicyDir);
70 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile);
71 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile);
72
73 scoped_ptr<CloudPolicyStore> store(
74 new UserCloudPolicyStoreChromeOS(
75 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
76 token_cache_file, policy_cache_file));
77 return scoped_ptr<UserCloudPolicyManager>( 64 return scoped_ptr<UserCloudPolicyManager>(
78 new UserCloudPolicyManager(store.Pass(), wait_for_policy_fetch)); 65 new UserCloudPolicyManager(store.Pass(), wait_for_policy_fetch));
79 } 66 }
80 #endif
81 67
82 void UserCloudPolicyManager::Initialize(PrefService* prefs, 68 void UserCloudPolicyManager::Initialize(PrefService* prefs,
83 DeviceManagementService* service, 69 DeviceManagementService* service,
84 UserAffiliation user_affiliation) { 70 UserAffiliation user_affiliation) {
71 DCHECK(service);
72 DCHECK(prefs);
85 DCHECK(!service_.get()); 73 DCHECK(!service_.get());
86 prefs_ = prefs; 74 prefs_ = prefs;
87 scoped_ptr<CloudPolicyClient> client( 75 scoped_ptr<CloudPolicyClient> client(
88 new CloudPolicyClient(std::string(), std::string(), user_affiliation, 76 new CloudPolicyClient(std::string(), std::string(), user_affiliation,
89 POLICY_SCOPE_USER, NULL, service)); 77 POLICY_SCOPE_USER, NULL, service));
90 service_.reset(new CloudPolicyService(client.Pass(), store_.get())); 78 service_.reset(new CloudPolicyService(client.Pass(), store_.get()));
91 service_->client()->AddObserver(this); 79 service_->client()->AddObserver(this);
92 80
93 if (wait_for_policy_fetch_) { 81 if (wait_for_policy_fetch_) {
94 // If we are supposed to wait for a policy fetch, we trigger an explicit 82 // If we are supposed to wait for a policy fetch, we trigger an explicit
(...skipping 27 matching lines...) Expand all
122 // can be started. 110 // can be started.
123 if (service_.get() && !refresh_scheduler_.get() && prefs_) { 111 if (service_.get() && !refresh_scheduler_.get() && prefs_) {
124 refresh_scheduler_.reset( 112 refresh_scheduler_.reset(
125 new CloudPolicyRefreshScheduler( 113 new CloudPolicyRefreshScheduler(
126 service_->client(), store_.get(), prefs_, 114 service_->client(), store_.get(), prefs_,
127 prefs::kUserPolicyRefreshRate, 115 prefs::kUserPolicyRefreshRate,
128 MessageLoop::current()->message_loop_proxy())); 116 MessageLoop::current()->message_loop_proxy()));
129 } 117 }
130 } 118 }
131 119
120 bool UserCloudPolicyManager::IsClientRegistered() const {
121 if (!service_.get())
122 return false;
123 return service_->client()->is_registered();
124 }
125
126 void UserCloudPolicyManager::RegisterClient(const std::string& access_token) {
127 DCHECK(cloud_policy_service()) << "Callers must invoke Initialize() first";
128 if (!cloud_policy_service()->client()->is_registered())
129 cloud_policy_service()->client()->Register(access_token);
130 }
131
132 bool UserCloudPolicyManager::IsInitializationComplete() const { 132 bool UserCloudPolicyManager::IsInitializationComplete() const {
133 return store_->is_initialized() && !wait_for_policy_fetch_; 133 return store_->is_initialized() && !wait_for_policy_fetch_;
134 } 134 }
135 135
136 void UserCloudPolicyManager::RefreshPolicies() { 136 void UserCloudPolicyManager::RefreshPolicies() {
137 if (service_.get()) { 137 if (service_.get()) {
138 wait_for_policy_refresh_ = true; 138 wait_for_policy_refresh_ = true;
139 service_->RefreshPolicy( 139 service_->RefreshPolicy(
140 base::Bind(&UserCloudPolicyManager::OnRefreshComplete, 140 base::Bind(&UserCloudPolicyManager::OnRefreshComplete,
141 base::Unretained(this))); 141 base::Unretained(this)));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void UserCloudPolicyManager::OnInitialPolicyFetchComplete() { 189 void UserCloudPolicyManager::OnInitialPolicyFetchComplete() {
190 CancelWaitForPolicyFetch(); 190 CancelWaitForPolicyFetch();
191 } 191 }
192 192
193 void UserCloudPolicyManager::OnRefreshComplete() { 193 void UserCloudPolicyManager::OnRefreshComplete() {
194 wait_for_policy_refresh_ = false; 194 wait_for_policy_refresh_ = false;
195 CheckAndPublishPolicy(); 195 CheckAndPublishPolicy();
196 } 196 }
197 197
198 } // namespace policy 198 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698