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

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

Powered by Google App Engine
This is Rietveld 408576698