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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/password_manager/password_manager_setting_migrater_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/password_manager/password_manager_setting_migrater_service.h
diff --git a/chrome/browser/password_manager/password_manager_setting_migrater_service.h b/chrome/browser/password_manager/password_manager_setting_migrater_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..587f50cbedbc8d874d15102459355cace96a5973
--- /dev/null
+++ b/chrome/browser/password_manager/password_manager_setting_migrater_service.h
@@ -0,0 +1,147 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SERVICE_H_
+#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SERVICE_H_
+
+#include <vector>
+
+#include "base/memory/singleton.h"
+#include "base/prefs/pref_change_registrar.h"
+#include "chrome/browser/prefs/pref_service_syncable_observer.h"
+#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+class Profile;
+
+namespace sync_driver {
+class SyncService;
+}
+
+// Service that is responsible for reconciling the legacy "Offer to save your
+// 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.
+// "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.
+//
+// It works as follows.
+//
+// Users who are not syncing (this is checked on a service startup by
engedy 2015/09/02 13:31:20 nit: not syncing preferences?
+// 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.
+// service. This users can be in following states:
+// 1. N = 0, L = 0
+// 2. N = 1, L = 1
+// 3. N = 1, L = 0
+// 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.
+// 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.
+// 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.
+// preferences is changed locally, then this change is propagated to the other
+// preference.
+//
+// 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.
+// 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.
+// models association step (|sync_data_|).
+// 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.
+// using following table:
engedy 2015/09/02 13:31:21 nit: Newline after this.
melandory 2015/09/02 19:03:34 Done.
+// NL* 0_ 1_ _0 _1 00 01 10 11
engedy 2015/09/02 13:31:21 nit: Label the axes of this table. :)
+//
+// 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
+// 01 x x x x x x x x # impossible state
+// 10 x x x x 00 00 00 11
+// 11 00 11 00 11 00 00 00 11
+// 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.
+// changes from UI) and propagate the change to the other preference if needed.
+//
+// After service is created it waits until Profile and profile related services
+// (such as ProfileSyncService) are initialized and after that observers for
+// the sync state change and preferences changes are registered.
+//
+// Note: componetization of this service currently is impossible, because it
+// depends on PrefServiceSyncable.
+class PasswordManagerSettingMigraterService
+ : public KeyedService,
+ public PrefServiceSyncableObserver,
+ public content::NotificationObserver {
+ public:
+ class Factory : public BrowserContextKeyedServiceFactory {
+ public:
+ static Factory* GetInstance();
+ static PasswordManagerSettingMigraterService* GetForProfile(
+ Profile* profile);
+
+ private:
+ friend struct DefaultSingletonTraits<Factory>;
+ friend class PasswordManagerSettingMigraterServiceTest;
+
+ Factory();
+ ~Factory() override;
+
+ // BrowserContextKeyedServiceFactory:
+ KeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* profile) const override;
+ bool ServiceIsCreatedWithBrowserContext() const override;
+ };
+
+ explicit PasswordManagerSettingMigraterService(Profile* profile);
+ ~PasswordManagerSettingMigraterService() override;
+
+ void Shutdown() override;
+
+ // PrefServiceSyncableObserver:
+ void OnIsSyncingChanged() override;
+
+ // content::NotificationObserver:
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ private:
+ // Initializes the observers: preferences observers and sync status observers.
+ void InitObservers();
+
+ // Called when the value of the |kCredentialsEnableService| preference
+ // changes, and updates the value of |kPasswordManagerSavingEnabled|
+ // preference accordingly.
+ void OnCredentialsEnableServicePrefChanged(
+ const std::string& changed_pref_name);
+
+ // Called when the value of the |kPasswordManagerSavingEnabled| preference
+ // changes, and updates the value of |kCredentialsEnableService| preference
+ // accordingly.
+ void OnPasswordManagerSavingEnabledPrefChanged(
+ const std::string& changed_pref_name);
+
+ // Turns off one pref if another pref is off.
+ void MigrateOffState(PrefService* prefs);
+
+ // Performs a migration after sync associates models. Migration is performed
+ // based on initial values for both preferences and values received from
+ // sync.
+ void MigrateAfterModelAssociation(PrefService* prefs);
+
+ Profile* const profile_;
+ sync_driver::SyncService* sync_service_;
+ PrefChangeRegistrar pref_change_registrar_;
+
+ // Used to register for notification that profile creation is complete.
+ content::NotificationRegistrar registrar_;
+
+ std::vector<bool> initial_values_;
+
+ // Contains values which has came from sync during model association step.
+ // After both preferences data types are associated, new value for the both
+ // preferences will be calculated.
+ std::vector<bool> sync_data_;
+
+ // This vector contains initial value for both preferences. The vector maximum
+ // size is two, where first element is new kCredentialsEnableService
+ // preference and second element is legacy kPasswordManagerSavingEnabled
+ // preference.
+ bool initial_new_pref_value_;
+ bool initial_legacy_pref_value_;
+
+ DISALLOW_COPY_AND_ASSIGN(PasswordManagerSettingMigraterService);
+};
+
+#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SERVICE_H_
« no previous file with comments | « no previous file | chrome/browser/password_manager/password_manager_setting_migrater_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698