| 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 "chrome/browser/sync/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 sync_prefs_.RemoveSyncPrefObserver(this); | 286 sync_prefs_.RemoveSyncPrefObserver(this); |
| 287 // Shutdown() should have been called before destruction. | 287 // Shutdown() should have been called before destruction. |
| 288 CHECK(!backend_initialized_); | 288 CHECK(!backend_initialized_); |
| 289 } | 289 } |
| 290 | 290 |
| 291 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { | 291 bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { |
| 292 // Exit if sync is disabled. | 292 // Exit if sync is disabled. |
| 293 if (IsManaged() || sync_prefs_.IsStartSuppressed()) | 293 if (IsManaged() || sync_prefs_.IsStartSuppressed()) |
| 294 return false; | 294 return false; |
| 295 | 295 |
| 296 // Sync is logged in if there is a non-empty effective username. | 296 // Sync is logged in if there is a non-empty effective account id. |
| 297 return !signin_->GetEffectiveUsername().empty(); | 297 return !signin_->GetAccountIdToUse().empty(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { | 300 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { |
| 301 if (!oauth2_token_service_) | 301 if (!oauth2_token_service_) |
| 302 return false; | 302 return false; |
| 303 | 303 |
| 304 return oauth2_token_service_->RefreshTokenIsAvailable( | 304 return oauth2_token_service_->RefreshTokenIsAvailable( |
| 305 signin_->GetAccountIdToUse()); | 305 signin_->GetAccountIdToUse()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 void ProfileSyncService::Initialize() { | 308 void ProfileSyncService::Initialize() { |
| 309 // We clear this here (vs Shutdown) because we want to remember that an error | 309 // We clear this here (vs Shutdown) because we want to remember that an error |
| 310 // happened on shutdown so we can display details (message, location) about it | 310 // happened on shutdown so we can display details (message, location) about it |
| 311 // in about:sync. | 311 // in about:sync. |
| 312 ClearStaleErrors(); | 312 ClearStaleErrors(); |
| 313 | 313 |
| 314 sync_prefs_.AddSyncPrefObserver(this); | 314 sync_prefs_.AddSyncPrefObserver(this); |
| 315 | 315 |
| 316 // For now, the only thing we can do through policy is to turn sync off. | 316 // For now, the only thing we can do through policy is to turn sync off. |
| 317 if (IsManaged()) { | 317 if (IsManaged()) { |
| 318 DisableForUser(); | 318 DisableForUser(); |
| 319 return; | 319 return; |
| 320 } | 320 } |
| 321 | 321 |
| 322 RegisterAuthNotifications(); | 322 RegisterAuthNotifications(); |
| 323 | 323 |
| 324 if (!HasSyncSetupCompleted() || signin_->GetEffectiveUsername().empty()) { | 324 if (!HasSyncSetupCompleted() || signin_->GetAccountIdToUse().empty()) { |
| 325 // Clean up in case of previous crash / setup abort / signout. | 325 // Clean up in case of previous crash / setup abort / signout. |
| 326 DisableForUser(); | 326 DisableForUser(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 TrySyncDatatypePrefRecovery(); | 329 TrySyncDatatypePrefRecovery(); |
| 330 | 330 |
| 331 #if defined(OS_CHROMEOS) | 331 #if defined(OS_CHROMEOS) |
| 332 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 332 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
| 333 if (bootstrap_token.empty()) { | 333 if (bootstrap_token.empty()) { |
| 334 sync_prefs_.SetEncryptionBootstrapToken( | 334 sync_prefs_.SetEncryptionBootstrapToken( |
| 335 sync_prefs_.GetSpareBootstrapToken()); | 335 sync_prefs_.GetSpareBootstrapToken()); |
| 336 } | 336 } |
| 337 #endif | 337 #endif |
| 338 | 338 |
| 339 #if !defined(OS_ANDROID) | 339 #if !defined(OS_ANDROID) |
| 340 DCHECK(sync_error_controller_ == NULL) | 340 DCHECK(sync_error_controller_ == NULL) |
| 341 << "Initialize() called more than once."; | 341 << "Initialize() called more than once."; |
| 342 sync_error_controller_.reset(new SyncErrorController(this)); | 342 sync_error_controller_.reset(new SyncErrorController(this)); |
| 343 AddObserver(sync_error_controller_.get()); | 343 AddObserver(sync_error_controller_.get()); |
| 344 #endif | 344 #endif |
| 345 | 345 |
| 346 bool running_rollback = false; | 346 bool running_rollback = false; |
| 347 if (browser_sync::BackupRollbackController::IsBackupEnabled()) { | 347 if (browser_sync::BackupRollbackController::IsBackupEnabled()) { |
| 348 // Backup is needed if user's not signed in or signed in but previous | 348 // Backup is needed if user's not signed in or signed in but previous |
| 349 // backup didn't finish, i.e. backend didn't switch from backup to sync. | 349 // backup didn't finish, i.e. backend didn't switch from backup to sync. |
| 350 need_backup_ = signin_->GetEffectiveUsername().empty() || | 350 need_backup_ = signin_->GetAccountIdToUse().empty() || |
| 351 sync_prefs_.GetFirstSyncTime().is_null(); | 351 sync_prefs_.GetFirstSyncTime().is_null(); |
| 352 | 352 |
| 353 // Try to resume rollback if it didn't finish in last session. | 353 // Try to resume rollback if it didn't finish in last session. |
| 354 running_rollback = backup_rollback_controller_->StartRollback(); | 354 running_rollback = backup_rollback_controller_->StartRollback(); |
| 355 } else { | 355 } else { |
| 356 need_backup_ = false; | 356 need_backup_ = false; |
| 357 } | 357 } |
| 358 | 358 |
| 359 #if defined(ENABLE_PRE_SYNC_BACKUP) | 359 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 360 if (!running_rollback && signin_->GetEffectiveUsername().empty()) { | 360 if (!running_rollback && signin_->GetAccountIdToUse().empty()) { |
| 361 CleanUpBackup(); | 361 CleanUpBackup(); |
| 362 } | 362 } |
| 363 #else | 363 #else |
| 364 DCHECK(!running_rollback); | 364 DCHECK(!running_rollback); |
| 365 #endif | 365 #endif |
| 366 | 366 |
| 367 startup_controller_->Reset(GetRegisteredDataTypes()); | 367 startup_controller_->Reset(GetRegisteredDataTypes()); |
| 368 startup_controller_->TryStart(); | 368 startup_controller_->TryStart(); |
| 369 } | 369 } |
| 370 | 370 |
| (...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2547 void ProfileSyncService::OverrideNetworkResourcesForTest( | 2547 void ProfileSyncService::OverrideNetworkResourcesForTest( |
| 2548 scoped_ptr<syncer::NetworkResources> network_resources) { | 2548 scoped_ptr<syncer::NetworkResources> network_resources) { |
| 2549 network_resources_ = network_resources.Pass(); | 2549 network_resources_ = network_resources.Pass(); |
| 2550 } | 2550 } |
| 2551 | 2551 |
| 2552 bool ProfileSyncService::HasSyncingBackend() const { | 2552 bool ProfileSyncService::HasSyncingBackend() const { |
| 2553 return backend_mode_ != SYNC ? false : backend_ != NULL; | 2553 return backend_mode_ != SYNC ? false : backend_ != NULL; |
| 2554 } | 2554 } |
| 2555 | 2555 |
| 2556 void ProfileSyncService::UpdateFirstSyncTimePref() { | 2556 void ProfileSyncService::UpdateFirstSyncTimePref() { |
| 2557 if (signin_->GetEffectiveUsername().empty()) { | 2557 if (signin_->GetAccountIdToUse().empty()) { |
| 2558 // Clear if user's not signed in and rollback is done. | 2558 // Clear if user's not signed in and rollback is done. |
| 2559 if (backend_mode_ != ROLLBACK) | 2559 if (backend_mode_ != ROLLBACK) |
| 2560 sync_prefs_.ClearFirstSyncTime(); | 2560 sync_prefs_.ClearFirstSyncTime(); |
| 2561 } else if (sync_prefs_.GetFirstSyncTime().is_null() && | 2561 } else if (sync_prefs_.GetFirstSyncTime().is_null() && |
| 2562 backend_mode_ == SYNC) { | 2562 backend_mode_ == SYNC) { |
| 2563 // Set if not set before and it's syncing now. | 2563 // Set if not set before and it's syncing now. |
| 2564 sync_prefs_.SetFirstSyncTime(base::Time::Now()); | 2564 sync_prefs_.SetFirstSyncTime(base::Time::Now()); |
| 2565 } | 2565 } |
| 2566 } | 2566 } |
| 2567 | 2567 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2710 std::string birthday; | 2710 std::string birthday; |
| 2711 syncer::UserShare* user_share = GetUserShare(); | 2711 syncer::UserShare* user_share = GetUserShare(); |
| 2712 if (user_share && user_share->directory.get()) { | 2712 if (user_share && user_share->directory.get()) { |
| 2713 birthday = user_share->directory->store_birthday(); | 2713 birthday = user_share->directory->store_birthday(); |
| 2714 } | 2714 } |
| 2715 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { | 2715 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { |
| 2716 sync_stopped_reporter_->ReportSyncStopped( | 2716 sync_stopped_reporter_->ReportSyncStopped( |
| 2717 access_token_, cache_guid, birthday); | 2717 access_token_, cache_guid, birthday); |
| 2718 } | 2718 } |
| 2719 } | 2719 } |
| OLD | NEW |