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 "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" | 10 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void StartupController::set_setup_in_progress(bool in_progress) { | 65 void StartupController::set_setup_in_progress(bool in_progress) { |
66 setup_in_progress_ = in_progress; | 66 setup_in_progress_ = in_progress; |
67 } | 67 } |
68 | 68 |
69 bool StartupController::StartUp(StartUpDeferredOption deferred_option) { | 69 bool StartupController::StartUp(StartUpDeferredOption deferred_option) { |
70 const bool first_start = start_up_time_.is_null(); | 70 const bool first_start = start_up_time_.is_null(); |
71 if (first_start) | 71 if (first_start) |
72 start_up_time_ = base::Time::Now(); | 72 start_up_time_ = base::Time::Now(); |
73 | 73 |
74 if (deferred_option == STARTUP_BACKEND_DEFERRED && | 74 if (deferred_option == STARTUP_BACKEND_DEFERRED && |
75 !CommandLine::ForCurrentProcess()->HasSwitch( | 75 CommandLine::ForCurrentProcess()->HasSwitch( |
76 switches::kSyncDisableDeferredStartup) && | 76 switches::kSyncEnableDeferredStartup) && |
77 sync_prefs_->GetPreferredDataTypes(registered_types_) | 77 sync_prefs_->GetPreferredDataTypes(registered_types_) |
78 .Has(syncer::SESSIONS)) { | 78 .Has(syncer::SESSIONS)) { |
79 if (first_start) { | 79 if (first_start) { |
80 base::MessageLoop::current()->PostDelayedTask( | 80 base::MessageLoop::current()->PostDelayedTask( |
81 FROM_HERE, | 81 FROM_HERE, |
82 base::Bind(&StartupController::OnFallbackStartupTimerExpired, | 82 base::Bind(&StartupController::OnFallbackStartupTimerExpired, |
83 weak_factory_.GetWeakPtr()), fallback_timeout_); | 83 weak_factory_.GetWeakPtr()), fallback_timeout_); |
84 } | 84 } |
85 return false; | 85 return false; |
86 } | 86 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } else if (setup_in_progress_ || auto_start_enabled_) { | 145 } else if (setup_in_progress_ || auto_start_enabled_) { |
146 // We haven't completed sync setup. Start immediately if the user explicitly | 146 // We haven't completed sync setup. Start immediately if the user explicitly |
147 // kicked this off or we're supposed to automatically start syncing. | 147 // kicked this off or we're supposed to automatically start syncing. |
148 return StartUp(STARTUP_IMMEDIATE); | 148 return StartUp(STARTUP_IMMEDIATE); |
149 } | 149 } |
150 | 150 |
151 return false; | 151 return false; |
152 } | 152 } |
153 | 153 |
154 void StartupController::OnFallbackStartupTimerExpired() { | 154 void StartupController::OnFallbackStartupTimerExpired() { |
155 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | 155 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
156 switches::kSyncDisableDeferredStartup)); | 156 switches::kSyncEnableDeferredStartup)); |
157 | 157 |
158 if (!start_backend_time_.is_null()) | 158 if (!start_backend_time_.is_null()) |
159 return; | 159 return; |
160 | 160 |
161 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; | 161 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; |
162 DCHECK(!start_up_time_.is_null()); | 162 DCHECK(!start_up_time_.is_null()); |
163 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; | 163 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; |
164 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); | 164 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); |
165 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", | 165 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", |
166 TRIGGER_FALLBACK_TIMER, | 166 TRIGGER_FALLBACK_TIMER, |
167 MAX_TRIGGER_VALUE); | 167 MAX_TRIGGER_VALUE); |
168 received_start_request_ = true; | 168 received_start_request_ = true; |
169 TryStart(); | 169 TryStart(); |
170 } | 170 } |
171 | 171 |
172 std::string StartupController::GetBackendInitializationStateString() const { | 172 std::string StartupController::GetBackendInitializationStateString() const { |
173 if (!start_backend_time_.is_null()) | 173 if (!start_backend_time_.is_null()) |
174 return "Started"; | 174 return "Started"; |
175 else if (!start_up_time_.is_null()) | 175 else if (!start_up_time_.is_null()) |
176 return "Deferred"; | 176 return "Deferred"; |
177 else | 177 else |
178 return "Not started"; | 178 return "Not started"; |
179 } | 179 } |
180 | 180 |
181 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) { | 181 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) { |
182 if (CommandLine::ForCurrentProcess()->HasSwitch( | 182 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
183 switches::kSyncDisableDeferredStartup)) { | 183 switches::kSyncEnableDeferredStartup)) { |
184 DVLOG(2) << "Ignoring data type request for sync startup: " | 184 DVLOG(2) << "Ignoring data type request for sync startup: " |
185 << syncer::ModelTypeToString(type); | 185 << syncer::ModelTypeToString(type); |
186 return; | 186 return; |
187 } | 187 } |
188 | 188 |
189 if (!start_backend_time_.is_null()) | 189 if (!start_backend_time_.is_null()) |
190 return; | 190 return; |
191 | 191 |
192 DVLOG(2) << "Data type requesting sync startup: " | 192 DVLOG(2) << "Data type requesting sync startup: " |
193 << syncer::ModelTypeToString(type); | 193 << syncer::ModelTypeToString(type); |
194 // Measure the time spent waiting for init and the type that triggered it. | 194 // Measure the time spent waiting for init and the type that triggered it. |
195 // We could measure the time spent deferred on a per-datatype basis, but | 195 // We could measure the time spent deferred on a per-datatype basis, but |
196 // for now this is probably sufficient. | 196 // for now this is probably sufficient. |
197 if (!start_up_time_.is_null()) { | 197 if (!start_up_time_.is_null()) { |
198 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; | 198 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; |
199 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); | 199 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); |
200 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", | 200 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", |
201 ModelTypeToHistogramInt(type), | 201 ModelTypeToHistogramInt(type), |
202 syncer::MODEL_TYPE_COUNT); | 202 syncer::MODEL_TYPE_COUNT); |
203 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", | 203 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", |
204 TRIGGER_DATA_TYPE_REQUEST, | 204 TRIGGER_DATA_TYPE_REQUEST, |
205 MAX_TRIGGER_VALUE); | 205 MAX_TRIGGER_VALUE); |
206 } | 206 } |
207 received_start_request_ = true; | 207 received_start_request_ = true; |
208 TryStart(); | 208 TryStart(); |
209 } | 209 } |
210 | 210 |
211 } // namespace browser_sync | 211 } // namespace browser_sync |
OLD | NEW |