| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SETTINGS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SETTINGS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SETTINGS_SERVICE_H_ | 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SETTINGS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/callback_list.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/prefs/pref_store.h" | 15 #include "base/prefs/pref_store.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/supervised_user/supervised_users.h" | 17 #include "chrome/browser/supervised_user/supervised_users.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "sync/api/syncable_service.h" | 19 #include "sync/api/syncable_service.h" |
| 19 | 20 |
| 20 class PersistentPrefStore; | 21 class PersistentPrefStore; |
| 21 class Profile; | 22 class Profile; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 // } | 50 // } |
| 50 // would be encoded as two sync items, one with key "Moose:foo" and value "bar", | 51 // would be encoded as two sync items, one with key "Moose:foo" and value "bar", |
| 51 // and one with key "Moose:baz" and value "blurp". | 52 // and one with key "Moose:baz" and value "blurp". |
| 52 class SupervisedUserSettingsService : public KeyedService, | 53 class SupervisedUserSettingsService : public KeyedService, |
| 53 public syncer::SyncableService, | 54 public syncer::SyncableService, |
| 54 public PrefStore::Observer { | 55 public PrefStore::Observer { |
| 55 public: | 56 public: |
| 56 // A callback whose first parameter is a dictionary containing all supervised | 57 // A callback whose first parameter is a dictionary containing all supervised |
| 57 // user settings. If the dictionary is NULL, it means that the service is | 58 // user settings. If the dictionary is NULL, it means that the service is |
| 58 // inactive, i.e. the user is not supervised. | 59 // inactive, i.e. the user is not supervised. |
| 59 typedef base::Callback<void(const base::DictionaryValue*)> SettingsCallback; | 60 using SettingsCallbackType = void(const base::DictionaryValue*); |
| 61 using SettingsCallback = base::Callback<SettingsCallbackType>; |
| 62 using SettingsCallbackList = base::CallbackList<SettingsCallbackType>; |
| 60 | 63 |
| 61 SupervisedUserSettingsService(); | 64 SupervisedUserSettingsService(); |
| 62 ~SupervisedUserSettingsService() override; | 65 ~SupervisedUserSettingsService() override; |
| 63 | 66 |
| 64 // Initializes the service by loading its settings from a file underneath the | 67 // Initializes the service by loading its settings from a file underneath the |
| 65 // |profile_path|. File I/O will be serialized via the | 68 // |profile_path|. File I/O will be serialized via the |
| 66 // |sequenced_task_runner|. If |load_synchronously| is true, the settings will | 69 // |sequenced_task_runner|. If |load_synchronously| is true, the settings will |
| 67 // be loaded synchronously, otherwise asynchronously. | 70 // be loaded synchronously, otherwise asynchronously. |
| 68 void Init(base::FilePath profile_path, | 71 void Init(base::FilePath profile_path, |
| 69 base::SequencedTaskRunner* sequenced_task_runner, | 72 base::SequencedTaskRunner* sequenced_task_runner, |
| 70 bool load_synchronously); | 73 bool load_synchronously); |
| 71 | 74 |
| 72 // Initializes the service by loading its settings from the |pref_store|. | 75 // Initializes the service by loading its settings from the |pref_store|. |
| 73 // Use this method in tests to inject a different PrefStore than the | 76 // Use this method in tests to inject a different PrefStore than the |
| 74 // default one. | 77 // default one. |
| 75 void Init(scoped_refptr<PersistentPrefStore> pref_store); | 78 void Init(scoped_refptr<PersistentPrefStore> pref_store); |
| 76 | 79 |
| 77 // Adds a callback to be called when supervised user settings are initially | 80 // Adds a callback to be called when supervised user settings are initially |
| 78 // available, or when they change. | 81 // available, or when they change. |
| 79 void Subscribe(const SettingsCallback& callback); | 82 scoped_ptr<base::CallbackList<SettingsCallbackType>::Subscription> |
| 83 Subscribe(const SettingsCallback& callback); |
| 80 | 84 |
| 81 // Activates/deactivates the service. This is called by the | 85 // Activates/deactivates the service. This is called by the |
| 82 // SupervisedUserService when it is (de)activated. | 86 // SupervisedUserService when it is (de)activated. |
| 83 void SetActive(bool active); | 87 void SetActive(bool active); |
| 84 | 88 |
| 85 // Whether supervised user settings are available. | 89 // Whether supervised user settings are available. |
| 86 bool IsReady(); | 90 bool IsReady(); |
| 87 | 91 |
| 88 // Clears all supervised user settings and items. | 92 // Clears all supervised user settings and items. |
| 89 void Clear(); | 93 void Clear(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // directly hooked up to the PrefService. | 154 // directly hooked up to the PrefService. |
| 151 scoped_refptr<PersistentPrefStore> store_; | 155 scoped_refptr<PersistentPrefStore> store_; |
| 152 | 156 |
| 153 bool active_; | 157 bool active_; |
| 154 | 158 |
| 155 bool initialization_failed_; | 159 bool initialization_failed_; |
| 156 | 160 |
| 157 // A set of local settings that are fixed and not configured remotely. | 161 // A set of local settings that are fixed and not configured remotely. |
| 158 scoped_ptr<base::DictionaryValue> local_settings_; | 162 scoped_ptr<base::DictionaryValue> local_settings_; |
| 159 | 163 |
| 160 std::vector<SettingsCallback> subscribers_; | 164 SettingsCallbackList callback_list_; |
| 161 | 165 |
| 162 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 166 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 163 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 167 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
| 164 | 168 |
| 165 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSettingsService); | 169 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSettingsService); |
| 166 }; | 170 }; |
| 167 | 171 |
| 168 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SETTINGS_SERVICE_H_ | 172 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SETTINGS_SERVICE_H_ |
| OLD | NEW |