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

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

Issue 7669073: [Sync] Add support for enabling session sync remotely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DOUBLE R..ebase Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stddef.h> 7 #include <stddef.h>
8 #include <map> 8 #include <map>
9 #include <ostream>
10 #include <set> 9 #include <set>
11 #include <utility> 10 #include <utility>
12 11
13 #include "base/basictypes.h" 12 #include "base/basictypes.h"
14 #include "base/command_line.h" 13 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
16 #include "base/logging.h" 15 #include "base/logging.h"
17 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
18 #include "base/message_loop.h" 17 #include "base/message_loop.h"
19 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
20 #include "base/string16.h" 19 #include "base/string16.h"
21 #include "base/stringprintf.h" 20 #include "base/stringprintf.h"
22 #include "base/task.h" 21 #include "base/task.h"
23 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
23 #include "chrome/browser/about_flags.h"
24 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/net/chrome_cookie_notification_details.h" 25 #include "chrome/browser/net/chrome_cookie_notification_details.h"
25 #include "chrome/browser/net/gaia/token_service.h" 26 #include "chrome/browser/net/gaia/token_service.h"
26 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
27 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/sync/backend_migrator.h" 29 #include "chrome/browser/sync/backend_migrator.h"
29 #include "chrome/browser/sync/engine/configure_reason.h" 30 #include "chrome/browser/sync/engine/configure_reason.h"
30 #include "chrome/browser/sync/glue/change_processor.h" 31 #include "chrome/browser/sync/glue/change_processor.h"
31 #include "chrome/browser/sync/glue/data_type_controller.h" 32 #include "chrome/browser/sync/glue/data_type_controller.h"
33 #include "chrome/browser/sync/glue/session_data_type_controller.h"
34 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
32 #include "chrome/browser/sync/glue/data_type_manager.h" 35 #include "chrome/browser/sync/glue/data_type_manager.h"
33 #include "chrome/browser/sync/glue/session_data_type_controller.h" 36 #include "chrome/browser/sync/glue/session_data_type_controller.h"
34 #include "chrome/browser/sync/internal_api/sync_manager.h" 37 #include "chrome/browser/sync/internal_api/sync_manager.h"
35 #include "chrome/browser/sync/js/js_arg_list.h" 38 #include "chrome/browser/sync/js/js_arg_list.h"
36 #include "chrome/browser/sync/js/js_event_details.h" 39 #include "chrome/browser/sync/js/js_event_details.h"
37 #include "chrome/browser/sync/profile_sync_factory.h" 40 #include "chrome/browser/sync/profile_sync_factory.h"
38 #include "chrome/browser/sync/signin_manager.h" 41 #include "chrome/browser/sync/signin_manager.h"
39 #include "chrome/browser/sync/util/oauth.h" 42 #include "chrome/browser/sync/util/oauth.h"
40 #include "chrome/browser/ui/browser.h" 43 #include "chrome/browser/ui/browser.h"
41 #include "chrome/browser/ui/browser_list.h" 44 #include "chrome/browser/ui/browser_list.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 PrefService::UNSYNCABLE_PREF); 312 PrefService::UNSYNCABLE_PREF);
310 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, 313 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced,
311 enable_by_default, 314 enable_by_default,
312 PrefService::UNSYNCABLE_PREF); 315 PrefService::UNSYNCABLE_PREF);
313 pref_service->RegisterBooleanPref(prefs::kSyncManaged, 316 pref_service->RegisterBooleanPref(prefs::kSyncManaged,
314 false, 317 false,
315 PrefService::UNSYNCABLE_PREF); 318 PrefService::UNSYNCABLE_PREF);
316 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, 319 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken,
317 "", 320 "",
318 PrefService::UNSYNCABLE_PREF); 321 PrefService::UNSYNCABLE_PREF);
319
320 pref_service->RegisterBooleanPref(prefs::kSyncAutofillProfile, 322 pref_service->RegisterBooleanPref(prefs::kSyncAutofillProfile,
321 enable_by_default, 323 enable_by_default,
322 PrefService::UNSYNCABLE_PREF); 324 PrefService::UNSYNCABLE_PREF);
323 325
324 // We started prompting people about new data types starting with the 326 // We started prompting people about new data types starting with the
325 // rollout of TYPED_URLs - all previously launched data types are treated 327 // rollout of TYPED_URLs - all previously launched data types are treated
326 // as if they are already acknowledged. 328 // as if they are already acknowledged.
327 syncable::ModelTypeBitSet model_set; 329 syncable::ModelTypeBitSet model_set;
328 model_set.set(syncable::BOOKMARKS); 330 model_set.set(syncable::BOOKMARKS);
329 model_set.set(syncable::PREFERENCES); 331 model_set.set(syncable::PREFERENCES);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 return prefs::kSyncApps; 545 return prefs::kSyncApps;
544 case syncable::SESSIONS: 546 case syncable::SESSIONS:
545 return prefs::kSyncSessions; 547 return prefs::kSyncSessions;
546 default: 548 default:
547 break; 549 break;
548 } 550 }
549 NOTREACHED(); 551 NOTREACHED();
550 return NULL; 552 return NULL;
551 } 553 }
552 554
555 // static
556 std::string ProfileSyncService::GetExperimentNameForDataType(
557 syncable::ModelType data_type) {
558 switch (data_type) {
559 case syncable::SESSIONS:
560 return "sync-sessions";
561 case syncable::TYPED_URLS:
562 return "sync-typed-urls";
563 default:
564 break;
565 }
566 NOTREACHED();
567 return "";
568 }
569
570 void ProfileSyncService::RegisterNewDataType(syncable::ModelType data_type) {
571 if (data_type_controllers_.count(data_type) > 0)
572 return;
573 switch (data_type) {
574 case syncable::SESSIONS:
575 RegisterDataTypeController(
576 new browser_sync::SessionDataTypeController(factory_,
577 profile_,
578 this));
579 return;
580 case syncable::TYPED_URLS:
581 RegisterDataTypeController(
582 new browser_sync::TypedUrlDataTypeController(factory_, profile_));
583 return;
584 default:
585 break;
586 }
587 NOTREACHED();
588 }
589
553 // An invariant has been violated. Transition to an error state where we try 590 // An invariant has been violated. Transition to an error state where we try
554 // to do as little work as possible, to avoid further corruption or crashes. 591 // to do as little work as possible, to avoid further corruption or crashes.
555 void ProfileSyncService::OnUnrecoverableError( 592 void ProfileSyncService::OnUnrecoverableError(
556 const tracked_objects::Location& from_here, 593 const tracked_objects::Location& from_here,
557 const std::string& message) { 594 const std::string& message) {
558 unrecoverable_error_detected_ = true; 595 unrecoverable_error_detected_ = true;
559 unrecoverable_error_message_ = message; 596 unrecoverable_error_message_ = message;
560 unrecoverable_error_location_.reset( 597 unrecoverable_error_location_.reset(
561 new tracked_objects::Location(from_here.function_name(), 598 new tracked_objects::Location(from_here.function_name(),
562 from_here.file_name(), 599 from_here.file_name(),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 DVLOG(1) << "Setup not complete, no wizard - integration tests?"; 657 DVLOG(1) << "Setup not complete, no wizard - integration tests?";
621 } 658 }
622 } 659 }
623 660
624 void ProfileSyncService::OnSyncCycleCompleted() { 661 void ProfileSyncService::OnSyncCycleCompleted() {
625 UpdateLastSyncedTime(); 662 UpdateLastSyncedTime();
626 VLOG(2) << "Notifying observers sync cycle completed"; 663 VLOG(2) << "Notifying observers sync cycle completed";
627 NotifyObservers(); 664 NotifyObservers();
628 } 665 }
629 666
667 // TODO(sync): eventually support removing datatypes too.
668 void ProfileSyncService::OnDataTypesChanged(
669 const syncable::ModelTypeSet& to_add) {
670 // We don't bother doing anything if the migrator is busy.
671 if (migrator_->state() != browser_sync::BackendMigrator::IDLE) {
672 VLOG(1) << "Dropping OnDataTypesChanged due to migrator busy.";
673 return;
674 }
675
676 syncable::ModelTypeSet new_types;
677 syncable::ModelTypeSet preferred_types;
678 GetPreferredDataTypes(&preferred_types);
679 syncable::ModelTypeSet registered_types;
680 GetRegisteredDataTypes(&registered_types);
681
682 for (syncable::ModelTypeSet::const_iterator iter = to_add.begin();
683 iter != to_add.end();
684 ++iter) {
685 // Received notice to enable session sync. Check if sessions are
686 // registered, and if not register a new datatype controller.
687 if (registered_types.count(*iter) == 0) {
688 RegisterNewDataType(*iter);
689 // Enable the about:flags switch for sessions so we don't have to always
690 // perform this reconfiguration. Once we set this, sessions will remain
691 // registered, so we will no longer go down this code path.
692 std::string experiment_name = GetExperimentNameForDataType(*iter);
693 if (experiment_name.empty())
694 continue;
695 about_flags::SetExperimentEnabled(g_browser_process->local_state(),
696 experiment_name,
697 true);
698
699 // Check if the user has "Keep Everything Synced" enabled. If so, we want
700 // to turn on sessions if it's not already on. Otherwise we leave it off.
701 // Note: if sessions are already registered, we don't turn it on. This
702 // covers the case where we're already in the process of reconfiguring
703 // to turn sessions on.
704 if (profile_->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced) &&
705 preferred_types.count(*iter) == 0){
706 std::string pref_name = GetPrefNameForDataType(*iter);
707 if (pref_name.empty())
708 continue;
709 profile_->GetPrefs()->SetBoolean(pref_name.c_str(), true);
710 }
711 }
712 }
713
714 if (!new_types.empty()) {
715 VLOG(1) << "Dynamically enabling new datatypes: "
716 << syncable::ModelTypeSetToString(new_types);
717 OnMigrationNeededForTypes(new_types);
718 }
719 }
720
630 void ProfileSyncService::UpdateAuthErrorState( 721 void ProfileSyncService::UpdateAuthErrorState(
631 const GoogleServiceAuthError& error) { 722 const GoogleServiceAuthError& error) {
632 last_auth_error_ = error; 723 last_auth_error_ = error;
633 // Protect against the in-your-face dialogs that pop out of nowhere. 724 // Protect against the in-your-face dialogs that pop out of nowhere.
634 // Require the user to click somewhere to run the setup wizard in the case 725 // Require the user to click somewhere to run the setup wizard in the case
635 // of a steady-state auth failure. 726 // of a steady-state auth failure.
636 if (WizardIsVisible()) { 727 if (WizardIsVisible()) {
637 wizard_.Step(last_auth_error_.state() == AuthError::NONE ? 728 wizard_.Step(last_auth_error_.state() == AuthError::NONE ?
638 SyncSetupWizard::GAIA_SUCCESS : SyncSetupWizard::GetLoginState()); 729 SyncSetupWizard::GAIA_SUCCESS : SyncSetupWizard::GetLoginState());
639 } else { 730 } else {
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 // knows what it's doing. 1210 // knows what it's doing.
1120 return backend_.get(); 1211 return backend_.get();
1121 } 1212 }
1122 1213
1123 void ProfileSyncService::ConfigureDataTypeManager() { 1214 void ProfileSyncService::ConfigureDataTypeManager() {
1124 bool restart = false; 1215 bool restart = false;
1125 if (!data_type_manager_.get()) { 1216 if (!data_type_manager_.get()) {
1126 restart = true; 1217 restart = true;
1127 data_type_manager_.reset( 1218 data_type_manager_.reset(
1128 factory_->CreateDataTypeManager(backend_.get(), 1219 factory_->CreateDataTypeManager(backend_.get(),
1129 data_type_controllers_)); 1220 &data_type_controllers_));
1130 registrar_.Add(this, 1221 registrar_.Add(this,
1131 chrome::NOTIFICATION_SYNC_CONFIGURE_START, 1222 chrome::NOTIFICATION_SYNC_CONFIGURE_START,
1132 Source<DataTypeManager>(data_type_manager_.get())); 1223 Source<DataTypeManager>(data_type_manager_.get()));
1133 registrar_.Add(this, 1224 registrar_.Add(this,
1134 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, 1225 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE,
1135 Source<DataTypeManager>(data_type_manager_.get())); 1226 Source<DataTypeManager>(data_type_manager_.get()));
1136 1227
1137 // We create the migrator at the same time. 1228 // We create the migrator at the same time.
1138 migrator_.reset( 1229 migrator_.reset(
1139 new browser_sync::BackendMigrator(this, data_type_manager_.get())); 1230 new browser_sync::BackendMigrator(this, data_type_manager_.get()));
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); 1574 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes));
1484 syncable::ModelTypeSet registered; 1575 syncable::ModelTypeSet registered;
1485 GetRegisteredDataTypes(&registered); 1576 GetRegisteredDataTypes(&registered);
1486 syncable::ModelTypeBitSet registered_bit_set = 1577 syncable::ModelTypeBitSet registered_bit_set =
1487 syncable::ModelTypeBitSetFromSet(registered); 1578 syncable::ModelTypeBitSetFromSet(registered);
1488 unacknowledged = registered_bit_set & ~acknowledged; 1579 unacknowledged = registered_bit_set & ~acknowledged;
1489 } 1580 }
1490 return unacknowledged; 1581 return unacknowledged;
1491 } 1582 }
1492 1583
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_harness.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698