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

Side by Side Diff: chrome/browser/password_manager/password_manager_setting_migrater_service.h

Issue 1256803002: [Smart Lock, Prefs reconciliation] Prefs migration logic for desktop platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add guard Created 5 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
OLDNEW
(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 (henceforth denoted 'L', for legacy) with the new
26 // "Enable Smart Lock for Passwords" setting (henceforth denoted 'N', for new).
27 //
28 // It works as follows.
29 //
30 // Users who are not syncing (this is checked on start-up of the service
31 // calling to SyncService:CanSyncStart()) are migrated on a startup of a
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 //
37 // Nothing should be done in case 1 and 2 since settings are already in sync;
38 // in case 3 we change value of N to 0.
39 // The service also observes changes to both preferences, so if one of the
40 // preferences is changed locally, then this change is propagated to the other
41 // preference.
42 //
43 // For users who are syncing we save the values for the new and legacy
44 // preference on service start up (|inital_values_|) and the values that come
45 // from sync during models association step (|sync_data_|). Propagating change
46 // of one preference to another preference without having this special treatment
47 // will not always work. Here is an example which illustrates possible corner
48 // case: the client executes the migration code for the first time, legacy
49 // preference has a value equals to 1, new preference was registered for the
50 // first time and has default value which is also 1, the sync data snapshot
51 // which user has on a client contains new preference equals to 0 and old
52 // preference equals to 1, if we blindly propagate these values we first get
53 // both preferences equals to 0 after priority pref model was associated and
54 // then both preferences equals to 1 after preferences model was associated.
55 // But correct final value in this case is 0.
Nicolas Zea 2015/09/08 17:42:03 Why is the correct value in the final case 0? Shou
melandory 2015/09/08 19:54:09 Yeah, so flow which breaks everything in this case
56 //
57 // On the finish of model association step we derive the new values for both
58 // settings using following table (first column contains local values for the
59 // preferences, first row contains values which has came from sync, where _ that
60 // value doesn't came):
61 //
62 // NL* 0_ 1_ _0 _1 00 01 10 11
63 //
64 // 00 00 11 00 11 00 11 11 11
65 // 01 x x x x x x x x # impossible state
66 // 10 x x x x 00 00 00 11
67 // 11 00 11 00 11 00 00 00 11
68 //
69 // The service observes changes to both preferences (e.g. changes from sync,
70 // changes from UI) and propagate the change to the other preference if needed.
71 //
72 // After service is created it waits until Profile and profile related services
73 // (such as ProfileSyncService) are initialized and after that observers for
74 // the sync state change and preferences changes are registered.
75 //
76 // Note: componetization of this service currently is impossible, because it
77 // depends on PrefServiceSyncable.
78 class PasswordManagerSettingMigraterService
79 : public KeyedService,
80 public PrefServiceSyncableObserver,
81 public content::NotificationObserver {
82 public:
83 class Factory : public BrowserContextKeyedServiceFactory {
84 public:
85 static Factory* GetInstance();
86 static PasswordManagerSettingMigraterService* GetForProfile(
87 Profile* profile);
88
89 private:
90 friend struct DefaultSingletonTraits<Factory>;
91 friend class PasswordManagerSettingMigraterServiceTest;
92
93 Factory();
94 ~Factory() override;
95
96 // BrowserContextKeyedServiceFactory:
97 KeyedService* BuildServiceInstanceFor(
98 content::BrowserContext* profile) const override;
99 bool ServiceIsCreatedWithBrowserContext() const override;
100 };
101
102 explicit PasswordManagerSettingMigraterService(Profile* profile);
103 ~PasswordManagerSettingMigraterService() override;
104
105 void Shutdown() override;
106
107 // PrefServiceSyncableObserver:
108 void OnIsSyncingChanged() override;
109
110 // content::NotificationObserver:
111 void Observe(int type,
112 const content::NotificationSource& source,
113 const content::NotificationDetails& details) override;
114
115 private:
116 // Initializes the observers: preferences observers and sync status observers.
117 void InitObservers();
118
119 // Called when the value of the |kCredentialsEnableService| preference
120 // changes, and updates the value of |kPasswordManagerSavingEnabled|
121 // preference accordingly.
122 void OnCredentialsEnableServicePrefChanged(
123 const std::string& changed_pref_name);
124
125 // Called when the value of the |kPasswordManagerSavingEnabled| preference
126 // changes, and updates the value of |kCredentialsEnableService| preference
127 // accordingly.
128 void OnPasswordManagerSavingEnabledPrefChanged(
129 const std::string& changed_pref_name);
130
131 // Turns off one pref if another pref is off.
132 void MigrateOffState(PrefService* prefs);
133
134 // Performs a migration after sync associates models. Migration is performed
135 // based on initial values for both preferences and values received from
136 // sync.
137 void MigrateAfterModelAssociation(PrefService* prefs);
138
139 Profile* const profile_;
140 sync_driver::SyncService* sync_service_;
141 PrefChangeRegistrar pref_change_registrar_;
142
143 // Used to register for notification that profile creation is complete.
144 content::NotificationRegistrar registrar_;
145
146 // Contains values which has came from sync during model association step.
147 // After both preferences data types are associated, new value for the both
148 // preferences will be calculated.
149 std::vector<bool> sync_data_;
150
151 // This vector contains initial value for both preferences. The vector maximum
152 // size is two, where first element is new kCredentialsEnableService
153 // preference and second element is legacy kPasswordManagerSavingEnabled
154 // preference.
155 bool initial_new_pref_value_;
156 bool initial_legacy_pref_value_;
157
158 DISALLOW_COPY_AND_ASSIGN(PasswordManagerSettingMigraterService);
159 };
160
161 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SER VICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698