| 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/browser/profile_sync_service.h" | 5 #include "components/browser_sync/browser/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 return; | 353 return; |
| 354 } | 354 } |
| 355 | 355 |
| 356 RegisterAuthNotifications(); | 356 RegisterAuthNotifications(); |
| 357 | 357 |
| 358 if (!IsFirstSetupComplete() || !IsSignedIn()) { | 358 if (!IsFirstSetupComplete() || !IsSignedIn()) { |
| 359 // Clean up in case of previous crash / setup abort / signout. | 359 // Clean up in case of previous crash / setup abort / signout. |
| 360 StopImpl(CLEAR_DATA); | 360 StopImpl(CLEAR_DATA); |
| 361 } | 361 } |
| 362 | 362 |
| 363 TrySyncDatatypePrefRecovery(); | |
| 364 | |
| 365 #if defined(OS_CHROMEOS) | 363 #if defined(OS_CHROMEOS) |
| 366 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 364 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
| 367 if (bootstrap_token.empty()) { | 365 if (bootstrap_token.empty()) { |
| 368 sync_prefs_.SetEncryptionBootstrapToken( | 366 sync_prefs_.SetEncryptionBootstrapToken( |
| 369 sync_prefs_.GetSpareBootstrapToken()); | 367 sync_prefs_.GetSpareBootstrapToken()); |
| 370 } | 368 } |
| 371 #endif | 369 #endif |
| 372 | 370 |
| 373 #if !defined(OS_ANDROID) | 371 #if !defined(OS_ANDROID) |
| 374 DCHECK(sync_error_controller_ == NULL) | 372 DCHECK(sync_error_controller_ == NULL) |
| 375 << "Initialize() called more than once."; | 373 << "Initialize() called more than once."; |
| 376 sync_error_controller_.reset(new SyncErrorController(this)); | 374 sync_error_controller_.reset(new SyncErrorController(this)); |
| 377 AddObserver(sync_error_controller_.get()); | 375 AddObserver(sync_error_controller_.get()); |
| 378 #endif | 376 #endif |
| 379 | 377 |
| 380 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( | 378 memory_pressure_listener_.reset(new base::MemoryPressureListener(base::Bind( |
| 381 &ProfileSyncService::OnMemoryPressure, weak_factory_.GetWeakPtr()))); | 379 &ProfileSyncService::OnMemoryPressure, weak_factory_.GetWeakPtr()))); |
| 382 startup_controller_->Reset(GetRegisteredDataTypes()); | 380 startup_controller_->Reset(GetRegisteredDataTypes()); |
| 383 startup_controller_->TryStart(); | 381 startup_controller_->TryStart(); |
| 384 } | 382 } |
| 385 | 383 |
| 386 void ProfileSyncService::TrySyncDatatypePrefRecovery() { | |
| 387 DCHECK(!IsBackendInitialized()); | |
| 388 if (!IsFirstSetupComplete()) | |
| 389 return; | |
| 390 | |
| 391 // There was a bug where OnUserChoseDatatypes was not properly called on | |
| 392 // configuration (see crbug.com/154940). We detect this by checking whether | |
| 393 // kSyncKeepEverythingSynced has a default value. If so, and sync setup has | |
| 394 // completed, it means sync was not properly configured, so we manually | |
| 395 // set kSyncKeepEverythingSynced. | |
| 396 PrefService* const pref_service = sync_client_->GetPrefService(); | |
| 397 if (!pref_service) | |
| 398 return; | |
| 399 if (GetPreferredDataTypes().Size() > 1) | |
| 400 return; | |
| 401 | |
| 402 const PrefService::Preference* keep_everything_synced = | |
| 403 pref_service->FindPreference( | |
| 404 sync_driver::prefs::kSyncKeepEverythingSynced); | |
| 405 // This will be false if the preference was properly set or if it's controlled | |
| 406 // by policy. | |
| 407 if (!keep_everything_synced->IsDefaultValue()) | |
| 408 return; | |
| 409 | |
| 410 // kSyncKeepEverythingSynced was not properly set. Set it and the preferred | |
| 411 // types now, before we configure. | |
| 412 UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); | |
| 413 sync_prefs_.SetKeepEverythingSynced(true); | |
| 414 syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); | |
| 415 } | |
| 416 | |
| 417 void ProfileSyncService::StartSyncingWithServer() { | 384 void ProfileSyncService::StartSyncingWithServer() { |
| 418 DCHECK(thread_checker_.CalledOnValidThread()); | 385 DCHECK(thread_checker_.CalledOnValidThread()); |
| 419 | 386 |
| 420 if (base::FeatureList::IsEnabled( | 387 if (base::FeatureList::IsEnabled( |
| 421 switches::kSyncClearDataOnPassphraseEncryption) && | 388 switches::kSyncClearDataOnPassphraseEncryption) && |
| 422 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { | 389 sync_prefs_.GetPassphraseEncryptionTransitionInProgress()) { |
| 423 BeginConfigureCatchUpBeforeClear(); | 390 BeginConfigureCatchUpBeforeClear(); |
| 424 return; | 391 return; |
| 425 } | 392 } |
| 426 | 393 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 const std::string& access_token, | 611 const std::string& access_token, |
| 645 const base::Time& expiration_time) { | 612 const base::Time& expiration_time) { |
| 646 DCHECK_EQ(access_token_request_.get(), request); | 613 DCHECK_EQ(access_token_request_.get(), request); |
| 647 access_token_request_.reset(); | 614 access_token_request_.reset(); |
| 648 access_token_ = access_token; | 615 access_token_ = access_token; |
| 649 token_receive_time_ = base::Time::Now(); | 616 token_receive_time_ = base::Time::Now(); |
| 650 last_get_token_error_ = GoogleServiceAuthError::AuthErrorNone(); | 617 last_get_token_error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 651 | 618 |
| 652 if (sync_prefs_.SyncHasAuthError()) { | 619 if (sync_prefs_.SyncHasAuthError()) { |
| 653 sync_prefs_.SetSyncAuthError(false); | 620 sync_prefs_.SetSyncAuthError(false); |
| 654 UMA_HISTOGRAM_ENUMERATION("Sync.SyncAuthError", | |
| 655 AUTH_ERROR_FIXED, | |
| 656 AUTH_ERROR_LIMIT); | |
| 657 } | 621 } |
| 658 | 622 |
| 659 if (HasSyncingBackend()) | 623 if (HasSyncingBackend()) |
| 660 backend_->UpdateCredentials(GetCredentials()); | 624 backend_->UpdateCredentials(GetCredentials()); |
| 661 else | 625 else |
| 662 startup_controller_->TryStart(); | 626 startup_controller_->TryStart(); |
| 663 } | 627 } |
| 664 | 628 |
| 665 void ProfileSyncService::OnGetTokenFailure( | 629 void ProfileSyncService::OnGetTokenFailure( |
| 666 const OAuth2TokenService::Request* request, | 630 const OAuth2TokenService::Request* request, |
| (...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2537 } | 2501 } |
| 2538 | 2502 |
| 2539 std::string ProfileSyncService::unrecoverable_error_message() const { | 2503 std::string ProfileSyncService::unrecoverable_error_message() const { |
| 2540 return unrecoverable_error_message_; | 2504 return unrecoverable_error_message_; |
| 2541 } | 2505 } |
| 2542 | 2506 |
| 2543 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() | 2507 tracked_objects::Location ProfileSyncService::unrecoverable_error_location() |
| 2544 const { | 2508 const { |
| 2545 return unrecoverable_error_location_; | 2509 return unrecoverable_error_location_; |
| 2546 } | 2510 } |
| OLD | NEW |