Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.cc

Issue 2568973002: chromeos: Replace user image notifications with observer (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h" 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" 9 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
10 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" 10 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h"
(...skipping 27 matching lines...) Expand all
38 38
39 } // anonymous namespace 39 } // anonymous namespace
40 40
41 UserImageSyncObserver::Observer::~Observer() {} 41 UserImageSyncObserver::Observer::~Observer() {}
42 42
43 UserImageSyncObserver::UserImageSyncObserver(const user_manager::User* user) 43 UserImageSyncObserver::UserImageSyncObserver(const user_manager::User* user)
44 : user_(user), 44 : user_(user),
45 prefs_(NULL), 45 prefs_(NULL),
46 is_synced_(false), 46 is_synced_(false),
47 local_image_changed_(false) { 47 local_image_changed_(false) {
48 user_manager::UserManager::Get()->AddObserver(this);
49
48 notification_registrar_.reset(new content::NotificationRegistrar); 50 notification_registrar_.reset(new content::NotificationRegistrar);
49 notification_registrar_->Add(this,
50 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
51 content::NotificationService::AllSources());
52 if (Profile* profile = ProfileHelper::Get()->GetProfileByUser(user)) { 51 if (Profile* profile = ProfileHelper::Get()->GetProfileByUser(user)) {
53 OnProfileGained(profile); 52 OnProfileGained(profile);
54 } else { 53 } else {
55 notification_registrar_->Add(this, 54 notification_registrar_->Add(this,
56 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 55 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
57 content::NotificationService::AllSources()); 56 content::NotificationService::AllSources());
58 } 57 }
59 } 58 }
60 59
61 UserImageSyncObserver::~UserImageSyncObserver() { 60 UserImageSyncObserver::~UserImageSyncObserver() {
62 if (!is_synced_ && prefs_) 61 if (!is_synced_ && prefs_)
63 prefs_->RemoveObserver(this); 62 prefs_->RemoveObserver(this);
64 if (pref_change_registrar_) 63 if (pref_change_registrar_)
65 pref_change_registrar_->RemoveAll(); 64 pref_change_registrar_->RemoveAll();
65
66 user_manager::UserManager::Get()->RemoveObserver(this);
66 } 67 }
67 68
68 // static 69 // static
69 void UserImageSyncObserver::RegisterProfilePrefs( 70 void UserImageSyncObserver::RegisterProfilePrefs(
70 user_prefs::PrefRegistrySyncable* registry_) { 71 user_prefs::PrefRegistrySyncable* registry_) {
71 registry_->RegisterDictionaryPref( 72 registry_->RegisterDictionaryPref(
72 kUserImageInfo, 73 kUserImageInfo,
73 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); 74 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
74 } 75 }
75 76
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 OnInitialSync(); 118 OnInitialSync();
118 } else if (CanUpdateLocalImageNow()) { 119 } else if (CanUpdateLocalImageNow()) {
119 UpdateLocalImageFromSynced(); 120 UpdateLocalImageFromSynced();
120 } 121 }
121 } 122 }
122 123
123 void UserImageSyncObserver::Observe( 124 void UserImageSyncObserver::Observe(
124 int type, 125 int type,
125 const content::NotificationSource& source, 126 const content::NotificationSource& source,
126 const content::NotificationDetails& details) { 127 const content::NotificationDetails& details) {
127 if (type == chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) { 128 DCHECK_EQ(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, type);
128 if (Profile* profile = ProfileHelper::Get()->GetProfileByUser(user_)) { 129
129 notification_registrar_->Remove( 130 if (Profile* profile = ProfileHelper::Get()->GetProfileByUser(user_)) {
130 this, 131 notification_registrar_->Remove(
131 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 132 this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
132 content::NotificationService::AllSources()); 133 content::NotificationService::AllSources());
133 OnProfileGained(profile); 134 OnProfileGained(profile);
134 }
135 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) {
136 if (is_synced_)
137 UpdateSyncedImageFromLocal();
138 else
139 local_image_changed_ = true;
140 } else {
141 NOTREACHED();
142 } 135 }
143 } 136 }
144 137
138 void UserImageSyncObserver::OnUserImageChanged(const user_manager::User& user) {
139 if (is_synced_)
140 UpdateSyncedImageFromLocal();
141 else
142 local_image_changed_ = true;
143 }
144
145 void UserImageSyncObserver::OnIsSyncingChanged() { 145 void UserImageSyncObserver::OnIsSyncingChanged() {
146 is_synced_ = prefs_->IsPrioritySyncing(); 146 is_synced_ = prefs_->IsPrioritySyncing();
147 if (is_synced_) { 147 if (is_synced_) {
148 prefs_->RemoveObserver(this); 148 prefs_->RemoveObserver(this);
149 OnInitialSync(); 149 OnInitialSync();
150 } 150 }
151 } 151 }
152 152
153 void UserImageSyncObserver::UpdateSyncedImageFromLocal() { 153 void UserImageSyncObserver::UpdateSyncedImageFromLocal() {
154 int local_index = user_->image_index(); 154 int local_index = user_->image_index();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 UserImageScreen* screen = UserImageScreen::Get(wizard_controller); 192 UserImageScreen* screen = UserImageScreen::Get(wizard_controller);
193 if (wizard_controller->current_screen() == screen) { 193 if (wizard_controller->current_screen() == screen) {
194 if (screen->user_selected_image()) 194 if (screen->user_selected_image())
195 return false; 195 return false;
196 } 196 }
197 } 197 }
198 return true; 198 return true;
199 } 199 }
200 200
201 } // namespace chromeos 201 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698