| 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 "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 5 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || | 75 state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || |
| 76 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; | 76 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 | 81 |
| 82 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( | 82 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( |
| 83 const std::string& user_email, | 83 const std::string& user_email, |
| 84 PrefService* pref_service, | 84 PrefService* pref_service, |
| 85 ScreenlockBridge* screenlock_bridge) | 85 SigninScreenBridge* signin_screen_bridge) |
| 86 : state_(STATE_INACTIVE), | 86 : state_(STATE_INACTIVE), |
| 87 user_email_(user_email), | 87 user_email_(user_email), |
| 88 pref_service_(pref_service), | 88 pref_service_(pref_service), |
| 89 screenlock_bridge_(screenlock_bridge) { | 89 signin_screen_bridge_(signin_screen_bridge) { |
| 90 DCHECK(screenlock_bridge_); | 90 DCHECK(signin_screen_bridge_); |
| 91 screenlock_bridge_->AddObserver(this); | 91 signin_screen_bridge_->AddObserver(this); |
| 92 } | 92 } |
| 93 | 93 |
| 94 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { | 94 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { |
| 95 screenlock_bridge_->RemoveObserver(this); | 95 signin_screen_bridge_->RemoveObserver(this); |
| 96 // Make sure the screenlock state set by this gets cleared. | 96 // Make sure the screenlock state set by this gets cleared. |
| 97 ChangeState(STATE_INACTIVE); | 97 ChangeState(STATE_INACTIVE); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) { | 100 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) { |
| 101 if (state_ == new_state) | 101 if (state_ == new_state) |
| 102 return; | 102 return; |
| 103 | 103 |
| 104 state_ = new_state; | 104 state_ = new_state; |
| 105 | 105 |
| 106 // If lock screen is not active or it forces offline password, just cache the | 106 // If lock screen is not active or it forces offline password, just cache the |
| 107 // current state. The screenlock state will get refreshed in |ScreenDidLock|. | 107 // current state. The screenlock state will get refreshed in |ScreenDidLock|. |
| 108 if (!screenlock_bridge_->IsLocked() || | 108 if (!signin_screen_bridge_->IsLocked() || |
| 109 screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == | 109 signin_screen_bridge_->lock_handler()->GetAuthType(user_email_) == |
| 110 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) { | 110 SigninScreenBridge::LockHandler::FORCE_OFFLINE_PASSWORD) { |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 UpdateScreenlockAuthType(); | 114 UpdateScreenlockAuthType(); |
| 115 | 115 |
| 116 ScreenlockBridge::UserPodCustomIconOptions icon_options; | 116 SigninScreenBridge::UserPodCustomIconOptions icon_options; |
| 117 | 117 |
| 118 std::string icon_url = GetIconURLForState(state_); | 118 std::string icon_url = GetIconURLForState(state_); |
| 119 if (icon_url.empty()) { | 119 if (icon_url.empty()) { |
| 120 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 120 signin_screen_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 icon_options.SetIconAsResourceURL(icon_url); | 123 icon_options.SetIconAsResourceURL(icon_url); |
| 124 | 124 |
| 125 bool trial_run = IsTrialRun(); | 125 bool trial_run = IsTrialRun(); |
| 126 | 126 |
| 127 UpdateTooltipOptions(trial_run, &icon_options); | 127 UpdateTooltipOptions(trial_run, &icon_options); |
| 128 | 128 |
| 129 icon_options.SetSize(kIconSize, kIconSize); | 129 icon_options.SetSize(kIconSize, kIconSize); |
| 130 | 130 |
| 131 if (HasAnimation(state_)) | 131 if (HasAnimation(state_)) |
| 132 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); | 132 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); |
| 133 | 133 |
| 134 // Hardlocking is disabled in trial run. | 134 // Hardlocking is disabled in trial run. |
| 135 if (!trial_run && HardlockOnClick(state_)) | 135 if (!trial_run && HardlockOnClick(state_)) |
| 136 icon_options.SetHardlockOnClick(); | 136 icon_options.SetHardlockOnClick(); |
| 137 | 137 |
| 138 if (trial_run && state_ == STATE_AUTHENTICATED) | 138 if (trial_run && state_ == STATE_AUTHENTICATED) |
| 139 MarkTrialRunComplete(); | 139 MarkTrialRunComplete(); |
| 140 | 140 |
| 141 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 141 signin_screen_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, |
| 142 icon_options); | 142 icon_options); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void EasyUnlockScreenlockStateHandler::OnScreenDidLock() { | 145 void EasyUnlockScreenlockStateHandler::OnScreenDidLock() { |
| 146 State last_state = state_; | 146 State last_state = state_; |
| 147 // This should force updating screenlock state. | 147 // This should force updating screenlock state. |
| 148 state_ = STATE_INACTIVE; | 148 state_ = STATE_INACTIVE; |
| 149 ChangeState(last_state); | 149 ChangeState(last_state); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock() { | 152 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock() { |
| 153 } | 153 } |
| 154 | 154 |
| 155 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( | 155 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( |
| 156 const std::string& user_id) { | 156 const std::string& user_id) { |
| 157 } | 157 } |
| 158 | 158 |
| 159 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( | 159 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( |
| 160 bool trial_run, | 160 bool trial_run, |
| 161 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { | 161 SigninScreenBridge::UserPodCustomIconOptions* icon_options) { |
| 162 size_t resource_id = 0; | 162 size_t resource_id = 0; |
| 163 base::string16 device_name; | 163 base::string16 device_name; |
| 164 if (trial_run && state_ == STATE_AUTHENTICATED) { | 164 if (trial_run && state_ == STATE_AUTHENTICATED) { |
| 165 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; | 165 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; |
| 166 } else { | 166 } else { |
| 167 resource_id = GetTooltipResourceId(state_); | 167 resource_id = GetTooltipResourceId(state_); |
| 168 if (TooltipContainsDeviceType(state_)) | 168 if (TooltipContainsDeviceType(state_)) |
| 169 device_name = GetDeviceName(); | 169 device_name = GetDeviceName(); |
| 170 } | 170 } |
| 171 | 171 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 201 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { | 201 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { |
| 202 #if defined(OS_CHROMEOS) | 202 #if defined(OS_CHROMEOS) |
| 203 return chromeos::GetChromeDeviceType(); | 203 return chromeos::GetChromeDeviceType(); |
| 204 #else | 204 #else |
| 205 // TODO(tbarzic): Figure out the name for non Chrome OS case. | 205 // TODO(tbarzic): Figure out the name for non Chrome OS case. |
| 206 return base::ASCIIToUTF16("Chrome"); | 206 return base::ASCIIToUTF16("Chrome"); |
| 207 #endif | 207 #endif |
| 208 } | 208 } |
| 209 | 209 |
| 210 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { | 210 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { |
| 211 if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == | 211 if (signin_screen_bridge_->lock_handler()->GetAuthType(user_email_) == |
| 212 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) | 212 SigninScreenBridge::LockHandler::FORCE_OFFLINE_PASSWORD) |
| 213 return; | 213 return; |
| 214 | 214 |
| 215 if (state_ == STATE_AUTHENTICATED) { | 215 if (state_ == STATE_AUTHENTICATED) { |
| 216 screenlock_bridge_->lock_handler()->SetAuthType( | 216 signin_screen_bridge_->lock_handler()->SetAuthType( |
| 217 user_email_, | 217 user_email_, |
| 218 ScreenlockBridge::LockHandler::USER_CLICK, | 218 SigninScreenBridge::LockHandler::USER_CLICK, |
| 219 l10n_util::GetStringUTF16( | 219 l10n_util::GetStringUTF16( |
| 220 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 220 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
| 221 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != | 221 } else if (signin_screen_bridge_->lock_handler()->GetAuthType(user_email_) != |
| 222 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 222 SigninScreenBridge::LockHandler::OFFLINE_PASSWORD) { |
| 223 screenlock_bridge_->lock_handler()->SetAuthType( | 223 signin_screen_bridge_->lock_handler()->SetAuthType( |
| 224 user_email_, | 224 user_email_, |
| 225 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 225 SigninScreenBridge::LockHandler::OFFLINE_PASSWORD, |
| 226 base::string16()); | 226 base::string16()); |
| 227 } | 227 } |
| 228 } | 228 } |
| OLD | NEW |