Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / startup_controller.cc
index ca0fb44..a609d86 100644 (file)
@@ -8,7 +8,7 @@
 #include "base/message_loop/message_loop.h"
 #include "base/metrics/histogram.h"
 #include "base/strings/string_number_conversions.h"
-#include "chrome/browser/sync/managed_user_signin_manager_wrapper.h"
+#include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
 #include "chrome/common/chrome_switches.h"
 #include "components/signin/core/browser/profile_oauth2_token_service.h"
 #include "components/sync_driver/sync_prefs.h"
@@ -38,7 +38,7 @@ StartupController::StartupController(
     ProfileSyncServiceStartBehavior start_behavior,
     const ProfileOAuth2TokenService* token_service,
     const sync_driver::SyncPrefs* sync_prefs,
-    const ManagedUserSigninManagerWrapper* signin,
+    const SupervisedUserSigninManagerWrapper* signin,
     base::Closure start_backend)
     : received_start_request_(false),
       setup_in_progress_(false),
@@ -49,6 +49,7 @@ StartupController::StartupController(
       start_backend_(start_backend),
       fallback_timeout_(
           base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)),
+      first_start_(true),
       weak_factory_(this) {
 
   if (CommandLine::ForCurrentProcess()->HasSwitch(
@@ -56,7 +57,7 @@ StartupController::StartupController(
     int timeout = kDeferredInitFallbackSeconds;
     if (base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
             switches::kSyncDeferredStartupTimeoutSeconds), &timeout)) {
-      DCHECK_GE(0, timeout);
+      DCHECK_GE(timeout, 0);
       DVLOG(2) << "Sync StartupController overriding startup timeout to "
                << timeout << " seconds.";
       fallback_timeout_ = base::TimeDelta::FromSeconds(timeout);
@@ -68,7 +69,6 @@ StartupController::~StartupController() {}
 
 void StartupController::Reset(const syncer::ModelTypeSet registered_types) {
   received_start_request_ = false;
-  setup_in_progress_ = false;
   start_up_time_ = base::Time();
   start_backend_time_ = base::Time();
   // Don't let previous timers affect us post-reset.
@@ -102,6 +102,7 @@ bool StartupController::StartUp(StartUpDeferredOption deferred_option) {
   if (start_backend_time_.is_null()) {
     start_backend_time_ = base::Time::Now();
     start_backend_.Run();
+    first_start_ = false;
   }
 
   return true;
@@ -152,7 +153,12 @@ bool StartupController::TryStart() {
   // for performance reasons and maximizing parallelism at chrome startup, we
   // defer the heavy lifting for sync init until things have calmed down.
   if (sync_prefs_->HasSyncSetupCompleted()) {
-    if (!received_start_request_)
+    // For first time, defer start if data type hasn't requested sync to avoid
+    // stressing browser start. If |first_start_| is false, most likely the
+    // first attempt to start is intercepted by backup. When backup finishes,
+    // TryStart() is called again and we should start immediately to avoid
+    // unnecessary delay.
+    if (!received_start_request_ && first_start_)
       return StartUp(STARTUP_BACKEND_DEFERRED);
     else
       return StartUp(STARTUP_IMMEDIATE);