Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SERVIC E_H_ | |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SERVIC E_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/memory/singleton.h" | |
| 11 #include "base/prefs/pref_change_registrar.h" | |
| 12 #include "chrome/browser/prefs/pref_service_syncable_observer.h" | |
| 13 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" | |
| 14 #include "components/keyed_service/core/keyed_service.h" | |
| 15 #include "content/public/browser/notification_observer.h" | |
| 16 #include "content/public/browser/notification_registrar.h" | |
| 17 | |
| 18 class Profile; | |
| 19 | |
| 20 namespace sync_driver { | |
| 21 class SyncService; | |
| 22 } | |
| 23 | |
| 24 // Service that is responsible for reconciling the legacy "Offer to save your | |
| 25 // web passwords" setting (L, which is states for legacy) with the new | |
|
engedy
2015/09/02 13:31:20
nit: (henceforth denoted 'L', for legacy)
melandory
2015/09/02 19:03:34
Done.
| |
| 26 // "Enable Smart Lock for Passwords" setting (N, which is states for new). | |
|
engedy
2015/09/02 13:31:21
nit: ('N', for new)
melandory
2015/09/02 19:03:34
Done.
| |
| 27 // | |
| 28 // It works as follows. | |
| 29 // | |
| 30 // Users who are not syncing (this is checked on a service startup by | |
|
engedy
2015/09/02 13:31:20
nit: not syncing preferences?
| |
| 31 // calling to SyncService:CanSyncStart()) are migrated on a startup of a | |
|
engedy
2015/09/02 13:31:21
nit: on start-up of the
melandory
2015/09/02 19:03:34
Done.
| |
| 32 // service. This users can be in following states: | |
| 33 // 1. N = 0, L = 0 | |
| 34 // 2. N = 1, L = 1 | |
| 35 // 3. N = 1, L = 0 | |
| 36 // Nothing should be done in case 1 and 2 since settings are in sync with each | |
|
engedy
2015/09/02 13:31:20
nit: are already in sync
melandory
2015/09/02 19:03:34
Done.
| |
| 37 // other, in case 3 we change value of N to 1. | |
|
engedy
2015/09/02 13:31:20
nit: s/,/;/
melandory
2015/09/02 19:03:34
Done.
| |
| 38 // Service is also observes changes to both preferences, so if one of the | |
|
engedy
2015/09/02 13:31:20
nit: The service also
melandory
2015/09/02 19:03:34
Done.
| |
| 39 // preferences is changed locally, then this change is propagated to the other | |
| 40 // preference. | |
| 41 // | |
| 42 // For users who are syncing we save the values for new and legacy preference on | |
|
engedy
2015/09/02 13:31:21
nit: the new and legacy preferences
melandory
2015/09/02 19:03:34
Done.
| |
| 43 // a service start up (|inital_values_|) and values come from sync during | |
|
engedy
2015/09/02 13:31:20
nit: and the values that
engedy
2015/09/02 13:31:21
nit: -a
melandory
2015/09/02 19:03:34
Done.
melandory
2015/09/02 19:03:34
Done.
| |
| 44 // models association step (|sync_data_|). | |
| 45 // On the finish of model association step we derive new value for both settings | |
|
engedy
2015/09/02 13:31:21
nit: the new values
engedy
2015/09/02 13:31:21
We should explain:
-- why it is not enough to le
melandory
2015/09/02 19:03:34
Done.
melandory
2015/09/02 19:03:34
Done.
| |
| 46 // using following table: | |
|
engedy
2015/09/02 13:31:21
nit: Newline after this.
melandory
2015/09/02 19:03:34
Done.
| |
| 47 // NL* 0_ 1_ _0 _1 00 01 10 11 | |
|
engedy
2015/09/02 13:31:21
nit: Label the axes of this table. :)
| |
| 48 // | |
| 49 // 00 00 11 00 11 00 11 11 11 | |
|
engedy
2015/09/02 13:31:20
With our recent revelations about how Sync works,
melandory
2015/09/02 19:03:34
Yes, some of this combinations are not possible. W
| |
| 50 // 01 x x x x x x x x # impossible state | |
| 51 // 10 x x x x 00 00 00 11 | |
| 52 // 11 00 11 00 11 00 00 00 11 | |
| 53 // Service observes changes to the both preferences (e.g. changes from sync, | |
|
engedy
2015/09/02 13:31:20
nit: Newline before this line, also indent -1.
engedy
2015/09/02 13:31:21
nit: to both preferences
engedy
2015/09/02 13:31:21
nit: The service
melandory
2015/09/02 19:03:34
Done.
melandory
2015/09/02 19:03:34
Done.
melandory
2015/09/02 19:03:34
Done.
| |
| 54 // changes from UI) and propagate the change to the other preference if needed. | |
| 55 // | |
| 56 // After service is created it waits until Profile and profile related services | |
| 57 // (such as ProfileSyncService) are initialized and after that observers for | |
| 58 // the sync state change and preferences changes are registered. | |
| 59 // | |
| 60 // Note: componetization of this service currently is impossible, because it | |
| 61 // depends on PrefServiceSyncable. | |
| 62 class PasswordManagerSettingMigraterService | |
| 63 : public KeyedService, | |
| 64 public PrefServiceSyncableObserver, | |
| 65 public content::NotificationObserver { | |
| 66 public: | |
| 67 class Factory : public BrowserContextKeyedServiceFactory { | |
| 68 public: | |
| 69 static Factory* GetInstance(); | |
| 70 static PasswordManagerSettingMigraterService* GetForProfile( | |
| 71 Profile* profile); | |
| 72 | |
| 73 private: | |
| 74 friend struct DefaultSingletonTraits<Factory>; | |
| 75 friend class PasswordManagerSettingMigraterServiceTest; | |
| 76 | |
| 77 Factory(); | |
| 78 ~Factory() override; | |
| 79 | |
| 80 // BrowserContextKeyedServiceFactory: | |
| 81 KeyedService* BuildServiceInstanceFor( | |
| 82 content::BrowserContext* profile) const override; | |
| 83 bool ServiceIsCreatedWithBrowserContext() const override; | |
| 84 }; | |
| 85 | |
| 86 explicit PasswordManagerSettingMigraterService(Profile* profile); | |
| 87 ~PasswordManagerSettingMigraterService() override; | |
| 88 | |
| 89 void Shutdown() override; | |
| 90 | |
| 91 // PrefServiceSyncableObserver: | |
| 92 void OnIsSyncingChanged() override; | |
| 93 | |
| 94 // content::NotificationObserver: | |
| 95 void Observe(int type, | |
| 96 const content::NotificationSource& source, | |
| 97 const content::NotificationDetails& details) override; | |
| 98 | |
| 99 private: | |
| 100 // Initializes the observers: preferences observers and sync status observers. | |
| 101 void InitObservers(); | |
| 102 | |
| 103 // Called when the value of the |kCredentialsEnableService| preference | |
| 104 // changes, and updates the value of |kPasswordManagerSavingEnabled| | |
| 105 // preference accordingly. | |
| 106 void OnCredentialsEnableServicePrefChanged( | |
| 107 const std::string& changed_pref_name); | |
| 108 | |
| 109 // Called when the value of the |kPasswordManagerSavingEnabled| preference | |
| 110 // changes, and updates the value of |kCredentialsEnableService| preference | |
| 111 // accordingly. | |
| 112 void OnPasswordManagerSavingEnabledPrefChanged( | |
| 113 const std::string& changed_pref_name); | |
| 114 | |
| 115 // Turns off one pref if another pref is off. | |
| 116 void MigrateOffState(PrefService* prefs); | |
| 117 | |
| 118 // Performs a migration after sync associates models. Migration is performed | |
| 119 // based on initial values for both preferences and values received from | |
| 120 // sync. | |
| 121 void MigrateAfterModelAssociation(PrefService* prefs); | |
| 122 | |
| 123 Profile* const profile_; | |
| 124 sync_driver::SyncService* sync_service_; | |
| 125 PrefChangeRegistrar pref_change_registrar_; | |
| 126 | |
| 127 // Used to register for notification that profile creation is complete. | |
| 128 content::NotificationRegistrar registrar_; | |
| 129 | |
| 130 std::vector<bool> initial_values_; | |
| 131 | |
| 132 // Contains values which has came from sync during model association step. | |
| 133 // After both preferences data types are associated, new value for the both | |
| 134 // preferences will be calculated. | |
| 135 std::vector<bool> sync_data_; | |
| 136 | |
| 137 // This vector contains initial value for both preferences. The vector maximum | |
| 138 // size is two, where first element is new kCredentialsEnableService | |
| 139 // preference and second element is legacy kPasswordManagerSavingEnabled | |
| 140 // preference. | |
| 141 bool initial_new_pref_value_; | |
| 142 bool initial_legacy_pref_value_; | |
| 143 | |
| 144 DISALLOW_COPY_AND_ASSIGN(PasswordManagerSettingMigraterService); | |
| 145 }; | |
| 146 | |
| 147 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SER VICE_H_ | |
| OLD | NEW |