| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync/startup_controller.h" | 5 #include "chrome/browser/sync/startup_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" | 11 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 12 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 13 #include "chrome/browser/sync/sync_prefs.h" | |
| 14 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "components/sync_driver/sync_prefs.h" |
| 15 | 15 |
| 16 namespace browser_sync { | 16 namespace browser_sync { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // The amount of time we'll wait to initialize sync if no data type triggers | 20 // The amount of time we'll wait to initialize sync if no data type triggers |
| 21 // initialization via a StartSyncFlare. | 21 // initialization via a StartSyncFlare. |
| 22 const int kDeferredInitFallbackSeconds = 10; | 22 const int kDeferredInitFallbackSeconds = 10; |
| 23 | 23 |
| 24 // Enum (for UMA, primarily) defining different events that cause us to | 24 // Enum (for UMA, primarily) defining different events that cause us to |
| 25 // exit the "deferred" state of initialization and invoke start_backend. | 25 // exit the "deferred" state of initialization and invoke start_backend. |
| 26 enum DeferredInitTrigger { | 26 enum DeferredInitTrigger { |
| 27 // We have received a signal from a SyncableService requesting that sync | 27 // We have received a signal from a SyncableService requesting that sync |
| 28 // starts as soon as possible. | 28 // starts as soon as possible. |
| 29 TRIGGER_DATA_TYPE_REQUEST, | 29 TRIGGER_DATA_TYPE_REQUEST, |
| 30 // No data type requested sync to start and our fallback timer expired. | 30 // No data type requested sync to start and our fallback timer expired. |
| 31 TRIGGER_FALLBACK_TIMER, | 31 TRIGGER_FALLBACK_TIMER, |
| 32 MAX_TRIGGER_VALUE | 32 MAX_TRIGGER_VALUE |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 StartupController::StartupController( | 37 StartupController::StartupController( |
| 38 ProfileSyncServiceStartBehavior start_behavior, | 38 ProfileSyncServiceStartBehavior start_behavior, |
| 39 const ProfileOAuth2TokenService* token_service, | 39 const ProfileOAuth2TokenService* token_service, |
| 40 const browser_sync::SyncPrefs* sync_prefs, | 40 const sync_driver::SyncPrefs* sync_prefs, |
| 41 const ManagedUserSigninManagerWrapper* signin, | 41 const ManagedUserSigninManagerWrapper* signin, |
| 42 base::Closure start_backend) | 42 base::Closure start_backend) |
| 43 : received_start_request_(false), | 43 : received_start_request_(false), |
| 44 setup_in_progress_(false), | 44 setup_in_progress_(false), |
| 45 auto_start_enabled_(start_behavior == AUTO_START), | 45 auto_start_enabled_(start_behavior == AUTO_START), |
| 46 sync_prefs_(sync_prefs), | 46 sync_prefs_(sync_prefs), |
| 47 token_service_(token_service), | 47 token_service_(token_service), |
| 48 signin_(signin), | 48 signin_(signin), |
| 49 start_backend_(start_backend), | 49 start_backend_(start_backend), |
| 50 fallback_timeout_(base::TimeDelta::FromSeconds( | 50 fallback_timeout_( |
| 51 kDeferredInitFallbackSeconds)), | 51 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), |
| 52 weak_factory_(this) { | 52 weak_factory_(this) { |
| 53 | 53 |
| 54 if (CommandLine::ForCurrentProcess()->HasSwitch( | 54 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 55 switches::kSyncDeferredStartupTimeoutSeconds)) { | 55 switches::kSyncDeferredStartupTimeoutSeconds)) { |
| 56 int timeout = kDeferredInitFallbackSeconds; | 56 int timeout = kDeferredInitFallbackSeconds; |
| 57 if (base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 57 if (base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 58 switches::kSyncDeferredStartupTimeoutSeconds), &timeout)) { | 58 switches::kSyncDeferredStartupTimeoutSeconds), &timeout)) { |
| 59 DCHECK_GE(0, timeout); | 59 DCHECK_GE(0, timeout); |
| 60 DVLOG(2) << "Sync StartupController overriding startup timeout to " | 60 DVLOG(2) << "Sync StartupController overriding startup timeout to " |
| 61 << timeout << " seconds."; | 61 << timeout << " seconds."; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 syncer::MODEL_TYPE_COUNT); | 216 syncer::MODEL_TYPE_COUNT); |
| 217 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", | 217 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", |
| 218 TRIGGER_DATA_TYPE_REQUEST, | 218 TRIGGER_DATA_TYPE_REQUEST, |
| 219 MAX_TRIGGER_VALUE); | 219 MAX_TRIGGER_VALUE); |
| 220 } | 220 } |
| 221 received_start_request_ = true; | 221 received_start_request_ = true; |
| 222 TryStart(); | 222 TryStart(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace browser_sync | 225 } // namespace browser_sync |
| OLD | NEW |