Chromium Code Reviews| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 if (accept_photo_after_decoding_) | 118 if (accept_photo_after_decoding_) |
| 119 OnImageAccepted(); | 119 OnImageAccepted(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void UserImageScreen::OnDecodeImageFailed() { | 122 void UserImageScreen::OnDecodeImageFailed() { |
| 123 NOTREACHED() << "Failed to decode PNG image from WebUI"; | 123 NOTREACHED() << "Failed to decode PNG image from WebUI"; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void UserImageScreen::OnInitialSync(bool local_image_updated) { | 126 void UserImageScreen::OnInitialSync(bool local_image_updated) { |
| 127 DCHECK(sync_timer_); | 127 DCHECK(sync_timer_); |
| 128 ReportSyncResult(SyncResult::SUCCEED); | |
| 128 if (!local_image_updated) { | 129 if (!local_image_updated) { |
| 129 sync_timer_.reset(); | 130 sync_timer_.reset(); |
| 130 GetSyncObserver()->RemoveObserver(this); | 131 GetSyncObserver()->RemoveObserver(this); |
| 131 if (is_screen_ready_) | 132 if (is_screen_ready_) |
| 132 HideCurtain(); | 133 HideCurtain(); |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 ExitScreen(); | 136 ExitScreen(); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void UserImageScreen::OnSyncTimeout() { | 139 void UserImageScreen::OnSyncTimeout() { |
| 140 ReportSyncResult(SyncResult::TIMED_OUT); | |
| 139 sync_timer_.reset(); | 141 sync_timer_.reset(); |
| 140 GetSyncObserver()->RemoveObserver(this); | 142 GetSyncObserver()->RemoveObserver(this); |
| 141 if (is_screen_ready_) | 143 if (is_screen_ready_) |
| 142 HideCurtain(); | 144 HideCurtain(); |
| 143 } | 145 } |
| 144 | 146 |
| 145 bool UserImageScreen::IsWaitingForSync() const { | 147 bool UserImageScreen::IsWaitingForSync() const { |
| 146 return sync_timer_.get() && sync_timer_->IsRunning(); | 148 return sync_timer_.get() && sync_timer_->IsRunning(); |
| 147 } | 149 } |
| 148 | 150 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 policy_registrar_->Observe( | 256 policy_registrar_->Observe( |
| 255 policy::key::kUserAvatarImage, | 257 policy::key::kUserAvatarImage, |
| 256 base::Bind(&UserImageScreen::OnUserImagePolicyChanged, | 258 base::Bind(&UserImageScreen::OnUserImagePolicyChanged, |
| 257 base::Unretained(this))); | 259 base::Unretained(this))); |
| 258 } else { | 260 } else { |
| 259 NOTREACHED(); | 261 NOTREACHED(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 if (GetUser()->CanSyncImage()) { | 264 if (GetUser()->CanSyncImage()) { |
| 263 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) { | 265 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) { |
| 266 sync_waiting_start_time_ = base::Time::Now(); | |
| 264 // We have synced image already. | 267 // We have synced image already. |
| 265 if (sync_observer->is_synced()) { | 268 if (sync_observer->is_synced()) { |
| 269 ReportSyncResult(SyncResult::SUCCEED); | |
| 266 ExitScreen(); | 270 ExitScreen(); |
| 267 return; | 271 return; |
| 268 } | 272 } |
| 269 sync_observer->AddObserver(this); | 273 sync_observer->AddObserver(this); |
| 270 sync_timer_.reset(new base::Timer( | 274 sync_timer_.reset(new base::Timer( |
| 271 FROM_HERE, | 275 FROM_HERE, |
| 272 base::TimeDelta::FromSeconds(kSyncTimeoutSeconds), | 276 base::TimeDelta::FromSeconds(kSyncTimeoutSeconds), |
| 273 base::Bind(&UserImageScreen::OnSyncTimeout, base::Unretained(this)), | 277 base::Bind(&UserImageScreen::OnSyncTimeout, base::Unretained(this)), |
| 274 false)); | 278 false)); |
| 275 sync_timer_->Reset(); | 279 sync_timer_->Reset(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 } | 339 } |
| 336 | 340 |
| 337 void UserImageScreen::ExitScreen() { | 341 void UserImageScreen::ExitScreen() { |
| 338 policy_registrar_.reset(); | 342 policy_registrar_.reset(); |
| 339 sync_timer_.reset(); | 343 sync_timer_.reset(); |
| 340 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) | 344 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) |
| 341 sync_observer->RemoveObserver(this); | 345 sync_observer->RemoveObserver(this); |
| 342 Finish(BaseScreenDelegate::USER_IMAGE_SELECTED); | 346 Finish(BaseScreenDelegate::USER_IMAGE_SELECTED); |
| 343 } | 347 } |
| 344 | 348 |
| 349 void UserImageScreen::ReportSyncResult(SyncResult timed_out) const { | |
| 350 base::TimeDelta duration = base::Time::Now() - sync_waiting_start_time_; | |
| 351 UMA_HISTOGRAM_TIMES("Login.NewUserPriorityPrefsSyncTime", duration); | |
| 352 UMA_HISTOGRAM_ENUMERATION("Login.NewUserPriorityPrefsSyncResult", | |
| 353 static_cast<int>(timed_out), 2); | |
|
Ilya Sherman
2015/05/15 17:36:40
nit: Maybe write this as below? I'm not too happy
dzhioev (left Google)
2015/05/15 20:36:50
I've added |COUNT| element to the enum, and use it
| |
| 354 } | |
| 355 | |
| 345 } // namespace chromeos | 356 } // namespace chromeos |
| OLD | NEW |