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

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: Removed unneeded #include 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 // The code below is somewhat racy in that if the store is not initialized
130 // by the time we get here, we won't register the client. In practice, we
131 // handle the case where there's no policy file because checking for the
132 // file always completes before the token DB is loaded (since they use the
133 // same thread for their operations).
134 // TODO(atwilson): If there's a problem loading the stored policy, we could
135 // be left with no policy, so we should move this code to
136 // UserCloudPolicyManager and have it initiate a DMToken fetch only once
137 // the policy load is complete (http://crbug.com/143187).
138 if (!manager_->IsClientRegistered() &&
139 manager_->cloud_policy_service()->store()->is_initialized()) {
130 RegisterCloudPolicyService(); 140 RegisterCloudPolicyService();
141 }
131 } 142 }
132 } 143 }
133 144
134 void UserPolicySigninService::RegisterCloudPolicyService() { 145 void UserPolicySigninService::RegisterCloudPolicyService() {
146 DVLOG(1) << "Fetching new DM Token";
135 // TODO(atwilson): Move the code to mint the devicemanagement token into 147 // TODO(atwilson): Move the code to mint the devicemanagement token into
136 // TokenService. 148 // TokenService.
137 std::string token = TokenServiceFactory::GetForProfile(profile_)-> 149 std::string token = TokenServiceFactory::GetForProfile(profile_)->
138 GetOAuth2LoginRefreshToken(); 150 GetOAuth2LoginRefreshToken();
139 if (token.empty()) { 151 if (token.empty()) {
140 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; 152 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download";
141 return; 153 return;
142 } 154 }
143 155
144 // Do nothing if already fetching an access token. 156 // Do nothing if already fetching an access token.
(...skipping 18 matching lines...) Expand all
163 DLOG(WARNING) << "Could not fetch access token for " 175 DLOG(WARNING) << "Could not fetch access token for "
164 << kServiceScopeChromeOSDeviceManagement; 176 << kServiceScopeChromeOSDeviceManagement;
165 oauth2_access_token_fetcher_.reset(); 177 oauth2_access_token_fetcher_.reset();
166 manager_->CancelWaitForPolicyFetch(); 178 manager_->CancelWaitForPolicyFetch();
167 } 179 }
168 180
169 void UserPolicySigninService::OnGetTokenSuccess( 181 void UserPolicySigninService::OnGetTokenSuccess(
170 const std::string& access_token, 182 const std::string& access_token,
171 const base::Time& expiration_time) { 183 const base::Time& expiration_time) {
172 // Pass along the new access token to the CloudPolicyClient. 184 // Pass along the new access token to the CloudPolicyClient.
185 DVLOG(1) << "Fetched new scoped OAuth token:" << access_token;
173 manager_->RegisterClient(access_token); 186 manager_->RegisterClient(access_token);
174 oauth2_access_token_fetcher_.reset(); 187 oauth2_access_token_fetcher_.reset();
175 } 188 }
176 189
177 } // namespace policy 190 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698