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 "components/proximity_auth/proximity_auth_system.h" | 5 #include "components/proximity_auth/proximity_auth_system.h" |
| 6 | 6 |
| 7 #include "base/thread_task_runner_handle.h" | |
| 8 #include "base/time/default_tick_clock.h" | |
| 9 #include "components/proximity_auth/logging/logging.h" | |
| 10 #include "components/proximity_auth/proximity_auth_client.h" | |
| 11 #include "components/proximity_auth/proximity_monitor_impl.h" | |
| 12 #include "components/proximity_auth/remote_device_life_cycle_impl.h" | |
| 13 #include "components/proximity_auth/unlock_manager.h" | |
| 14 | |
| 7 namespace proximity_auth { | 15 namespace proximity_auth { |
| 8 | 16 |
| 17 namespace { | |
| 18 | |
| 19 // The time to wait after the device wakes up before beginning to connect to the | |
| 20 // remote device. | |
| 21 const int kWakeUpTimeoutSeconds = 2; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 9 ProximityAuthSystem::ProximityAuthSystem( | 25 ProximityAuthSystem::ProximityAuthSystem( |
| 10 const std::vector<RemoteDevice>& remote_devices) | 26 RemoteDevice remote_device, |
| 11 : remote_devices_(remote_devices) { | 27 ProximityAuthClient* proximity_auth_client) |
| 28 : remote_device_(remote_device), | |
| 29 proximity_auth_client_(proximity_auth_client), | |
| 30 unlock_manager_(new UnlockManager( | |
| 31 UnlockManager::ScreenlockType::SESSION_LOCK, | |
| 32 make_scoped_ptr<ProximityMonitor>(new ProximityMonitorImpl( | |
| 33 remote_device, | |
| 34 make_scoped_ptr(new base::DefaultTickClock()))), | |
| 35 proximity_auth_client)), | |
| 36 suspended_(false), | |
| 37 weak_ptr_factory_(this) {} | |
| 38 | |
| 39 ProximityAuthSystem::~ProximityAuthSystem() { | |
| 40 ScreenlockBridge::Get()->RemoveObserver(this); | |
| 12 } | 41 } |
| 13 | 42 |
| 14 ProximityAuthSystem::~ProximityAuthSystem() { | 43 void ProximityAuthSystem::Start() { |
| 44 ScreenlockBridge::Get()->AddObserver(this); | |
| 45 if (ScreenlockBridge::Get()->IsLocked()) | |
| 46 OnFocusedUserChanged(ScreenlockBridge::Get()->GetFocusedUser()); | |
| 15 } | 47 } |
| 16 | 48 |
| 17 const std::vector<RemoteDevice>& ProximityAuthSystem::GetRemoteDevices() { | 49 void ProximityAuthSystem::OnAuthAttempted(const std::string& user_id) { |
| 18 return remote_devices_; | 50 // TODO(tengs): There is no reason to pass the |user_id| argument anymore. |
| 51 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | |
| 52 } | |
| 53 | |
| 54 void ProximityAuthSystem::OnSuspend() { | |
| 55 PA_LOG(INFO) << "Preparing for device suspension."; | |
| 56 DCHECK(!suspended_); | |
| 57 suspended_ = true; | |
| 58 remote_device_life_cycle_.reset(); | |
| 59 } | |
| 60 | |
| 61 void ProximityAuthSystem::OnSuspendDone() { | |
| 62 PA_LOG(INFO) << "Device resumed from suspension."; | |
| 63 DCHECK(suspended_); | |
| 64 | |
| 65 // TODO(tengs): On ChromeOS, the system's Bluetooth adapter is invalidated | |
| 66 // when the system suspends. However, Chrome does not receive this | |
| 67 // notification until a second or so after the system wakes up. That means | |
| 68 // using the adapter during this time will be problematic, so we wait instead. | |
| 69 // See crbug.com/537057. | |
| 70 proximity_auth_client_->UpdateScreenlockState( | |
| 71 ScreenlockState::BLUETOOTH_CONNECTING); | |
| 72 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 73 FROM_HERE, base::Bind(&ProximityAuthSystem::ResumeAfterWakeUpTimeout, | |
| 74 weak_ptr_factory_.GetWeakPtr()), | |
| 75 base::TimeDelta::FromSeconds(kWakeUpTimeoutSeconds)); | |
| 76 } | |
| 77 | |
| 78 void ProximityAuthSystem::ResumeAfterWakeUpTimeout() { | |
| 79 PA_LOG(INFO) << "Resume after suspend"; | |
| 80 suspended_ = false; | |
| 81 OnFocusedUserChanged(ScreenlockBridge::Get()->GetFocusedUser()); | |
| 82 } | |
| 83 | |
| 84 void ProximityAuthSystem::OnLifeCycleStateChanged( | |
| 85 RemoteDeviceLifeCycle::State old_state, | |
| 86 RemoteDeviceLifeCycle::State new_state) { | |
| 87 unlock_manager_->OnLifeCycleStateChanged(); | |
| 88 } | |
| 89 | |
| 90 void ProximityAuthSystem::OnScreenDidLock( | |
| 91 ScreenlockBridge::LockHandler::ScreenType screen_type) {} | |
|
sacomoto
2015/09/29 20:58:33
Shouldn't you start the |remote_device_life_cycle_
Tim Song
2015/09/30 00:05:04
Done.
| |
| 92 | |
| 93 void ProximityAuthSystem::OnScreenDidUnlock( | |
| 94 ScreenlockBridge::LockHandler::ScreenType screen_type) { | |
| 95 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); | |
| 96 remote_device_life_cycle_.reset(); | |
| 97 } | |
| 98 | |
| 99 void ProximityAuthSystem::OnFocusedUserChanged(const std::string& user_id) { | |
| 100 PA_LOG(INFO) << "Focused user changed to " << user_id; | |
| 101 if (remote_device_.user_id != user_id) { | |
| 102 remote_device_life_cycle_.reset(); | |
| 103 } else if (!remote_device_life_cycle_ && !suspended_) { | |
| 104 remote_device_life_cycle_.reset( | |
| 105 new RemoteDeviceLifeCycleImpl(remote_device_, proximity_auth_client_)); | |
| 106 unlock_manager_->SetRemoteDeviceLifeCycle(remote_device_life_cycle_.get()); | |
| 107 remote_device_life_cycle_->AddObserver(this); | |
| 108 remote_device_life_cycle_->Start(); | |
| 109 } | |
| 19 } | 110 } |
| 20 | 111 |
| 21 } // proximity_auth | 112 } // proximity_auth |
| OLD | NEW |