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 once this service has started |
| 50 // syncing managed users (i.e. has finished its initial merge of local and |
| 51 // server-side data, via MergeDataAndStartSyncing), as the stored data might |
| 52 // be outdated before that. |
| 53 const base::DictionaryValue* GetManagedUsers(); |
| 54 |
| 55 // Calls the passed |callback| with a dictionary containing all managed users |
| 56 // managed by this custodian. |
| 57 void GetManagedUsersAsync(const ManagedUsersCallback& callback); |
| 58 |
37 // BrowserContextKeyedService implementation: | 59 // BrowserContextKeyedService implementation: |
38 virtual void Shutdown() OVERRIDE; | 60 virtual void Shutdown() OVERRIDE; |
39 | 61 |
40 // SyncableService implementation: | 62 // SyncableService implementation: |
41 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 63 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
42 syncer::ModelType type, | 64 syncer::ModelType type, |
43 const syncer::SyncDataList& initial_sync_data, | 65 const syncer::SyncDataList& initial_sync_data, |
44 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 66 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
45 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 67 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
46 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 68 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
47 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | 69 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const |
48 OVERRIDE; | 70 OVERRIDE; |
49 virtual syncer::SyncError ProcessSyncChanges( | 71 virtual syncer::SyncError ProcessSyncChanges( |
50 const tracked_objects::Location& from_here, | 72 const tracked_objects::Location& from_here, |
51 const syncer::SyncChangeList& change_list) OVERRIDE; | 73 const syncer::SyncChangeList& change_list) OVERRIDE; |
52 | 74 |
53 private: | 75 private: |
54 friend class ManagedUserSyncServiceFactory; | 76 friend class ManagedUserSyncServiceFactory; |
55 | 77 |
56 // Use |ManagedUserSyncServiceFactory::GetForProfile(...)| to get an | 78 // Use |ManagedUserSyncServiceFactory::GetForProfile(...)| to get an |
57 // instance of this service. | 79 // instance of this service. |
58 explicit ManagedUserSyncService(PrefService* prefs); | 80 explicit ManagedUserSyncService(PrefService* prefs); |
59 | 81 |
60 void OnLastSignedInUsernameChange(); | 82 void OnLastSignedInUsernameChange(); |
61 | 83 |
62 void NotifyManagedUserAcknowledged(const std::string& managed_user_id); | 84 void NotifyManagedUserAcknowledged(const std::string& managed_user_id); |
63 void NotifyManagedUsersSyncingStopped(); | 85 void NotifyManagedUsersSyncingStopped(); |
64 | 86 |
| 87 void DispatchCallbacks(); |
| 88 |
65 PrefService* prefs_; | 89 PrefService* prefs_; |
66 PrefChangeRegistrar pref_change_registrar_; | 90 PrefChangeRegistrar pref_change_registrar_; |
67 | 91 |
68 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 92 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
69 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 93 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
70 | 94 |
71 ObserverList<ManagedUserSyncServiceObserver> observers_; | 95 ObserverList<ManagedUserSyncServiceObserver> observers_; |
72 | 96 |
| 97 std::vector<ManagedUsersCallback> callbacks_; |
| 98 |
73 DISALLOW_COPY_AND_ASSIGN(ManagedUserSyncService); | 99 DISALLOW_COPY_AND_ASSIGN(ManagedUserSyncService); |
74 }; | 100 }; |
75 | 101 |
76 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_ | 102 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SYNC_SERVICE_H_ |
OLD | NEW |