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 #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 "base/prefs/pref_change_registrar.h" | 8 #include "base/prefs/pref_change_registrar.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" | 12 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" |
13 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" | 13 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" |
| 14 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
14 #include "chrome/browser/chromeos/login/wizard_controller.h" | 15 #include "chrome/browser/chromeos/login/wizard_controller.h" |
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
16 #include "chrome/browser/prefs/pref_service_syncable.h" | 17 #include "chrome/browser/prefs/pref_service_syncable.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "components/user_manager/user.h" | 21 #include "components/user_manager/user.h" |
21 #include "components/user_manager/user_image/default_user_images.h" | 22 #include "components/user_manager/user_image/default_user_images.h" |
22 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 VLOG(1) << "Saved avatar index " << local_index << " to sync."; | 176 VLOG(1) << "Saved avatar index " << local_index << " to sync."; |
176 } | 177 } |
177 | 178 |
178 void UserImageSyncObserver::UpdateLocalImageFromSynced() { | 179 void UserImageSyncObserver::UpdateLocalImageFromSynced() { |
179 int synced_index; | 180 int synced_index; |
180 GetSyncedImageIndex(&synced_index); | 181 GetSyncedImageIndex(&synced_index); |
181 int local_index = user_->image_index(); | 182 int local_index = user_->image_index(); |
182 if ((synced_index == local_index) || !IsIndexSupported(synced_index)) | 183 if ((synced_index == local_index) || !IsIndexSupported(synced_index)) |
183 return; | 184 return; |
184 UserImageManager* image_manager = | 185 UserImageManager* image_manager = |
185 UserManager::Get()->GetUserImageManager(user_->email()); | 186 ChromeUserManager::Get()->GetUserImageManager(user_->email()); |
186 if (synced_index == user_manager::User::USER_IMAGE_PROFILE) { | 187 if (synced_index == user_manager::User::USER_IMAGE_PROFILE) { |
187 image_manager->SaveUserImageFromProfileImage(); | 188 image_manager->SaveUserImageFromProfileImage(); |
188 } else { | 189 } else { |
189 image_manager->SaveUserDefaultImageIndex(synced_index); | 190 image_manager->SaveUserDefaultImageIndex(synced_index); |
190 } | 191 } |
191 VLOG(1) << "Loaded avatar index " << synced_index << " from sync."; | 192 VLOG(1) << "Loaded avatar index " << synced_index << " from sync."; |
192 } | 193 } |
193 | 194 |
194 bool UserImageSyncObserver::GetSyncedImageIndex(int* index) { | 195 bool UserImageSyncObserver::GetSyncedImageIndex(int* index) { |
195 *index = user_manager::User::USER_IMAGE_INVALID; | 196 *index = user_manager::User::USER_IMAGE_INVALID; |
196 const base::DictionaryValue* dict = prefs_->GetDictionary(kUserImageInfo); | 197 const base::DictionaryValue* dict = prefs_->GetDictionary(kUserImageInfo); |
197 return dict && dict->GetInteger(kImageIndex, index); | 198 return dict && dict->GetInteger(kImageIndex, index); |
198 } | 199 } |
199 | 200 |
200 bool UserImageSyncObserver::CanUpdateLocalImageNow() { | 201 bool UserImageSyncObserver::CanUpdateLocalImageNow() { |
201 if (WizardController* wizard_controller = | 202 if (WizardController* wizard_controller = |
202 WizardController::default_controller()) { | 203 WizardController::default_controller()) { |
203 UserImageScreen* screen = wizard_controller->GetUserImageScreen(); | 204 UserImageScreen* screen = wizard_controller->GetUserImageScreen(); |
204 if (wizard_controller->current_screen() == screen) { | 205 if (wizard_controller->current_screen() == screen) { |
205 if (screen->user_selected_image()) | 206 if (screen->user_selected_image()) |
206 return false; | 207 return false; |
207 } | 208 } |
208 } | 209 } |
209 return true; | 210 return true; |
210 } | 211 } |
211 | 212 |
212 } // namespace chromeos | 213 } // namespace chromeos |
213 | 214 |
OLD | NEW |