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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 | 49 |
50 namespace chromeos { | 50 namespace chromeos { |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 // Time histogram suffix for profile image download. | 54 // Time histogram suffix for profile image download. |
55 const char kProfileDownloadReason[] = "OOBE"; | 55 const char kProfileDownloadReason[] = "OOBE"; |
56 | 56 |
57 // Maximum amount of time to wait for the user image to sync. | 57 // Maximum amount of time to wait for the user image to sync. |
58 // The screen is shown iff sync failed or time limit exceeded. | 58 // The screen is shown iff sync failed or time limit exceeded. |
59 const int kSyncTimeoutSeconds = 10; | 59 const int kSyncTimeoutSeconds = 0; |
Nikita (slow)
2014/08/13 16:30:29
Debug change?
dzhioev (left Google)
2014/08/13 18:06:42
Yes. Fixed.
| |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 UserImageScreen::UserImageScreen(ScreenObserver* screen_observer, | 63 UserImageScreen::UserImageScreen(ScreenObserver* screen_observer, |
64 UserImageScreenActor* actor) | 64 UserImageScreenActor* actor) |
65 : WizardScreen(screen_observer), | 65 : WizardScreen(screen_observer), |
66 actor_(actor), | 66 actor_(actor), |
67 accept_photo_after_decoding_(false), | 67 accept_photo_after_decoding_(false), |
68 selected_image_(user_manager::User::USER_IMAGE_INVALID), | 68 selected_image_(user_manager::User::USER_IMAGE_INVALID), |
69 profile_picture_enabled_(false), | |
70 profile_picture_data_url_(url::kAboutBlankURL), | 69 profile_picture_data_url_(url::kAboutBlankURL), |
71 profile_picture_absent_(false), | 70 profile_picture_absent_(false), |
72 is_screen_ready_(false), | 71 is_screen_ready_(false), |
73 user_has_selected_image_(false) { | 72 user_has_selected_image_(false) { |
74 actor_->SetDelegate(this); | 73 actor_->SetDelegate(this); |
75 SetProfilePictureEnabled(true); | 74 notification_registrar_.Add(this, |
75 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | |
76 content::NotificationService::AllSources()); | |
77 notification_registrar_.Add(this, | |
78 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | |
79 content::NotificationService::AllSources()); | |
76 notification_registrar_.Add(this, | 80 notification_registrar_.Add(this, |
77 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 81 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
78 content::NotificationService::AllSources()); | 82 content::NotificationService::AllSources()); |
79 } | 83 } |
80 | 84 |
81 UserImageScreen::~UserImageScreen() { | 85 UserImageScreen::~UserImageScreen() { |
82 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | 86 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); |
83 if (actor_) | 87 if (actor_) |
84 actor_->SetDelegate(NULL); | 88 actor_->SetDelegate(NULL); |
85 if (image_decoder_.get()) | 89 if (image_decoder_.get()) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 } | 210 } |
207 if (user_has_selected_image_) { | 211 if (user_has_selected_image_) { |
208 UMA_HISTOGRAM_ENUMERATION("UserImage.FirstTimeChoice", | 212 UMA_HISTOGRAM_ENUMERATION("UserImage.FirstTimeChoice", |
209 uma_index, | 213 uma_index, |
210 user_manager::kHistogramImagesCount); | 214 user_manager::kHistogramImagesCount); |
211 } | 215 } |
212 ExitScreen(); | 216 ExitScreen(); |
213 } | 217 } |
214 | 218 |
215 | 219 |
216 void UserImageScreen::SetProfilePictureEnabled(bool profile_picture_enabled) { | |
217 if (profile_picture_enabled_ == profile_picture_enabled) | |
218 return; | |
219 profile_picture_enabled_ = profile_picture_enabled; | |
220 if (profile_picture_enabled) { | |
221 notification_registrar_.Add(this, | |
222 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | |
223 content::NotificationService::AllSources()); | |
224 notification_registrar_.Add( | |
225 this, | |
226 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | |
227 content::NotificationService::AllSources()); | |
228 } else { | |
229 notification_registrar_.Remove(this, | |
Nikita (slow)
2014/08/13 16:30:29
What about this code of removing notification subs
dzhioev (left Google)
2014/08/13 18:06:42
Done.
| |
230 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | |
231 content::NotificationService::AllSources()); | |
232 notification_registrar_.Remove( | |
233 this, | |
234 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | |
235 content::NotificationService::AllSources()); | |
236 } | |
237 if (actor_) | |
238 actor_->SetProfilePictureEnabled(profile_picture_enabled); | |
239 } | |
240 | |
241 void UserImageScreen::SetUserID(const std::string& user_id) { | |
242 DCHECK(!user_id.empty()); | |
243 user_id_ = user_id; | |
244 } | |
245 | |
246 void UserImageScreen::PrepareToShow() { | 220 void UserImageScreen::PrepareToShow() { |
247 if (actor_) | 221 if (actor_) |
248 actor_->PrepareToShow(); | 222 actor_->PrepareToShow(); |
249 } | 223 } |
250 | 224 |
251 const user_manager::User* UserImageScreen::GetUser() { | 225 const user_manager::User* UserImageScreen::GetUser() { |
252 if (user_id_.empty()) | 226 return UserManager::Get()->GetLoggedInUser(); |
253 return UserManager::Get()->GetLoggedInUser(); | |
254 return UserManager::Get()->FindUser(user_id_); | |
255 } | 227 } |
256 | 228 |
257 UserImageManager* UserImageScreen::GetUserImageManager() { | 229 UserImageManager* UserImageScreen::GetUserImageManager() { |
258 return UserManager::Get()->GetUserImageManager(GetUser()->email()); | 230 return UserManager::Get()->GetUserImageManager(GetUser()->email()); |
259 } | 231 } |
260 | 232 |
261 UserImageSyncObserver* UserImageScreen::GetSyncObserver() { | 233 UserImageSyncObserver* UserImageScreen::GetSyncObserver() { |
262 return GetUserImageManager()->GetSyncObserver(); | 234 return GetUserImageManager()->GetSyncObserver(); |
263 } | 235 } |
264 | 236 |
265 void UserImageScreen::Show() { | 237 void UserImageScreen::Show() { |
266 if (!actor_) | 238 if (!actor_) |
267 return; | 239 return; |
268 | 240 |
269 DCHECK(!policy_registrar_); | 241 DCHECK(!policy_registrar_); |
270 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(GetUser()); | 242 if (Profile* profile = ProfileHelper::Get()->GetProfileByUser(GetUser())) { |
271 if (profile) { | |
272 policy::PolicyService* policy_service = | 243 policy::PolicyService* policy_service = |
273 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)-> | 244 policy::ProfilePolicyConnectorFactory::GetForProfile(profile)-> |
274 policy_service(); | 245 policy_service(); |
275 if (policy_service->GetPolicies( | 246 if (policy_service->GetPolicies( |
276 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, | 247 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
277 std::string())) | 248 std::string())) |
278 .Get(policy::key::kUserAvatarImage)) { | 249 .Get(policy::key::kUserAvatarImage)) { |
279 // If the user image is managed by policy, skip the screen because the | 250 // If the user image is managed by policy, skip the screen because the |
280 // user is not allowed to override a policy-set image. | 251 // user is not allowed to override a policy-set image. |
281 ExitScreen(); | 252 ExitScreen(); |
(...skipping 24 matching lines...) Expand all Loading... | |
306 sync_timer_.reset(new base::Timer( | 277 sync_timer_.reset(new base::Timer( |
307 FROM_HERE, | 278 FROM_HERE, |
308 base::TimeDelta::FromSeconds(kSyncTimeoutSeconds), | 279 base::TimeDelta::FromSeconds(kSyncTimeoutSeconds), |
309 base::Bind(&UserImageScreen::OnSyncTimeout, base::Unretained(this)), | 280 base::Bind(&UserImageScreen::OnSyncTimeout, base::Unretained(this)), |
310 false)); | 281 false)); |
311 sync_timer_->Reset(); | 282 sync_timer_->Reset(); |
312 } | 283 } |
313 } | 284 } |
314 CameraPresenceNotifier::GetInstance()->AddObserver(this); | 285 CameraPresenceNotifier::GetInstance()->AddObserver(this); |
315 actor_->Show(); | 286 actor_->Show(); |
316 actor_->SetProfilePictureEnabled(profile_picture_enabled_); | |
317 | 287 |
318 selected_image_ = GetUser()->image_index(); | 288 selected_image_ = GetUser()->image_index(); |
319 actor_->SelectImage(selected_image_); | 289 actor_->SelectImage(selected_image_); |
320 | 290 |
321 if (profile_picture_enabled_) { | 291 // Start fetching the profile image. |
322 // Start fetching the profile image. | 292 GetUserImageManager()->DownloadProfileImage(kProfileDownloadReason); |
323 GetUserImageManager()->DownloadProfileImage(kProfileDownloadReason); | |
324 } | |
325 } | 293 } |
326 | 294 |
327 void UserImageScreen::Hide() { | 295 void UserImageScreen::Hide() { |
328 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | 296 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); |
329 if (actor_) | 297 if (actor_) |
330 actor_->Hide(); | 298 actor_->Hide(); |
331 } | 299 } |
332 | 300 |
333 std::string UserImageScreen::GetName() const { | 301 std::string UserImageScreen::GetName() const { |
334 return WizardController::kUserImageScreenName; | 302 return WizardController::kUserImageScreenName; |
335 } | 303 } |
336 | 304 |
337 void UserImageScreen::OnActorDestroyed(UserImageScreenActor* actor) { | 305 void UserImageScreen::OnActorDestroyed(UserImageScreenActor* actor) { |
338 if (actor_ == actor) | 306 if (actor_ == actor) |
339 actor_ = NULL; | 307 actor_ = NULL; |
340 } | 308 } |
341 | 309 |
342 void UserImageScreen::Observe(int type, | 310 void UserImageScreen::Observe(int type, |
343 const content::NotificationSource& source, | 311 const content::NotificationSource& source, |
344 const content::NotificationDetails& details) { | 312 const content::NotificationDetails& details) { |
345 DCHECK(profile_picture_enabled_); | |
346 switch (type) { | 313 switch (type) { |
347 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED: { | 314 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED: { |
348 // We've got a new profile image. | 315 // We've got a new profile image. |
349 profile_picture_data_url_ = webui::GetBitmapDataUrl( | 316 profile_picture_data_url_ = webui::GetBitmapDataUrl( |
350 *content::Details<const gfx::ImageSkia>(details).ptr()->bitmap()); | 317 *content::Details<const gfx::ImageSkia>(details).ptr()->bitmap()); |
351 if (actor_) | 318 if (actor_) |
352 actor_->SendProfileImage(profile_picture_data_url_); | 319 actor_->SendProfileImage(profile_picture_data_url_); |
353 break; | 320 break; |
354 } | 321 } |
355 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED: { | 322 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED: { |
(...skipping 27 matching lines...) Expand all Loading... | |
383 | 350 |
384 void UserImageScreen::ExitScreen() { | 351 void UserImageScreen::ExitScreen() { |
385 policy_registrar_.reset(); | 352 policy_registrar_.reset(); |
386 sync_timer_.reset(); | 353 sync_timer_.reset(); |
387 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) | 354 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) |
388 sync_observer->RemoveObserver(this); | 355 sync_observer->RemoveObserver(this); |
389 get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED); | 356 get_screen_observer()->OnExit(ScreenObserver::USER_IMAGE_SELECTED); |
390 } | 357 } |
391 | 358 |
392 } // namespace chromeos | 359 } // namespace chromeos |
OLD | NEW |