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" |
11 #include "chrome/browser/chromeos/chromeos_utils.h" | 11 #include "chrome/browser/chromeos/chromeos_utils.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 size_t kIconSize = 27u; | 18 size_t kIconSize = 27u; |
19 size_t kSpinnerResourceWidth = 1215u; | 19 size_t kSpinnerResourceWidth = 1215u; |
20 size_t kSpinnerIntervalMs = 50u; | 20 size_t kSpinnerIntervalMs = 50u; |
21 | 21 |
| 22 const char kHardlockIconResourceURL[] = |
| 23 "chrome://theme/IDR_EASY_UNLOCK_HARDLOCKED"; |
| 24 |
| 25 const char kLockedIconResourceURL[] = |
| 26 "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; |
| 27 |
| 28 const char kSpinnerIconResourceURL[] = |
| 29 "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; |
| 30 |
| 31 const char kUnlockedIconResourceURL[] = |
| 32 "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; |
| 33 |
22 std::string GetIconURLForState(EasyUnlockScreenlockStateHandler::State state) { | 34 std::string GetIconURLForState(EasyUnlockScreenlockStateHandler::State state) { |
23 switch (state) { | 35 switch (state) { |
24 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: | 36 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: |
25 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: | 37 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: |
26 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: | 38 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: |
27 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: | 39 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: |
28 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: | 40 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: |
29 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: | 41 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: |
30 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED: | 42 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED: |
31 return "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; | 43 return kLockedIconResourceURL; |
32 case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING: | 44 case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING: |
33 return "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; | 45 return kSpinnerIconResourceURL; |
34 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: | 46 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: |
35 return "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; | 47 return kUnlockedIconResourceURL; |
36 default: | 48 default: |
37 return ""; | 49 return ""; |
38 } | 50 } |
39 } | 51 } |
40 | 52 |
41 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { | 53 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { |
42 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; | 54 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; |
43 } | 55 } |
44 | 56 |
45 bool HardlockOnClick(EasyUnlockScreenlockStateHandler::State state) { | 57 bool HardlockOnClick(EasyUnlockScreenlockStateHandler::State state) { |
(...skipping 28 matching lines...) Expand all Loading... |
74 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE || | 86 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE || |
75 state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || | 87 state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || |
76 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; | 88 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; |
77 } | 89 } |
78 | 90 |
79 } // namespace | 91 } // namespace |
80 | 92 |
81 | 93 |
82 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( | 94 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( |
83 const std::string& user_email, | 95 const std::string& user_email, |
| 96 bool initially_hardlocked, |
84 PrefService* pref_service, | 97 PrefService* pref_service, |
85 ScreenlockBridge* screenlock_bridge) | 98 ScreenlockBridge* screenlock_bridge) |
86 : state_(STATE_INACTIVE), | 99 : state_(STATE_INACTIVE), |
87 user_email_(user_email), | 100 user_email_(user_email), |
88 pref_service_(pref_service), | 101 pref_service_(pref_service), |
89 screenlock_bridge_(screenlock_bridge) { | 102 screenlock_bridge_(screenlock_bridge), |
| 103 hardlocked_(initially_hardlocked), |
| 104 hardlock_ui_shown_(false) { |
90 DCHECK(screenlock_bridge_); | 105 DCHECK(screenlock_bridge_); |
91 screenlock_bridge_->AddObserver(this); | 106 screenlock_bridge_->AddObserver(this); |
92 } | 107 } |
93 | 108 |
94 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { | 109 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { |
95 screenlock_bridge_->RemoveObserver(this); | 110 screenlock_bridge_->RemoveObserver(this); |
96 // Make sure the screenlock state set by this gets cleared. | 111 // Make sure the screenlock state set by this gets cleared. |
97 ChangeState(STATE_INACTIVE); | 112 ChangeState(STATE_INACTIVE); |
98 } | 113 } |
99 | 114 |
100 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) { | 115 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) { |
101 if (state_ == new_state) | 116 if (state_ == new_state) |
102 return; | 117 return; |
103 | 118 |
104 state_ = new_state; | 119 state_ = new_state; |
105 | 120 |
106 // If lock screen is not active or it forces offline password, just cache the | 121 // 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|. | 122 // current state. The screenlock state will get refreshed in |ScreenDidLock|. |
108 if (!screenlock_bridge_->IsLocked() || | 123 if (!screenlock_bridge_->IsLocked()) |
109 screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == | 124 return; |
110 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) { | 125 |
| 126 if (hardlocked_) { |
| 127 ShowHardlockUI(); |
111 return; | 128 return; |
112 } | 129 } |
113 | 130 |
114 UpdateScreenlockAuthType(); | 131 UpdateScreenlockAuthType(); |
115 | 132 |
116 ScreenlockBridge::UserPodCustomIconOptions icon_options; | 133 ScreenlockBridge::UserPodCustomIconOptions icon_options; |
117 | 134 |
118 std::string icon_url = GetIconURLForState(state_); | 135 std::string icon_url = GetIconURLForState(state_); |
119 if (icon_url.empty()) { | 136 if (icon_url.empty()) { |
120 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 137 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); |
121 return; | 138 return; |
122 } | 139 } |
123 icon_options.SetIconAsResourceURL(icon_url); | 140 icon_options.SetIconAsResourceURL(icon_url); |
124 | 141 |
125 bool trial_run = IsTrialRun(); | 142 bool trial_run = IsTrialRun(); |
126 | 143 |
127 UpdateTooltipOptions(trial_run, &icon_options); | 144 UpdateTooltipOptions(trial_run, &icon_options); |
128 | 145 |
129 icon_options.SetSize(kIconSize, kIconSize); | 146 icon_options.SetSize(kIconSize, kIconSize); |
130 | 147 |
131 if (HasAnimation(state_)) | 148 if (HasAnimation(state_)) |
132 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); | 149 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); |
133 | 150 |
134 // Hardlocking is disabled in trial run. | 151 // Don't hardlock on trial run. |
135 if (!trial_run && HardlockOnClick(state_)) | 152 if (!trial_run && HardlockOnClick(state_)) |
136 icon_options.SetHardlockOnClick(); | 153 icon_options.SetHardlockOnClick(); |
137 | 154 |
138 if (trial_run && state_ == STATE_AUTHENTICATED) | 155 if (trial_run && state_ == STATE_AUTHENTICATED) |
139 MarkTrialRunComplete(); | 156 MarkTrialRunComplete(); |
140 | 157 |
141 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, | 158 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, |
142 icon_options); | 159 icon_options); |
143 } | 160 } |
144 | 161 |
| 162 void EasyUnlockScreenlockStateHandler::SetHardlocked(bool value) { |
| 163 if (hardlocked_ == value) |
| 164 return; |
| 165 |
| 166 hardlocked_ = value; |
| 167 |
| 168 // If hardlocked_ was set to false, this means the screen is about to get |
| 169 // unlocked. No need to update it in this case. |
| 170 if (hardlocked_) { |
| 171 State last_state = state_; |
| 172 // This should force updating screenlock state. |
| 173 state_ = STATE_INACTIVE; |
| 174 ChangeState(last_state); |
| 175 } |
| 176 } |
| 177 |
145 void EasyUnlockScreenlockStateHandler::OnScreenDidLock() { | 178 void EasyUnlockScreenlockStateHandler::OnScreenDidLock() { |
146 State last_state = state_; | 179 State last_state = state_; |
147 // This should force updating screenlock state. | 180 // This should force updating screenlock state. |
148 state_ = STATE_INACTIVE; | 181 state_ = STATE_INACTIVE; |
149 ChangeState(last_state); | 182 ChangeState(last_state); |
150 } | 183 } |
151 | 184 |
152 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock() { | 185 void EasyUnlockScreenlockStateHandler::OnScreenDidUnlock() { |
| 186 hardlock_ui_shown_ = false; |
| 187 if (state_ != STATE_INACTIVE) |
| 188 MarkTrialRunComplete(); |
153 } | 189 } |
154 | 190 |
155 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( | 191 void EasyUnlockScreenlockStateHandler::OnFocusedUserChanged( |
156 const std::string& user_id) { | 192 const std::string& user_id) { |
157 } | 193 } |
158 | 194 |
| 195 void EasyUnlockScreenlockStateHandler::ShowHardlockUI() { |
| 196 DCHECK(hardlocked_); |
| 197 |
| 198 if (!screenlock_bridge_->IsLocked()) |
| 199 return; |
| 200 |
| 201 if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != |
| 202 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
| 203 screenlock_bridge_->lock_handler()->SetAuthType( |
| 204 user_email_, |
| 205 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
| 206 base::string16()); |
| 207 } |
| 208 |
| 209 if (state_ == STATE_INACTIVE) { |
| 210 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); |
| 211 hardlock_ui_shown_ = false; |
| 212 return; |
| 213 } |
| 214 |
| 215 if (hardlock_ui_shown_) |
| 216 return; |
| 217 |
| 218 ScreenlockBridge::UserPodCustomIconOptions icon_options; |
| 219 icon_options.SetIconAsResourceURL(kHardlockIconResourceURL); |
| 220 icon_options.SetSize(kIconSize, kIconSize); |
| 221 icon_options.SetTooltip( |
| 222 l10n_util::GetStringFUTF16(IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK, |
| 223 GetDeviceName()), |
| 224 false /* don't autoshow */); |
| 225 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, |
| 226 icon_options); |
| 227 hardlock_ui_shown_ = true; |
| 228 } |
| 229 |
159 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( | 230 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( |
160 bool trial_run, | 231 bool trial_run, |
161 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { | 232 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { |
162 size_t resource_id = 0; | 233 size_t resource_id = 0; |
163 base::string16 device_name; | 234 base::string16 device_name; |
164 if (trial_run && state_ == STATE_AUTHENTICATED) { | 235 if (trial_run && state_ == STATE_AUTHENTICATED) { |
165 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; | 236 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; |
166 } else { | 237 } else { |
167 resource_id = GetTooltipResourceId(state_); | 238 resource_id = GetTooltipResourceId(state_); |
168 if (TooltipContainsDeviceType(state_)) | 239 if (TooltipContainsDeviceType(state_)) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { | 272 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { |
202 #if defined(OS_CHROMEOS) | 273 #if defined(OS_CHROMEOS) |
203 return chromeos::GetChromeDeviceType(); | 274 return chromeos::GetChromeDeviceType(); |
204 #else | 275 #else |
205 // TODO(tbarzic): Figure out the name for non Chrome OS case. | 276 // TODO(tbarzic): Figure out the name for non Chrome OS case. |
206 return base::ASCIIToUTF16("Chrome"); | 277 return base::ASCIIToUTF16("Chrome"); |
207 #endif | 278 #endif |
208 } | 279 } |
209 | 280 |
210 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { | 281 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { |
211 if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) == | 282 if (hardlocked_) |
212 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD) | |
213 return; | 283 return; |
214 | 284 |
215 if (state_ == STATE_AUTHENTICATED) { | 285 if (state_ == STATE_AUTHENTICATED) { |
216 screenlock_bridge_->lock_handler()->SetAuthType( | 286 screenlock_bridge_->lock_handler()->SetAuthType( |
217 user_email_, | 287 user_email_, |
218 ScreenlockBridge::LockHandler::USER_CLICK, | 288 ScreenlockBridge::LockHandler::USER_CLICK, |
219 l10n_util::GetStringUTF16( | 289 l10n_util::GetStringUTF16( |
220 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 290 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
221 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != | 291 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != |
222 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 292 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
223 screenlock_bridge_->lock_handler()->SetAuthType( | 293 screenlock_bridge_->lock_handler()->SetAuthType( |
224 user_email_, | 294 user_email_, |
225 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 295 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
226 base::string16()); | 296 base::string16()); |
227 } | 297 } |
228 } | 298 } |
OLD | NEW |