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

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

Issue 10825415: Added code to persist downloaded cloud policy to disk. (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_policy_signin_service.h" 5 #include "chrome/browser/policy/user_policy_signin_service.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/policy/browser_policy_connector.h" 8 #include "chrome/browser/policy/browser_policy_connector.h"
9 #include "chrome/browser/policy/cloud_policy_service.h" 9 #include "chrome/browser/policy/cloud_policy_service.h"
10 #include "chrome/browser/policy/user_cloud_policy_manager.h" 10 #include "chrome/browser/policy/user_cloud_policy_manager.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 kPolicyServiceInitializationDelayMilliseconds); 118 kPolicyServiceInitializationDelayMilliseconds);
119 // Initialize the UserCloudPolicyManager if it isn't already initialized. 119 // Initialize the UserCloudPolicyManager if it isn't already initialized.
120 policy::DeviceManagementService* service = g_browser_process-> 120 policy::DeviceManagementService* service = g_browser_process->
121 browser_policy_connector()->device_management_service(); 121 browser_policy_connector()->device_management_service();
122 manager_->Initialize(g_browser_process->local_state(), 122 manager_->Initialize(g_browser_process->local_state(),
123 service, 123 service,
124 policy::USER_AFFILIATION_NONE); 124 policy::USER_AFFILIATION_NONE);
125 DCHECK(manager_->cloud_policy_service()); 125 DCHECK(manager_->cloud_policy_service());
126 } 126 }
127 127
128 // Register the CloudPolicyService if needed. 128 // Register the CloudPolicyService if the cloud policy store is complete.
129 if (!manager_->IsClientRegistered()) 129 // TODO(atwilson): If there's a problem loading the stored policy, we could
130 // be left with no policy, so we should move this code to
131 // UserCloudPolicyManager and have it initiate a DMToken fetch only once
132 // the policy load is complete (http://crbug.com/143187).
133 if (!manager_->IsClientRegistered() &&
134 manager_->cloud_policy_service()->store()->is_initialized()) {
Mattias Nissler (ping if slow) 2012/08/20 15:29:30 Isn't this racy? What if the store just hasn't ini
Andrew T Wilson (Slow) 2012/08/20 18:04:37 It is indeed racy. The solution is to move the reg
Mattias Nissler (ping if slow) 2012/08/21 10:45:16 Fair enough. Also mention a) in the comment?
Andrew T Wilson (Slow) 2012/08/21 23:18:19 Done.
130 RegisterCloudPolicyService(); 135 RegisterCloudPolicyService();
136 }
131 } 137 }
132 } 138 }
133 139
134 void UserPolicySigninService::RegisterCloudPolicyService() { 140 void UserPolicySigninService::RegisterCloudPolicyService() {
141 DVLOG(1) << "Fetching new DM Token";
135 // TODO(atwilson): Move the code to mint the devicemanagement token into 142 // TODO(atwilson): Move the code to mint the devicemanagement token into
136 // TokenService. 143 // TokenService.
137 std::string token = TokenServiceFactory::GetForProfile(profile_)-> 144 std::string token = TokenServiceFactory::GetForProfile(profile_)->
138 GetOAuth2LoginRefreshToken(); 145 GetOAuth2LoginRefreshToken();
139 if (token.empty()) { 146 if (token.empty()) {
140 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; 147 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download";
141 return; 148 return;
142 } 149 }
143 150
144 // Do nothing if already fetching an access token. 151 // Do nothing if already fetching an access token.
(...skipping 18 matching lines...) Expand all
163 DLOG(WARNING) << "Could not fetch access token for " 170 DLOG(WARNING) << "Could not fetch access token for "
164 << kServiceScopeChromeOSDeviceManagement; 171 << kServiceScopeChromeOSDeviceManagement;
165 oauth2_access_token_fetcher_.reset(); 172 oauth2_access_token_fetcher_.reset();
166 manager_->CancelWaitForPolicyFetch(); 173 manager_->CancelWaitForPolicyFetch();
167 } 174 }
168 175
169 void UserPolicySigninService::OnGetTokenSuccess( 176 void UserPolicySigninService::OnGetTokenSuccess(
170 const std::string& access_token, 177 const std::string& access_token,
171 const base::Time& expiration_time) { 178 const base::Time& expiration_time) {
172 // Pass along the new access token to the CloudPolicyClient. 179 // Pass along the new access token to the CloudPolicyClient.
180 DVLOG(1) << "Fetched new scoped OAuth token:" << access_token;
173 manager_->RegisterClient(access_token); 181 manager_->RegisterClient(access_token);
174 oauth2_access_token_fetcher_.reset(); 182 oauth2_access_token_fetcher_.reset();
175 } 183 }
176 184
177 } // namespace policy 185 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698