| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/feature_list.h" | 17 #include "base/feature_list.h" |
| 18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 23 #include "base/path_service.h" | |
| 24 #include "base/profiler/scoped_tracker.h" | 23 #include "base/profiler/scoped_tracker.h" |
| 25 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 26 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 27 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "components/autofill/core/common/autofill_pref_names.h" | 28 #include "components/autofill/core/common/autofill_pref_names.h" |
| 30 #include "components/browser_sync/browser_sync_switches.h" | 29 #include "components/browser_sync/browser_sync_switches.h" |
| 31 #include "components/history/core/browser/typed_url_data_type_controller.h" | 30 #include "components/history/core/browser/typed_url_data_type_controller.h" |
| 32 #include "components/invalidation/impl/invalidation_prefs.h" | 31 #include "components/invalidation/impl/invalidation_prefs.h" |
| 33 #include "components/invalidation/public/invalidation_service.h" | 32 #include "components/invalidation/public/invalidation_service.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 144 |
| 146 // Don't use initial delay unless the last request was an error. | 145 // Don't use initial delay unless the last request was an error. |
| 147 false, | 146 false, |
| 148 }; | 147 }; |
| 149 | 148 |
| 150 static const base::FilePath::CharType kSyncDataFolderName[] = | 149 static const base::FilePath::CharType kSyncDataFolderName[] = |
| 151 FILE_PATH_LITERAL("Sync Data"); | 150 FILE_PATH_LITERAL("Sync Data"); |
| 152 static const base::FilePath::CharType kLevelDBFolderName[] = | 151 static const base::FilePath::CharType kLevelDBFolderName[] = |
| 153 FILE_PATH_LITERAL("LevelDB"); | 152 FILE_PATH_LITERAL("LevelDB"); |
| 154 | 153 |
| 155 #if defined(OS_WIN) | |
| 156 static const base::FilePath::CharType kLoopbackServerBackendFilename[] = | |
| 157 FILE_PATH_LITERAL("profile.pb"); | |
| 158 #endif | |
| 159 | |
| 160 namespace { | 154 namespace { |
| 161 | 155 |
| 162 // Perform the actual sync data folder deletion. | 156 // Perform the actual sync data folder deletion. |
| 163 // This should only be called on the sync thread. | 157 // This should only be called on the sync thread. |
| 164 void DeleteSyncDataFolder(const base::FilePath& directory_path) { | 158 void DeleteSyncDataFolder(const base::FilePath& directory_path) { |
| 165 if (base::DirectoryExists(directory_path)) { | 159 if (base::DirectoryExists(directory_path)) { |
| 166 if (!base::DeleteFile(directory_path, true)) | 160 if (!base::DeleteFile(directory_path, true)) |
| 167 LOG(DFATAL) << "Could not delete the Sync Data folder."; | 161 LOG(DFATAL) << "Could not delete the Sync Data folder."; |
| 168 } | 162 } |
| 169 } | 163 } |
| 170 | 164 |
| 171 } // namespace | 165 } // namespace |
| 172 | 166 |
| 173 ProfileSyncService::InitParams::InitParams() = default; | 167 ProfileSyncService::InitParams::InitParams() = default; |
| 174 ProfileSyncService::InitParams::~InitParams() = default; | 168 ProfileSyncService::InitParams::~InitParams() = default; |
| 175 ProfileSyncService::InitParams::InitParams(InitParams&& other) // NOLINT | 169 ProfileSyncService::InitParams::InitParams(InitParams&& other) // NOLINT |
| 176 : sync_client(std::move(other.sync_client)), | 170 : sync_client(std::move(other.sync_client)), |
| 177 signin_wrapper(std::move(other.signin_wrapper)), | 171 signin_wrapper(std::move(other.signin_wrapper)), |
| 178 oauth2_token_service(other.oauth2_token_service), | 172 oauth2_token_service(other.oauth2_token_service), |
| 179 gaia_cookie_manager_service(other.gaia_cookie_manager_service), | 173 gaia_cookie_manager_service(other.gaia_cookie_manager_service), |
| 180 start_behavior(other.start_behavior), | 174 start_behavior(other.start_behavior), |
| 181 network_time_update_callback( | 175 network_time_update_callback( |
| 182 std::move(other.network_time_update_callback)), | 176 std::move(other.network_time_update_callback)), |
| 183 base_directory(std::move(other.base_directory)), | 177 base_directory(std::move(other.base_directory)), |
| 184 url_request_context(std::move(other.url_request_context)), | 178 url_request_context(std::move(other.url_request_context)), |
| 185 debug_identifier(std::move(other.debug_identifier)), | 179 debug_identifier(std::move(other.debug_identifier)), |
| 186 channel(other.channel), | 180 channel(other.channel), |
| 187 blocking_pool(other.blocking_pool) {} | 181 blocking_pool(other.blocking_pool), |
| 182 local_sync_backend_folder(other.local_sync_backend_folder) {} |
| 188 | 183 |
| 189 ProfileSyncService::ProfileSyncService(InitParams init_params) | 184 ProfileSyncService::ProfileSyncService(InitParams init_params) |
| 190 : OAuth2TokenService::Consumer("sync"), | 185 : OAuth2TokenService::Consumer("sync"), |
| 191 last_auth_error_(AuthError::AuthErrorNone()), | 186 last_auth_error_(AuthError::AuthErrorNone()), |
| 192 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), | 187 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), |
| 193 sync_client_(std::move(init_params.sync_client)), | 188 sync_client_(std::move(init_params.sync_client)), |
| 194 sync_prefs_(sync_client_->GetPrefService()), | 189 sync_prefs_(sync_client_->GetPrefService()), |
| 195 sync_service_url_( | 190 sync_service_url_( |
| 196 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), | 191 syncer::GetSyncServiceURL(*base::CommandLine::ForCurrentProcess(), |
| 197 init_params.channel)), | 192 init_params.channel)), |
| 198 network_time_update_callback_( | 193 network_time_update_callback_( |
| 199 std::move(init_params.network_time_update_callback)), | 194 std::move(init_params.network_time_update_callback)), |
| 200 base_directory_(init_params.base_directory), | 195 base_directory_(init_params.base_directory), |
| 201 url_request_context_(init_params.url_request_context), | 196 url_request_context_(init_params.url_request_context), |
| 202 debug_identifier_(std::move(init_params.debug_identifier)), | 197 debug_identifier_(std::move(init_params.debug_identifier)), |
| 203 channel_(init_params.channel), | 198 channel_(init_params.channel), |
| 204 blocking_pool_(init_params.blocking_pool), | 199 blocking_pool_(init_params.blocking_pool), |
| 205 is_first_time_sync_configure_(false), | 200 is_first_time_sync_configure_(false), |
| 206 engine_initialized_(false), | 201 engine_initialized_(false), |
| 207 sync_disabled_by_admin_(false), | 202 sync_disabled_by_admin_(false), |
| 208 is_auth_in_progress_(false), | 203 is_auth_in_progress_(false), |
| 204 local_sync_backend_folder_(init_params.local_sync_backend_folder), |
| 209 signin_(std::move(init_params.signin_wrapper)), | 205 signin_(std::move(init_params.signin_wrapper)), |
| 210 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 206 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
| 211 expect_sync_configuration_aborted_(false), | 207 expect_sync_configuration_aborted_(false), |
| 212 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 208 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
| 213 encrypt_everything_allowed_(true), | 209 encrypt_everything_allowed_(true), |
| 214 encrypt_everything_(false), | 210 encrypt_everything_(false), |
| 215 encryption_pending_(false), | 211 encryption_pending_(false), |
| 216 configure_status_(DataTypeManager::UNKNOWN), | 212 configure_status_(DataTypeManager::UNKNOWN), |
| 217 oauth2_token_service_(init_params.oauth2_token_service), | 213 oauth2_token_service_(init_params.oauth2_token_service), |
| 218 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), | 214 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 245 DCHECK(thread_checker_.CalledOnValidThread()); | 241 DCHECK(thread_checker_.CalledOnValidThread()); |
| 246 if (gaia_cookie_manager_service_) | 242 if (gaia_cookie_manager_service_) |
| 247 gaia_cookie_manager_service_->RemoveObserver(this); | 243 gaia_cookie_manager_service_->RemoveObserver(this); |
| 248 sync_prefs_.RemoveSyncPrefObserver(this); | 244 sync_prefs_.RemoveSyncPrefObserver(this); |
| 249 // Shutdown() should have been called before destruction. | 245 // Shutdown() should have been called before destruction. |
| 250 CHECK(!engine_initialized_); | 246 CHECK(!engine_initialized_); |
| 251 } | 247 } |
| 252 | 248 |
| 253 bool ProfileSyncService::CanSyncStart() const { | 249 bool ProfileSyncService::CanSyncStart() const { |
| 254 DCHECK(thread_checker_.CalledOnValidThread()); | 250 DCHECK(thread_checker_.CalledOnValidThread()); |
| 255 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); | 251 return (IsSyncAllowed() && IsSyncRequested() && |
| 252 (IsLocalSyncEnabled() || IsSignedIn())); |
| 256 } | 253 } |
| 257 | 254 |
| 258 void ProfileSyncService::Initialize() { | 255 void ProfileSyncService::Initialize() { |
| 259 DCHECK(thread_checker_.CalledOnValidThread()); | 256 DCHECK(thread_checker_.CalledOnValidThread()); |
| 260 sync_client_->Initialize(); | 257 sync_client_->Initialize(); |
| 261 | 258 |
| 262 // We don't pass StartupController an Unretained reference to future-proof | 259 // We don't pass StartupController an Unretained reference to future-proof |
| 263 // against the controller impl changing to post tasks. | 260 // against the controller impl changing to post tasks. |
| 264 startup_controller_ = base::MakeUnique<syncer::StartupController>( | 261 startup_controller_ = base::MakeUnique<syncer::StartupController>( |
| 265 &sync_prefs_, | 262 &sync_prefs_, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 gaia_cookie_manager_service_->AddObserver(this); | 309 gaia_cookie_manager_service_->AddObserver(this); |
| 313 | 310 |
| 314 // We clear this here (vs Shutdown) because we want to remember that an error | 311 // We clear this here (vs Shutdown) because we want to remember that an error |
| 315 // happened on shutdown so we can display details (message, location) about it | 312 // happened on shutdown so we can display details (message, location) about it |
| 316 // in about:sync. | 313 // in about:sync. |
| 317 ClearStaleErrors(); | 314 ClearStaleErrors(); |
| 318 | 315 |
| 319 sync_prefs_.AddSyncPrefObserver(this); | 316 sync_prefs_.AddSyncPrefObserver(this); |
| 320 | 317 |
| 321 SyncInitialState sync_state = CAN_START; | 318 SyncInitialState sync_state = CAN_START; |
| 322 if (!IsSignedIn()) { | 319 if (!IsLocalSyncEnabled() && !IsSignedIn()) { |
| 323 sync_state = NOT_SIGNED_IN; | 320 sync_state = NOT_SIGNED_IN; |
| 324 } else if (IsManaged()) { | 321 } else if (IsManaged()) { |
| 325 sync_state = IS_MANAGED; | 322 sync_state = IS_MANAGED; |
| 326 } else if (!IsSyncAllowedByPlatform()) { | 323 } else if (!IsSyncAllowedByPlatform()) { |
| 327 // This case should currently never be hit, as Android's master sync isn't | 324 // This case should currently never be hit, as Android's master sync isn't |
| 328 // plumbed into PSS until after this function. See http://crbug.com/568771. | 325 // plumbed into PSS until after this function. See http://crbug.com/568771. |
| 329 sync_state = NOT_ALLOWED_BY_PLATFORM; | 326 sync_state = NOT_ALLOWED_BY_PLATFORM; |
| 330 } else if (!IsSyncRequested()) { | 327 } else if (!IsSyncRequested()) { |
| 331 if (IsFirstSetupComplete()) { | 328 if (IsFirstSetupComplete()) { |
| 332 sync_state = NOT_REQUESTED; | 329 sync_state = NOT_REQUESTED; |
| 333 } else { | 330 } else { |
| 334 sync_state = NOT_REQUESTED_NOT_SETUP; | 331 sync_state = NOT_REQUESTED_NOT_SETUP; |
| 335 } | 332 } |
| 336 } else if (!IsFirstSetupComplete()) { | 333 } else if (!IsFirstSetupComplete()) { |
| 337 sync_state = NEEDS_CONFIRMATION; | 334 sync_state = NEEDS_CONFIRMATION; |
| 338 } | 335 } |
| 339 UMA_HISTOGRAM_ENUMERATION("Sync.InitialState", sync_state, | 336 UMA_HISTOGRAM_ENUMERATION("Sync.InitialState", sync_state, |
| 340 SYNC_INITIAL_STATE_LIMIT); | 337 SYNC_INITIAL_STATE_LIMIT); |
| 341 | 338 |
| 342 // If sync isn't allowed, the only thing to do is to turn it off. | 339 // If sync isn't allowed, the only thing to do is to turn it off. |
| 343 if (!IsSyncAllowed()) { | 340 if (!IsSyncAllowed()) { |
| 344 // Only clear data if disallowed by policy. | 341 // Only clear data if disallowed by policy. |
| 345 RequestStop(IsManaged() ? CLEAR_DATA : KEEP_DATA); | 342 RequestStop(IsManaged() ? CLEAR_DATA : KEEP_DATA); |
| 346 return; | 343 return; |
| 347 } | 344 } |
| 348 | 345 |
| 349 RegisterAuthNotifications(); | 346 if (!IsLocalSyncEnabled()) { |
| 347 RegisterAuthNotifications(); |
| 350 | 348 |
| 351 if (!IsSignedIn()) { | 349 if (!IsSignedIn()) { |
| 352 // Clean up in case of previous crash during signout. | 350 // Clean up in case of previous crash during signout. |
| 353 StopImpl(CLEAR_DATA); | 351 StopImpl(CLEAR_DATA); |
| 352 } |
| 354 } | 353 } |
| 355 | 354 |
| 356 #if defined(OS_CHROMEOS) | 355 #if defined(OS_CHROMEOS) |
| 357 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 356 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
| 358 if (bootstrap_token.empty()) { | 357 if (bootstrap_token.empty()) { |
| 359 sync_prefs_.SetEncryptionBootstrapToken( | 358 sync_prefs_.SetEncryptionBootstrapToken( |
| 360 sync_prefs_.GetSpareBootstrapToken()); | 359 sync_prefs_.GetSpareBootstrapToken()); |
| 361 } | 360 } |
| 362 #endif | 361 #endif |
| 363 | 362 |
| 364 #if !defined(OS_ANDROID) | 363 #if !defined(OS_ANDROID) |
| 365 DCHECK(sync_error_controller_ == nullptr) | 364 DCHECK(sync_error_controller_ == nullptr) |
| 366 << "Initialize() called more than once."; | 365 << "Initialize() called more than once."; |
| 367 sync_error_controller_ = base::MakeUnique<syncer::SyncErrorController>(this); | 366 sync_error_controller_ = base::MakeUnique<syncer::SyncErrorController>(this); |
| 368 AddObserver(sync_error_controller_.get()); | 367 AddObserver(sync_error_controller_.get()); |
| 369 #endif | 368 #endif |
| 370 | 369 |
| 371 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>( | 370 memory_pressure_listener_ = base::MakeUnique<base::MemoryPressureListener>( |
| 372 base::Bind(&ProfileSyncService::OnMemoryPressure, | 371 base::Bind(&ProfileSyncService::OnMemoryPressure, |
| 373 sync_enabled_weak_factory_.GetWeakPtr())); | 372 sync_enabled_weak_factory_.GetWeakPtr())); |
| 374 startup_controller_->Reset(GetRegisteredDataTypes()); | 373 startup_controller_->Reset(GetRegisteredDataTypes()); |
| 375 | 374 |
| 376 // Auto-start means means the first time the profile starts up, sync should | 375 // Auto-start means the first time the profile starts up, sync should start up |
| 377 // start up immediately. | 376 // immediately. |
| 378 if (start_behavior_ == AUTO_START && IsSyncRequested() && | 377 if (start_behavior_ == AUTO_START && IsSyncRequested() && |
| 379 !IsFirstSetupComplete()) { | 378 !IsFirstSetupComplete()) { |
| 380 startup_controller_->TryStartImmediately(); | 379 startup_controller_->TryStartImmediately(); |
| 381 } else { | 380 } else { |
| 382 startup_controller_->TryStart(); | 381 startup_controller_->TryStart(); |
| 383 } | 382 } |
| 384 } | 383 } |
| 385 | 384 |
| 386 void ProfileSyncService::StartSyncingWithServer() { | 385 void ProfileSyncService::StartSyncingWithServer() { |
| 387 if (base::FeatureList::IsEnabled( | 386 if (base::FeatureList::IsEnabled( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 399 DCHECK(thread_checker_.CalledOnValidThread()); | 398 DCHECK(thread_checker_.CalledOnValidThread()); |
| 400 oauth2_token_service_->AddObserver(this); | 399 oauth2_token_service_->AddObserver(this); |
| 401 if (signin()) | 400 if (signin()) |
| 402 signin()->AddObserver(this); | 401 signin()->AddObserver(this); |
| 403 } | 402 } |
| 404 | 403 |
| 405 void ProfileSyncService::UnregisterAuthNotifications() { | 404 void ProfileSyncService::UnregisterAuthNotifications() { |
| 406 DCHECK(thread_checker_.CalledOnValidThread()); | 405 DCHECK(thread_checker_.CalledOnValidThread()); |
| 407 if (signin()) | 406 if (signin()) |
| 408 signin()->RemoveObserver(this); | 407 signin()->RemoveObserver(this); |
| 409 oauth2_token_service_->RemoveObserver(this); | 408 if (oauth2_token_service_) |
| 409 oauth2_token_service_->RemoveObserver(this); |
| 410 } | 410 } |
| 411 | 411 |
| 412 void ProfileSyncService::RegisterDataTypeController( | 412 void ProfileSyncService::RegisterDataTypeController( |
| 413 std::unique_ptr<syncer::DataTypeController> data_type_controller) { | 413 std::unique_ptr<syncer::DataTypeController> data_type_controller) { |
| 414 DCHECK(thread_checker_.CalledOnValidThread()); | 414 DCHECK(thread_checker_.CalledOnValidThread()); |
| 415 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 415 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
| 416 data_type_controllers_[data_type_controller->type()] = | 416 data_type_controllers_[data_type_controller->type()] = |
| 417 std::move(data_type_controller); | 417 std::move(data_type_controller); |
| 418 } | 418 } |
| 419 | 419 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 return; | 475 return; |
| 476 } | 476 } |
| 477 DCHECK(iter->second); | 477 DCHECK(iter->second); |
| 478 | 478 |
| 479 static_cast<sync_sessions::SessionDataTypeController*>(iter->second.get()) | 479 static_cast<sync_sessions::SessionDataTypeController*>(iter->second.get()) |
| 480 ->OnSessionRestoreComplete(); | 480 ->OnSessionRestoreComplete(); |
| 481 } | 481 } |
| 482 | 482 |
| 483 SyncCredentials ProfileSyncService::GetCredentials() { | 483 SyncCredentials ProfileSyncService::GetCredentials() { |
| 484 SyncCredentials credentials; | 484 SyncCredentials credentials; |
| 485 |
| 486 // No credentials exist or are needed for the local sync backend. |
| 487 if (IsLocalSyncEnabled()) |
| 488 return credentials; |
| 489 |
| 485 credentials.account_id = signin_->GetAccountIdToUse(); | 490 credentials.account_id = signin_->GetAccountIdToUse(); |
| 486 DCHECK(!credentials.account_id.empty()); | 491 DCHECK(!credentials.account_id.empty()); |
| 487 credentials.email = signin_->GetEffectiveUsername(); | 492 credentials.email = signin_->GetEffectiveUsername(); |
| 488 credentials.sync_token = access_token_; | 493 credentials.sync_token = access_token_; |
| 489 | 494 |
| 490 if (credentials.sync_token.empty()) | 495 if (credentials.sync_token.empty()) |
| 491 credentials.sync_token = "credentials_lost"; | 496 credentials.sync_token = "credentials_lost"; |
| 492 | 497 |
| 493 credentials.scope_set.insert(signin_->GetSyncScopeToUse()); | 498 credentials.scope_set.insert(signin_->GetSyncScopeToUse()); |
| 494 | 499 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 510 base::Thread::Options options; | 515 base::Thread::Options options; |
| 511 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 516 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 512 CHECK(sync_thread_->StartWithOptions(options)); | 517 CHECK(sync_thread_->StartWithOptions(options)); |
| 513 } | 518 } |
| 514 | 519 |
| 515 SyncCredentials credentials = GetCredentials(); | 520 SyncCredentials credentials = GetCredentials(); |
| 516 | 521 |
| 517 if (delete_stale_data) | 522 if (delete_stale_data) |
| 518 ClearStaleErrors(); | 523 ClearStaleErrors(); |
| 519 | 524 |
| 520 bool enable_local_sync_backend = false; | |
| 521 base::FilePath local_sync_backend_folder = | |
| 522 sync_prefs_.GetLocalSyncBackendDir(); | |
| 523 #if defined(OS_WIN) | |
| 524 enable_local_sync_backend = sync_prefs_.IsLocalSyncEnabled(); | |
| 525 if (local_sync_backend_folder.empty()) { | |
| 526 // TODO(pastarmovj): Add DIR_ROAMING_USER_DATA to PathService to simplify | |
| 527 // this code and move the logic in its right place. See crbug/657810. | |
| 528 CHECK( | |
| 529 base::PathService::Get(base::DIR_APP_DATA, &local_sync_backend_folder)); | |
| 530 local_sync_backend_folder = | |
| 531 local_sync_backend_folder.Append(FILE_PATH_LITERAL("Chrome/User Data")); | |
| 532 } | |
| 533 // This code as it is now will assume the same profile order is present on all | |
| 534 // machines, which is not a given. It is to be defined if only the Default | |
| 535 // profile should get this treatment or all profile as is the case now. The | |
| 536 // solution for now will be to assume profiles are created in the same order | |
| 537 // on all machines and in the future decide if only the Default one should be | |
| 538 // considered roamed. | |
| 539 local_sync_backend_folder = | |
| 540 local_sync_backend_folder.Append(base_directory_.BaseName()); | |
| 541 local_sync_backend_folder = | |
| 542 local_sync_backend_folder.Append(kLoopbackServerBackendFilename); | |
| 543 #endif // defined(OS_WIN) | |
| 544 | |
| 545 SyncEngine::HttpPostProviderFactoryGetter http_post_provider_factory_getter = | 525 SyncEngine::HttpPostProviderFactoryGetter http_post_provider_factory_getter = |
| 546 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, | 526 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
| 547 base::Unretained(network_resources_.get()), | 527 base::Unretained(network_resources_.get()), |
| 548 url_request_context_, network_time_update_callback_); | 528 url_request_context_, network_time_update_callback_); |
| 549 | 529 |
| 550 engine_->Initialize( | 530 engine_->Initialize( |
| 551 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_, | 531 this, sync_thread_->task_runner(), GetJsEventHandler(), sync_service_url_, |
| 552 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, | 532 local_device_->GetSyncUserAgent(), credentials, delete_stale_data, |
| 553 enable_local_sync_backend, local_sync_backend_folder, | 533 IsLocalSyncEnabled(), local_sync_backend_folder_, |
| 554 base::MakeUnique<syncer::SyncManagerFactory>(), | 534 base::MakeUnique<syncer::SyncManagerFactory>(), |
| 555 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), | 535 MakeWeakHandle(sync_enabled_weak_factory_.GetWeakPtr()), |
| 556 base::Bind(syncer::ReportUnrecoverableError, channel_), | 536 base::Bind(syncer::ReportUnrecoverableError, channel_), |
| 557 http_post_provider_factory_getter, std::move(saved_nigori_state_)); | 537 http_post_provider_factory_getter, std::move(saved_nigori_state_)); |
| 558 } | 538 } |
| 559 | 539 |
| 560 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 540 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
| 561 if (encryption_pending()) | 541 if (encryption_pending()) |
| 562 return true; | 542 return true; |
| 563 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); | 543 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 OnInternalUnrecoverableError(FROM_HERE, "BackendInitialize failure", false, | 970 OnInternalUnrecoverableError(FROM_HERE, "BackendInitialize failure", false, |
| 991 ERROR_REASON_ENGINE_INIT_FAILURE); | 971 ERROR_REASON_ENGINE_INIT_FAILURE); |
| 992 return; | 972 return; |
| 993 } | 973 } |
| 994 | 974 |
| 995 engine_initialized_ = true; | 975 engine_initialized_ = true; |
| 996 | 976 |
| 997 sync_js_controller_.AttachJsBackend(js_backend); | 977 sync_js_controller_.AttachJsBackend(js_backend); |
| 998 debug_info_listener_ = debug_info_listener; | 978 debug_info_listener_ = debug_info_listener; |
| 999 | 979 |
| 1000 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); | 980 std::string signin_scoped_device_id; |
| 1001 DCHECK(signin_client); | 981 if (IsLocalSyncEnabled()) { |
| 1002 std::string signin_scoped_device_id = | 982 signin_scoped_device_id = "local_device"; |
| 1003 signin_client->GetSigninScopedDeviceId(); | 983 } else { |
| 984 SigninClient* signin_client = signin_->GetOriginal()->signin_client(); |
| 985 DCHECK(signin_client); |
| 986 std::string signin_scoped_device_id = |
| 987 signin_client->GetSigninScopedDeviceId(); |
| 988 } |
| 1004 | 989 |
| 1005 // Initialize local device info. | 990 // Initialize local device info. |
| 1006 local_device_->Initialize(cache_guid, signin_scoped_device_id, | 991 local_device_->Initialize(cache_guid, signin_scoped_device_id, |
| 1007 blocking_pool_); | 992 blocking_pool_); |
| 1008 | 993 |
| 1009 if (protocol_event_observers_.might_have_observers()) { | 994 if (protocol_event_observers_.might_have_observers()) { |
| 1010 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); | 995 engine_->RequestBufferedProtocolEventsAndEnableForwarding(); |
| 1011 } | 996 } |
| 1012 | 997 |
| 1013 if (type_debug_info_observers_.might_have_observers()) { | 998 if (type_debug_info_observers_.might_have_observers()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1043 std::vector<gaia::ListedAccount> accounts; | 1028 std::vector<gaia::ListedAccount> accounts; |
| 1044 std::vector<gaia::ListedAccount> signed_out_accounts; | 1029 std::vector<gaia::ListedAccount> signed_out_accounts; |
| 1045 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); | 1030 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 1046 if (gaia_cookie_manager_service_ && | 1031 if (gaia_cookie_manager_service_ && |
| 1047 gaia_cookie_manager_service_->ListAccounts( | 1032 gaia_cookie_manager_service_->ListAccounts( |
| 1048 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) { | 1033 &accounts, &signed_out_accounts, "ChromiumProfileSyncService")) { |
| 1049 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); | 1034 OnGaiaAccountsInCookieUpdated(accounts, signed_out_accounts, error); |
| 1050 } | 1035 } |
| 1051 | 1036 |
| 1052 NotifyObservers(); | 1037 NotifyObservers(); |
| 1038 |
| 1039 // Nobody will call us to start if no sign in is going to happen. |
| 1040 if (IsLocalSyncEnabled()) |
| 1041 RequestStart(); |
| 1053 } | 1042 } |
| 1054 | 1043 |
| 1055 void ProfileSyncService::OnSyncCycleCompleted() { | 1044 void ProfileSyncService::OnSyncCycleCompleted() { |
| 1056 DCHECK(thread_checker_.CalledOnValidThread()); | 1045 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1057 UpdateLastSyncedTime(); | 1046 UpdateLastSyncedTime(); |
| 1058 const syncer::SyncCycleSnapshot snapshot = GetLastCycleSnapshot(); | 1047 const syncer::SyncCycleSnapshot snapshot = GetLastCycleSnapshot(); |
| 1059 if (IsDataTypeControllerRunning(syncer::SESSIONS) && | 1048 if (IsDataTypeControllerRunning(syncer::SESSIONS) && |
| 1060 snapshot.model_neutral_state().get_updates_request_types.Has( | 1049 snapshot.model_neutral_state().get_updates_request_types.Has( |
| 1061 syncer::SESSIONS) && | 1050 syncer::SESSIONS) && |
| 1062 !syncer::HasSyncerError(snapshot.model_neutral_state())) { | 1051 !syncer::HasSyncerError(snapshot.model_neutral_state())) { |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 DCHECK(thread_checker_.CalledOnValidThread()); | 1547 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1559 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); | 1548 return IsSyncAllowedByFlag() && !IsManaged() && IsSyncAllowedByPlatform(); |
| 1560 } | 1549 } |
| 1561 | 1550 |
| 1562 bool ProfileSyncService::IsSyncActive() const { | 1551 bool ProfileSyncService::IsSyncActive() const { |
| 1563 DCHECK(thread_checker_.CalledOnValidThread()); | 1552 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1564 return engine_initialized_ && data_type_manager_ && | 1553 return engine_initialized_ && data_type_manager_ && |
| 1565 data_type_manager_->state() != DataTypeManager::STOPPED; | 1554 data_type_manager_->state() != DataTypeManager::STOPPED; |
| 1566 } | 1555 } |
| 1567 | 1556 |
| 1557 bool ProfileSyncService::IsLocalSyncEnabled() const { |
| 1558 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1559 return sync_prefs_.IsLocalSyncEnabled(); |
| 1560 } |
| 1561 |
| 1568 void ProfileSyncService::TriggerRefresh(const syncer::ModelTypeSet& types) { | 1562 void ProfileSyncService::TriggerRefresh(const syncer::ModelTypeSet& types) { |
| 1569 DCHECK(thread_checker_.CalledOnValidThread()); | 1563 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1570 if (engine_initialized_) | 1564 if (engine_initialized_) |
| 1571 engine_->TriggerRefresh(types); | 1565 engine_->TriggerRefresh(types); |
| 1572 } | 1566 } |
| 1573 | 1567 |
| 1574 bool ProfileSyncService::IsSignedIn() const { | 1568 bool ProfileSyncService::IsSignedIn() const { |
| 1575 // Sync is logged in if there is a non-empty effective account id. | 1569 // Sync is logged in if there is a non-empty effective account id. |
| 1576 return !signin_->GetAccountIdToUse().empty(); | 1570 return !signin_->GetAccountIdToUse().empty(); |
| 1577 } | 1571 } |
| 1578 | 1572 |
| 1579 bool ProfileSyncService::CanEngineStart() const { | 1573 bool ProfileSyncService::CanEngineStart() const { |
| 1574 if (IsLocalSyncEnabled()) |
| 1575 return true; |
| 1580 return CanSyncStart() && oauth2_token_service_ && | 1576 return CanSyncStart() && oauth2_token_service_ && |
| 1581 oauth2_token_service_->RefreshTokenIsAvailable( | 1577 oauth2_token_service_->RefreshTokenIsAvailable( |
| 1582 signin_->GetAccountIdToUse()); | 1578 signin_->GetAccountIdToUse()); |
| 1583 } | 1579 } |
| 1584 | 1580 |
| 1585 bool ProfileSyncService::IsEngineInitialized() const { | 1581 bool ProfileSyncService::IsEngineInitialized() const { |
| 1586 DCHECK(thread_checker_.CalledOnValidThread()); | 1582 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1587 return engine_initialized_; | 1583 return engine_initialized_; |
| 1588 } | 1584 } |
| 1589 | 1585 |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2527 std::unique_ptr<syncer::NetworkResources> network_resources) { | 2523 std::unique_ptr<syncer::NetworkResources> network_resources) { |
| 2528 DCHECK(thread_checker_.CalledOnValidThread()); | 2524 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2529 network_resources_ = std::move(network_resources); | 2525 network_resources_ = std::move(network_resources); |
| 2530 } | 2526 } |
| 2531 | 2527 |
| 2532 bool ProfileSyncService::HasSyncingEngine() const { | 2528 bool ProfileSyncService::HasSyncingEngine() const { |
| 2533 return engine_ != nullptr; | 2529 return engine_ != nullptr; |
| 2534 } | 2530 } |
| 2535 | 2531 |
| 2536 void ProfileSyncService::UpdateFirstSyncTimePref() { | 2532 void ProfileSyncService::UpdateFirstSyncTimePref() { |
| 2537 if (!IsSignedIn()) { | 2533 if (!IsLocalSyncEnabled() && !IsSignedIn()) { |
| 2538 sync_prefs_.ClearFirstSyncTime(); | 2534 sync_prefs_.ClearFirstSyncTime(); |
| 2539 } else if (sync_prefs_.GetFirstSyncTime().is_null()) { | 2535 } else if (sync_prefs_.GetFirstSyncTime().is_null()) { |
| 2540 // Set if not set before and it's syncing now. | 2536 // Set if not set before and it's syncing now. |
| 2541 sync_prefs_.SetFirstSyncTime(base::Time::Now()); | 2537 sync_prefs_.SetFirstSyncTime(base::Time::Now()); |
| 2542 } | 2538 } |
| 2543 } | 2539 } |
| 2544 | 2540 |
| 2545 void ProfileSyncService::FlushDirectory() const { | 2541 void ProfileSyncService::FlushDirectory() const { |
| 2546 DCHECK(thread_checker_.CalledOnValidThread()); | 2542 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2547 // engine_initialized_ implies engine_ isn't null and the manager exists. | 2543 // engine_initialized_ implies engine_ isn't null and the manager exists. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2638 | 2634 |
| 2639 DCHECK(startup_controller_->IsSetupInProgress()); | 2635 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2640 startup_controller_->SetSetupInProgress(false); | 2636 startup_controller_->SetSetupInProgress(false); |
| 2641 | 2637 |
| 2642 if (IsEngineInitialized()) | 2638 if (IsEngineInitialized()) |
| 2643 ReconfigureDatatypeManager(); | 2639 ReconfigureDatatypeManager(); |
| 2644 NotifyObservers(); | 2640 NotifyObservers(); |
| 2645 } | 2641 } |
| 2646 | 2642 |
| 2647 } // namespace browser_sync | 2643 } // namespace browser_sync |
| OLD | NEW |