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

Side by Side Diff: chrome/browser/policy/user_cloud_policy_manager.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_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(
61 Profile* profile,
62 bool wait_for_policy_fetch) { 62 bool wait_for_policy_fetch) {
63 FilePath profile_dir; 63 scoped_ptr<CloudPolicyStore> store =
64 CHECK(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); 64 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>( 65 return scoped_ptr<UserCloudPolicyManager>(
78 new UserCloudPolicyManager(store.Pass(), wait_for_policy_fetch)); 66 new UserCloudPolicyManager(store.Pass(), wait_for_policy_fetch));
79 } 67 }
80 #endif
81 68
82 void UserCloudPolicyManager::Initialize(PrefService* prefs, 69 void UserCloudPolicyManager::Initialize(PrefService* prefs,
83 DeviceManagementService* service, 70 DeviceManagementService* service,
84 UserAffiliation user_affiliation) { 71 UserAffiliation user_affiliation) {
72 DCHECK(service);
73 DCHECK(prefs);
85 DCHECK(!service_.get()); 74 DCHECK(!service_.get());
86 prefs_ = prefs; 75 prefs_ = prefs;
87 scoped_ptr<CloudPolicyClient> client( 76 scoped_ptr<CloudPolicyClient> client(
88 new CloudPolicyClient(std::string(), std::string(), user_affiliation, 77 new CloudPolicyClient(std::string(), std::string(), user_affiliation,
89 POLICY_SCOPE_USER, NULL, service)); 78 POLICY_SCOPE_USER, NULL, service));
90 service_.reset(new CloudPolicyService(client.Pass(), store_.get())); 79 service_.reset(new CloudPolicyService(client.Pass(), store_.get()));
91 service_->client()->AddObserver(this); 80 service_->client()->AddObserver(this);
92 81
93 if (wait_for_policy_fetch_) { 82 if (wait_for_policy_fetch_) {
94 // If we are supposed to wait for a policy fetch, we trigger an explicit 83 // If we are supposed to wait for a policy fetch, we trigger an explicit
(...skipping 27 matching lines...) Expand all
122 // can be started. 111 // can be started.
123 if (service_.get() && !refresh_scheduler_.get() && prefs_) { 112 if (service_.get() && !refresh_scheduler_.get() && prefs_) {
124 refresh_scheduler_.reset( 113 refresh_scheduler_.reset(
125 new CloudPolicyRefreshScheduler( 114 new CloudPolicyRefreshScheduler(
126 service_->client(), store_.get(), prefs_, 115 service_->client(), store_.get(), prefs_,
127 prefs::kUserPolicyRefreshRate, 116 prefs::kUserPolicyRefreshRate,
128 MessageLoop::current()->message_loop_proxy())); 117 MessageLoop::current()->message_loop_proxy()));
129 } 118 }
130 } 119 }
131 120
121 bool UserCloudPolicyManager::IsClientRegistered() const {
122 if (!service_.get())
123 return false;
124 return service_->client()->is_registered();
125 }
126
127 void UserCloudPolicyManager::RegisterClient(const std::string& access_token) {
128 DCHECK(cloud_policy_service()) << "Callers must invoke Initialize() first";
129 if (!cloud_policy_service()->client()->is_registered())
130 cloud_policy_service()->client()->Register(access_token);
131 }
132
132 bool UserCloudPolicyManager::IsInitializationComplete() const { 133 bool UserCloudPolicyManager::IsInitializationComplete() const {
133 return store_->is_initialized() && !wait_for_policy_fetch_; 134 return store_->is_initialized() && !wait_for_policy_fetch_;
134 } 135 }
135 136
136 void UserCloudPolicyManager::RefreshPolicies() { 137 void UserCloudPolicyManager::RefreshPolicies() {
137 if (service_.get()) { 138 if (service_.get()) {
138 wait_for_policy_refresh_ = true; 139 wait_for_policy_refresh_ = true;
139 service_->RefreshPolicy( 140 service_->RefreshPolicy(
140 base::Bind(&UserCloudPolicyManager::OnRefreshComplete, 141 base::Bind(&UserCloudPolicyManager::OnRefreshComplete,
141 base::Unretained(this))); 142 base::Unretained(this)));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void UserCloudPolicyManager::OnInitialPolicyFetchComplete() { 190 void UserCloudPolicyManager::OnInitialPolicyFetchComplete() {
190 CancelWaitForPolicyFetch(); 191 CancelWaitForPolicyFetch();
191 } 192 }
192 193
193 void UserCloudPolicyManager::OnRefreshComplete() { 194 void UserCloudPolicyManager::OnRefreshComplete() {
194 wait_for_policy_refresh_ = false; 195 wait_for_policy_refresh_ = false;
195 CheckAndPublishPolicy(); 196 CheckAndPublishPolicy();
196 } 197 }
197 198
198 } // namespace policy 199 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_cloud_policy_manager.h ('k') | chrome/browser/policy/user_cloud_policy_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698