Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Side by Side Diff: components/sync_driver/startup_controller.cc

Issue 2159453002: [Sync] Don't start up sync when FirstSetupCompleted is false and no setup in progress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 start_up_time_ = base::Time(); 69 start_up_time_ = base::Time();
70 start_backend_time_ = base::Time(); 70 start_backend_time_ = base::Time();
71 // Don't let previous timers affect us post-reset. 71 // Don't let previous timers affect us post-reset.
72 weak_factory_.InvalidateWeakPtrs(); 72 weak_factory_.InvalidateWeakPtrs();
73 registered_types_ = registered_types; 73 registered_types_ = registered_types;
74 } 74 }
75 75
76 void StartupController::SetSetupInProgress(bool setup_in_progress) { 76 void StartupController::SetSetupInProgress(bool setup_in_progress) {
77 setup_in_progress_ = setup_in_progress; 77 setup_in_progress_ = setup_in_progress;
78 if (setup_in_progress_) { 78 if (setup_in_progress_) {
79 TryStart(); 79 TryStart(false);
80 } 80 }
81 } 81 }
82 82
83 bool StartupController::StartUp(StartUpDeferredOption deferred_option) { 83 bool StartupController::StartUp(StartUpDeferredOption deferred_option) {
84 const bool first_start = start_up_time_.is_null(); 84 const bool first_start = start_up_time_.is_null();
85 if (first_start) 85 if (first_start)
86 start_up_time_ = base::Time::Now(); 86 start_up_time_ = base::Time::Now();
87 87
88 if (deferred_option == STARTUP_BACKEND_DEFERRED && 88 if (deferred_option == STARTUP_BACKEND_DEFERRED &&
89 !base::CommandLine::ForCurrentProcess()->HasSwitch( 89 !base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 16 matching lines...) Expand all
106 } 106 }
107 107
108 return true; 108 return true;
109 } 109 }
110 110
111 void StartupController::OverrideFallbackTimeoutForTest( 111 void StartupController::OverrideFallbackTimeoutForTest(
112 const base::TimeDelta& timeout) { 112 const base::TimeDelta& timeout) {
113 fallback_timeout_ = timeout; 113 fallback_timeout_ = timeout;
114 } 114 }
115 115
116 bool StartupController::TryStart() { 116 bool StartupController::TryStart(bool request_immediate) {
117 if (request_immediate)
118 received_start_request_ = true;
119
117 if (!can_start_.Run()) 120 if (!can_start_.Run())
118 return false; 121 return false;
119 122
120 // For performance reasons, defer the heavy lifting for sync init unless: 123 // For performance reasons, defer the heavy lifting for sync init unless:
121 // 124 //
122 // - a datatype has requested an immediate start of sync, or 125 // - a datatype has requested an immediate start of sync, or
123 // - sync needs to start up the backend immediately to provide control state 126 // - sync needs to start up the backend immediately to provide control state
124 // and encryption information to the UI, or 127 // and encryption information to the UI.
125 // - this is the first time sync is ever starting up. 128 // Do not start up the sync backend if setup has not completed and isn't
126 if (received_start_request_ || setup_in_progress_ || 129 // in progress.
127 !sync_prefs_->IsFirstSetupComplete()) { 130 if (setup_in_progress_) {
128 return StartUp(STARTUP_IMMEDIATE); 131 return StartUp(STARTUP_IMMEDIATE);
132 } else if (sync_prefs_->IsFirstSetupComplete()) {
133 if (received_start_request_)
134 return StartUp(STARTUP_IMMEDIATE);
135 else
maxbogue 2016/07/15 21:44:48 nit: this is somewhat personal style but I very mu
Nicolas Zea 2016/07/15 22:42:22 Consistency within the file is important in this c
136 return StartUp(STARTUP_BACKEND_DEFERRED);
129 } else { 137 } else {
130 return StartUp(STARTUP_BACKEND_DEFERRED); 138 return false;
131 } 139 }
132 } 140 }
133 141
134 void StartupController::RecordTimeDeferred() { 142 void StartupController::RecordTimeDeferred() {
135 DCHECK(!start_up_time_.is_null()); 143 DCHECK(!start_up_time_.is_null());
136 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_; 144 base::TimeDelta time_deferred = base::Time::Now() - start_up_time_;
137 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2", 145 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.Startup.TimeDeferred2",
138 time_deferred, 146 time_deferred,
139 base::TimeDelta::FromSeconds(0), 147 base::TimeDelta::FromSeconds(0),
140 base::TimeDelta::FromMinutes(2), 148 base::TimeDelta::FromMinutes(2),
141 60); 149 60);
142 } 150 }
143 151
144 void StartupController::OnFallbackStartupTimerExpired() { 152 void StartupController::OnFallbackStartupTimerExpired() {
145 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( 153 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
146 switches::kSyncDisableDeferredStartup)); 154 switches::kSyncDisableDeferredStartup));
147 155
148 if (!start_backend_time_.is_null()) 156 if (!start_backend_time_.is_null())
149 return; 157 return;
150 158
151 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend."; 159 DVLOG(2) << "Sync deferred init fallback timer expired, starting backend.";
152 RecordTimeDeferred(); 160 RecordTimeDeferred();
153 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 161 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
154 TRIGGER_FALLBACK_TIMER, 162 TRIGGER_FALLBACK_TIMER,
155 MAX_TRIGGER_VALUE); 163 MAX_TRIGGER_VALUE);
156 received_start_request_ = true; 164 received_start_request_ = true;
157 TryStart(); 165 TryStart(false);
158 } 166 }
159 167
160 std::string StartupController::GetBackendInitializationStateString() const { 168 std::string StartupController::GetBackendInitializationStateString() const {
161 if (!start_backend_time_.is_null()) 169 if (!start_backend_time_.is_null())
162 return "Started"; 170 return "Started";
163 else if (!start_up_time_.is_null()) 171 else if (!start_up_time_.is_null())
164 return "Deferred"; 172 return "Deferred";
165 else 173 else
166 return "Not started"; 174 return "Not started";
167 } 175 }
(...skipping 17 matching lines...) Expand all
185 if (!start_up_time_.is_null()) { 193 if (!start_up_time_.is_null()) {
186 RecordTimeDeferred(); 194 RecordTimeDeferred();
187 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", 195 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit",
188 ModelTypeToHistogramInt(type), 196 ModelTypeToHistogramInt(type),
189 syncer::MODEL_TYPE_COUNT); 197 syncer::MODEL_TYPE_COUNT);
190 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 198 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
191 TRIGGER_DATA_TYPE_REQUEST, 199 TRIGGER_DATA_TYPE_REQUEST,
192 MAX_TRIGGER_VALUE); 200 MAX_TRIGGER_VALUE);
193 } 201 }
194 received_start_request_ = true; 202 received_start_request_ = true;
195 TryStart(); 203 TryStart(false);
196 } 204 }
197 205
198 } // namespace browser_sync 206 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698