| 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "components/sync_driver/sync_driver_switches.h" | 15 #include "components/sync/driver/sync_driver_switches.h" |
| 16 #include "components/sync_driver/sync_prefs.h" | 16 #include "components/sync/driver/sync_prefs.h" |
| 17 | 17 |
| 18 namespace browser_sync { | 18 namespace browser_sync { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // The amount of time we'll wait to initialize sync if no data type triggers | 22 // The amount of time we'll wait to initialize sync if no data type triggers |
| 23 // initialization via a StartSyncFlare. | 23 // initialization via a StartSyncFlare. |
| 24 const int kDeferredInitFallbackSeconds = 10; | 24 const int kDeferredInitFallbackSeconds = 10; |
| 25 | 25 |
| 26 // Enum (for UMA, primarily) defining different events that cause us to | 26 // Enum (for UMA, primarily) defining different events that cause us to |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 bool StartupController::TryStartImmediately() { | 139 bool StartupController::TryStartImmediately() { |
| 140 received_start_request_ = true; | 140 received_start_request_ = true; |
| 141 bypass_setup_complete_ = true; | 141 bypass_setup_complete_ = true; |
| 142 return TryStart(); | 142 return TryStart(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void StartupController::RecordTimeDeferred() { | 145 void StartupController::RecordTimeDeferred() { |
| 146 DCHECK(!start_up_time_.is_null()); | 146 DCHECK(!start_up_time_.is_null()); |
| 147 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; | 147 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; |
| 148 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2", | 148 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2", time_deferred, |
| 149 time_deferred, | 149 base::TimeDelta::FromSeconds(0), |
| 150 base::TimeDelta::FromSeconds(0), | 150 base::TimeDelta::FromMinutes(2), 60); |
| 151 base::TimeDelta::FromMinutes(2), | |
| 152 60); | |
| 153 } | 151 } |
| 154 | 152 |
| 155 void StartupController::OnFallbackStartupTimerExpired() { | 153 void StartupController::OnFallbackStartupTimerExpired() { |
| 156 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 154 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 157 switches::kSyncDisableDeferredStartup)); | 155 switches::kSyncDisableDeferredStartup)); |
| 158 | 156 |
| 159 if (!start_backend_time_.is_null()) | 157 if (!start_backend_time_.is_null()) |
| 160 return; | 158 return; |
| 161 | 159 |
| 162 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; | 160 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; |
| 163 RecordTimeDeferred(); | 161 RecordTimeDeferred(); |
| 164 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", | 162 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", |
| 165 TRIGGER_FALLBACK_TIMER, | 163 TRIGGER_FALLBACK_TIMER, MAX_TRIGGER_VALUE); |
| 166 MAX_TRIGGER_VALUE); | |
| 167 received_start_request_ = true; | 164 received_start_request_ = true; |
| 168 TryStart(); | 165 TryStart(); |
| 169 } | 166 } |
| 170 | 167 |
| 171 std::string StartupController::GetBackendInitializationStateString() const { | 168 std::string StartupController::GetBackendInitializationStateString() const { |
| 172 if (!start_backend_time_.is_null()) | 169 if (!start_backend_time_.is_null()) |
| 173 return "Started"; | 170 return "Started"; |
| 174 else if (!start_up_time_.is_null()) | 171 else if (!start_up_time_.is_null()) |
| 175 return "Deferred"; | 172 return "Deferred"; |
| 176 else | 173 else |
| (...skipping 15 matching lines...) Expand all Loading... |
| 192 << syncer::ModelTypeToString(type); | 189 << syncer::ModelTypeToString(type); |
| 193 // Measure the time spent waiting for init and the type that triggered it. | 190 // Measure the time spent waiting for init and the type that triggered it. |
| 194 // We could measure the time spent deferred on a per-datatype basis, but | 191 // We could measure the time spent deferred on a per-datatype basis, but |
| 195 // for now this is probably sufficient. | 192 // for now this is probably sufficient. |
| 196 if (!start_up_time_.is_null()) { | 193 if (!start_up_time_.is_null()) { |
| 197 RecordTimeDeferred(); | 194 RecordTimeDeferred(); |
| 198 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", | 195 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", |
| 199 ModelTypeToHistogramInt(type), | 196 ModelTypeToHistogramInt(type), |
| 200 syncer::MODEL_TYPE_COUNT); | 197 syncer::MODEL_TYPE_COUNT); |
| 201 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", | 198 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", |
| 202 TRIGGER_DATA_TYPE_REQUEST, | 199 TRIGGER_DATA_TYPE_REQUEST, MAX_TRIGGER_VALUE); |
| 203 MAX_TRIGGER_VALUE); | |
| 204 } | 200 } |
| 205 received_start_request_ = true; | 201 received_start_request_ = true; |
| 206 TryStart(); | 202 TryStart(); |
| 207 } | 203 } |
| 208 | 204 |
| 209 } // namespace browser_sync | 205 } // namespace browser_sync |
| OLD | NEW |