Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / user_image_sync_observer.h
blob16a9eb7cb1e1dab7f63f2ba3f7a0d03ecdd357d6
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_SYNC_OBSERVER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_SYNC_OBSERVER_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "chrome/browser/chromeos/login/user_manager.h"
13 #include "chrome/browser/prefs/pref_service_syncable_observer.h"
14 #include "content/public/browser/notification_observer.h"
16 class PrefChangeRegistrar;
17 class PrefServiceSyncable;
18 class Profile;
19 namespace chromeos {
20 class User;
22 namespace content {
23 class NotificationRegistrar;
25 namespace user_prefs {
26 class PrefRegistrySyncable;
29 namespace chromeos {
31 // This class is responsible for keeping local user image synced with
32 // image saved in syncable preference.
33 class UserImageSyncObserver: public PrefServiceSyncableObserver,
34 public content::NotificationObserver {
35 public:
36 class Observer {
37 public:
38 // Called right after image info synced (i.e. |is_synced| became |true|).
39 // |local_image_updated| indicates if we desided to update local image in
40 // result of sync.
41 virtual void OnInitialSync(bool local_image_updated) = 0;
42 virtual ~Observer();
45 public:
46 explicit UserImageSyncObserver(const User* user);
47 virtual ~UserImageSyncObserver();
49 // Register syncable preference for profile.
50 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
52 // Returns |true| if sync was initialized and prefs have actual state.
53 bool is_synced() const { return is_synced_; }
55 // Adds |observer| into observers list.
56 void AddObserver(Observer* observer);
57 // Removes |observer| from observers list.
58 void RemoveObserver(Observer* observer);
60 private:
61 // PrefServiceSyncableObserver implementation.
62 virtual void OnIsSyncingChanged() OVERRIDE;
64 // content::NotificationObserver implementation.
65 virtual void Observe(int type,
66 const content::NotificationSource& source,
67 const content::NotificationDetails& details) OVERRIDE;
69 // Called after user profile was loaded.
70 void OnProfileGained(Profile* profile);
72 // Called when sync servise started it's work and we are able to sync needed
73 // preferences.
74 void OnInitialSync();
76 // Called when preference |pref_name| was changed.j
77 void OnPreferenceChanged(const std::string& pref_name);
79 // Saves local image preferences to sync.
80 void UpdateSyncedImageFromLocal();
82 // Saves sync preferences to local state and updates user image.
83 void UpdateLocalImageFromSynced();
85 // Gets synced image index. Returns false if user has no needed preferences.
86 bool GetSyncedImageIndex(int* result);
88 // If it is allowed to change user image now.
89 bool CanUpdateLocalImageNow();
91 const User* user_;
92 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
93 scoped_ptr<content::NotificationRegistrar> notification_registrar_;
94 PrefServiceSyncable* prefs_;
95 bool is_synced_;
96 // Indicates if local user image changed during initialization.
97 bool local_image_changed_;
98 ObserverList<Observer> observer_list_;
101 } // namespace chromeos
103 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_SYNC_OBSERVER_H_