Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: chrome/browser/signin/easy_unlock_service.cc

Issue 799623003: Reimplement EasyUnlock.StartupTimeFromSuspend metric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile on mac/win Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 time
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();
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
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 defined(OS_CHROMEOS)
353 if (power_monitor_)
354 power_monitor_->RecordStartUpTime();
355 #endif
356 } else if (auth_attempt_.get()) {
357 // Clean up existing auth attempt if we can no longer authenticate the
358 // remote device.
338 auth_attempt_.reset(); 359 auth_attempt_.reset();
339 360
340 if (!handler->InStateValidOnRemoteAuthFailure()) 361 if (!handler->InStateValidOnRemoteAuthFailure())
341 HandleAuthFailure(GetUserEmail()); 362 HandleAuthFailure(GetUserEmail());
342 } 363 }
343 return true; 364 return true;
344 } 365 }
345 366
346 void EasyUnlockService::AttemptAuth(const std::string& user_id) { 367 void EasyUnlockService::AttemptAuth(const std::string& user_id) {
347 auth_attempt_.reset(new EasyUnlockAuthAttempt( 368 auth_attempt_.reset(new EasyUnlockAuthAttempt(
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 } 684 }
664 #endif 685 #endif
665 686
666 void EasyUnlockService::PrepareForSuspend() { 687 void EasyUnlockService::PrepareForSuspend() {
667 DisableAppIfLoaded(); 688 DisableAppIfLoaded();
668 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { 689 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) {
669 UpdateScreenlockState( 690 UpdateScreenlockState(
670 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); 691 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
671 } 692 }
672 } 693 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698