| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 return factory_switches; | 52 return factory_switches; |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 SyncServiceBase::SyncServiceBase(std::unique_ptr<SyncClient> sync_client, | 57 SyncServiceBase::SyncServiceBase(std::unique_ptr<SyncClient> sync_client, |
| 58 std::unique_ptr<SigninManagerWrapper> signin, | 58 std::unique_ptr<SigninManagerWrapper> signin, |
| 59 const version_info::Channel& channel, | 59 const version_info::Channel& channel, |
| 60 const base::FilePath& base_directory, | 60 const base::FilePath& base_directory, |
| 61 const base::FilePath& local_sync_directory, |
| 61 const std::string& debug_identifier) | 62 const std::string& debug_identifier) |
| 62 : sync_client_(std::move(sync_client)), | 63 : sync_client_(std::move(sync_client)), |
| 63 signin_(std::move(signin)), | 64 signin_(std::move(signin)), |
| 64 channel_(channel), | 65 channel_(channel), |
| 65 base_directory_(base_directory), | 66 base_directory_(base_directory), |
| 66 sync_data_folder_( | 67 sync_data_folder_( |
| 67 base_directory_.Append(base::FilePath(kSyncDataFolderName))), | 68 base_directory_.Append(base::FilePath(kSyncDataFolderName))), |
| 69 local_sync_directory_(local_sync_directory), |
| 68 debug_identifier_(debug_identifier), | 70 debug_identifier_(debug_identifier), |
| 69 sync_prefs_(sync_client_->GetPrefService()) { | 71 sync_prefs_(sync_client_->GetPrefService()) { |
| 70 ResetCryptoState(); | 72 ResetCryptoState(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 SyncServiceBase::~SyncServiceBase() = default; | 75 SyncServiceBase::~SyncServiceBase() = default; |
| 74 | 76 |
| 75 void SyncServiceBase::AddObserver(SyncServiceObserver* observer) { | 77 void SyncServiceBase::AddObserver(SyncServiceObserver* observer) { |
| 76 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
| 77 observers_.AddObserver(observer); | 79 observers_.AddObserver(observer); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 base::Bind(ReportUnrecoverableError, channel_); | 140 base::Bind(ReportUnrecoverableError, channel_); |
| 139 params.saved_nigori_state = crypto_->TakeSavedNigoriState(); | 141 params.saved_nigori_state = crypto_->TakeSavedNigoriState(); |
| 140 sync_prefs_.GetInvalidationVersions(¶ms.invalidation_versions); | 142 sync_prefs_.GetInvalidationVersions(¶ms.invalidation_versions); |
| 141 | 143 |
| 142 engine_->Initialize(std::move(params)); | 144 engine_->Initialize(std::move(params)); |
| 143 } | 145 } |
| 144 | 146 |
| 145 bool SyncServiceBase::GetLocalSyncConfig( | 147 bool SyncServiceBase::GetLocalSyncConfig( |
| 146 base::FilePath* local_sync_backend_folder) const { | 148 base::FilePath* local_sync_backend_folder) const { |
| 147 bool enable_local_sync_backend = false; | 149 bool enable_local_sync_backend = false; |
| 148 *local_sync_backend_folder = sync_prefs_.GetLocalSyncBackendDir(); | |
| 149 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
| 150 enable_local_sync_backend = sync_prefs_.IsLocalSyncEnabled(); | 151 enable_local_sync_backend = sync_prefs_.IsLocalSyncEnabled(); |
| 152 *local_sync_backend_folder = local_sync_directory_; |
| 151 UMA_HISTOGRAM_BOOLEAN("Sync.Local.Enabled", enable_local_sync_backend); | 153 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) | 154 #endif // defined(OS_WIN) |
| 176 return enable_local_sync_backend; | 155 return enable_local_sync_backend; |
| 177 } | 156 } |
| 178 | 157 |
| 179 void SyncServiceBase::ResetCryptoState() { | 158 void SyncServiceBase::ResetCryptoState() { |
| 180 crypto_ = base::MakeUnique<SyncServiceCrypto>( | 159 crypto_ = base::MakeUnique<SyncServiceCrypto>( |
| 181 base::BindRepeating(&SyncServiceBase::NotifyObservers, | 160 base::BindRepeating(&SyncServiceBase::NotifyObservers, |
| 182 base::Unretained(this)), | 161 base::Unretained(this)), |
| 183 base::BindRepeating(&SyncService::GetPreferredDataTypes, | 162 base::BindRepeating(&SyncService::GetPreferredDataTypes, |
| 184 base::Unretained(this)), | 163 base::Unretained(this)), |
| 185 &sync_prefs_); | 164 &sync_prefs_); |
| 186 } | 165 } |
| 187 | 166 |
| 188 } // namespace syncer | 167 } // namespace syncer |
| OLD | NEW |