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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc

Issue 1727413002: Reland: No longer start up profile if there was an error fetching policy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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/chromeos/policy/user_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
15 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chromeos/login/helper.h" 19 #include "chrome/browser/chromeos/login/helper.h"
19 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 20 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
20 #include "chrome/browser/chromeos/login/users/affiliation.h" 21 #include "chrome/browser/chromeos/login/users/affiliation.h"
21 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" 22 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
22 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" 23 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
23 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" 24 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h"
24 #include "chrome/browser/chromeos/policy/wildcard_login_checker.h" 25 #include "chrome/browser/chromeos/policy/wildcard_login_checker.h"
25 #include "chrome/browser/lifetime/application_lifetime.h" 26 #include "chrome/browser/lifetime/application_lifetime.h"
26 #include "chrome/common/chrome_content_client.h" 27 #include "chrome/common/chrome_content_client.h"
28 #include "chromeos/chromeos_switches.h"
27 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" 29 #include "components/policy/core/common/cloud/cloud_external_data_manager.h"
28 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" 30 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
29 #include "components/policy/core/common/cloud/device_management_service.h" 31 #include "components/policy/core/common/cloud/device_management_service.h"
30 #include "components/policy/core/common/cloud/system_policy_request_context.h" 32 #include "components/policy/core/common/cloud/system_policy_request_context.h"
31 #include "components/policy/core/common/policy_map.h" 33 #include "components/policy/core/common/policy_map.h"
32 #include "components/policy/core/common/policy_pref_names.h" 34 #include "components/policy/core/common/policy_pref_names.h"
33 #include "components/policy/core/common/policy_types.h" 35 #include "components/policy/core/common/policy_types.h"
36 #include "components/user_manager/user.h"
34 #include "components/user_manager/user_manager.h" 37 #include "components/user_manager/user_manager.h"
35 #include "net/url_request/url_request_context_getter.h" 38 #include "net/url_request/url_request_context_getter.h"
36 #include "policy/policy_constants.h" 39 #include "policy/policy_constants.h"
37 #include "url/gurl.h" 40 #include "url/gurl.h"
38 41
39 namespace em = enterprise_management; 42 namespace em = enterprise_management;
40 43
41 namespace policy { 44 namespace policy {
42 45
43 namespace { 46 namespace {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 store.get(), 95 store.get(),
93 task_runner, 96 task_runner,
94 file_task_runner, 97 file_task_runner,
95 io_task_runner), 98 io_task_runner),
96 store_(std::move(store)), 99 store_(std::move(store)),
97 external_data_manager_(std::move(external_data_manager)), 100 external_data_manager_(std::move(external_data_manager)),
98 component_policy_cache_path_(component_policy_cache_path), 101 component_policy_cache_path_(component_policy_cache_path),
99 wait_for_policy_fetch_(wait_for_policy_fetch), 102 wait_for_policy_fetch_(wait_for_policy_fetch),
100 policy_fetch_timeout_(false, false) { 103 policy_fetch_timeout_(false, false) {
101 time_init_started_ = base::Time::Now(); 104 time_init_started_ = base::Time::Now();
102 if (wait_for_policy_fetch_ && !initial_policy_fetch_timeout.is_max()) { 105
106 // Caller should pass a non-zero policy_fetch_timeout iff
107 // |wait_for_policy_fetch| is true.
108 DCHECK_NE(wait_for_policy_fetch_, initial_policy_fetch_timeout.is_zero());
109 allow_failed_policy_fetches_ =
110 base::CommandLine::ForCurrentProcess()->HasSwitch(
111 chromeos::switches::kAllowFailedPolicyFetchForTest) ||
112 !initial_policy_fetch_timeout.is_max();
113 if (wait_for_policy_fetch_ && allow_failed_policy_fetches_) {
103 policy_fetch_timeout_.Start( 114 policy_fetch_timeout_.Start(
104 FROM_HERE, 115 FROM_HERE,
105 initial_policy_fetch_timeout, 116 initial_policy_fetch_timeout,
106 base::Bind(&UserCloudPolicyManagerChromeOS::OnBlockingFetchTimeout, 117 base::Bind(&UserCloudPolicyManagerChromeOS::OnBlockingFetchTimeout,
107 base::Unretained(this))); 118 base::Unretained(this)));
108 } 119 }
109 } 120 }
110 121
111 UserCloudPolicyManagerChromeOS::~UserCloudPolicyManagerChromeOS() {} 122 UserCloudPolicyManagerChromeOS::~UserCloudPolicyManagerChromeOS() {}
112 123
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 264
254 // If we're blocked on the policy fetch, now is a good time to issue it. 265 // If we're blocked on the policy fetch, now is a good time to issue it.
255 if (client()->is_registered()) { 266 if (client()->is_registered()) {
256 service()->RefreshPolicy( 267 service()->RefreshPolicy(
257 base::Bind( 268 base::Bind(
258 &UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete, 269 &UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete,
259 base::Unretained(this))); 270 base::Unretained(this)));
260 } else { 271 } else {
261 // If the client has switched to not registered, we bail out as this 272 // If the client has switched to not registered, we bail out as this
262 // indicates the cloud policy setup flow has been aborted. 273 // indicates the cloud policy setup flow has been aborted.
263 CancelWaitForPolicyFetch(); 274 CancelWaitForPolicyFetch(true);
264 } 275 }
265 } 276 }
266 } 277 }
267 278
268 void UserCloudPolicyManagerChromeOS::OnClientError( 279 void UserCloudPolicyManagerChromeOS::OnClientError(
269 CloudPolicyClient* cloud_policy_client) { 280 CloudPolicyClient* cloud_policy_client) {
270 DCHECK_EQ(client(), cloud_policy_client); 281 DCHECK_EQ(client(), cloud_policy_client);
271 if (wait_for_policy_fetch_) { 282 if (wait_for_policy_fetch_) {
272 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError, 283 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError,
273 cloud_policy_client->status()); 284 cloud_policy_client->status());
274 } 285 }
275 CancelWaitForPolicyFetch(); 286 switch (client()->status()) {
287 case DM_STATUS_SUCCESS:
288 case DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED:
289 // If management is not supported for this user, then a registration
290 // error is to be expected.
291 CancelWaitForPolicyFetch(true);
292 break;
293 default:
294 // Unexpected error fetching policy.
295 CancelWaitForPolicyFetch(false);
296 break;
297 }
276 } 298 }
277 299
278 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { 300 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() {
279 CloudPolicyManager::OnComponentCloudPolicyUpdated(); 301 CloudPolicyManager::OnComponentCloudPolicyUpdated();
280 StartRefreshSchedulerIfReady(); 302 StartRefreshSchedulerIfReady();
281 } 303 }
282 304
283 void UserCloudPolicyManagerChromeOS::OnStoreLoaded( 305 void UserCloudPolicyManagerChromeOS::OnStoreLoaded(
284 CloudPolicyStore* cloud_policy_store) { 306 CloudPolicyStore* cloud_policy_store) {
285 CloudPolicyManager::OnStoreLoaded(cloud_policy_store); 307 CloudPolicyManager::OnStoreLoaded(cloud_policy_store);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 369 }
348 370
349 if (error.state() == GoogleServiceAuthError::NONE) { 371 if (error.state() == GoogleServiceAuthError::NONE) {
350 // Start client registration. Either OnRegistrationStateChanged() or 372 // Start client registration. Either OnRegistrationStateChanged() or
351 // OnClientError() will be called back. 373 // OnClientError() will be called back.
352 client()->Register(em::DeviceRegisterRequest::USER, 374 client()->Register(em::DeviceRegisterRequest::USER,
353 em::DeviceRegisterRequest::FLAVOR_USER_REGISTRATION, 375 em::DeviceRegisterRequest::FLAVOR_USER_REGISTRATION,
354 policy_token, std::string(), std::string(), 376 policy_token, std::string(), std::string(),
355 std::string()); 377 std::string());
356 } else { 378 } else {
357 // Failed to get a token, stop waiting and use an empty policy.
358 CancelWaitForPolicyFetch();
359
360 UMA_HISTOGRAM_ENUMERATION(kUMAInitialFetchOAuth2Error, 379 UMA_HISTOGRAM_ENUMERATION(kUMAInitialFetchOAuth2Error,
361 error.state(), 380 error.state(),
362 GoogleServiceAuthError::NUM_STATES); 381 GoogleServiceAuthError::NUM_STATES);
363 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { 382 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
364 // Network errors are negative in the code, but the histogram data type 383 // Network errors are negative in the code, but the histogram data type
365 // expects the corresponding positive value. 384 // expects the corresponding positive value.
366 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchOAuth2NetworkError, 385 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchOAuth2NetworkError,
367 -error.network_error()); 386 -error.network_error());
368 } 387 }
388 // Failed to get a token, stop waiting if policy is not required for this
389 // user.
390 CancelWaitForPolicyFetch(false);
369 } 391 }
370 392
371 token_fetcher_.reset(); 393 token_fetcher_.reset();
372 } 394 }
373 395
374 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete( 396 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete(
375 bool success) { 397 bool success) {
376 const base::Time now = base::Time::Now(); 398 const base::Time now = base::Time::Now();
377 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayPolicyFetch, 399 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayPolicyFetch,
378 now - time_client_registered_); 400 now - time_client_registered_);
379 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayTotal, 401 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayTotal,
380 now - time_init_started_); 402 now - time_init_started_);
381 CancelWaitForPolicyFetch(); 403 CancelWaitForPolicyFetch(success);
382 } 404 }
383 405
384 void UserCloudPolicyManagerChromeOS::OnBlockingFetchTimeout() { 406 void UserCloudPolicyManagerChromeOS::OnBlockingFetchTimeout() {
385 if (!wait_for_policy_fetch_) 407 if (!wait_for_policy_fetch_)
386 return; 408 return;
387 LOG(WARNING) << "Timed out while waiting for the initial policy fetch. " 409 LOG(WARNING) << "Timed out while waiting for the policy fetch. "
388 << "The first session will start without policy."; 410 << "The session will start with the cached policy.";
389 CancelWaitForPolicyFetch(); 411 CancelWaitForPolicyFetch(false);
390 } 412 }
391 413
392 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() { 414 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch(bool success) {
393 if (!wait_for_policy_fetch_) 415 if (!wait_for_policy_fetch_)
394 return; 416 return;
395 417
418 policy_fetch_timeout_.Stop();
419
420 // If there was an error, and we don't want to allow profile initialization
421 // to go forward after a failed policy fetch, then just return (profile
422 // initialization will not complete).
423 // TODO(atwilson): Add code to retry policy fetching.
424 if (!success && !allow_failed_policy_fetches_) {
425 LOG(ERROR) << "Policy fetch failed for "
426 << user_manager::UserManager::Get()->GetActiveUser()->email()
427 << " - aborting profile initialization";
428 // Need to exit the current user, because we've already started this user's
429 // session.
430 chrome::AttemptUserExit();
431 return;
432 }
433
396 wait_for_policy_fetch_ = false; 434 wait_for_policy_fetch_ = false;
397 policy_fetch_timeout_.Stop();
398 CheckAndPublishPolicy(); 435 CheckAndPublishPolicy();
399 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler 436 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler
400 // can be started. 437 // can be started.
401 StartRefreshSchedulerIfReady(); 438 StartRefreshSchedulerIfReady();
402 } 439 }
403 440
404 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() { 441 void UserCloudPolicyManagerChromeOS::StartRefreshSchedulerIfReady() {
405 if (core()->refresh_scheduler()) 442 if (core()->refresh_scheduler())
406 return; // Already started. 443 return; // Already started.
407 444
(...skipping 10 matching lines...) Expand all
418 // OnComponentCloudPolicyUpdated() once it's ready. 455 // OnComponentCloudPolicyUpdated() once it's ready.
419 return; 456 return;
420 } 457 }
421 458
422 core()->StartRefreshScheduler(); 459 core()->StartRefreshScheduler();
423 core()->TrackRefreshDelayPref(local_state_, 460 core()->TrackRefreshDelayPref(local_state_,
424 policy_prefs::kUserPolicyRefreshRate); 461 policy_prefs::kUserPolicyRefreshRate);
425 } 462 }
426 463
427 } // namespace policy 464 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698