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/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" | 11 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" |
12 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" | 12 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" |
| 13 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
13 #include "chrome/browser/chromeos/login/wizard_controller.h" | 14 #include "chrome/browser/chromeos/login/wizard_controller.h" |
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
15 #include "chrome/browser/prefs/pref_service_syncable.h" | 16 #include "chrome/browser/prefs/pref_service_syncable.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "components/user_manager/user.h" | 18 #include "components/user_manager/user.h" |
18 #include "components/user_manager/user_image/default_user_images.h" | 19 #include "components/user_manager/user_image/default_user_images.h" |
| 20 #include "components/user_manager/user_manager.h" |
19 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
21 | 23 |
22 namespace chromeos { | 24 namespace chromeos { |
23 namespace { | 25 namespace { |
24 | 26 |
25 // A dictionary containing info about user image. | 27 // A dictionary containing info about user image. |
26 const char kUserImageInfo[] = "user_image_info"; | 28 const char kUserImageInfo[] = "user_image_info"; |
27 // Path to value with image index. | 29 // Path to value with image index. |
28 const char kImageIndex[] = "image_index"; | 30 const char kImageIndex[] = "image_index"; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 VLOG(1) << "Saved avatar index " << local_index << " to sync."; | 163 VLOG(1) << "Saved avatar index " << local_index << " to sync."; |
162 } | 164 } |
163 | 165 |
164 void UserImageSyncObserver::UpdateLocalImageFromSynced() { | 166 void UserImageSyncObserver::UpdateLocalImageFromSynced() { |
165 int synced_index; | 167 int synced_index; |
166 GetSyncedImageIndex(&synced_index); | 168 GetSyncedImageIndex(&synced_index); |
167 int local_index = user_->image_index(); | 169 int local_index = user_->image_index(); |
168 if ((synced_index == local_index) || !IsIndexSupported(synced_index)) | 170 if ((synced_index == local_index) || !IsIndexSupported(synced_index)) |
169 return; | 171 return; |
170 UserImageManager* image_manager = | 172 UserImageManager* image_manager = |
171 UserManager::Get()->GetUserImageManager(user_->email()); | 173 ChromeUserManager::Get()->GetUserImageManager(user_->email()); |
172 if (synced_index == user_manager::User::USER_IMAGE_PROFILE) { | 174 if (synced_index == user_manager::User::USER_IMAGE_PROFILE) { |
173 image_manager->SaveUserImageFromProfileImage(); | 175 image_manager->SaveUserImageFromProfileImage(); |
174 } else { | 176 } else { |
175 image_manager->SaveUserDefaultImageIndex(synced_index); | 177 image_manager->SaveUserDefaultImageIndex(synced_index); |
176 } | 178 } |
177 VLOG(1) << "Loaded avatar index " << synced_index << " from sync."; | 179 VLOG(1) << "Loaded avatar index " << synced_index << " from sync."; |
178 } | 180 } |
179 | 181 |
180 bool UserImageSyncObserver::GetSyncedImageIndex(int* index) { | 182 bool UserImageSyncObserver::GetSyncedImageIndex(int* index) { |
181 *index = user_manager::User::USER_IMAGE_INVALID; | 183 *index = user_manager::User::USER_IMAGE_INVALID; |
182 const base::DictionaryValue* dict = prefs_->GetDictionary(kUserImageInfo); | 184 const base::DictionaryValue* dict = prefs_->GetDictionary(kUserImageInfo); |
183 return dict && dict->GetInteger(kImageIndex, index); | 185 return dict && dict->GetInteger(kImageIndex, index); |
184 } | 186 } |
185 | 187 |
186 bool UserImageSyncObserver::CanUpdateLocalImageNow() { | 188 bool UserImageSyncObserver::CanUpdateLocalImageNow() { |
187 if (WizardController* wizard_controller = | 189 if (WizardController* wizard_controller = |
188 WizardController::default_controller()) { | 190 WizardController::default_controller()) { |
189 UserImageScreen* screen = wizard_controller->GetUserImageScreen(); | 191 UserImageScreen* screen = wizard_controller->GetUserImageScreen(); |
190 if (wizard_controller->current_screen() == screen) { | 192 if (wizard_controller->current_screen() == screen) { |
191 if (screen->user_selected_image()) | 193 if (screen->user_selected_image()) |
192 return false; | 194 return false; |
193 } | 195 } |
194 } | 196 } |
195 return true; | 197 return true; |
196 } | 198 } |
197 | 199 |
198 } // namespace chromeos | 200 } // namespace chromeos |
199 | 201 |
OLD | NEW |