OLD | NEW |
---|---|
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_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_ |
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_ |
7 | 7 |
8 #include <vector> | |
9 | |
10 #include "base/callback_forward.h" | |
8 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
9 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
10 #include "base/prefs/pref_change_registrar.h" | 13 #include "base/prefs/pref_change_registrar.h" |
11 #include "chrome/browser/managed_mode/managed_user_sync_service_observer.h" | 14 #include "chrome/browser/managed_mode/managed_user_sync_service_observer.h" |
12 #include "chrome/browser/managed_mode/managed_users.h" | 15 #include "chrome/browser/managed_mode/managed_users.h" |
13 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
14 #include "sync/api/syncable_service.h" | 17 #include "sync/api/syncable_service.h" |
15 | 18 |
16 class PrefService; | 19 namespace base { |
20 class DictionaryValue; | |
21 } | |
17 | 22 |
18 namespace user_prefs { | 23 namespace user_prefs { |
19 class PrefRegistrySyncable; | 24 class PrefRegistrySyncable; |
20 } | 25 } |
21 | 26 |
27 class PrefService; | |
28 | |
22 class ManagedUserSyncService : public BrowserContextKeyedService, | 29 class ManagedUserSyncService : public BrowserContextKeyedService, |
23 public syncer::SyncableService { | 30 public syncer::SyncableService { |
24 public: | 31 public: |
32 // For use with GetAllManagedUsers() below. | |
33 typedef base::Callback<void(const base::DictionaryValue*)> | |
34 ManagedUsersCallback; | |
35 | |
25 virtual ~ManagedUserSyncService(); | 36 virtual ~ManagedUserSyncService(); |
26 | 37 |
27 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 38 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
28 | 39 |
29 void AddObserver(ManagedUserSyncServiceObserver* observer); | 40 void AddObserver(ManagedUserSyncServiceObserver* observer); |
30 void RemoveObserver(ManagedUserSyncServiceObserver* observer); | 41 void RemoveObserver(ManagedUserSyncServiceObserver* observer); |
31 | 42 |
32 void AddManagedUser(const std::string& id, | 43 void AddManagedUser(const std::string& id, |
33 const std::string& name, | 44 const std::string& name, |
34 const std::string& master_key); | 45 const std::string& master_key); |
35 void DeleteManagedUser(const std::string& id); | 46 void DeleteManagedUser(const std::string& id); |
36 | 47 |
48 // Returns a dictionary containing all managed users managed by this | |
49 // custodian. This method should only be called if this service is syncing | |
50 // managed users (as the stored data might be outdated before that). | |
Pam (message me for reviews)
2013/09/05 11:11:56
I don't understand this comment. What does it mean
Bernhard Bauer
2013/09/05 12:15:41
A SyncableService needs to do an initial merge of
Pam (message me for reviews)
2013/09/05 12:29:30
OK -- could you add a brief comment explaining bot
Bernhard Bauer
2013/09/05 12:52:35
Done.
| |
51 const base::DictionaryValue* GetManagedUsers(); | |
52 | |
53 // Calls the passed |callback| with a dictionary containing all managed users | |
54 // managed by this custodian. | |
55 void GetManagedUsersAsync(const ManagedUsersCallback& callback); | |
56 | |
37 // BrowserContextKeyedService implementation: | 57 // BrowserContextKeyedService implementation: |
38 virtual void Shutdown() OVERRIDE; | 58 virtual void Shutdown() OVERRIDE; |
39 | 59 |
40 // SyncableService implementation: | 60 // SyncableService implementation: |
41 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 61 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
42 syncer::ModelType type, | 62 syncer::ModelType type, |
43 const syncer::SyncDataList& initial_sync_data, | 63 const syncer::SyncDataList& initial_sync_data, |
44 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 64 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
45 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 65 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
46 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 66 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
47 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | 67 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const |
48 OVERRIDE; | 68 OVERRIDE; |
49 virtual syncer::SyncError ProcessSyncChanges( | 69 virtual syncer::SyncError ProcessSyncChanges( |
50 const tracked_objects::Location& from_here, | 70 const tracked_objects::Location& from_here, |
51 const syncer::SyncChangeList& change_list) OVERRIDE; | 71 const syncer::SyncChangeList& change_list) OVERRIDE; |
52 | 72 |
53 private: | 73 private: |
54 friend class ManagedUserSyncServiceFactory; | 74 friend class ManagedUserSyncServiceFactory; |
55 | 75 |
56 // Use |ManagedUserSyncServiceFactory::GetForProfile(...)| to get an | 76 // Use |ManagedUserSyncServiceFactory::GetForProfile(...)| to get an |
57 // instance of this service. | 77 // instance of this service. |
58 explicit ManagedUserSyncService(PrefService* prefs); | 78 explicit ManagedUserSyncService(PrefService* prefs); |
59 | 79 |
60 void OnLastSignedInUsernameChange(); | 80 void OnLastSignedInUsernameChange(); |
61 | 81 |
62 void NotifyManagedUserAcknowledged(const std::string& managed_user_id); | 82 void NotifyManagedUserAcknowledged(const std::string& managed_user_id); |
63 void NotifyManagedUsersSyncingStopped(); | 83 void NotifyManagedUsersSyncingStopped(); |
64 | 84 |
85 void DispatchCallbacks(); | |
86 | |
65 PrefService* prefs_; | 87 PrefService* prefs_; |
66 PrefChangeRegistrar pref_change_registrar_; | 88 PrefChangeRegistrar pref_change_registrar_; |
67 | 89 |
68 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 90 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
69 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 91 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
70 | 92 |
71 ObserverList<ManagedUserSyncServiceObserver> observers_; | 93 ObserverList<ManagedUserSyncServiceObserver> observers_; |
72 | 94 |
95 std::vector<ManagedUsersCallback> callbacks_; | |
96 | |
73 DISALLOW_COPY_AND_ASSIGN(ManagedUserSyncService); | 97 DISALLOW_COPY_AND_ASSIGN(ManagedUserSyncService); |
74 }; | 98 }; |
75 | 99 |
76 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_ | 100 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_ |
OLD | NEW |