| 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" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "components/proximity_auth/logging/logging.h" | 8 #include "components/proximity_auth/logging/logging.h" |
| 9 #include "components/proximity_auth/proximity_auth_client.h" | 9 #include "components/proximity_auth/proximity_auth_client.h" |
| 10 #include "components/proximity_auth/remote_device_life_cycle_impl.h" | 10 #include "components/proximity_auth/remote_device_life_cycle_impl.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 ProximityAuthSystem::~ProximityAuthSystem() { | 33 ProximityAuthSystem::~ProximityAuthSystem() { |
| 34 ScreenlockBridge::Get()->RemoveObserver(this); | 34 ScreenlockBridge::Get()->RemoveObserver(this); |
| 35 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); | 35 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ProximityAuthSystem::Start() { | 38 void ProximityAuthSystem::Start() { |
| 39 if (started_) | 39 if (started_) |
| 40 return; | 40 return; |
| 41 started_ = true; | 41 started_ = true; |
| 42 ScreenlockBridge::Get()->AddObserver(this); | 42 ScreenlockBridge::Get()->AddObserver(this); |
| 43 std::string focused_user_id = ScreenlockBridge::Get()->focused_user_id(); | 43 const AccountId& focused_account_id = |
| 44 if (!focused_user_id.empty()) | 44 ScreenlockBridge::Get()->focused_account_id(); |
| 45 OnFocusedUserChanged(focused_user_id); | 45 if (focused_account_id.is_valid()) |
| 46 OnFocusedUserChanged(focused_account_id); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void ProximityAuthSystem::Stop() { | 49 void ProximityAuthSystem::Stop() { |
| 49 if (!started_) | 50 if (!started_) |
| 50 return; | 51 return; |
| 51 started_ = false; | 52 started_ = false; |
| 52 ScreenlockBridge::Get()->RemoveObserver(this); | 53 ScreenlockBridge::Get()->RemoveObserver(this); |
| 53 OnFocusedUserChanged(std::string()); | 54 OnFocusedUserChanged(EmptyAccountId()); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void ProximityAuthSystem::SetRemoteDevicesForUser( | 57 void ProximityAuthSystem::SetRemoteDevicesForUser( |
| 57 const std::string& user_id, | 58 const AccountId& account_id, |
| 58 const RemoteDeviceList& remote_devices) { | 59 const RemoteDeviceList& remote_devices) { |
| 59 remote_devices_map_[user_id] = remote_devices; | 60 remote_devices_map_[account_id] = remote_devices; |
| 60 if (started_) { | 61 if (started_) { |
| 61 std::string focused_user_id = ScreenlockBridge::Get()->focused_user_id(); | 62 const AccountId& focused_account_id = |
| 62 if (!focused_user_id.empty()) | 63 ScreenlockBridge::Get()->focused_account_id(); |
| 63 OnFocusedUserChanged(focused_user_id); | 64 if (focused_account_id.is_valid()) |
| 65 OnFocusedUserChanged(focused_account_id); |
| 64 } | 66 } |
| 65 } | 67 } |
| 66 | 68 |
| 67 RemoteDeviceList ProximityAuthSystem::GetRemoteDevicesForUser( | 69 RemoteDeviceList ProximityAuthSystem::GetRemoteDevicesForUser( |
| 68 const std::string& user_id) const { | 70 const AccountId& account_id) const { |
| 69 if (remote_devices_map_.find(user_id) == remote_devices_map_.end()) | 71 if (remote_devices_map_.find(account_id) == remote_devices_map_.end()) |
| 70 return RemoteDeviceList(); | 72 return RemoteDeviceList(); |
| 71 return remote_devices_map_.at(user_id); | 73 return remote_devices_map_.at(account_id); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void ProximityAuthSystem::OnAuthAttempted(const std::string& user_id) { | 76 void ProximityAuthSystem::OnAuthAttempted(const AccountId& /* account_id */) { |
| 75 // TODO(tengs): There is no reason to pass the |user_id| argument anymore. | 77 // TODO(tengs): There is no reason to pass the |account_id| argument anymore. |
| 76 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 78 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void ProximityAuthSystem::OnSuspend() { | 81 void ProximityAuthSystem::OnSuspend() { |
| 80 PA_LOG(INFO) << "Preparing for device suspension."; | 82 PA_LOG(INFO) << "Preparing for device suspension."; |
| 81 DCHECK(!suspended_); | 83 DCHECK(!suspended_); |
| 82 suspended_ = true; | 84 suspended_ = true; |
| 83 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); | 85 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
| 84 remote_device_life_cycle_.reset(); | 86 remote_device_life_cycle_.reset(); |
| 85 } | 87 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 103 | 105 |
| 104 void ProximityAuthSystem::ResumeAfterWakeUpTimeout() { | 106 void ProximityAuthSystem::ResumeAfterWakeUpTimeout() { |
| 105 PA_LOG(INFO) << "Resume after suspend"; | 107 PA_LOG(INFO) << "Resume after suspend"; |
| 106 suspended_ = false; | 108 suspended_ = false; |
| 107 | 109 |
| 108 if (!ScreenlockBridge::Get()->IsLocked()) { | 110 if (!ScreenlockBridge::Get()->IsLocked()) { |
| 109 PA_LOG(INFO) << "Suspend done, but no lock screen."; | 111 PA_LOG(INFO) << "Suspend done, but no lock screen."; |
| 110 } else if (!started_) { | 112 } else if (!started_) { |
| 111 PA_LOG(INFO) << "Suspend done, but not system started."; | 113 PA_LOG(INFO) << "Suspend done, but not system started."; |
| 112 } else { | 114 } else { |
| 113 OnFocusedUserChanged(ScreenlockBridge::Get()->focused_user_id()); | 115 OnFocusedUserChanged(ScreenlockBridge::Get()->focused_account_id()); |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 117 void ProximityAuthSystem::OnLifeCycleStateChanged( | 119 void ProximityAuthSystem::OnLifeCycleStateChanged( |
| 118 RemoteDeviceLifeCycle::State old_state, | 120 RemoteDeviceLifeCycle::State old_state, |
| 119 RemoteDeviceLifeCycle::State new_state) { | 121 RemoteDeviceLifeCycle::State new_state) { |
| 120 unlock_manager_->OnLifeCycleStateChanged(); | 122 unlock_manager_->OnLifeCycleStateChanged(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void ProximityAuthSystem::OnScreenDidLock( | 125 void ProximityAuthSystem::OnScreenDidLock( |
| 124 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 126 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 125 OnFocusedUserChanged(ScreenlockBridge::Get()->focused_user_id()); | 127 OnFocusedUserChanged(ScreenlockBridge::Get()->focused_account_id()); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void ProximityAuthSystem::OnScreenDidUnlock( | 130 void ProximityAuthSystem::OnScreenDidUnlock( |
| 129 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 131 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 130 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); | 132 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
| 131 remote_device_life_cycle_.reset(); | 133 remote_device_life_cycle_.reset(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 void ProximityAuthSystem::OnFocusedUserChanged(const std::string& user_id) { | 136 void ProximityAuthSystem::OnFocusedUserChanged(const AccountId& account_id) { |
| 135 // Update the current RemoteDeviceLifeCycle to the focused user. | 137 // Update the current RemoteDeviceLifeCycle to the focused user. |
| 136 if (!user_id.empty() && remote_device_life_cycle_ && | 138 if (account_id.is_valid() && remote_device_life_cycle_ && |
| 137 remote_device_life_cycle_->GetRemoteDevice().user_id != user_id) { | 139 remote_device_life_cycle_->GetRemoteDevice().user_id != |
| 140 account_id.GetUserEmail()) { |
| 138 PA_LOG(INFO) << "Focused user changed, destroying life cycle for " | 141 PA_LOG(INFO) << "Focused user changed, destroying life cycle for " |
| 139 << user_id << "."; | 142 << account_id.Serialize() << "."; |
| 140 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); | 143 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); |
| 141 remote_device_life_cycle_.reset(); | 144 remote_device_life_cycle_.reset(); |
| 142 } | 145 } |
| 143 | 146 |
| 144 if (remote_devices_map_.find(user_id) == remote_devices_map_.end() || | 147 if (remote_devices_map_.find(account_id) == remote_devices_map_.end() || |
| 145 remote_devices_map_[user_id].size() == 0) { | 148 remote_devices_map_[account_id].size() == 0) { |
| 146 PA_LOG(INFO) << "User " << user_id << " does not have a RemoteDevice."; | 149 PA_LOG(INFO) << "User " << account_id.Serialize() |
| 150 << " does not have a RemoteDevice."; |
| 147 return; | 151 return; |
| 148 } | 152 } |
| 149 | 153 |
| 150 // TODO(tengs): We currently assume each user has only one RemoteDevice, so we | 154 // TODO(tengs): We currently assume each user has only one RemoteDevice, so we |
| 151 // can simply take the first item in the list. | 155 // can simply take the first item in the list. |
| 152 RemoteDevice remote_device = remote_devices_map_[user_id][0]; | 156 RemoteDevice remote_device = remote_devices_map_[account_id][0]; |
| 153 if (!suspended_) { | 157 if (!suspended_) { |
| 154 PA_LOG(INFO) << "Creating RemoteDeviceLifeCycle for focused user: " | 158 PA_LOG(INFO) << "Creating RemoteDeviceLifeCycle for focused user: " |
| 155 << user_id; | 159 << account_id.Serialize(); |
| 156 remote_device_life_cycle_.reset( | 160 remote_device_life_cycle_.reset( |
| 157 new RemoteDeviceLifeCycleImpl(remote_device, proximity_auth_client_)); | 161 new RemoteDeviceLifeCycleImpl(remote_device, proximity_auth_client_)); |
| 158 unlock_manager_->SetRemoteDeviceLifeCycle(remote_device_life_cycle_.get()); | 162 unlock_manager_->SetRemoteDeviceLifeCycle(remote_device_life_cycle_.get()); |
| 159 remote_device_life_cycle_->AddObserver(this); | 163 remote_device_life_cycle_->AddObserver(this); |
| 160 remote_device_life_cycle_->Start(); | 164 remote_device_life_cycle_->Start(); |
| 161 } | 165 } |
| 162 } | 166 } |
| 163 | 167 |
| 164 } // proximity_auth | 168 } // proximity_auth |
| OLD | NEW |