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

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

Issue 644873002: Easy Unlock Show connecting user pod icon when waking up from sleep (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 months 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 | « chrome/browser/signin/easy_unlock_service.h ('k') | 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/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/prefs/scoped_user_pref_update.h" 13 #include "base/prefs/scoped_user_pref_update.h"
14 #include "base/thread_task_runner_handle.h"
15 #include "base/time/time.h"
14 #include "base/values.h" 16 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/extensions/component_loader.h" 18 #include "chrome/browser/extensions/component_loader.h"
17 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/signin/easy_unlock_auth_attempt.h" 21 #include "chrome/browser/signin/easy_unlock_auth_attempt.h"
20 #include "chrome/browser/signin/easy_unlock_service_factory.h" 22 #include "chrome/browser/signin/easy_unlock_service_factory.h"
21 #include "chrome/browser/signin/easy_unlock_service_observer.h" 23 #include "chrome/browser/signin/easy_unlock_service_observer.h"
22 #include "chrome/browser/signin/screenlock_bridge.h" 24 #include "chrome/browser/signin/screenlock_bridge.h"
23 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 scoped_refptr<device::BluetoothAdapter> adapter_; 138 scoped_refptr<device::BluetoothAdapter> adapter_;
137 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_; 139 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_;
138 140
139 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector); 141 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector);
140 }; 142 };
141 143
142 #if defined(OS_CHROMEOS) 144 #if defined(OS_CHROMEOS)
143 class EasyUnlockService::PowerMonitor 145 class EasyUnlockService::PowerMonitor
144 : public chromeos::PowerManagerClient::Observer { 146 : public chromeos::PowerManagerClient::Observer {
145 public: 147 public:
146 explicit PowerMonitor(EasyUnlockService* service) : service_(service) { 148 explicit PowerMonitor(EasyUnlockService* service)
149 : service_(service),
150 waking_up_(false),
151 weak_ptr_factory_(this) {
147 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> 152 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
148 AddObserver(this); 153 AddObserver(this);
149 } 154 }
150 155
151 virtual ~PowerMonitor() { 156 virtual ~PowerMonitor() {
152 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> 157 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
153 RemoveObserver(this); 158 RemoveObserver(this);
154 } 159 }
155 160
161 bool waking_up() const { return waking_up_; }
162
156 private: 163 private:
157 // chromeos::PowerManagerClient::Observer: 164 // chromeos::PowerManagerClient::Observer:
158 virtual void SuspendImminent() override { 165 virtual void SuspendImminent() override {
159 service_->DisableAppIfLoaded(); 166 service_->PrepareForSuspend();
160 } 167 }
161 168
162 virtual void SuspendDone(const base::TimeDelta& sleep_duration) override { 169 virtual void SuspendDone(const base::TimeDelta& sleep_duration) override {
163 service_->LoadApp(); 170 waking_up_ = true;
171 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
172 FROM_HERE,
173 base::Bind(&PowerMonitor::ResetWakingUp,
174 weak_ptr_factory_.GetWeakPtr()),
175 base::TimeDelta::FromSeconds(5));
176 service_->UpdateAppState();
177 // Note that |this| may get deleted after |UpdateAppState| is called.
178 }
179
180 void ResetWakingUp() {
181 waking_up_ = false;
182 service_->UpdateAppState();
164 } 183 }
165 184
166 EasyUnlockService* service_; 185 EasyUnlockService* service_;
186 bool waking_up_;
187 base::WeakPtrFactory<PowerMonitor> weak_ptr_factory_;
167 188
168 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); 189 DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
169 }; 190 };
170 #endif 191 #endif
171 192
172 EasyUnlockService::EasyUnlockService(Profile* profile) 193 EasyUnlockService::EasyUnlockService(Profile* profile)
173 : profile_(profile), 194 : profile_(profile),
174 bluetooth_detector_(new BluetoothDetector(this)), 195 bluetooth_detector_(new BluetoothDetector(this)),
175 shut_down_(false), 196 shut_down_(false),
176 weak_ptr_factory_(this) { 197 weak_ptr_factory_(this) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 ExtensionService* extension_service = 437 ExtensionService* extension_service =
417 extensions::ExtensionSystem::Get(profile_)->extension_service(); 438 extensions::ExtensionSystem::Get(profile_)->extension_service();
418 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); 439 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId);
419 440
420 NotifyUserUpdated(); 441 NotifyUserUpdated();
421 } 442 }
422 #endif // defined(GOOGLE_CHROME_BUILD) 443 #endif // defined(GOOGLE_CHROME_BUILD)
423 } 444 }
424 445
425 void EasyUnlockService::DisableAppIfLoaded() { 446 void EasyUnlockService::DisableAppIfLoaded() {
426 // Make sure lock screen state set by the extension gets reset.
427 ResetScreenlockState();
428
429 extensions::ComponentLoader* loader = GetComponentLoader(profile_); 447 extensions::ComponentLoader* loader = GetComponentLoader(profile_);
430 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) 448 if (!loader->Exists(extension_misc::kEasyUnlockAppId))
431 return; 449 return;
432 450
433 ExtensionService* extension_service = 451 ExtensionService* extension_service =
434 extensions::ExtensionSystem::Get(profile_)->extension_service(); 452 extensions::ExtensionSystem::Get(profile_)->extension_service();
435 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, 453 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId,
436 extensions::Extension::DISABLE_RELOAD); 454 extensions::Extension::DISABLE_RELOAD);
437 } 455 }
438 456
(...skipping 12 matching lines...) Expand all
451 extension_system->extension_service()->ReloadExtension( 469 extension_system->extension_service()->ReloadExtension(
452 extension_misc::kEasyUnlockAppId); 470 extension_misc::kEasyUnlockAppId);
453 NotifyUserUpdated(); 471 NotifyUserUpdated();
454 } 472 }
455 473
456 void EasyUnlockService::UpdateAppState() { 474 void EasyUnlockService::UpdateAppState() {
457 if (IsAllowed()) { 475 if (IsAllowed()) {
458 LoadApp(); 476 LoadApp();
459 477
460 #if defined(OS_CHROMEOS) 478 #if defined(OS_CHROMEOS)
461 if (!power_monitor_) 479 if (!power_monitor_)
462 power_monitor_.reset(new PowerMonitor(this)); 480 power_monitor_.reset(new PowerMonitor(this));
463 #endif 481 #endif
464 } else { 482 } else {
465 DisableAppIfLoaded(); 483 bool bluetooth_waking_up = false;
466 #if defined(OS_CHROMEOS) 484 #if defined(OS_CHROMEOS)
467 power_monitor_.reset(); 485 // If the service is not allowed due to bluetooth not being detected just
486 // after system suspend is done, give bluetooth more time to be detected
487 // before disabling the app (and resetting screenlock state).
488 bluetooth_waking_up =
489 power_monitor_.get() && power_monitor_->waking_up() &&
490 !bluetooth_detector_->IsPresent();
468 #endif 491 #endif
492
493 if (!bluetooth_waking_up) {
494 DisableAppIfLoaded();
495 ResetScreenlockState();
496 #if defined(OS_CHROMEOS)
497 power_monitor_.reset();
498 #endif
499 }
469 } 500 }
470 } 501 }
471 502
472 void EasyUnlockService::NotifyUserUpdated() { 503 void EasyUnlockService::NotifyUserUpdated() {
473 std::string user_id = GetUserEmail(); 504 std::string user_id = GetUserEmail();
474 if (user_id.empty()) 505 if (user_id.empty())
475 return; 506 return;
476 507
477 // Notify the easy unlock app that the user info changed. 508 // Notify the easy unlock app that the user info changed.
478 extensions::api::easy_unlock_private::UserInfo info; 509 extensions::api::easy_unlock_private::UserInfo info;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 devices_in_cryptohome.insert(device_key_data.public_key); 593 devices_in_cryptohome.insert(device_key_data.public_key);
563 594
564 if (paired_devices != devices_in_cryptohome || 595 if (paired_devices != devices_in_cryptohome ||
565 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { 596 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) {
566 SetHardlockStateForUser(user_id, 597 SetHardlockStateForUser(user_id,
567 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); 598 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
568 } 599 }
569 } 600 }
570 #endif 601 #endif
571 602
603 void EasyUnlockService::PrepareForSuspend() {
604 DisableAppIfLoaded();
605 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) {
606 UpdateScreenlockState(
607 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING);
608 }
609 }
610
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698