OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_SYNC_OBSERVER_H_ | 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_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_SYNC_OBSERVER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "components/syncable_prefs/pref_service_syncable_observer.h" | 12 #include "components/sync_preferences/pref_service_syncable_observer.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 | 14 |
15 class PrefChangeRegistrar; | 15 class PrefChangeRegistrar; |
16 class Profile; | 16 class Profile; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class NotificationRegistrar; | 19 class NotificationRegistrar; |
20 } | 20 } |
21 | 21 |
22 namespace syncable_prefs { | 22 namespace sync_preferences { |
23 class PrefServiceSyncable; | 23 class PrefServiceSyncable; |
24 } | 24 } |
25 | 25 |
26 namespace user_prefs { | 26 namespace user_prefs { |
27 class PrefRegistrySyncable; | 27 class PrefRegistrySyncable; |
28 } | 28 } |
29 | 29 |
30 namespace user_manager { | 30 namespace user_manager { |
31 class User; | 31 class User; |
32 } | 32 } |
33 | 33 |
34 namespace chromeos { | 34 namespace chromeos { |
35 | 35 |
36 // This class is responsible for keeping local user image synced with | 36 // This class is responsible for keeping local user image synced with |
37 // image saved in syncable preference. | 37 // image saved in syncable preference. |
38 class UserImageSyncObserver | 38 class UserImageSyncObserver |
39 : public syncable_prefs::PrefServiceSyncableObserver, | 39 : public sync_preferences::PrefServiceSyncableObserver, |
40 public content::NotificationObserver { | 40 public content::NotificationObserver { |
41 public: | 41 public: |
42 class Observer { | 42 class Observer { |
43 public: | 43 public: |
44 // Called right after image info synced (i.e. |is_synced| became |true|). | 44 // Called right after image info synced (i.e. |is_synced| became |true|). |
45 // |local_image_updated| indicates if we desided to update local image in | 45 // |local_image_updated| indicates if we desided to update local image in |
46 // result of sync. | 46 // result of sync. |
47 virtual void OnInitialSync(bool local_image_updated) = 0; | 47 virtual void OnInitialSync(bool local_image_updated) = 0; |
48 virtual ~Observer(); | 48 virtual ~Observer(); |
49 }; | 49 }; |
50 | 50 |
51 public: | 51 public: |
52 explicit UserImageSyncObserver(const user_manager::User* user); | 52 explicit UserImageSyncObserver(const user_manager::User* user); |
53 ~UserImageSyncObserver() override; | 53 ~UserImageSyncObserver() override; |
54 | 54 |
55 // Register syncable preference for profile. | 55 // Register syncable preference for profile. |
56 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 56 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
57 | 57 |
58 // Returns |true| if sync was initialized and prefs have actual state. | 58 // Returns |true| if sync was initialized and prefs have actual state. |
59 bool is_synced() const { return is_synced_; } | 59 bool is_synced() const { return is_synced_; } |
60 | 60 |
61 // Adds |observer| into observers list. | 61 // Adds |observer| into observers list. |
62 void AddObserver(Observer* observer); | 62 void AddObserver(Observer* observer); |
63 // Removes |observer| from observers list. | 63 // Removes |observer| from observers list. |
64 void RemoveObserver(Observer* observer); | 64 void RemoveObserver(Observer* observer); |
65 | 65 |
66 private: | 66 private: |
67 // syncable_prefs::PrefServiceSyncableObserver implementation. | 67 // sync_preferences::PrefServiceSyncableObserver implementation. |
68 void OnIsSyncingChanged() override; | 68 void OnIsSyncingChanged() override; |
69 | 69 |
70 // content::NotificationObserver implementation. | 70 // content::NotificationObserver implementation. |
71 void Observe(int type, | 71 void Observe(int type, |
72 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
73 const content::NotificationDetails& details) override; | 73 const content::NotificationDetails& details) override; |
74 | 74 |
75 // Called after user profile was loaded. | 75 // Called after user profile was loaded. |
76 void OnProfileGained(Profile* profile); | 76 void OnProfileGained(Profile* profile); |
77 | 77 |
(...skipping 12 matching lines...) Expand all Loading... |
90 | 90 |
91 // Gets synced image index. Returns false if user has no needed preferences. | 91 // Gets synced image index. Returns false if user has no needed preferences. |
92 bool GetSyncedImageIndex(int* result); | 92 bool GetSyncedImageIndex(int* result); |
93 | 93 |
94 // If it is allowed to change user image now. | 94 // If it is allowed to change user image now. |
95 bool CanUpdateLocalImageNow(); | 95 bool CanUpdateLocalImageNow(); |
96 | 96 |
97 const user_manager::User* user_; | 97 const user_manager::User* user_; |
98 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | 98 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; |
99 std::unique_ptr<content::NotificationRegistrar> notification_registrar_; | 99 std::unique_ptr<content::NotificationRegistrar> notification_registrar_; |
100 syncable_prefs::PrefServiceSyncable* prefs_; | 100 sync_preferences::PrefServiceSyncable* prefs_; |
101 bool is_synced_; | 101 bool is_synced_; |
102 // Indicates if local user image changed during initialization. | 102 // Indicates if local user image changed during initialization. |
103 bool local_image_changed_; | 103 bool local_image_changed_; |
104 base::ObserverList<Observer> observer_list_; | 104 base::ObserverList<Observer> observer_list_; |
105 }; | 105 }; |
106 | 106 |
107 } // namespace chromeos | 107 } // namespace chromeos |
108 | 108 |
109 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_SYNC_OBSERVER_H
_ | 109 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_SYNC_OBSERVER_H
_ |
110 | 110 |
OLD | NEW |