Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 2847072: Green Tree Tactical Force: Revert skrul's bad commits (probably a git-cl bug). (Closed)
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // For now, the only thing we can do through policy is to turn sync off. 137 // For now, the only thing we can do through policy is to turn sync off.
138 if (IsManaged()) { 138 if (IsManaged()) {
139 DisableForUser(); 139 DisableForUser();
140 return; 140 return;
141 } 141 }
142 142
143 if (!profile()->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) { 143 if (!profile()->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) {
144 DisableForUser(); // Clean up in case of previous crash / setup abort. 144 DisableForUser(); // Clean up in case of previous crash / setup abort.
145 145
146 // Automatically start sync in Chromium OS. 146 // Automatically start sync in Chromium OS.
147 if (bootstrap_sync_authentication_ && 147 if (bootstrap_sync_authentication_) {
148 !profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) {
149 // If the LSID is empty, we're in a CrOS UI test that is not testing sync 148 // If the LSID is empty, we're in a CrOS UI test that is not testing sync
150 // behavior, so we don't want the sync service to start. 149 // behavior, so we don't want the sync service to start.
151 if (profile()->GetTokenService() && 150 if (profile()->GetTokenService() &&
152 !profile()->GetTokenService()->HasLsid()) { 151 !profile()->GetTokenService()->HasLsid()) {
153 LOG(WARNING) << "Skipping CrOS sync startup, no LSID present."; 152 LOG(WARNING) << "Skipping CrOS sync startup, no LSID present.";
154 return; 153 return;
155 } 154 }
156 StartUp(); 155 StartUp();
157 } 156 }
158 } else { 157 } else {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 browser_sync::StringToNotificationMethod(notification_method_str); 209 browser_sync::StringToNotificationMethod(notification_method_str);
211 } 210 }
212 } 211 }
213 212
214 void ProfileSyncService::RegisterPreferences() { 213 void ProfileSyncService::RegisterPreferences() {
215 PrefService* pref_service = profile_->GetPrefs(); 214 PrefService* pref_service = profile_->GetPrefs();
216 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) 215 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime))
217 return; 216 return;
218 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); 217 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0);
219 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false); 218 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false);
220 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, false);
221 219
222 // If you've never synced before, or if you're using Chrome OS, all datatypes 220 // If you've never synced before, or if you're using Chrome OS, all datatypes
223 // are on by default. 221 // are on by default.
224 // TODO(nick): Perhaps a better model would be to always default to false, 222 // TODO(nick): Perhaps a better model would be to always default to false,
225 // and explicitly call SetDataTypes() when the user shows the wizard. 223 // and explicitly call SetDataTypes() when the user shows the wizard.
226 #if defined(OS_CHROMEOS) 224 #if defined(OS_CHROMEOS)
227 bool enable_by_default = true; 225 bool enable_by_default = true;
228 #else 226 #else
229 bool enable_by_default = 227 bool enable_by_default =
230 !pref_service->HasPrefPath(prefs::kSyncHasSetupCompleted); 228 !pref_service->HasPrefPath(prefs::kSyncHasSetupCompleted);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 359 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
362 } 360 }
363 361
364 bool ProfileSyncService::HasSyncSetupCompleted() const { 362 bool ProfileSyncService::HasSyncSetupCompleted() const {
365 return profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted); 363 return profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted);
366 } 364 }
367 365
368 void ProfileSyncService::SetSyncSetupCompleted() { 366 void ProfileSyncService::SetSyncSetupCompleted() {
369 PrefService* prefs = profile()->GetPrefs(); 367 PrefService* prefs = profile()->GetPrefs();
370 prefs->SetBoolean(prefs::kSyncHasSetupCompleted, true); 368 prefs->SetBoolean(prefs::kSyncHasSetupCompleted, true);
371 prefs->SetBoolean(prefs::kSyncSuppressStart, false);
372 prefs->ScheduleSavePersistentPrefs(); 369 prefs->ScheduleSavePersistentPrefs();
373 } 370 }
374 371
375 void ProfileSyncService::UpdateLastSyncedTime() { 372 void ProfileSyncService::UpdateLastSyncedTime() {
376 last_synced_time_ = base::Time::Now(); 373 last_synced_time_ = base::Time::Now();
377 profile_->GetPrefs()->SetInt64(prefs::kSyncLastSyncedTime, 374 profile_->GetPrefs()->SetInt64(prefs::kSyncLastSyncedTime,
378 last_synced_time_.ToInternalValue()); 375 last_synced_time_.ToInternalValue());
379 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); 376 profile_->GetPrefs()->ScheduleSavePersistentPrefs();
380 } 377 }
381 378
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 backend_initialized_ = true; 441 backend_initialized_ = true;
445 442
446 // The very first time the backend initializes is effectively the first time 443 // The very first time the backend initializes is effectively the first time
447 // we can say we successfully "synced". last_synced_time_ will only be null 444 // we can say we successfully "synced". last_synced_time_ will only be null
448 // in this case, because the pref wasn't restored on StartUp. 445 // in this case, because the pref wasn't restored on StartUp.
449 if (last_synced_time_.is_null()) 446 if (last_synced_time_.is_null())
450 UpdateLastSyncedTime(); 447 UpdateLastSyncedTime();
451 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 448 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
452 449
453 if (bootstrap_sync_authentication_) { 450 if (bootstrap_sync_authentication_) {
454 if (profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) { 451 SetSyncSetupCompleted();
455 ShowChooseDataTypes(NULL);
456 } else {
457 SetSyncSetupCompleted();
458 }
459 } 452 }
460 453
461 if (HasSyncSetupCompleted()) 454 if (HasSyncSetupCompleted())
462 ConfigureDataTypeManager(); 455 ConfigureDataTypeManager();
463 } 456 }
464 457
465 void ProfileSyncService::OnSyncCycleCompleted() { 458 void ProfileSyncService::OnSyncCycleCompleted() {
466 UpdateLastSyncedTime(); 459 UpdateLastSyncedTime();
467 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 460 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
468 } 461 }
(...skipping 26 matching lines...) Expand all
495 is_auth_in_progress_ = false; 488 is_auth_in_progress_ = false;
496 // Fan the notification out to interested UI-thread components. 489 // Fan the notification out to interested UI-thread components.
497 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 490 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
498 } 491 }
499 492
500 void ProfileSyncService::OnStopSyncingPermanently() { 493 void ProfileSyncService::OnStopSyncingPermanently() {
501 if (SetupInProgress()) { 494 if (SetupInProgress()) {
502 wizard_.Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); 495 wizard_.Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR);
503 expect_sync_configuration_aborted_ = true; 496 expect_sync_configuration_aborted_ = true;
504 } 497 }
505 profile_->GetPrefs()->SetBoolean(prefs::kSyncSuppressStart, true); 498
506 DisableForUser(); 499 DisableForUser();
507 } 500 }
508 501
509 void ProfileSyncService::ShowLoginDialog(gfx::NativeWindow parent_window) { 502 void ProfileSyncService::ShowLoginDialog(gfx::NativeWindow parent_window) {
510 if (WizardIsVisible()) { 503 if (WizardIsVisible()) {
511 wizard_.Focus(); 504 wizard_.Focus();
512 return; 505 return;
513 } 506 }
514 507
515 if (!auth_error_time_.is_null()) { 508 if (!auth_error_time_.is_null()) {
(...skipping 27 matching lines...) Expand all
543 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { 536 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() {
544 if (backend_.get()) { 537 if (backend_.get()) {
545 return backend_->GetDetailedStatus(); 538 return backend_->GetDetailedStatus();
546 } else { 539 } else {
547 SyncBackendHost::Status status = 540 SyncBackendHost::Status status =
548 { SyncBackendHost::Status::OFFLINE_UNUSABLE }; 541 { SyncBackendHost::Status::OFFLINE_UNUSABLE };
549 return status; 542 return status;
550 } 543 }
551 } 544 }
552 545
553 bool ProfileSyncService::SetupInProgress() const {
554 return !HasSyncSetupCompleted() && WizardIsVisible();
555 }
556
557 std::wstring ProfileSyncService::BuildSyncStatusSummaryText( 546 std::wstring ProfileSyncService::BuildSyncStatusSummaryText(
558 const sync_api::SyncManager::Status::Summary& summary) { 547 const sync_api::SyncManager::Status::Summary& summary) {
559 switch (summary) { 548 switch (summary) {
560 case sync_api::SyncManager::Status::OFFLINE: 549 case sync_api::SyncManager::Status::OFFLINE:
561 return L"OFFLINE"; 550 return L"OFFLINE";
562 case sync_api::SyncManager::Status::OFFLINE_UNSYNCED: 551 case sync_api::SyncManager::Status::OFFLINE_UNSYNCED:
563 return L"OFFLINE_UNSYNCED"; 552 return L"OFFLINE_UNSYNCED";
564 case sync_api::SyncManager::Status::SYNCING: 553 case sync_api::SyncManager::Status::SYNCING:
565 return L"SYNCING"; 554 return L"SYNCING";
566 case sync_api::SyncManager::Status::READY: 555 case sync_api::SyncManager::Status::READY:
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 // is initialized, all enabled data types are consistent with one 818 // is initialized, all enabled data types are consistent with one
830 // another, and no unrecoverable error has transpired. 819 // another, and no unrecoverable error has transpired.
831 if (unrecoverable_error_detected_) 820 if (unrecoverable_error_detected_)
832 return false; 821 return false;
833 822
834 if (!data_type_manager_.get()) 823 if (!data_type_manager_.get())
835 return false; 824 return false;
836 825
837 return data_type_manager_->state() == DataTypeManager::CONFIGURED; 826 return data_type_manager_->state() == DataTypeManager::CONFIGURED;
838 } 827 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698