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 <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "chrome/common/time_format.h" | 56 #include "chrome/common/time_format.h" |
57 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
58 #include "content/public/browser/notification_details.h" | 58 #include "content/public/browser/notification_details.h" |
59 #include "content/public/browser/notification_source.h" | 59 #include "content/public/browser/notification_source.h" |
60 #include "grit/generated_resources.h" | 60 #include "grit/generated_resources.h" |
61 #include "net/cookies/cookie_monster.h" | 61 #include "net/cookies/cookie_monster.h" |
62 #include "sync/internal_api/configure_reason.h" | 62 #include "sync/internal_api/configure_reason.h" |
63 #include "sync/js/js_arg_list.h" | 63 #include "sync/js/js_arg_list.h" |
64 #include "sync/js/js_event_details.h" | 64 #include "sync/js/js_event_details.h" |
65 #include "sync/util/cryptographer.h" | 65 #include "sync/util/cryptographer.h" |
| 66 #include "sync/util/sync_experiments.h" |
66 #include "ui/base/l10n/l10n_util.h" | 67 #include "ui/base/l10n/l10n_util.h" |
67 | 68 |
68 using browser_sync::ChangeProcessor; | 69 using browser_sync::ChangeProcessor; |
69 using browser_sync::DataTypeController; | 70 using browser_sync::DataTypeController; |
70 using browser_sync::DataTypeManager; | 71 using browser_sync::DataTypeManager; |
71 using browser_sync::JsBackend; | 72 using browser_sync::JsBackend; |
72 using browser_sync::JsController; | 73 using browser_sync::JsController; |
73 using browser_sync::JsEventDetails; | 74 using browser_sync::JsEventDetails; |
74 using browser_sync::JsEventHandler; | 75 using browser_sync::JsEventHandler; |
75 using browser_sync::SyncBackendHost; | 76 using browser_sync::SyncBackendHost; |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 // server time as last reported by CheckServerReachable, so we don't have to | 703 // server time as last reported by CheckServerReachable, so we don't have to |
703 // rely on the local clock, which may be off significantly. | 704 // rely on the local clock, which may be off significantly. |
704 MessageLoop::current()->PostTask(FROM_HERE, | 705 MessageLoop::current()->PostTask(FROM_HERE, |
705 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, | 706 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, |
706 GetSessionModelAssociator()->AsWeakPtr())); | 707 GetSessionModelAssociator()->AsWeakPtr())); |
707 } | 708 } |
708 DVLOG(2) << "Notifying observers sync cycle completed"; | 709 DVLOG(2) << "Notifying observers sync cycle completed"; |
709 NotifyObservers(); | 710 NotifyObservers(); |
710 } | 711 } |
711 | 712 |
712 // TODO(sync): eventually support removing datatypes too. | 713 void ProfileSyncService::OnExperimentsChanged( |
713 void ProfileSyncService::OnDataTypesChanged( | 714 const browser_sync::SyncExperiments& experiments) { |
714 syncable::ModelTypeSet to_add) { | 715 if (current_experiments.Matches(experiments)) |
| 716 return; |
| 717 |
715 // If this is a first time sync for a client, this will be called before | 718 // If this is a first time sync for a client, this will be called before |
716 // OnBackendInitialized() to ensure the new datatypes are available at sync | 719 // OnBackendInitialized() to ensure the new datatypes are available at sync |
717 // setup. As a result, the migrator won't exist yet. This is fine because for | 720 // setup. As a result, the migrator won't exist yet. This is fine because for |
718 // first time sync cases we're only concerned with making the datatype | 721 // first time sync cases we're only concerned with making the datatype |
719 // available. | 722 // available. |
720 if (migrator_.get() && | 723 if (migrator_.get() && |
721 migrator_->state() != browser_sync::BackendMigrator::IDLE) { | 724 migrator_->state() != browser_sync::BackendMigrator::IDLE) { |
722 DVLOG(1) << "Dropping OnDataTypesChanged due to migrator busy."; | 725 DVLOG(1) << "Dropping OnExperimentsChanged due to migrator busy."; |
723 return; | 726 return; |
724 } | 727 } |
725 | 728 |
726 DVLOG(2) << "OnDataTypesChanged called with types: " | |
727 << syncable::ModelTypeSetToString(to_add); | |
728 | |
729 const syncable::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 729 const syncable::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
730 | 730 syncable::ModelTypeSet to_add; |
| 731 if (experiments.sync_tabs) |
| 732 to_add.Put(syncable::SESSIONS); |
731 const syncable::ModelTypeSet to_register = | 733 const syncable::ModelTypeSet to_register = |
732 Difference(to_add, registered_types); | 734 Difference(to_add, registered_types); |
733 | 735 DVLOG(2) << "OnExperimentsChanged called with types: " |
| 736 << syncable::ModelTypeSetToString(to_add); |
734 DVLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register); | 737 DVLOG(2) << "Enabling types: " << syncable::ModelTypeSetToString(to_register); |
735 | 738 |
736 for (syncable::ModelTypeSet::Iterator it = to_register.First(); | 739 for (syncable::ModelTypeSet::Iterator it = to_register.First(); |
737 it.Good(); it.Inc()) { | 740 it.Good(); it.Inc()) { |
738 // Received notice to enable experimental type. Check if the type is | 741 // Received notice to enable experimental type. Check if the type is |
739 // registered, and if not register a new datatype controller. | 742 // registered, and if not register a new datatype controller. |
740 RegisterNewDataType(it.Get()); | 743 RegisterNewDataType(it.Get()); |
741 #if !defined(OS_ANDROID) | 744 #if !defined(OS_ANDROID) |
742 // Enable the about:flags switch for the experimental type so we don't have | 745 // Enable the about:flags switch for the experimental type so we don't have |
743 // to always perform this reconfiguration. Once we set this, the type will | 746 // to always perform this reconfiguration. Once we set this, the type will |
(...skipping 19 matching lines...) Expand all Loading... |
763 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); | 766 sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); |
764 | 767 |
765 // Only automatically turn on types if we have already finished set up. | 768 // Only automatically turn on types if we have already finished set up. |
766 // Otherwise, just leave the experimental types on by default. | 769 // Otherwise, just leave the experimental types on by default. |
767 if (!to_register.Empty() && HasSyncSetupCompleted() && migrator_.get()) { | 770 if (!to_register.Empty() && HasSyncSetupCompleted() && migrator_.get()) { |
768 DVLOG(1) << "Dynamically enabling new datatypes: " | 771 DVLOG(1) << "Dynamically enabling new datatypes: " |
769 << syncable::ModelTypeSetToString(to_register); | 772 << syncable::ModelTypeSetToString(to_register); |
770 OnMigrationNeededForTypes(to_register); | 773 OnMigrationNeededForTypes(to_register); |
771 } | 774 } |
772 } | 775 } |
| 776 |
| 777 // Now enable any non-datatype features. |
| 778 if (experiments.sync_tab_favicons) { |
| 779 DVLOG(1) << "Enabling syncing of tab favicons."; |
| 780 about_flags::SetExperimentEnabled(g_browser_process->local_state(), |
| 781 "sync-tab-favicons", |
| 782 true); |
| 783 } |
| 784 |
| 785 current_experiments = experiments; |
773 } | 786 } |
774 | 787 |
775 void ProfileSyncService::UpdateAuthErrorState( | 788 void ProfileSyncService::UpdateAuthErrorState( |
776 const GoogleServiceAuthError& error) { | 789 const GoogleServiceAuthError& error) { |
777 is_auth_in_progress_ = false; | 790 is_auth_in_progress_ = false; |
778 last_auth_error_ = error; | 791 last_auth_error_ = error; |
779 | 792 |
780 // Fan the notification out to interested UI-thread components. | 793 // Fan the notification out to interested UI-thread components. |
781 NotifyObservers(); | 794 NotifyObservers(); |
782 } | 795 } |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 1667 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
1655 ProfileSyncService* old_this = this; | 1668 ProfileSyncService* old_this = this; |
1656 this->~ProfileSyncService(); | 1669 this->~ProfileSyncService(); |
1657 new(old_this) ProfileSyncService( | 1670 new(old_this) ProfileSyncService( |
1658 new ProfileSyncComponentsFactoryImpl(profile, | 1671 new ProfileSyncComponentsFactoryImpl(profile, |
1659 CommandLine::ForCurrentProcess()), | 1672 CommandLine::ForCurrentProcess()), |
1660 profile, | 1673 profile, |
1661 signin, | 1674 signin, |
1662 behavior); | 1675 behavior); |
1663 } | 1676 } |
OLD | NEW |