OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/sync_service_base.h" | 5 #include "components/sync/driver/sync_service_base.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/syslog_logging.h" | 15 #include "base/syslog_logging.h" |
16 #include "components/invalidation/public/invalidation_service.h" | 16 #include "components/invalidation/public/invalidation_service.h" |
17 #include "components/sync/base/report_unrecoverable_error.h" | 17 #include "components/sync/base/report_unrecoverable_error.h" |
18 #include "components/sync/device_info/local_device_info_provider.h" | 18 #include "components/sync/device_info/local_device_info_provider.h" |
19 #include "components/sync/driver/sync_driver_switches.h" | 19 #include "components/sync/driver/sync_driver_switches.h" |
20 #include "components/sync/engine/engine_components_factory_impl.h" | 20 #include "components/sync/engine/engine_components_factory_impl.h" |
21 | 21 |
22 namespace syncer { | 22 namespace syncer { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const base::FilePath::CharType kSyncDataFolderName[] = | 26 const base::FilePath::CharType kSyncDataFolderName[] = |
27 FILE_PATH_LITERAL("Sync Data"); | 27 FILE_PATH_LITERAL("Sync Data"); |
28 | 28 |
29 #if defined(OS_WIN) | |
30 const base::FilePath::CharType kLoopbackServerBackendFilename[] = | |
31 FILE_PATH_LITERAL("profile.pb"); | |
32 #endif | |
33 | |
34 EngineComponentsFactory::Switches EngineSwitchesFromCommandLine() { | 29 EngineComponentsFactory::Switches EngineSwitchesFromCommandLine() { |
35 EngineComponentsFactory::Switches factory_switches = { | 30 EngineComponentsFactory::Switches factory_switches = { |
36 EngineComponentsFactory::ENCRYPTION_KEYSTORE, | 31 EngineComponentsFactory::ENCRYPTION_KEYSTORE, |
37 EngineComponentsFactory::BACKOFF_NORMAL}; | 32 EngineComponentsFactory::BACKOFF_NORMAL}; |
38 | 33 |
39 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 34 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
40 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { | 35 if (cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) { |
41 factory_switches.backoff_override = | 36 factory_switches.backoff_override = |
42 EngineComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; | 37 EngineComponentsFactory::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; |
43 } | 38 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); | 112 params.http_factory_getter = MakeHttpPostProviderFactoryGetter(); |
118 params.credentials = GetCredentials(); | 113 params.credentials = GetCredentials(); |
119 invalidation::InvalidationService* invalidator = | 114 invalidation::InvalidationService* invalidator = |
120 sync_client_->GetInvalidationService(); | 115 sync_client_->GetInvalidationService(); |
121 params.invalidator_client_id = | 116 params.invalidator_client_id = |
122 invalidator ? invalidator->GetInvalidatorClientId() : "", | 117 invalidator ? invalidator->GetInvalidatorClientId() : "", |
123 params.sync_manager_factory = base::MakeUnique<SyncManagerFactory>(); | 118 params.sync_manager_factory = base::MakeUnique<SyncManagerFactory>(); |
124 // The first time we start up the engine we want to ensure we have a clean | 119 // The first time we start up the engine we want to ensure we have a clean |
125 // directory, so delete any old one that might be there. | 120 // directory, so delete any old one that might be there. |
126 params.delete_sync_data_folder = !IsFirstSetupComplete(); | 121 params.delete_sync_data_folder = !IsFirstSetupComplete(); |
127 params.enable_local_sync_backend = | 122 params.enable_local_sync_backend = sync_prefs_.IsLocalSyncEnabled(); |
128 GetLocalSyncConfig(¶ms.local_sync_backend_folder); | 123 params.local_sync_backend_folder = sync_client_->GetLocalSyncBackendFolder(); |
129 params.restored_key_for_bootstrapping = | 124 params.restored_key_for_bootstrapping = |
130 sync_prefs_.GetEncryptionBootstrapToken(); | 125 sync_prefs_.GetEncryptionBootstrapToken(); |
131 params.restored_keystore_key_for_bootstrapping = | 126 params.restored_keystore_key_for_bootstrapping = |
132 sync_prefs_.GetKeystoreEncryptionBootstrapToken(); | 127 sync_prefs_.GetKeystoreEncryptionBootstrapToken(); |
133 params.engine_components_factory = | 128 params.engine_components_factory = |
134 base::MakeUnique<EngineComponentsFactoryImpl>( | 129 base::MakeUnique<EngineComponentsFactoryImpl>( |
135 EngineSwitchesFromCommandLine()); | 130 EngineSwitchesFromCommandLine()); |
136 params.unrecoverable_error_handler = GetUnrecoverableErrorHandler(); | 131 params.unrecoverable_error_handler = GetUnrecoverableErrorHandler(); |
137 params.report_unrecoverable_error_function = | 132 params.report_unrecoverable_error_function = |
138 base::Bind(ReportUnrecoverableError, channel_); | 133 base::Bind(ReportUnrecoverableError, channel_); |
139 params.saved_nigori_state = crypto_->TakeSavedNigoriState(); | 134 params.saved_nigori_state = crypto_->TakeSavedNigoriState(); |
140 sync_prefs_.GetInvalidationVersions(¶ms.invalidation_versions); | 135 sync_prefs_.GetInvalidationVersions(¶ms.invalidation_versions); |
141 | 136 |
142 engine_->Initialize(std::move(params)); | 137 engine_->Initialize(std::move(params)); |
143 } | 138 } |
144 | 139 |
145 bool SyncServiceBase::GetLocalSyncConfig( | |
146 base::FilePath* local_sync_backend_folder) const { | |
147 bool enable_local_sync_backend = false; | |
148 *local_sync_backend_folder = sync_prefs_.GetLocalSyncBackendDir(); | |
149 #if defined(OS_WIN) | |
150 enable_local_sync_backend = sync_prefs_.IsLocalSyncEnabled(); | |
151 UMA_HISTOGRAM_BOOLEAN("Sync.Local.Enabled", enable_local_sync_backend); | |
152 if (local_sync_backend_folder->empty()) { | |
153 // TODO(pastarmovj): Add DIR_ROAMING_USER_DATA to PathService to simplify | |
154 // this code and move the logic in its right place. See crbug/657810. | |
155 if (!base::PathService::Get(base::DIR_APP_DATA, | |
156 local_sync_backend_folder)) { | |
157 SYSLOG(WARNING) << "Local sync can not get the roaming profile folder."; | |
158 UMA_HISTOGRAM_BOOLEAN("Sync.Local.RoamingProfileUnavailable", false); | |
159 return false; | |
160 } | |
161 *local_sync_backend_folder = local_sync_backend_folder->Append( | |
162 FILE_PATH_LITERAL("Chrome/User Data")); | |
163 } | |
164 // This code as it is now will assume the same profile order is present on all | |
165 // machines, which is not a given. It is to be defined if only the Default | |
166 // profile should get this treatment or all profile as is the case now. The | |
167 // solution for now will be to assume profiles are created in the same order | |
168 // on all machines and in the future decide if only the Default one should be | |
169 // considered roamed. | |
170 // See http://crbug.com/674928. | |
171 *local_sync_backend_folder = | |
172 local_sync_backend_folder->Append(base_directory_.BaseName()); | |
173 *local_sync_backend_folder = | |
174 local_sync_backend_folder->Append(kLoopbackServerBackendFilename); | |
175 #endif // defined(OS_WIN) | |
176 return enable_local_sync_backend; | |
177 } | |
178 | |
179 void SyncServiceBase::ResetCryptoState() { | 140 void SyncServiceBase::ResetCryptoState() { |
180 crypto_ = base::MakeUnique<SyncServiceCrypto>( | 141 crypto_ = base::MakeUnique<SyncServiceCrypto>( |
181 base::BindRepeating(&SyncServiceBase::NotifyObservers, | 142 base::BindRepeating(&SyncServiceBase::NotifyObservers, |
182 base::Unretained(this)), | 143 base::Unretained(this)), |
183 base::BindRepeating(&SyncService::GetPreferredDataTypes, | 144 base::BindRepeating(&SyncService::GetPreferredDataTypes, |
184 base::Unretained(this)), | 145 base::Unretained(this)), |
185 &sync_prefs_); | 146 &sync_prefs_); |
186 } | 147 } |
187 | 148 |
188 } // namespace syncer | 149 } // namespace syncer |
OLD | NEW |