• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_PREF_MAPPING_SERVICE_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_PREF_MAPPING_SERVICE_H_
7 
8 #include "base/callback.h"
9 #include "base/callback_list.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/prefs/pref_change_registrar.h"
13 #include "chrome/browser/supervised_user/supervised_users.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 
16 class PrefService;
17 class SupervisedUserSharedSettingsService;
18 
19 // SupervisedUserPrefMappingService maps shared supervised user settings to user
20 // preferences. When a shared supervised user setting is updated via sync, the
21 // corresponding local user preference is set to this new value.
22 class SupervisedUserPrefMappingService : public KeyedService {
23  public:
24   typedef base::CallbackList<void(const std::string&, const std::string&)>
25       CallbackList;
26 
27   SupervisedUserPrefMappingService(
28       PrefService* prefs,
29       SupervisedUserSharedSettingsService* shared_settings);
30   virtual ~SupervisedUserPrefMappingService();
31 
32   // KeyedService implementation:
33   virtual void Shutdown() OVERRIDE;
34 
35   void Init();
36 
37   // Updates the supervised user shared setting when the avatar has changed.
38   void OnAvatarChanged();
39 
40   // Called when a supervised user shared setting was changed by receiving new
41   // sync data. Updates the corresponding user pref.
42   void OnSharedSettingChanged(const std::string& su_id, const std::string& key);
43 
44  private:
45   // Returns the current chrome avatar index that is stored as a supervised user
46   // shared setting, or -1 if no avatar index is stored.
47   int GetChromeAvatarIndex();
48 
49   PrefService* prefs_;
50   SupervisedUserSharedSettingsService* shared_settings_;
51   scoped_ptr<CallbackList::Subscription> subscription_;
52   std::string supervised_user_id_;
53   PrefChangeRegistrar pref_change_registrar_;
54   base::WeakPtrFactory<SupervisedUserPrefMappingService> weak_ptr_factory_;
55 
56   DISALLOW_COPY_AND_ASSIGN(SupervisedUserPrefMappingService);
57 };
58 
59 #endif  // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_PREF_MAPPING_SERVICE_H_
60