Unwind the URL-based experiment IDs.
[chromium-blink-merge.git] / chrome / browser / supervised_user / supervised_user_whitelist_service.h
blob81d4ebbf1565e3c1cdb70ce8a5fde7af4c59ab29
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_WHITELIST_SERVICE_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_WHITELIST_SERVICE_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/time/time.h"
17 #include "chrome/browser/supervised_user/supervised_users.h"
18 #include "sync/api/syncable_service.h"
20 class PrefService;
21 class SupervisedUserSiteList;
23 namespace base {
24 class DictionaryValue;
25 class FilePath;
28 namespace component_updater {
29 class SupervisedUserWhitelistInstaller;
32 namespace user_prefs {
33 class PrefRegistrySyncable;
36 namespace sync_pb {
37 class ManagedUserWhitelistSpecifics;
40 class SupervisedUserWhitelistService : public syncer::SyncableService {
41 public:
42 typedef base::Callback<void(
43 const std::vector<scoped_refptr<SupervisedUserSiteList> >&)>
44 SiteListsChangedCallback;
46 SupervisedUserWhitelistService(
47 PrefService* prefs,
48 component_updater::SupervisedUserWhitelistInstaller* installer,
49 const std::string& client_id);
50 ~SupervisedUserWhitelistService() override;
52 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
54 void Init();
56 // Adds a callback to be called when the list of loaded site lists changes.
57 // The callback will also be called immediately, to get the current
58 // site lists.
59 void AddSiteListsChangedCallback(const SiteListsChangedCallback& callback);
61 // Loads an already existing whitelist on disk (i.e. without downloading it as
62 // a component).
63 void LoadWhitelistForTesting(const std::string& id,
64 const base::FilePath& path);
66 // Unloads a whitelist. Public for testing.
67 void UnloadWhitelist(const std::string& id);
69 // Creates Sync data for a whitelist with the given |id| and |name|.
70 // Public for testing.
71 static syncer::SyncData CreateWhitelistSyncData(const std::string& id,
72 const std::string& name);
74 // SyncableService implementation:
75 syncer::SyncMergeResult MergeDataAndStartSyncing(
76 syncer::ModelType type,
77 const syncer::SyncDataList& initial_sync_data,
78 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
79 scoped_ptr<syncer::SyncErrorFactory> error_handler) override;
80 void StopSyncing(syncer::ModelType type) override;
81 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override;
82 syncer::SyncError ProcessSyncChanges(
83 const tracked_objects::Location& from_here,
84 const syncer::SyncChangeList& change_list) override;
86 private:
87 // The following methods handle whitelist additions, updates and removals,
88 // usually coming from Sync.
89 void AddNewWhitelist(base::DictionaryValue* pref_dict,
90 const sync_pb::ManagedUserWhitelistSpecifics& whitelist);
91 void SetWhitelistProperties(
92 base::DictionaryValue* pref_dict,
93 const sync_pb::ManagedUserWhitelistSpecifics& whitelist);
94 void RemoveWhitelist(base::DictionaryValue* pref_dict, const std::string& id);
96 // Registers a new or existing whitelist.
97 void RegisterWhitelist(const std::string& id,
98 const std::string& name,
99 bool new_installation);
101 void GetLoadedWhitelists(
102 std::vector<scoped_refptr<SupervisedUserSiteList>>* whitelists);
104 void NotifyWhitelistsChanged();
106 void OnWhitelistReady(const std::string& id,
107 const base::FilePath& whitelist_path);
108 void OnWhitelistLoaded(
109 const std::string& id,
110 base::TimeTicks start_time,
111 const scoped_refptr<SupervisedUserSiteList>& whitelist);
113 PrefService* prefs_;
114 component_updater::SupervisedUserWhitelistInstaller* installer_;
116 std::string client_id_;
117 std::vector<SiteListsChangedCallback> site_lists_changed_callbacks_;
119 // The set of registered whitelists. A whitelist might be registered but not
120 // loaded yet, in which case it will not be in |loaded_whitelists_| yet.
121 // On the other hand, every loaded whitelist has to be registered.
122 std::set<std::string> registered_whitelists_;
123 std::map<std::string, scoped_refptr<SupervisedUserSiteList> >
124 loaded_whitelists_;
126 base::WeakPtrFactory<SupervisedUserWhitelistService> weak_ptr_factory_;
128 DISALLOW_COPY_AND_ASSIGN(SupervisedUserWhitelistService);
131 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_WHITELIST_SERVICE_H_