| OLD | NEW |
| 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/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 FetchPolicyOAuthTokenUsingRefreshToken(); | 141 FetchPolicyOAuthTokenUsingRefreshToken(); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (!wait_for_policy_fetch_) { | 145 if (!wait_for_policy_fetch_) { |
| 146 // If this isn't blocking on a policy fetch then | 146 // If this isn't blocking on a policy fetch then |
| 147 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. | 147 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. |
| 148 // Start the refresh scheduler now, which will eventually refresh the | 148 // Start the refresh scheduler now, which will eventually refresh the |
| 149 // cached policy or make the first fetch once the OAuth2 token is | 149 // cached policy or make the first fetch once the OAuth2 token is |
| 150 // available. | 150 // available. |
| 151 StartRefreshScheduler(); | 151 StartRefreshSchedulerIfReady(); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 void UserCloudPolicyManagerChromeOS::OnPolicyFetched( | 155 void UserCloudPolicyManagerChromeOS::OnPolicyFetched( |
| 156 CloudPolicyClient* client) { | 156 CloudPolicyClient* client) { |
| 157 // No action required. If we're blocked on a policy fetch, we'll learn about | 157 // No action required. If we're blocked on a policy fetch, we'll learn about |
| 158 // completion of it through OnInitialPolicyFetchComplete(). | 158 // completion of it through OnInitialPolicyFetchComplete(). |
| 159 } | 159 } |
| 160 | 160 |
| 161 void UserCloudPolicyManagerChromeOS::OnRegistrationStateChanged( | 161 void UserCloudPolicyManagerChromeOS::OnRegistrationStateChanged( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 181 DCHECK_EQ(client(), cloud_policy_client); | 181 DCHECK_EQ(client(), cloud_policy_client); |
| 182 CancelWaitForPolicyFetch(); | 182 CancelWaitForPolicyFetch(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() { | 185 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() { |
| 186 core()->RefreshSoon(); | 186 core()->RefreshSoon(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { | 189 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { |
| 190 CheckAndPublishPolicy(); | 190 CheckAndPublishPolicy(); |
| 191 StartRefreshScheduler(); | 191 StartRefreshSchedulerIfReady(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { | 194 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { |
| 195 scoped_refptr<net::URLRequestContextGetter> signin_context; | 195 scoped_refptr<net::URLRequestContextGetter> signin_context; |
| 196 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); | 196 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); |
| 197 if (signin_profile) | 197 if (signin_profile) |
| 198 signin_context = signin_profile->GetRequestContext(); | 198 signin_context = signin_profile->GetRequestContext(); |
| 199 if (!signin_context.get()) { | 199 if (!signin_context.get()) { |
| 200 LOG(ERROR) << "No signin Profile for policy oauth token fetch!"; | 200 LOG(ERROR) << "No signin Profile for policy oauth token fetch!"; |
| 201 OnOAuth2PolicyTokenFetched(std::string()); | 201 OnOAuth2PolicyTokenFetched(std::string()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete( | 243 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete( |
| 244 bool success) { | 244 bool success) { |
| 245 CancelWaitForPolicyFetch(); | 245 CancelWaitForPolicyFetch(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() { | 248 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() { |
| 249 wait_for_policy_fetch_ = false; | 249 wait_for_policy_fetch_ = false; |
| 250 CheckAndPublishPolicy(); | 250 CheckAndPublishPolicy(); |
| 251 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler | 251 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler |
| 252 // can be started. | 252 // can be started. |
| 253 StartRefreshScheduler(); | 253 StartRefreshSchedulerIfReady(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void UserCloudPolicyManagerChromeOS::StartRefreshScheduler() { | 256 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() { |
| 257 if (core()->refresh_scheduler()) | 257 if (core()->refresh_scheduler()) |
| 258 return; // Already started. | 258 return; // Already started. |
| 259 | 259 |
| 260 if (wait_for_policy_fetch_) | 260 if (wait_for_policy_fetch_) |
| 261 return; // Still waiting for the initial, blocking fetch. | 261 return; // Still waiting for the initial, blocking fetch. |
| 262 | 262 |
| 263 if (!service() || !local_state_) | 263 if (!service() || !local_state_) |
| 264 return; // Not connected. | 264 return; // Not connected. |
| 265 | 265 |
| 266 if (component_policy_service_ && | 266 if (component_policy_service_ && |
| 267 !component_policy_service_->is_initialized()) { | 267 !component_policy_service_->is_initialized()) { |
| 268 // If the client doesn't have the list of components to fetch yet then don't | 268 // If the client doesn't have the list of components to fetch yet then don't |
| 269 // start the scheduler. The |component_policy_service_| will call back into | 269 // start the scheduler. The |component_policy_service_| will call back into |
| 270 // OnComponentCloudPolicyUpdated() once it's ready. | 270 // OnComponentCloudPolicyUpdated() once it's ready. |
| 271 return; | 271 return; |
| 272 } | 272 } |
| 273 | 273 |
| 274 core()->StartRefreshScheduler(); | 274 StartRefreshScheduler(); |
| 275 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate); | 275 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace policy | 278 } // namespace policy |
| OLD | NEW |