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

Side by Side Diff: chrome/browser/managed_mode/managed_user_sync_service.h

Issue 335833003: Rename "managed (mode|user)" to "supervised user" (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments (+ a few other cleanups) Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_
7
8 #include <vector>
9
10 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "chrome/browser/managed_mode/managed_user_sync_service_observer.h"
15 #include "chrome/browser/managed_mode/managed_users.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "sync/api/syncable_service.h"
18
19 namespace base {
20 class DictionaryValue;
21 }
22
23 namespace user_prefs {
24 class PrefRegistrySyncable;
25 }
26
27 class PrefService;
28
29 class ManagedUserSyncService : public KeyedService,
30 public syncer::SyncableService {
31 public:
32 // For use with GetManagedUsersAsync() below.
33 typedef base::Callback<void(const base::DictionaryValue*)>
34 ManagedUsersCallback;
35
36 // Dictionary keys for entry values of |prefs::kManagedUsers|.
37 static const char kAcknowledged[];
38 static const char kChromeAvatar[];
39 static const char kChromeOsAvatar[];
40 static const char kMasterKey[];
41 static const char kPasswordSignatureKey[];
42 static const char kPasswordEncryptionKey[];
43 static const char kName[];
44
45 // Represents a non-existing avatar on Chrome and Chrome OS.
46 static const int kNoAvatar;
47
48 virtual ~ManagedUserSyncService();
49
50 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
51
52 // Extracts the avatar index from the input |avatar_str| and set
53 // |avatar_index| to hold the extracted value. Returns true if the
54 // index was extracted successfully and false otherwise.
55 // |avatar_str| should have the format: "chrome-avatar-index:INDEX"
56 // where INDEX is the integer to be extracted. |avatar_str| can be empty
57 // in case there is no avatar synced for a managed user in which case
58 // |avatar_index| is set to -1.
59 static bool GetAvatarIndex(const std::string& avatar_str,
60 int* avatar_index);
61
62 // Given an |avatar_index|, it returns a string of the form:
63 // "chrome-avatar-index:INDEX" where INDEX = |avatar_index|.
64 // It is exposed for testing purposes only.
65 static std::string BuildAvatarString(int avatar_index);
66
67 void AddObserver(ManagedUserSyncServiceObserver* observer);
68 void RemoveObserver(ManagedUserSyncServiceObserver* observer);
69
70 void AddManagedUser(const std::string& id,
71 const std::string& name,
72 const std::string& master_key,
73 const std::string& password_signature_key,
74 const std::string& password_encryption_key,
75 int avatar_index);
76 void UpdateManagedUser(const std::string& id,
77 const std::string& name,
78 const std::string& master_key,
79 const std::string& signature_key,
80 const std::string& encryption_key,
81 int avatar_index);
82
83 void DeleteManagedUser(const std::string& id);
84
85 // Updates the managed user avatar only if the managed user has
86 // no avatar and |avatar_index| is set to some value other than
87 // |kNoAvatar|. If |avatar_index| equals |kNoAvatar| and the
88 // managed user has an avatar, it will be cleared. However,
89 // to clear an avatar call the convenience method |ClearManagedUserAvatar()|.
90 // Returns true if the avatar value is changed (either updated or cleared)
91 // and false otherwise.
92 bool UpdateManagedUserAvatarIfNeeded(const std::string& id, int avatar_index);
93 void ClearManagedUserAvatar(const std::string& id);
94
95 // Returns a dictionary containing all managed users managed by this
96 // custodian. This method should only be called once this service has started
97 // syncing managed users (i.e. has finished its initial merge of local and
98 // server-side data, via MergeDataAndStartSyncing), as the stored data might
99 // be outdated before that.
100 const base::DictionaryValue* GetManagedUsers();
101
102 // Calls the passed |callback| with a dictionary containing all managed users
103 // managed by this custodian.
104 void GetManagedUsersAsync(const ManagedUsersCallback& callback);
105
106 // KeyedService implementation:
107 virtual void Shutdown() OVERRIDE;
108
109 // SyncableService implementation:
110 virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
111 syncer::ModelType type,
112 const syncer::SyncDataList& initial_sync_data,
113 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
114 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
115 virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
116 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
117 OVERRIDE;
118 virtual syncer::SyncError ProcessSyncChanges(
119 const tracked_objects::Location& from_here,
120 const syncer::SyncChangeList& change_list) OVERRIDE;
121
122 private:
123 friend class ManagedUserSyncServiceFactory;
124
125 // Use |ManagedUserSyncServiceFactory::GetForProfile(...)| to get an
126 // instance of this service.
127 explicit ManagedUserSyncService(PrefService* prefs);
128
129 void OnLastSignedInUsernameChange();
130
131 scoped_ptr<base::DictionaryValue> CreateDictionary(
132 const std::string& name,
133 const std::string& master_key,
134 const std::string& signature_key,
135 const std::string& encryption_key,
136 int avatar_index);
137
138 void UpdateManagedUserImpl(const std::string& id,
139 const std::string& name,
140 const std::string& master_key,
141 const std::string& signature_key,
142 const std::string& encryption_key,
143 int avatar_index,
144 bool add_user);
145
146 void NotifyManagedUserAcknowledged(const std::string& managed_user_id);
147 void NotifyManagedUsersSyncingStopped();
148 void NotifyManagedUsersChanged();
149
150 void DispatchCallbacks();
151
152 PrefService* prefs_;
153 PrefChangeRegistrar pref_change_registrar_;
154
155 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
156 scoped_ptr<syncer::SyncErrorFactory> error_handler_;
157
158 ObserverList<ManagedUserSyncServiceObserver> observers_;
159
160 std::vector<ManagedUsersCallback> callbacks_;
161
162 DISALLOW_COPY_AND_ASSIGN(ManagedUserSyncService);
163 };
164
165 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698