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

Side by Side Diff: components/sync/driver/startup_controller.cc

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 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"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.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 syncer {
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
27 // exit the "deferred" state of initialization and invoke start_backend. 27 // exit the "deferred" state of initialization and invoke start_backend.
28 enum DeferredInitTrigger { 28 enum DeferredInitTrigger {
29 // We have received a signal from a SyncableService requesting that sync 29 // We have received a signal from a SyncableService requesting that sync
30 // starts as soon as possible. 30 // starts as soon as possible.
31 TRIGGER_DATA_TYPE_REQUEST, 31 TRIGGER_DATA_TYPE_REQUEST,
32 // No data type requested sync to start and our fallback timer expired. 32 // No data type requested sync to start and our fallback timer expired.
33 TRIGGER_FALLBACK_TIMER, 33 TRIGGER_FALLBACK_TIMER,
34 MAX_TRIGGER_VALUE 34 MAX_TRIGGER_VALUE
35 }; 35 };
36 36
37 } // namespace 37 } // namespace
38 38
39 StartupController::StartupController(const sync_driver::SyncPrefs* sync_prefs, 39 StartupController::StartupController(const SyncPrefs* sync_prefs,
40 base::Callback<bool()> can_start, 40 base::Callback<bool()> can_start,
41 base::Closure start_backend) 41 base::Closure start_backend)
42 : bypass_setup_complete_(false), 42 : bypass_setup_complete_(false),
43 received_start_request_(false), 43 received_start_request_(false),
44 setup_in_progress_(false), 44 setup_in_progress_(false),
45 sync_prefs_(sync_prefs), 45 sync_prefs_(sync_prefs),
46 can_start_(can_start), 46 can_start_(can_start),
47 start_backend_(start_backend), 47 start_backend_(start_backend),
48 fallback_timeout_( 48 fallback_timeout_(
49 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)), 49 base::TimeDelta::FromSeconds(kDeferredInitFallbackSeconds)),
50 weak_factory_(this) { 50 weak_factory_(this) {
51 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 51 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
52 switches::kSyncDeferredStartupTimeoutSeconds)) { 52 switches::kSyncDeferredStartupTimeoutSeconds)) {
53 int timeout = kDeferredInitFallbackSeconds; 53 int timeout = kDeferredInitFallbackSeconds;
54 if (base::StringToInt( 54 if (base::StringToInt(
55 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 55 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
56 switches::kSyncDeferredStartupTimeoutSeconds), 56 switches::kSyncDeferredStartupTimeoutSeconds),
57 &timeout)) { 57 &timeout)) {
58 DCHECK_GE(timeout, 0); 58 DCHECK_GE(timeout, 0);
59 DVLOG(2) << "Sync StartupController overriding startup timeout to " 59 DVLOG(2) << "Sync StartupController overriding startup timeout to "
60 << timeout << " seconds."; 60 << timeout << " seconds.";
61 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout); 61 fallback_timeout_ = base::TimeDelta::FromSeconds(timeout);
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 StartupController::~StartupController() {} 66 StartupController::~StartupController() {}
67 67
68 void StartupController::Reset(const syncer::ModelTypeSet registered_types) { 68 void StartupController::Reset(const ModelTypeSet registered_types) {
69 received_start_request_ = false; 69 received_start_request_ = false;
70 bypass_setup_complete_ = false; 70 bypass_setup_complete_ = false;
71 start_up_time_ = base::Time(); 71 start_up_time_ = base::Time();
72 start_backend_time_ = base::Time(); 72 start_backend_time_ = base::Time();
73 // Don't let previous timers affect us post-reset. 73 // Don't let previous timers affect us post-reset.
74 weak_factory_.InvalidateWeakPtrs(); 74 weak_factory_.InvalidateWeakPtrs();
75 registered_types_ = registered_types; 75 registered_types_ = registered_types;
76 } 76 }
77 77
78 void StartupController::SetSetupInProgress(bool setup_in_progress) { 78 void StartupController::SetSetupInProgress(bool setup_in_progress) {
79 setup_in_progress_ = setup_in_progress; 79 setup_in_progress_ = setup_in_progress;
80 if (setup_in_progress_) { 80 if (setup_in_progress_) {
81 TryStart(); 81 TryStart();
82 } 82 }
83 } 83 }
84 84
85 bool StartupController::StartUp(StartUpDeferredOption deferred_option) { 85 bool StartupController::StartUp(StartUpDeferredOption deferred_option) {
86 const bool first_start = start_up_time_.is_null(); 86 const bool first_start = start_up_time_.is_null();
87 if (first_start) 87 if (first_start)
88 start_up_time_ = base::Time::Now(); 88 start_up_time_ = base::Time::Now();
89 89
90 if (deferred_option == STARTUP_BACKEND_DEFERRED && 90 if (deferred_option == STARTUP_BACKEND_DEFERRED &&
91 !base::CommandLine::ForCurrentProcess()->HasSwitch( 91 !base::CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kSyncDisableDeferredStartup) && 92 switches::kSyncDisableDeferredStartup) &&
93 sync_prefs_->GetPreferredDataTypes(registered_types_) 93 sync_prefs_->GetPreferredDataTypes(registered_types_).Has(SESSIONS)) {
94 .Has(syncer::SESSIONS)) {
95 if (first_start) { 94 if (first_start) {
96 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
97 FROM_HERE, 96 FROM_HERE,
98 base::Bind(&StartupController::OnFallbackStartupTimerExpired, 97 base::Bind(&StartupController::OnFallbackStartupTimerExpired,
99 weak_factory_.GetWeakPtr()), 98 weak_factory_.GetWeakPtr()),
100 fallback_timeout_); 99 fallback_timeout_);
101 } 100 }
102 return false; 101 return false;
103 } 102 }
104 103
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 166
168 std::string StartupController::GetBackendInitializationStateString() const { 167 std::string StartupController::GetBackendInitializationStateString() const {
169 if (!start_backend_time_.is_null()) 168 if (!start_backend_time_.is_null())
170 return "Started"; 169 return "Started";
171 else if (!start_up_time_.is_null()) 170 else if (!start_up_time_.is_null())
172 return "Deferred"; 171 return "Deferred";
173 else 172 else
174 return "Not started"; 173 return "Not started";
175 } 174 }
176 175
177 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) { 176 void StartupController::OnDataTypeRequestsSyncStartup(ModelType type) {
178 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 177 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
179 switches::kSyncDisableDeferredStartup)) { 178 switches::kSyncDisableDeferredStartup)) {
180 DVLOG(2) << "Ignoring data type request for sync startup: " 179 DVLOG(2) << "Ignoring data type request for sync startup: "
181 << syncer::ModelTypeToString(type); 180 << ModelTypeToString(type);
182 return; 181 return;
183 } 182 }
184 183
185 if (!start_backend_time_.is_null()) 184 if (!start_backend_time_.is_null())
186 return; 185 return;
187 186
188 DVLOG(2) << "Data type requesting sync startup: " 187 DVLOG(2) << "Data type requesting sync startup: " << ModelTypeToString(type);
189 << syncer::ModelTypeToString(type);
190 // Measure the time spent waiting for init and the type that triggered it. 188 // Measure the time spent waiting for init and the type that triggered it.
191 // We could measure the time spent deferred on a per-datatype basis, but 189 // We could measure the time spent deferred on a per-datatype basis, but
192 // for now this is probably sufficient. 190 // for now this is probably sufficient.
193 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", 191 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit",
194 ModelTypeToHistogramInt(type), 192 ModelTypeToHistogramInt(type), MODEL_TYPE_COUNT);
195 syncer::MODEL_TYPE_COUNT);
196 if (!start_up_time_.is_null()) { 193 if (!start_up_time_.is_null()) {
197 RecordTimeDeferred(); 194 RecordTimeDeferred();
198 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 195 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
199 TRIGGER_DATA_TYPE_REQUEST, MAX_TRIGGER_VALUE); 196 TRIGGER_DATA_TYPE_REQUEST, MAX_TRIGGER_VALUE);
200 } 197 }
201 received_start_request_ = true; 198 received_start_request_ = true;
202 TryStart(); 199 TryStart();
203 } 200 }
204 201
205 } // namespace browser_sync 202 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/startup_controller.h ('k') | components/sync/driver/startup_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698