Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / avatar / user_image_sync_observer.h
blob1b34439d35fcfb8039b8e604440d26273a87bcd8
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_SYNC_OBSERVER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_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/prefs/pref_service_syncable_observer.h"
13 #include "content/public/browser/notification_observer.h"
15 class PrefChangeRegistrar;
16 class PrefServiceSyncable;
17 class Profile;
19 namespace content {
20 class NotificationRegistrar;
22 namespace user_prefs {
23 class PrefRegistrySyncable;
26 namespace user_manager {
27 class User;
30 namespace chromeos {
32 // This class is responsible for keeping local user image synced with
33 // image saved in syncable preference.
34 class UserImageSyncObserver: public PrefServiceSyncableObserver,
35 public content::NotificationObserver {
36 public:
37 class Observer {
38 public:
39 // Called right after image info synced (i.e. |is_synced| became |true|).
40 // |local_image_updated| indicates if we desided to update local image in
41 // result of sync.
42 virtual void OnInitialSync(bool local_image_updated) = 0;
43 virtual ~Observer();
46 public:
47 explicit UserImageSyncObserver(const user_manager::User* user);
48 ~UserImageSyncObserver() override;
50 // Register syncable preference for profile.
51 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
53 // Returns |true| if sync was initialized and prefs have actual state.
54 bool is_synced() const { return is_synced_; }
56 // Adds |observer| into observers list.
57 void AddObserver(Observer* observer);
58 // Removes |observer| from observers list.
59 void RemoveObserver(Observer* observer);
61 private:
62 // PrefServiceSyncableObserver implementation.
63 void OnIsSyncingChanged() override;
65 // content::NotificationObserver implementation.
66 void Observe(int type,
67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) override;
70 // Called after user profile was loaded.
71 void OnProfileGained(Profile* profile);
73 // Called when sync servise started it's work and we are able to sync needed
74 // preferences.
75 void OnInitialSync();
77 // Called when preference |pref_name| was changed.j
78 void OnPreferenceChanged(const std::string& pref_name);
80 // Saves local image preferences to sync.
81 void UpdateSyncedImageFromLocal();
83 // Saves sync preferences to local state and updates user image.
84 void UpdateLocalImageFromSynced();
86 // Gets synced image index. Returns false if user has no needed preferences.
87 bool GetSyncedImageIndex(int* result);
89 // If it is allowed to change user image now.
90 bool CanUpdateLocalImageNow();
92 const user_manager::User* user_;
93 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
94 scoped_ptr<content::NotificationRegistrar> notification_registrar_;
95 PrefServiceSyncable* prefs_;
96 bool is_synced_;
97 // Indicates if local user image changed during initialization.
98 bool local_image_changed_;
99 base::ObserverList<Observer> observer_list_;
102 } // namespace chromeos
104 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_SYNC_OBSERVER_H_