| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 return state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || | 42 return state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || |
| 43 state == EasyUnlockScreenlockStateHandler::STATE_NO_PHONE || | 43 state == EasyUnlockScreenlockStateHandler::STATE_NO_PHONE || |
| 44 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY || | 44 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY || |
| 45 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE; | 45 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { | 48 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { |
| 49 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; | 49 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool HardlockOnClick(EasyUnlockScreenlockStateHandler::State state) { |
| 53 return state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED; |
| 54 } |
| 55 |
| 52 size_t GetTooltipResourceId(EasyUnlockScreenlockStateHandler::State state) { | 56 size_t GetTooltipResourceId(EasyUnlockScreenlockStateHandler::State state) { |
| 53 switch (state) { | 57 switch (state) { |
| 54 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: | 58 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: |
| 55 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_BLUETOOTH; | 59 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_BLUETOOTH; |
| 56 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: | 60 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: |
| 57 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_PHONE; | 61 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_PHONE; |
| 58 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: | 62 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: |
| 59 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_AUTHENTICATED; | 63 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_AUTHENTICATED; |
| 60 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: | 64 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: |
| 61 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED; | 65 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED; |
| 62 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: | 66 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: |
| 63 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_UNLOCKABLE; | 67 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_UNLOCKABLE; |
| 64 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: | 68 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: |
| 65 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_NEARBY; | 69 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_NEARBY; |
| 66 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: | 70 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: |
| 67 // TODO(tbarzic): When hard lock is enabled change this to | 71 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_INSTRUCTIONS; |
| 68 // IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_INSTRUCTIONS. | |
| 69 return 0; | |
| 70 default: | 72 default: |
| 71 return 0; | 73 return 0; |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 } // namespace | 77 } // namespace |
| 76 | 78 |
| 77 | 79 |
| 78 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( | 80 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( |
| 79 const std::string& user_email, | 81 const std::string& user_email, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 92 // Make sure the screenlock state set by this gets cleared. | 94 // Make sure the screenlock state set by this gets cleared. |
| 93 ChangeState(STATE_INACTIVE); | 95 ChangeState(STATE_INACTIVE); |
| 94 } | 96 } |
| 95 | 97 |
| 96 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) { | 98 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) { |
| 97 if (state_ == new_state) | 99 if (state_ == new_state) |
| 98 return; | 100 return; |
| 99 | 101 |
| 100 state_ = new_state; | 102 state_ = new_state; |
| 101 | 103 |
| 102 // If lock screen is not active, just cache the current state. | 104 // If lock screen is not active or it forces offline password, just cache the |
| 103 // The screenlock state will get refreshed in |ScreenDidLock|. | 105 // current state. The screenlock state will get refreshed in |ScreenDidLock|. |
| 104 if (!screenlock_bridge_->IsLocked()) | 106 if (!screenlock_bridge_->IsLocked() || |
| 107 screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == |
| 108 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) { |
| 105 return; | 109 return; |
| 110 } |
| 106 | 111 |
| 107 UpdateScreenlockAuthType(); | 112 UpdateScreenlockAuthType(); |
| 108 | 113 |
| 109 ScreenlockBridge::UserPodCustomIconOptions icon_options; | 114 ScreenlockBridge::UserPodCustomIconOptions icon_options; |
| 110 | 115 |
| 111 std::string icon_url = GetIconURLForState(state_); | 116 std::string icon_url = GetIconURLForState(state_); |
| 112 if (icon_url.empty()) { | 117 if (icon_url.empty()) { |
| 113 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 118 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); |
| 114 return; | 119 return; |
| 115 } | 120 } |
| 116 icon_options.SetIconAsResourceURL(icon_url); | 121 icon_options.SetIconAsResourceURL(icon_url); |
| 117 | 122 |
| 118 UpdateTooltipOptions(&icon_options); | 123 bool trial_run = IsTrialRun(); |
| 124 |
| 125 UpdateTooltipOptions(trial_run, &icon_options); |
| 119 | 126 |
| 120 if (UseOpaqueIcon(state_)) | 127 if (UseOpaqueIcon(state_)) |
| 121 icon_options.SetOpacity(kOpaqueIconOpacity); | 128 icon_options.SetOpacity(kOpaqueIconOpacity); |
| 122 | 129 |
| 123 icon_options.SetSize(kIconSize, kIconSize); | 130 icon_options.SetSize(kIconSize, kIconSize); |
| 124 | 131 |
| 125 if (HasAnimation(state_)) | 132 if (HasAnimation(state_)) |
| 126 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); | 133 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); |
| 127 | 134 |
| 135 // Hardlocking is disabled in trial run. |
| 136 if (!trial_run && HardlockOnClick(state_)) |
| 137 icon_options.SetHardlockOnClick(); |
| 138 |
| 139 if (trial_run && state_ == STATE_AUTHENTICATED) |
| 140 MarkTrialRunComplete(); |
| 141 |
| 128 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 142 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, |
| 129 icon_options); | 143 icon_options); |
| 130 } | 144 } |
| 131 | 145 |
| 132 void EasyUnlockScreenlockStateHandler::OnScreenDidLock() { | 146 void EasyUnlockScreenlockStateHandler::OnScreenDidLock() { |
| 133 State last_state = state_; | 147 State last_state = state_; |
| 134 // This should force updating screenlock state. | 148 // This should force updating screenlock state. |
| 135 state_ = STATE_INACTIVE; | 149 state_ = STATE_INACTIVE; |
| 136 ChangeState(last_state); | 150 ChangeState(last_state); |
| 137 } | 151 } |
| 138 | 152 |
| 139 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock() { | 153 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock() { |
| 140 } | 154 } |
| 141 | 155 |
| 142 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( | 156 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( |
| 157 bool trial_run, |
| 143 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { | 158 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { |
| 144 bool show_tutorial = ShouldShowTutorial(); | |
| 145 | |
| 146 size_t resource_id = 0; | 159 size_t resource_id = 0; |
| 147 base::string16 device_name; | 160 base::string16 device_name; |
| 148 if (show_tutorial) { | 161 if (trial_run && state_ == STATE_AUTHENTICATED) { |
| 149 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; | 162 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; |
| 150 } else { | 163 } else { |
| 151 resource_id = GetTooltipResourceId(state_); | 164 resource_id = GetTooltipResourceId(state_); |
| 152 if (state_ == STATE_AUTHENTICATED || state_ == STATE_PHONE_UNLOCKABLE) | 165 if (state_ == STATE_AUTHENTICATED || state_ == STATE_PHONE_UNLOCKABLE) |
| 153 device_name = GetDeviceName(); | 166 device_name = GetDeviceName(); |
| 154 } | 167 } |
| 155 | 168 |
| 156 if (!resource_id) | 169 if (!resource_id) |
| 157 return; | 170 return; |
| 158 | 171 |
| 159 base::string16 tooltip; | 172 base::string16 tooltip; |
| 160 if (device_name.empty()) { | 173 if (device_name.empty()) { |
| 161 tooltip = l10n_util::GetStringUTF16(resource_id); | 174 tooltip = l10n_util::GetStringUTF16(resource_id); |
| 162 } else { | 175 } else { |
| 163 tooltip = l10n_util::GetStringFUTF16(resource_id, device_name); | 176 tooltip = l10n_util::GetStringFUTF16(resource_id, device_name); |
| 164 } | 177 } |
| 165 | 178 |
| 166 if (tooltip.empty()) | 179 if (tooltip.empty()) |
| 167 return; | 180 return; |
| 168 | 181 |
| 169 if (show_tutorial) | 182 icon_options->SetTooltip( |
| 170 MarkTutorialShown(); | 183 tooltip, |
| 171 | 184 state_ == STATE_AUTHENTICATED && trial_run /* autoshow tooltip */); |
| 172 icon_options->SetTooltip(tooltip, show_tutorial /* autoshow tooltip */); | |
| 173 } | 185 } |
| 174 | 186 |
| 175 bool EasyUnlockScreenlockStateHandler::ShouldShowTutorial() { | 187 bool EasyUnlockScreenlockStateHandler::IsTrialRun() { |
| 176 if (state_ != STATE_AUTHENTICATED) | |
| 177 return false; | |
| 178 return pref_service_ && | 188 return pref_service_ && |
| 179 pref_service_->GetBoolean(prefs::kEasyUnlockShowTutorial); | 189 pref_service_->GetBoolean(prefs::kEasyUnlockShowTutorial); |
| 180 } | 190 } |
| 181 | 191 |
| 182 void EasyUnlockScreenlockStateHandler::MarkTutorialShown() { | 192 void EasyUnlockScreenlockStateHandler::MarkTrialRunComplete() { |
| 183 if (!pref_service_) | 193 if (!pref_service_) |
| 184 return; | 194 return; |
| 185 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); | 195 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); |
| 186 } | 196 } |
| 187 | 197 |
| 188 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { | 198 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { |
| 189 #if defined(OS_CHROMEOS) | 199 #if defined(OS_CHROMEOS) |
| 190 return chromeos::GetChromeDeviceType(); | 200 return chromeos::GetChromeDeviceType(); |
| 191 #else | 201 #else |
| 192 // TODO(tbarzic): Figure out the name for non Chrome OS case. | 202 // TODO(tbarzic): Figure out the name for non Chrome OS case. |
| 193 return base::ASCIIToUTF16("Chrome"); | 203 return base::ASCIIToUTF16("Chrome"); |
| 194 #endif | 204 #endif |
| 195 } | 205 } |
| 196 | 206 |
| 197 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { | 207 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { |
| 208 if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == |
| 209 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) |
| 210 return; |
| 211 |
| 198 if (state_ == STATE_AUTHENTICATED) { | 212 if (state_ == STATE_AUTHENTICATED) { |
| 199 screenlock_bridge_->lock_handler()->SetAuthType( | 213 screenlock_bridge_->lock_handler()->SetAuthType( |
| 200 user_email_, | 214 user_email_, |
| 201 ScreenlockBridge::LockHandler::USER_CLICK, | 215 ScreenlockBridge::LockHandler::USER_CLICK, |
| 202 l10n_util::GetStringUTF16( | 216 l10n_util::GetStringUTF16( |
| 203 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 217 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
| 204 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != | 218 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != |
| 205 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 219 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
| 206 screenlock_bridge_->lock_handler()->SetAuthType( | 220 screenlock_bridge_->lock_handler()->SetAuthType( |
| 207 user_email_, | 221 user_email_, |
| 208 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 222 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 209 base::string16()); | 223 base::string16()); |
| 210 } | 224 } |
| 211 } | 225 } |
| OLD | NEW |