OLD | NEW |
---|---|
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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 PrefService::UNSYNCABLE_PREF); | 311 PrefService::UNSYNCABLE_PREF); |
309 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, | 312 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, |
310 enable_by_default, | 313 enable_by_default, |
311 PrefService::UNSYNCABLE_PREF); | 314 PrefService::UNSYNCABLE_PREF); |
312 pref_service->RegisterBooleanPref(prefs::kSyncManaged, | 315 pref_service->RegisterBooleanPref(prefs::kSyncManaged, |
313 false, | 316 false, |
314 PrefService::UNSYNCABLE_PREF); | 317 PrefService::UNSYNCABLE_PREF); |
315 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, | 318 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, |
316 "", | 319 "", |
317 PrefService::UNSYNCABLE_PREF); | 320 PrefService::UNSYNCABLE_PREF); |
318 | |
319 pref_service->RegisterBooleanPref(prefs::kSyncAutofillProfile, | 321 pref_service->RegisterBooleanPref(prefs::kSyncAutofillProfile, |
320 enable_by_default, | 322 enable_by_default, |
321 PrefService::UNSYNCABLE_PREF); | 323 PrefService::UNSYNCABLE_PREF); |
322 | 324 |
323 // We started prompting people about new data types starting with the | 325 // We started prompting people about new data types starting with the |
324 // rollout of TYPED_URLs - all previously launched data types are treated | 326 // rollout of TYPED_URLs - all previously launched data types are treated |
325 // as if they are already acknowledged. | 327 // as if they are already acknowledged. |
326 syncable::ModelTypeBitSet model_set; | 328 syncable::ModelTypeBitSet model_set; |
327 model_set.set(syncable::BOOKMARKS); | 329 model_set.set(syncable::BOOKMARKS); |
328 model_set.set(syncable::PREFERENCES); | 330 model_set.set(syncable::PREFERENCES); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 return prefs::kSyncApps; | 543 return prefs::kSyncApps; |
542 case syncable::SESSIONS: | 544 case syncable::SESSIONS: |
543 return prefs::kSyncSessions; | 545 return prefs::kSyncSessions; |
544 default: | 546 default: |
545 break; | 547 break; |
546 } | 548 } |
547 NOTREACHED(); | 549 NOTREACHED(); |
548 return NULL; | 550 return NULL; |
549 } | 551 } |
550 | 552 |
553 // static | |
554 std::string ProfileSyncService::GetExperimentNameForDataType( | |
555 syncable::ModelType data_type) { | |
556 switch (data_type) { | |
557 case syncable::SESSIONS: | |
558 return "sync-sessions"; | |
559 case syncable::TYPED_URLS: | |
560 return "sync-typed-urls"; | |
tim (not reviewing)
2011/08/23 13:58:52
How come typed urls is here but the proto only has
Nicolas Zea
2011/08/23 16:48:25
Because it's an experimental type with a flag, but
| |
561 default: | |
562 break; | |
563 } | |
564 NOTREACHED(); | |
565 return ""; | |
566 } | |
567 | |
568 void ProfileSyncService::RegisterNewDataType(syncable::ModelType data_type) { | |
569 if (data_type_controllers_.count(data_type) > 0) | |
570 return; | |
571 switch (data_type) { | |
572 case syncable::SESSIONS: | |
573 RegisterDataTypeController( | |
574 new browser_sync::SessionDataTypeController(factory_, | |
575 profile_, | |
tim (not reviewing)
2011/08/23 13:58:52
nit - indent
Nicolas Zea
2011/08/23 16:48:25
Done.
| |
576 this)); | |
577 return; | |
578 case syncable::TYPED_URLS: | |
579 RegisterDataTypeController( | |
580 new browser_sync::TypedUrlDataTypeController(factory_, profile_)); | |
581 return; | |
582 default: | |
583 break; | |
584 } | |
585 NOTREACHED(); | |
586 } | |
587 | |
551 // An invariant has been violated. Transition to an error state where we try | 588 // An invariant has been violated. Transition to an error state where we try |
552 // to do as little work as possible, to avoid further corruption or crashes. | 589 // to do as little work as possible, to avoid further corruption or crashes. |
553 void ProfileSyncService::OnUnrecoverableError( | 590 void ProfileSyncService::OnUnrecoverableError( |
554 const tracked_objects::Location& from_here, | 591 const tracked_objects::Location& from_here, |
555 const std::string& message) { | 592 const std::string& message) { |
556 unrecoverable_error_detected_ = true; | 593 unrecoverable_error_detected_ = true; |
557 unrecoverable_error_message_ = message; | 594 unrecoverable_error_message_ = message; |
558 unrecoverable_error_location_.reset( | 595 unrecoverable_error_location_.reset( |
559 new tracked_objects::Location(from_here.function_name(), | 596 new tracked_objects::Location(from_here.function_name(), |
560 from_here.file_name(), | 597 from_here.file_name(), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 DVLOG(1) << "Setup not complete, no wizard - integration tests?"; | 655 DVLOG(1) << "Setup not complete, no wizard - integration tests?"; |
619 } | 656 } |
620 } | 657 } |
621 | 658 |
622 void ProfileSyncService::OnSyncCycleCompleted() { | 659 void ProfileSyncService::OnSyncCycleCompleted() { |
623 UpdateLastSyncedTime(); | 660 UpdateLastSyncedTime(); |
624 VLOG(2) << "Notifying observers sync cycle completed"; | 661 VLOG(2) << "Notifying observers sync cycle completed"; |
625 NotifyObservers(); | 662 NotifyObservers(); |
626 } | 663 } |
627 | 664 |
665 // TODO(sync): eventually support removing datatypes too. | |
666 void ProfileSyncService::OnDataTypesChanged( | |
667 const syncable::ModelTypeSet& to_add) { | |
668 // We don't bother doing anything if the migrator is busy. | |
669 if (migrator_->state() != browser_sync::BackendMigrator::IDLE) { | |
tim (not reviewing)
2011/08/23 13:58:52
Did you give any thought to keeping a second insta
Nicolas Zea
2011/08/23 16:48:25
I'm didn't really think the extra complexity there
| |
670 VLOG(1) << "Dropping OnDataTypesChanged due to migrator busy."; | |
671 return; | |
672 } | |
673 | |
674 syncable::ModelTypeSet new_types; | |
675 syncable::ModelTypeSet preferred_types; | |
676 GetPreferredDataTypes(&preferred_types); | |
677 syncable::ModelTypeSet registered_types; | |
678 GetRegisteredDataTypes(®istered_types); | |
679 | |
680 for (syncable::ModelTypeSet::const_iterator iter = to_add.begin(); | |
681 iter != to_add.end(); | |
682 ++iter) { | |
683 // Received notice to enable session sync. Check if sessions are | |
684 // registered, and if not register a new datatype controller. | |
685 if (registered_types.count(*iter) == 0) { | |
686 RegisterNewDataType(*iter); | |
687 // Enable the about:flags switch for sessions so we don't have to always | |
688 // perform this reconfiguration. Once we set this, sessions will remain | |
689 // registered, so we will no longer go down this code path. | |
690 std::string experiment_name = GetExperimentNameForDataType(*iter); | |
691 if (experiment_name.empty()) | |
692 continue; | |
693 about_flags::SetExperimentEnabled(g_browser_process->local_state(), | |
694 experiment_name, | |
695 true); | |
696 | |
697 // Check if the user has "Keep Everything Synced" enabled. If so, we want | |
698 // to turn on sessions if it's not already on. Otherwise we leave it off. | |
699 // Note: if sessions are already registered, we don't turn it on. This | |
700 // covers the case where we're already in the process of reconfiguring | |
701 // to turn sessions on. | |
702 if (profile_->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced) && | |
703 preferred_types.count(*iter) == 0){ | |
704 std::string pref_name = GetPrefNameForDataType(*iter); | |
705 if (pref_name.empty()) | |
706 continue; | |
707 profile_->GetPrefs()->SetBoolean(pref_name.c_str(), true); | |
708 } | |
709 } | |
710 } | |
711 | |
712 if (!new_types.empty()) { | |
713 VLOG(1) << "Dynamically enabling new datatypes: " | |
714 << syncable::ModelTypeSetToString(new_types); | |
715 OnMigrationNeededForTypes(new_types); | |
716 } | |
717 } | |
718 | |
628 void ProfileSyncService::UpdateAuthErrorState( | 719 void ProfileSyncService::UpdateAuthErrorState( |
629 const GoogleServiceAuthError& error) { | 720 const GoogleServiceAuthError& error) { |
630 last_auth_error_ = error; | 721 last_auth_error_ = error; |
631 // Protect against the in-your-face dialogs that pop out of nowhere. | 722 // Protect against the in-your-face dialogs that pop out of nowhere. |
632 // Require the user to click somewhere to run the setup wizard in the case | 723 // Require the user to click somewhere to run the setup wizard in the case |
633 // of a steady-state auth failure. | 724 // of a steady-state auth failure. |
634 if (WizardIsVisible()) { | 725 if (WizardIsVisible()) { |
635 wizard_.Step(last_auth_error_.state() == AuthError::NONE ? | 726 wizard_.Step(last_auth_error_.state() == AuthError::NONE ? |
636 SyncSetupWizard::GAIA_SUCCESS : SyncSetupWizard::GetLoginState()); | 727 SyncSetupWizard::GAIA_SUCCESS : SyncSetupWizard::GetLoginState()); |
637 } else { | 728 } else { |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 // knows what it's doing. | 1190 // knows what it's doing. |
1100 return backend_.get(); | 1191 return backend_.get(); |
1101 } | 1192 } |
1102 | 1193 |
1103 void ProfileSyncService::ConfigureDataTypeManager() { | 1194 void ProfileSyncService::ConfigureDataTypeManager() { |
1104 bool restart = false; | 1195 bool restart = false; |
1105 if (!data_type_manager_.get()) { | 1196 if (!data_type_manager_.get()) { |
1106 restart = true; | 1197 restart = true; |
1107 data_type_manager_.reset( | 1198 data_type_manager_.reset( |
1108 factory_->CreateDataTypeManager(backend_.get(), | 1199 factory_->CreateDataTypeManager(backend_.get(), |
1109 data_type_controllers_)); | 1200 &data_type_controllers_)); |
1110 registrar_.Add(this, | 1201 registrar_.Add(this, |
1111 chrome::NOTIFICATION_SYNC_CONFIGURE_START, | 1202 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
1112 Source<DataTypeManager>(data_type_manager_.get())); | 1203 Source<DataTypeManager>(data_type_manager_.get())); |
1113 registrar_.Add(this, | 1204 registrar_.Add(this, |
1114 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 1205 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
1115 Source<DataTypeManager>(data_type_manager_.get())); | 1206 Source<DataTypeManager>(data_type_manager_.get())); |
1116 | 1207 |
1117 // We create the migrator at the same time. | 1208 // We create the migrator at the same time. |
1118 migrator_.reset( | 1209 migrator_.reset( |
1119 new browser_sync::BackendMigrator(this, data_type_manager_.get())); | 1210 new browser_sync::BackendMigrator(this, data_type_manager_.get())); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1461 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); | 1552 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); |
1462 syncable::ModelTypeSet registered; | 1553 syncable::ModelTypeSet registered; |
1463 GetRegisteredDataTypes(®istered); | 1554 GetRegisteredDataTypes(®istered); |
1464 syncable::ModelTypeBitSet registered_bit_set = | 1555 syncable::ModelTypeBitSet registered_bit_set = |
1465 syncable::ModelTypeBitSetFromSet(registered); | 1556 syncable::ModelTypeBitSetFromSet(registered); |
1466 unacknowledged = registered_bit_set & ~acknowledged; | 1557 unacknowledged = registered_bit_set & ~acknowledged; |
1467 } | 1558 } |
1468 return unacknowledged; | 1559 return unacknowledged; |
1469 } | 1560 } |
1470 | 1561 |
OLD | NEW |