Chromium Code Reviews| Index: components/proximity_auth/proximity_auth_system.cc |
| diff --git a/components/proximity_auth/proximity_auth_system.cc b/components/proximity_auth/proximity_auth_system.cc |
| index 4279f47107aa63a987f336f6d81e6390c529702a..16c4bb19f4dd044d542186fa3693bf5baa5c6f40 100644 |
| --- a/components/proximity_auth/proximity_auth_system.cc |
| +++ b/components/proximity_auth/proximity_auth_system.cc |
| @@ -4,18 +4,109 @@ |
| #include "components/proximity_auth/proximity_auth_system.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "base/time/default_tick_clock.h" |
| +#include "components/proximity_auth/logging/logging.h" |
| +#include "components/proximity_auth/proximity_auth_client.h" |
| +#include "components/proximity_auth/proximity_monitor_impl.h" |
| +#include "components/proximity_auth/remote_device_life_cycle_impl.h" |
| +#include "components/proximity_auth/unlock_manager.h" |
| + |
| namespace proximity_auth { |
| +namespace { |
| + |
| +// The time to wait after the device wakes up before beginning to connect to the |
| +// remote device. |
| +const int kWakeUpTimeoutSeconds = 2; |
| + |
| +} // namespace |
| + |
| ProximityAuthSystem::ProximityAuthSystem( |
| - const std::vector<RemoteDevice>& remote_devices) |
| - : remote_devices_(remote_devices) { |
| -} |
| + RemoteDevice remote_device, |
| + ProximityAuthClient* proximity_auth_client) |
| + : remote_device_(remote_device), |
| + proximity_auth_client_(proximity_auth_client), |
| + unlock_manager_(new UnlockManager( |
| + UnlockManager::ScreenlockType::SESSION_LOCK, |
| + make_scoped_ptr<ProximityMonitor>(new ProximityMonitorImpl( |
| + remote_device, |
| + make_scoped_ptr(new base::DefaultTickClock()))), |
| + proximity_auth_client)), |
| + suspended_(false), |
| + weak_ptr_factory_(this) {} |
| ProximityAuthSystem::~ProximityAuthSystem() { |
| + ScreenlockBridge::Get()->RemoveObserver(this); |
| +} |
| + |
| +void ProximityAuthSystem::Start() { |
| + ScreenlockBridge::Get()->AddObserver(this); |
| + if (ScreenlockBridge::Get()->IsLocked()) |
| + OnFocusedUserChanged(ScreenlockBridge::Get()->GetFocusedUser()); |
| +} |
| + |
| +void ProximityAuthSystem::OnAuthAttempted(const std::string& user_id) { |
| + // TODO(tengs): There is no reason to pass the |user_id| argument anymore. |
| + unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); |
| +} |
| + |
| +void ProximityAuthSystem::OnSuspend() { |
| + PA_LOG(INFO) << "Preparing for device suspension."; |
| + DCHECK(!suspended_); |
| + suspended_ = true; |
| + remote_device_life_cycle_.reset(); |
| +} |
| + |
| +void ProximityAuthSystem::OnSuspendDone() { |
| + PA_LOG(INFO) << "Device resumed from suspension."; |
| + DCHECK(suspended_); |
| + |
| + // TODO(tengs): On ChromeOS, the system's Bluetooth adapter is invalidated |
| + // when the system suspends. However, Chrome does not receive this |
| + // notification until a second or so after the system wakes up. That means |
| + // using the adapter during this time will be problematic, so we wait instead. |
| + // See crbug.com/537057. |
| + proximity_auth_client_->UpdateScreenlockState( |
| + ScreenlockState::BLUETOOTH_CONNECTING); |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, base::Bind(&ProximityAuthSystem::ResumeAfterWakeUpTimeout, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromSeconds(kWakeUpTimeoutSeconds)); |
| +} |
| + |
| +void ProximityAuthSystem::ResumeAfterWakeUpTimeout() { |
| + PA_LOG(INFO) << "Resume after suspend"; |
| + suspended_ = false; |
| + OnFocusedUserChanged(ScreenlockBridge::Get()->GetFocusedUser()); |
| +} |
| + |
| +void ProximityAuthSystem::OnLifeCycleStateChanged( |
| + RemoteDeviceLifeCycle::State old_state, |
| + RemoteDeviceLifeCycle::State new_state) { |
| + unlock_manager_->OnLifeCycleStateChanged(); |
| +} |
| + |
| +void ProximityAuthSystem::OnScreenDidLock( |
| + 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.
|
| + |
| +void ProximityAuthSystem::OnScreenDidUnlock( |
| + ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| + unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
| + remote_device_life_cycle_.reset(); |
| } |
| -const std::vector<RemoteDevice>& ProximityAuthSystem::GetRemoteDevices() { |
| - return remote_devices_; |
| +void ProximityAuthSystem::OnFocusedUserChanged(const std::string& user_id) { |
| + PA_LOG(INFO) << "Focused user changed to " << user_id; |
| + if (remote_device_.user_id != user_id) { |
| + remote_device_life_cycle_.reset(); |
| + } else if (!remote_device_life_cycle_ && !suspended_) { |
| + remote_device_life_cycle_.reset( |
| + new RemoteDeviceLifeCycleImpl(remote_device_, proximity_auth_client_)); |
| + unlock_manager_->SetRemoteDeviceLifeCycle(remote_device_life_cycle_.get()); |
| + remote_device_life_cycle_->AddObserver(this); |
| + remote_device_life_cycle_->Start(); |
| + } |
| } |
| } // proximity_auth |