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 10 matching lines...) Expand all Loading... |
21 size_t kSpinnerIntervalMs = 50u; | 21 size_t kSpinnerIntervalMs = 50u; |
22 | 22 |
23 std::string GetIconURLForState(EasyUnlockScreenlockStateHandler::State state) { | 23 std::string GetIconURLForState(EasyUnlockScreenlockStateHandler::State state) { |
24 switch (state) { | 24 switch (state) { |
25 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: | 25 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: |
26 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: | 26 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: |
27 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: | 27 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: |
28 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: | 28 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: |
29 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: | 29 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: |
30 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: | 30 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: |
| 31 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED: |
31 return "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; | 32 return "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; |
32 case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING: | 33 case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING: |
33 return "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; | 34 return "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; |
34 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: | 35 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: |
35 return "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; | 36 return "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; |
36 default: | 37 default: |
37 return ""; | 38 return ""; |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 bool UseOpaqueIcon(EasyUnlockScreenlockStateHandler::State state) { | 42 bool UseOpaqueIcon(EasyUnlockScreenlockStateHandler::State state) { |
42 return state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || | 43 return state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || |
43 state == EasyUnlockScreenlockStateHandler::STATE_NO_PHONE || | 44 state == EasyUnlockScreenlockStateHandler::STATE_NO_PHONE || |
44 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY || | 45 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY || |
45 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE; | 46 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE || |
| 47 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; |
46 } | 48 } |
47 | 49 |
48 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { | 50 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { |
49 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; | 51 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; |
50 } | 52 } |
51 | 53 |
52 bool HardlockOnClick(EasyUnlockScreenlockStateHandler::State state) { | 54 bool HardlockOnClick(EasyUnlockScreenlockStateHandler::State state) { |
53 return state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED; | 55 return state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED; |
54 } | 56 } |
55 | 57 |
56 size_t GetTooltipResourceId(EasyUnlockScreenlockStateHandler::State state) { | 58 size_t GetTooltipResourceId(EasyUnlockScreenlockStateHandler::State state) { |
57 switch (state) { | 59 switch (state) { |
58 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: | 60 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: |
59 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_BLUETOOTH; | 61 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_BLUETOOTH; |
60 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: | 62 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: |
61 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_PHONE; | 63 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_NO_PHONE; |
62 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: | 64 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: |
63 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_AUTHENTICATED; | 65 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_AUTHENTICATED; |
64 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: | 66 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: |
65 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED; | 67 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_LOCKED; |
66 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: | 68 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: |
67 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_UNLOCKABLE; | 69 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_UNLOCKABLE; |
68 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: | 70 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: |
69 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_NEARBY; | 71 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_PHONE_NOT_NEARBY; |
70 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: | 72 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: |
71 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_INSTRUCTIONS; | 73 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_INSTRUCTIONS; |
| 74 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED: |
| 75 return IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_UNSUPPORTED_ANDROID_VERSION; |
72 default: | 76 default: |
73 return 0; | 77 return 0; |
74 } | 78 } |
75 } | 79 } |
76 | 80 |
| 81 bool TooltipContainsDeviceType(EasyUnlockScreenlockStateHandler::State state) { |
| 82 return state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED || |
| 83 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE || |
| 84 state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || |
| 85 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; |
| 86 } |
| 87 |
77 } // namespace | 88 } // namespace |
78 | 89 |
79 | 90 |
80 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( | 91 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( |
81 const std::string& user_email, | 92 const std::string& user_email, |
82 PrefService* pref_service, | 93 PrefService* pref_service, |
83 ScreenlockBridge* screenlock_bridge) | 94 ScreenlockBridge* screenlock_bridge) |
84 : state_(STATE_INACTIVE), | 95 : state_(STATE_INACTIVE), |
85 user_email_(user_email), | 96 user_email_(user_email), |
86 pref_service_(pref_service), | 97 pref_service_(pref_service), |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 166 |
156 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( | 167 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( |
157 bool trial_run, | 168 bool trial_run, |
158 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { | 169 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { |
159 size_t resource_id = 0; | 170 size_t resource_id = 0; |
160 base::string16 device_name; | 171 base::string16 device_name; |
161 if (trial_run && state_ == STATE_AUTHENTICATED) { | 172 if (trial_run && state_ == STATE_AUTHENTICATED) { |
162 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; | 173 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; |
163 } else { | 174 } else { |
164 resource_id = GetTooltipResourceId(state_); | 175 resource_id = GetTooltipResourceId(state_); |
165 if (state_ == STATE_AUTHENTICATED || state_ == STATE_PHONE_UNLOCKABLE) | 176 if (TooltipContainsDeviceType(state_)) |
166 device_name = GetDeviceName(); | 177 device_name = GetDeviceName(); |
167 } | 178 } |
168 | 179 |
169 if (!resource_id) | 180 if (!resource_id) |
170 return; | 181 return; |
171 | 182 |
172 base::string16 tooltip; | 183 base::string16 tooltip; |
173 if (device_name.empty()) { | 184 if (device_name.empty()) { |
174 tooltip = l10n_util::GetStringUTF16(resource_id); | 185 tooltip = l10n_util::GetStringUTF16(resource_id); |
175 } else { | 186 } else { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 l10n_util::GetStringUTF16( | 227 l10n_util::GetStringUTF16( |
217 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 228 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
218 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != | 229 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != |
219 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 230 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
220 screenlock_bridge_->lock_handler()->SetAuthType( | 231 screenlock_bridge_->lock_handler()->SetAuthType( |
221 user_email_, | 232 user_email_, |
222 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 233 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
223 base::string16()); | 234 base::string16()); |
224 } | 235 } |
225 } | 236 } |
OLD | NEW |