Chromium Code Reviews| 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 "components/sync_driver/startup_controller.h" | 5 #include "components/sync_driver/startup_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 // starts as soon as possible. | 32 // starts as soon as possible. |
| 33 TRIGGER_DATA_TYPE_REQUEST, | 33 TRIGGER_DATA_TYPE_REQUEST, |
| 34 // No data type requested sync to start and our fallback timer expired. | 34 // No data type requested sync to start and our fallback timer expired. |
| 35 TRIGGER_FALLBACK_TIMER, | 35 TRIGGER_FALLBACK_TIMER, |
| 36 MAX_TRIGGER_VALUE | 36 MAX_TRIGGER_VALUE |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 StartupController::StartupController( | 41 StartupController::StartupController( |
| 42 ProfileSyncServiceStartBehavior start_behavior, | |
| 43 const ProfileOAuth2TokenService* token_service, | 42 const ProfileOAuth2TokenService* token_service, |
| 44 const sync_driver::SyncPrefs* sync_prefs, | 43 const sync_driver::SyncPrefs* sync_prefs, |
| 45 const SigninManagerWrapper* signin, | 44 const SigninManagerWrapper* signin, |
| 46 base::Closure start_backend) | 45 base::Closure start_backend) |
| 47 : received_start_request_(false), | 46 : received_start_request_(false), |
| 48 setup_in_progress_(false), | 47 setup_in_progress_(false), |
| 49 auto_start_enabled_(start_behavior == AUTO_START), | |
| 50 sync_prefs_(sync_prefs), | 48 sync_prefs_(sync_prefs), |
| 51 token_service_(token_service), | 49 token_service_(token_service), |
| 52 signin_(signin), | 50 signin_(signin), |
| 53 start_backend_(start_backend), | 51 start_backend_(start_backend), |
| 54 fallback_timeout_( | 52 fallback_timeout_( |
| 55 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), | 53 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), |
| 56 first_start_(true), | 54 first_start_(true), |
| 57 weak_factory_(this) { | 55 weak_factory_(this) { |
| 58 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 56 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 59 switches::kSyncDeferredStartupTimeoutSeconds)) { | 57 switches::kSyncDeferredStartupTimeoutSeconds)) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 return false; | 134 return false; |
| 137 } | 135 } |
| 138 | 136 |
| 139 // TODO(tim): Seems wrong to always record this histogram here... | 137 // TODO(tim): Seems wrong to always record this histogram here... |
| 140 // If we got here then tokens are loaded and user logged in and sync is | 138 // If we got here then tokens are loaded and user logged in and sync is |
| 141 // enabled. If OAuth refresh token is not available then something is wrong. | 139 // enabled. If OAuth refresh token is not available then something is wrong. |
| 142 // When PSS requests access token, OAuth2TokenService will return error and | 140 // When PSS requests access token, OAuth2TokenService will return error and |
| 143 // PSS will show error to user asking to reauthenticate. | 141 // PSS will show error to user asking to reauthenticate. |
| 144 UMA_HISTOGRAM_BOOLEAN("Sync.RefreshTokenAvailable", true); | 142 UMA_HISTOGRAM_BOOLEAN("Sync.RefreshTokenAvailable", true); |
| 145 | 143 |
| 146 // If sync setup has completed we always start the backend. If the user is in | 144 // For performance reasons, defer the heavy lifting for sync init if: |
| 147 // the process of setting up now, we should start the backend to download | |
| 148 // account control state / encryption information). If autostart is enabled, | |
| 149 // but we haven't completed sync setup, we try to start sync anyway, since | |
| 150 // it's possible we crashed/shutdown after logging in but before the backend | |
| 151 // finished initializing the last time. | |
| 152 // | 145 // |
| 153 // However, the only time we actually need to start sync _immediately_ is if | 146 // - This is the first start of sync, to prevent competing for resources |
| 154 // we haven't completed sync setup and the user is in the process of setting | 147 // during browser startup. |
| 155 // up - either they just signed in (for the first time) on an auto-start | 148 // - No datatype has requested an immediate start of sync. |
| 156 // platform or they explicitly kicked off sync setup, and e.g we need to | 149 // - Sync does not need to start up the backend immediately to provide control |
| 157 // fetch account details like encryption state to populate UI. Otherwise, | 150 // state and encryption information to the UI. |
| 158 // for performance reasons and maximizing parallelism at chrome startup, we | 151 if (first_start_ && !received_start_request_ && !setup_in_progress_) { |
|
Nicolas Zea
2016/02/29 21:21:55
This doesn't seem right. Previously if this was Cr
maxbogue
2016/03/09 02:00:59
I've clarified the comment; first_start means the
Nicolas Zea
2016/03/09 19:49:45
Sync should always start up immediately the first
maxbogue
2016/03/10 18:48:15
I was wondering if first_start_ was actually neede
| |
| 159 // defer the heavy lifting for sync init until things have calmed down. | 152 return StartUp(STARTUP_BACKEND_DEFERRED); |
| 160 if (sync_prefs_->IsFirstSetupComplete()) { | 153 } else { |
| 161 // For first time, defer start if data type hasn't requested sync to avoid | |
| 162 // stressing browser start. | |
| 163 if (!received_start_request_ && first_start_) | |
| 164 return StartUp(STARTUP_BACKEND_DEFERRED); | |
| 165 else | |
| 166 return StartUp(STARTUP_IMMEDIATE); | |
| 167 } else if (setup_in_progress_ || auto_start_enabled_) { | |
| 168 // We haven't completed sync setup. Start immediately if the user explicitly | |
| 169 // kicked this off or we're supposed to automatically start syncing. | |
| 170 return StartUp(STARTUP_IMMEDIATE); | 154 return StartUp(STARTUP_IMMEDIATE); |
| 171 } | 155 } |
| 172 | |
| 173 return false; | |
| 174 } | 156 } |
| 175 | 157 |
| 176 void StartupController::RecordTimeDeferred() { | 158 void StartupController::RecordTimeDeferred() { |
| 177 DCHECK(!start_up_time_.is_null()); | 159 DCHECK(!start_up_time_.is_null()); |
| 178 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; | 160 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; |
| 179 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2", | 161 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2", |
| 180 time_deferred, | 162 time_deferred, |
| 181 base::TimeDelta::FromSeconds(0), | 163 base::TimeDelta::FromSeconds(0), |
| 182 base::TimeDelta::FromMinutes(2), | 164 base::TimeDelta::FromMinutes(2), |
| 183 60); | 165 60); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 syncer::MODEL_TYPE_COUNT); | 213 syncer::MODEL_TYPE_COUNT); |
| 232 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", | 214 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", |
| 233 TRIGGER_DATA_TYPE_REQUEST, | 215 TRIGGER_DATA_TYPE_REQUEST, |
| 234 MAX_TRIGGER_VALUE); | 216 MAX_TRIGGER_VALUE); |
| 235 } | 217 } |
| 236 received_start_request_ = true; | 218 received_start_request_ = true; |
| 237 TryStart(); | 219 TryStart(); |
| 238 } | 220 } |
| 239 | 221 |
| 240 } // namespace browser_sync | 222 } // namespace browser_sync |
| OLD | NEW |