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 "base/memory/singleton.h" | |
| 9 #include "base/prefs/pref_change_registrar.h" | |
| 10 #include "chrome/browser/prefs/pref_service_syncable_observer.h" | |
| 11 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" | |
| 12 #include "components/keyed_service/core/keyed_service.h" | |
| 13 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 | |
| 16 class Profile; | |
| 17 | |
| 18 namespace sync_driver { | |
| 19 class SyncService; | |
| 20 } | |
| 21 | |
| 22 namespace password_manager { | |
|
vabr (Chromium)
2015/08/12 08:25:51
nit: By convention, code in //chrome mostly does n
melandory
2015/08/13 15:49:15
Done.
| |
| 23 | |
| 24 // PasswordManagerSettingMigraterService is responsible for reconciling Chrome | |
| 25 // password manager and Smart Lock for passwords settings. | |
| 26 // Note: componetization of this service currently is impossible, because it | |
| 27 // depends on PrefServiceSyncable. | |
| 28 class PasswordManagerSettingMigraterService | |
| 29 : public KeyedService, | |
| 30 public PrefServiceSyncableObserver, | |
| 31 public content::NotificationObserver { | |
| 32 public: | |
| 33 class Factory : public BrowserContextKeyedServiceFactory { | |
| 34 public: | |
| 35 static Factory* GetInstance(); | |
| 36 static PasswordManagerSettingMigraterService* GetForProfile( | |
| 37 Profile* profile); | |
| 38 | |
| 39 private: | |
| 40 friend struct DefaultSingletonTraits<Factory>; | |
| 41 friend class PasswordManagerSettingMigraterServiceTest; | |
| 42 | |
| 43 Factory(); | |
| 44 ~Factory() override; | |
| 45 | |
| 46 // BrowserContextKeyedServiceFactory | |
| 47 KeyedService* BuildServiceInstanceFor( | |
| 48 content::BrowserContext* profile) const override; | |
| 49 bool ServiceIsCreatedWithBrowserContext() const override; | |
| 50 }; | |
| 51 | |
| 52 explicit PasswordManagerSettingMigraterService(Profile* profile); | |
| 53 ~PasswordManagerSettingMigraterService() override; | |
| 54 | |
| 55 // Initializes the observers: preferences observers and sync status observers. | |
| 56 void InitObservers(); | |
| 57 | |
| 58 // PrefServiceSyncableObserver | |
| 59 void OnIsSyncingChanged() override; | |
| 60 | |
| 61 // content::NotificationObserver | |
| 62 void Observe(int type, | |
| 63 const content::NotificationSource& source, | |
| 64 const content::NotificationDetails& details) override; | |
| 65 | |
| 66 private: | |
| 67 friend class PasswordManagerSettingMigraterServiceTest; | |
| 68 | |
| 69 // For unit testing only. | |
| 70 PasswordManagerSettingMigraterService(Profile* profile, | |
|
vabr (Chromium)
2015/08/12 08:25:51
As engedy@ noted before -- why not make this the o
melandory
2015/08/13 15:49:15
Found another way how to inject mock ProfileSyncSe
vabr (Chromium)
2015/08/14 14:11:45
Great, I like that it now comes with the notificat
| |
| 71 sync_driver::SyncService* sync_service); | |
| 72 | |
| 73 // Called on event of changing kCredentialsEnableService preference. Changes | |
| 74 // the value of kPasswordManagerSavingEnabled preference to be in sync with | |
| 75 // kCredentialsEnableService. | |
| 76 void OnCredentialsEnableServicePrefChanged( | |
| 77 const std::string& changed_pref_name); | |
| 78 | |
| 79 // Called on event of changing kPasswordManagerSavingEnabled preference. | |
| 80 // Changes the value of kCredentialsEnableService preference to be in sync | |
| 81 // with kPasswordManagerSavingEnabled. | |
| 82 void OnPasswordManagerSavingEnabledPrefChanged( | |
| 83 const std::string& changed_pref_name); | |
| 84 | |
| 85 // Turns off CredentialsEnableService when PasswordManagerSavingEnabled is | |
| 86 // turned off. | |
| 87 void MigrateLegacyOffState(PrefService* prefs); | |
| 88 | |
| 89 Profile* profile_; | |
|
vabr (Chromium)
2015/08/12 08:25:51
The member pointers which are not touched elsewher
melandory
2015/08/13 15:49:15
Done.
Can't do this for sync_service_, because it
vabr (Chromium)
2015/08/14 14:11:45
Acknowledged.
| |
| 90 | |
| 91 sync_driver::SyncService* sync_service_; | |
| 92 PrefChangeRegistrar pref_change_registrar_; | |
| 93 | |
| 94 // Used to register for notification that profile creation is complete. | |
| 95 content::NotificationRegistrar registrar_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(PasswordManagerSettingMigraterService); | |
| 98 }; | |
| 99 | |
| 100 } // namespace password_manager | |
| 101 | |
| 102 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_SETTING_MIGRATER_SER VICE_H_ | |
| OLD | NEW |