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

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

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: 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 syncer { 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
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 SyncPrefs* sync_prefs, 39 StartupController::StartupController(const sync_driver::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 ModelTypeSet registered_types) { 68 void StartupController::Reset(const syncer::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_).Has(SESSIONS)) { 93 sync_prefs_->GetPreferredDataTypes(registered_types_)
94 .Has(syncer::SESSIONS)) {
94 if (first_start) { 95 if (first_start) {
95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 96 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
96 FROM_HERE, 97 FROM_HERE,
97 base::Bind(&StartupController::OnFallbackStartupTimerExpired, 98 base::Bind(&StartupController::OnFallbackStartupTimerExpired,
98 weak_factory_.GetWeakPtr()), 99 weak_factory_.GetWeakPtr()),
99 fallback_timeout_); 100 fallback_timeout_);
100 } 101 }
101 return false; 102 return false;
102 } 103 }
103 104
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 167
167 std::string StartupController::GetBackendInitializationStateString() const { 168 std::string StartupController::GetBackendInitializationStateString() const {
168 if (!start_backend_time_.is_null()) 169 if (!start_backend_time_.is_null())
169 return "Started"; 170 return "Started";
170 else if (!start_up_time_.is_null()) 171 else if (!start_up_time_.is_null())
171 return "Deferred"; 172 return "Deferred";
172 else 173 else
173 return "Not started"; 174 return "Not started";
174 } 175 }
175 176
176 void StartupController::OnDataTypeRequestsSyncStartup(ModelType type) { 177 void StartupController::OnDataTypeRequestsSyncStartup(syncer::ModelType type) {
177 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 178 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
178 switches::kSyncDisableDeferredStartup)) { 179 switches::kSyncDisableDeferredStartup)) {
179 DVLOG(2) << "Ignoring data type request for sync startup: " 180 DVLOG(2) << "Ignoring data type request for sync startup: "
180 << ModelTypeToString(type); 181 << syncer::ModelTypeToString(type);
181 return; 182 return;
182 } 183 }
183 184
184 if (!start_backend_time_.is_null()) 185 if (!start_backend_time_.is_null())
185 return; 186 return;
186 187
187 DVLOG(2) << "Data type requesting sync startup: " << ModelTypeToString(type); 188 DVLOG(2) << "Data type requesting sync startup: "
189 << syncer::ModelTypeToString(type);
188 // 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.
189 // 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
190 // for now this is probably sufficient. 192 // for now this is probably sufficient.
191 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit", 193 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.TypeTriggeringInit",
192 ModelTypeToHistogramInt(type), MODEL_TYPE_COUNT); 194 ModelTypeToHistogramInt(type),
195 syncer::MODEL_TYPE_COUNT);
193 if (!start_up_time_.is_null()) { 196 if (!start_up_time_.is_null()) {
194 RecordTimeDeferred(); 197 RecordTimeDeferred();
195 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger", 198 UMA_HISTOGRAM_ENUMERATION("Sync.Startup.DeferredInitTrigger",
196 TRIGGER_DATA_TYPE_REQUEST, MAX_TRIGGER_VALUE); 199 TRIGGER_DATA_TYPE_REQUEST, MAX_TRIGGER_VALUE);
197 } 200 }
198 received_start_request_ = true; 201 received_start_request_ = true;
199 TryStart(); 202 TryStart();
200 } 203 }
201 204
202 } // namespace syncer 205 } // namespace browser_sync
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