OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/screens/user_image_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 const int kSyncTimeoutSeconds = 10; | 55 const int kSyncTimeoutSeconds = 10; |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 UserImageScreen::UserImageScreen(ScreenObserver* screen_observer, | 59 UserImageScreen::UserImageScreen(ScreenObserver* screen_observer, |
60 UserImageScreenActor* actor) | 60 UserImageScreenActor* actor) |
61 : WizardScreen(screen_observer), | 61 : WizardScreen(screen_observer), |
62 actor_(actor), | 62 actor_(actor), |
63 accept_photo_after_decoding_(false), | 63 accept_photo_after_decoding_(false), |
64 selected_image_(user_manager::User::USER_IMAGE_INVALID), | 64 selected_image_(user_manager::User::USER_IMAGE_INVALID), |
65 profile_picture_enabled_(false), | |
66 profile_picture_data_url_(url::kAboutBlankURL), | 65 profile_picture_data_url_(url::kAboutBlankURL), |
67 profile_picture_absent_(false), | 66 profile_picture_absent_(false), |
68 is_screen_ready_(false), | 67 is_screen_ready_(false), |
69 user_has_selected_image_(false) { | 68 user_has_selected_image_(false) { |
70 actor_->SetDelegate(this); | 69 actor_->SetDelegate(this); |
71 SetProfilePictureEnabled(true); | 70 notification_registrar_.Add(this, |
| 71 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, |
| 72 content::NotificationService::AllSources()); |
| 73 notification_registrar_.Add(this, |
| 74 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, |
| 75 content::NotificationService::AllSources()); |
72 notification_registrar_.Add(this, | 76 notification_registrar_.Add(this, |
73 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 77 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
74 content::NotificationService::AllSources()); | 78 content::NotificationService::AllSources()); |
75 } | 79 } |
76 | 80 |
77 UserImageScreen::~UserImageScreen() { | 81 UserImageScreen::~UserImageScreen() { |
78 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | 82 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); |
79 if (actor_) | 83 if (actor_) |
80 actor_->SetDelegate(NULL); | 84 actor_->SetDelegate(NULL); |
81 if (image_decoder_.get()) | 85 if (image_decoder_.get()) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 206 } |
203 if (user_has_selected_image_) { | 207 if (user_has_selected_image_) { |
204 UMA_HISTOGRAM_ENUMERATION("UserImage.FirstTimeChoice", | 208 UMA_HISTOGRAM_ENUMERATION("UserImage.FirstTimeChoice", |
205 uma_index, | 209 uma_index, |
206 user_manager::kHistogramImagesCount); | 210 user_manager::kHistogramImagesCount); |
207 } | 211 } |
208 ExitScreen(); | 212 ExitScreen(); |
209 } | 213 } |
210 | 214 |
211 | 215 |
212 void UserImageScreen::SetProfilePictureEnabled(bool profile_picture_enabled) { | |
213 if (profile_picture_enabled_ == profile_picture_enabled) | |
214 return; | |
215 profile_picture_enabled_ = profile_picture_enabled; | |
216 if (profile_picture_enabled) { | |
217 notification_registrar_.Add(this, | |
218 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | |
219 content::NotificationService::AllSources()); | |
220 notification_registrar_.Add( | |
221 this, | |
222 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | |
223 content::NotificationService::AllSources()); | |
224 } else { | |
225 notification_registrar_.Remove(this, | |
226 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | |
227 content::NotificationService::AllSources()); | |
228 notification_registrar_.Remove( | |
229 this, | |
230 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | |
231 content::NotificationService::AllSources()); | |
232 } | |
233 if (actor_) | |
234 actor_->SetProfilePictureEnabled(profile_picture_enabled); | |
235 } | |
236 | |
237 void UserImageScreen::SetUserID(const std::string& user_id) { | |
238 DCHECK(!user_id.empty()); | |
239 user_id_ = user_id; | |
240 } | |
241 | |
242 void UserImageScreen::PrepareToShow() { | 216 void UserImageScreen::PrepareToShow() { |
243 if (actor_) | 217 if (actor_) |
244 actor_->PrepareToShow(); | 218 actor_->PrepareToShow(); |
245 } | 219 } |
246 | 220 |
247 const user_manager::User* UserImageScreen::GetUser() { | 221 const user_manager::User* UserImageScreen::GetUser() { |
248 if (user_id_.empty()) | 222 return UserManager::Get()->GetLoggedInUser(); |
249 return UserManager::Get()->GetLoggedInUser(); | |
250 return UserManager::Get()->FindUser(user_id_); | |
251 } | 223 } |
252 | 224 |
253 UserImageManager* UserImageScreen::GetUserImageManager() { | 225 UserImageManager* UserImageScreen::GetUserImageManager() { |
254 return UserManager::Get()->GetUserImageManager(GetUser()->email()); | 226 return UserManager::Get()->GetUserImageManager(GetUser()->email()); |
255 } | 227 } |
256 | 228 |
257 UserImageSyncObserver* UserImageScreen::GetSyncObserver() { | 229 UserImageSyncObserver* UserImageScreen::GetSyncObserver() { |
258 return GetUserImageManager()->GetSyncObserver(); | 230 return GetUserImageManager()->GetSyncObserver(); |
259 } | 231 } |
260 | 232 |
261 void UserImageScreen::Show() { | 233 void UserImageScreen::Show() { |
262 if (!actor_) | 234 if (!actor_) |
263 return; | 235 return; |
264 | 236 |
265 DCHECK(!policy_registrar_); | 237 DCHECK(!policy_registrar_); |
266 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(GetUser()); | 238 if (Profile* profile = ProfileHelper::Get()->GetProfileByUser(GetUser())) { |
267 if (profile) { | |
268 policy::PolicyService* policy_service = | 239 policy::PolicyService* policy_service = |
269 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)-> | 240 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)-> |
270 policy_service(); | 241 policy_service(); |
271 if (policy_service->GetPolicies( | 242 if (policy_service->GetPolicies( |
272 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, | 243 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
273 std::string())) | 244 std::string())) |
274 .Get(policy::key::kUserAvatarImage)) { | 245 .Get(policy::key::kUserAvatarImage)) { |
275 // If the user image is managed by policy, skip the screen because the | 246 // If the user image is managed by policy, skip the screen because the |
276 // user is not allowed to override a policy-set image. | 247 // user is not allowed to override a policy-set image. |
277 ExitScreen(); | 248 ExitScreen(); |
(...skipping 24 matching lines...) Expand all Loading... |
302 sync_timer_.reset(new base::Timer( | 273 sync_timer_.reset(new base::Timer( |
303 FROM_HERE, | 274 FROM_HERE, |
304 base::TimeDelta::FromSeconds(kSyncTimeoutSeconds), | 275 base::TimeDelta::FromSeconds(kSyncTimeoutSeconds), |
305 base::Bind(&UserImageScreen::OnSyncTimeout, base::Unretained(this)), | 276 base::Bind(&UserImageScreen::OnSyncTimeout, base::Unretained(this)), |
306 false)); | 277 false)); |
307 sync_timer_->Reset(); | 278 sync_timer_->Reset(); |
308 } | 279 } |
309 } | 280 } |
310 CameraPresenceNotifier::GetInstance()->AddObserver(this); | 281 CameraPresenceNotifier::GetInstance()->AddObserver(this); |
311 actor_->Show(); | 282 actor_->Show(); |
312 actor_->SetProfilePictureEnabled(profile_picture_enabled_); | |
313 | 283 |
314 selected_image_ = GetUser()->image_index(); | 284 selected_image_ = GetUser()->image_index(); |
315 actor_->SelectImage(selected_image_); | 285 actor_->SelectImage(selected_image_); |
316 | 286 |
317 if (profile_picture_enabled_) { | 287 // Start fetching the profile image. |
318 // Start fetching the profile image. | 288 GetUserImageManager()->DownloadProfileImage(kProfileDownloadReason); |
319 GetUserImageManager()->DownloadProfileImage(kProfileDownloadReason); | |
320 } | |
321 } | 289 } |
322 | 290 |
323 void UserImageScreen::Hide() { | 291 void UserImageScreen::Hide() { |
324 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | 292 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); |
| 293 notification_registrar_.RemoveAll(); |
325 if (actor_) | 294 if (actor_) |
326 actor_->Hide(); | 295 actor_->Hide(); |
327 } | 296 } |
328 | 297 |
329 std::string UserImageScreen::GetName() const { | 298 std::string UserImageScreen::GetName() const { |
330 return WizardController::kUserImageScreenName; | 299 return WizardController::kUserImageScreenName; |
331 } | 300 } |
332 | 301 |
333 void UserImageScreen::OnActorDestroyed(UserImageScreenActor* actor) { | 302 void UserImageScreen::OnActorDestroyed(UserImageScreenActor* actor) { |
334 if (actor_ == actor) | 303 if (actor_ == actor) |
335 actor_ = NULL; | 304 actor_ = NULL; |
336 } | 305 } |
337 | 306 |
338 void UserImageScreen::Observe(int type, | 307 void UserImageScreen::Observe(int type, |
339 const content::NotificationSource& source, | 308 const content::NotificationSource& source, |
340 const content::NotificationDetails& details) { | 309 const content::NotificationDetails& details) { |
341 DCHECK(profile_picture_enabled_); | |
342 switch (type) { | 310 switch (type) { |
343 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED: { | 311 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED: { |
344 // We've got a new profile image. | 312 // We've got a new profile image. |
345 profile_picture_data_url_ = webui::GetBitmapDataUrl( | 313 profile_picture_data_url_ = webui::GetBitmapDataUrl( |
346 *content::Details<const gfx::ImageSkia>(details).ptr()->bitmap()); | 314 *content::Details<const gfx::ImageSkia>(details).ptr()->bitmap()); |
347 if (actor_) | 315 if (actor_) |
348 actor_->SendProfileImage(profile_picture_data_url_); | 316 actor_->SendProfileImage(profile_picture_data_url_); |
349 break; | 317 break; |
350 } | 318 } |
351 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED: { | 319 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED: { |
(...skipping 27 matching lines...) Expand all Loading... |
379 | 347 |
380 void UserImageScreen::ExitScreen() { | 348 void UserImageScreen::ExitScreen() { |
381 policy_registrar_.reset(); | 349 policy_registrar_.reset(); |
382 sync_timer_.reset(); | 350 sync_timer_.reset(); |
383 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) | 351 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) |
384 sync_observer->RemoveObserver(this); | 352 sync_observer->RemoveObserver(this); |
385 get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED); | 353 get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED); |
386 } | 354 } |
387 | 355 |
388 } // namespace chromeos | 356 } // namespace chromeos |
OLD | NEW |