Chromium Code Reviews| 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/signin/easy_unlock_service.h" | 5 #include "chrome/browser/signin/easy_unlock_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | |
| 10 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 11 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 13 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/extensions/component_loader.h" | 18 #include "chrome/browser/extensions/component_loader.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 weak_ptr_factory_(this) { | 141 weak_ptr_factory_(this) { |
| 141 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 142 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 142 AddObserver(this); | 143 AddObserver(this); |
| 143 } | 144 } |
| 144 | 145 |
| 145 virtual ~PowerMonitor() { | 146 virtual ~PowerMonitor() { |
| 146 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 147 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| 147 RemoveObserver(this); | 148 RemoveObserver(this); |
| 148 } | 149 } |
| 149 | 150 |
| 151 // Called when the remote device has been authenticated to record the the time | |
|
Ilya Sherman
2014/12/12 01:54:43
nit: "the the" -> "the"
Tim Song
2014/12/12 02:12:19
Done.
| |
| 152 // delta from waking up. No time will be recorded if the start-up time has | |
| 153 // already been recorded or if the system never went to sleep previously. | |
| 154 void RecordStartUpTime() { | |
| 155 if (wake_up_time_.is_null()) | |
| 156 return; | |
| 157 UMA_HISTOGRAM_MEDIUM_TIMES( | |
| 158 "EasyUnlock.StartupTimeFromSuspend", | |
| 159 base::Time::Now() - wake_up_time_); | |
| 160 wake_up_time_ = base::Time(); | |
|
Ilya Sherman
2014/12/12 01:54:43
nit: The indentation is off -- please adjust.
Tim Song
2014/12/12 02:12:19
Done.
| |
| 161 } | |
| 162 | |
| 150 bool waking_up() const { return waking_up_; } | 163 bool waking_up() const { return waking_up_; } |
| 151 | 164 |
| 152 private: | 165 private: |
| 153 // chromeos::PowerManagerClient::Observer: | 166 // chromeos::PowerManagerClient::Observer: |
| 154 virtual void SuspendImminent() override { | 167 virtual void SuspendImminent() override { |
| 155 service_->PrepareForSuspend(); | 168 service_->PrepareForSuspend(); |
| 156 } | 169 } |
| 157 | 170 |
| 158 virtual void SuspendDone(const base::TimeDelta& sleep_duration) override { | 171 virtual void SuspendDone(const base::TimeDelta& sleep_duration) override { |
| 159 waking_up_ = true; | 172 waking_up_ = true; |
| 173 wake_up_time_ = base::Time::Now(); | |
| 160 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 174 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 161 FROM_HERE, | 175 FROM_HERE, |
| 162 base::Bind(&PowerMonitor::ResetWakingUp, | 176 base::Bind(&PowerMonitor::ResetWakingUp, |
| 163 weak_ptr_factory_.GetWeakPtr()), | 177 weak_ptr_factory_.GetWeakPtr()), |
| 164 base::TimeDelta::FromSeconds(5)); | 178 base::TimeDelta::FromSeconds(5)); |
| 165 service_->UpdateAppState(); | 179 service_->UpdateAppState(); |
| 166 // Note that |this| may get deleted after |UpdateAppState| is called. | 180 // Note that |this| may get deleted after |UpdateAppState| is called. |
| 167 } | 181 } |
| 168 | 182 |
| 169 void ResetWakingUp() { | 183 void ResetWakingUp() { |
| 170 waking_up_ = false; | 184 waking_up_ = false; |
| 171 service_->UpdateAppState(); | 185 service_->UpdateAppState(); |
| 172 } | 186 } |
| 173 | 187 |
| 174 EasyUnlockService* service_; | 188 EasyUnlockService* service_; |
| 175 bool waking_up_; | 189 bool waking_up_; |
| 190 base::Time wake_up_time_; | |
| 176 base::WeakPtrFactory<PowerMonitor> weak_ptr_factory_; | 191 base::WeakPtrFactory<PowerMonitor> weak_ptr_factory_; |
| 177 | 192 |
| 178 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); | 193 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); |
| 179 }; | 194 }; |
| 180 #endif | 195 #endif |
| 181 | 196 |
| 182 EasyUnlockService::EasyUnlockService(Profile* profile) | 197 EasyUnlockService::EasyUnlockService(Profile* profile) |
| 183 : profile_(profile), | 198 : profile_(profile), |
| 184 bluetooth_detector_(new BluetoothDetector(this)), | 199 bluetooth_detector_(new BluetoothDetector(this)), |
| 185 shut_down_(false), | 200 shut_down_(false), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 } | 341 } |
| 327 | 342 |
| 328 bool EasyUnlockService::UpdateScreenlockState( | 343 bool EasyUnlockService::UpdateScreenlockState( |
| 329 EasyUnlockScreenlockStateHandler::State state) { | 344 EasyUnlockScreenlockStateHandler::State state) { |
| 330 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); | 345 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); |
| 331 if (!handler) | 346 if (!handler) |
| 332 return false; | 347 return false; |
| 333 | 348 |
| 334 handler->ChangeState(state); | 349 handler->ChangeState(state); |
| 335 | 350 |
| 336 if (state != EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED && | 351 if (state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED) { |
| 337 auth_attempt_.get()) { | 352 if (power_monitor_) |
| 353 power_monitor_->RecordStartUpTime(); | |
| 354 } else if (auth_attempt_.get()) { | |
| 355 // Clean up existing auth attempt if we can no longer authenticate the | |
| 356 // remote device. | |
| 338 auth_attempt_.reset(); | 357 auth_attempt_.reset(); |
| 339 | 358 |
| 340 if (!handler->InStateValidOnRemoteAuthFailure()) | 359 if (!handler->InStateValidOnRemoteAuthFailure()) |
| 341 HandleAuthFailure(GetUserEmail()); | 360 HandleAuthFailure(GetUserEmail()); |
| 342 } | 361 } |
| 343 return true; | 362 return true; |
| 344 } | 363 } |
| 345 | 364 |
| 346 void EasyUnlockService::AttemptAuth(const std::string& user_id) { | 365 void EasyUnlockService::AttemptAuth(const std::string& user_id) { |
| 347 auth_attempt_.reset(new EasyUnlockAuthAttempt( | 366 auth_attempt_.reset(new EasyUnlockAuthAttempt( |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 } | 682 } |
| 664 #endif | 683 #endif |
| 665 | 684 |
| 666 void EasyUnlockService::PrepareForSuspend() { | 685 void EasyUnlockService::PrepareForSuspend() { |
| 667 DisableAppIfLoaded(); | 686 DisableAppIfLoaded(); |
| 668 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { | 687 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { |
| 669 UpdateScreenlockState( | 688 UpdateScreenlockState( |
| 670 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 689 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 671 } | 690 } |
| 672 } | 691 } |
| OLD | NEW |