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 kOpaqueIconOpacity = 50u; | |
20 size_t kSpinnerResourceWidth = 1215u; | 19 size_t kSpinnerResourceWidth = 1215u; |
21 size_t kSpinnerIntervalMs = 50u; | 20 size_t kSpinnerIntervalMs = 50u; |
22 | 21 |
23 std::string GetIconURLForState(EasyUnlockScreenlockStateHandler::State state) { | 22 std::string GetIconURLForState(EasyUnlockScreenlockStateHandler::State state) { |
24 switch (state) { | 23 switch (state) { |
25 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: | 24 case EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH: |
26 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: | 25 case EasyUnlockScreenlockStateHandler::STATE_NO_PHONE: |
27 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: | 26 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_AUTHENTICATED: |
28 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: | 27 case EasyUnlockScreenlockStateHandler::STATE_PHONE_LOCKED: |
29 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: | 28 case EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY: |
30 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: | 29 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE: |
31 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED: | 30 case EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED: |
32 return "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; | 31 return "chrome://theme/IDR_EASY_UNLOCK_LOCKED"; |
33 case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING: | 32 case EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING: |
34 return "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; | 33 return "chrome://theme/IDR_EASY_UNLOCK_SPINNER"; |
35 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: | 34 case EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED: |
36 return "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; | 35 return "chrome://theme/IDR_EASY_UNLOCK_UNLOCKED"; |
37 default: | 36 default: |
38 return ""; | 37 return ""; |
39 } | 38 } |
40 } | 39 } |
41 | 40 |
42 bool UseOpaqueIcon(EasyUnlockScreenlockStateHandler::State state) { | |
43 return state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || | |
44 state == EasyUnlockScreenlockStateHandler::STATE_NO_PHONE || | |
45 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_NOT_NEARBY || | |
46 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE || | |
47 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; | |
48 } | |
49 | |
50 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { | 41 bool HasAnimation(EasyUnlockScreenlockStateHandler::State state) { |
51 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; | 42 return state == EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING; |
52 } | 43 } |
53 | 44 |
54 bool HardlockOnClick(EasyUnlockScreenlockStateHandler::State state) { | 45 bool HardlockOnClick(EasyUnlockScreenlockStateHandler::State state) { |
55 return state != EasyUnlockScreenlockStateHandler::STATE_INACTIVE; | 46 return state != EasyUnlockScreenlockStateHandler::STATE_INACTIVE; |
56 } | 47 } |
57 | 48 |
58 size_t GetTooltipResourceId(EasyUnlockScreenlockStateHandler::State state) { | 49 size_t GetTooltipResourceId(EasyUnlockScreenlockStateHandler::State state) { |
59 switch (state) { | 50 switch (state) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 if (icon_url.empty()) { | 119 if (icon_url.empty()) { |
129 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); | 120 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); |
130 return; | 121 return; |
131 } | 122 } |
132 icon_options.SetIconAsResourceURL(icon_url); | 123 icon_options.SetIconAsResourceURL(icon_url); |
133 | 124 |
134 bool trial_run = IsTrialRun(); | 125 bool trial_run = IsTrialRun(); |
135 | 126 |
136 UpdateTooltipOptions(trial_run, &icon_options); | 127 UpdateTooltipOptions(trial_run, &icon_options); |
137 | 128 |
138 if (UseOpaqueIcon(state_)) | |
139 icon_options.SetOpacity(kOpaqueIconOpacity); | |
140 | |
141 icon_options.SetSize(kIconSize, kIconSize); | 129 icon_options.SetSize(kIconSize, kIconSize); |
142 | 130 |
143 if (HasAnimation(state_)) | 131 if (HasAnimation(state_)) |
144 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); | 132 icon_options.SetAnimation(kSpinnerResourceWidth, kSpinnerIntervalMs); |
145 | 133 |
146 // Hardlocking is disabled in trial run. | 134 // Hardlocking is disabled in trial run. |
147 if (!trial_run && HardlockOnClick(state_)) | 135 if (!trial_run && HardlockOnClick(state_)) |
148 icon_options.SetHardlockOnClick(); | 136 icon_options.SetHardlockOnClick(); |
149 | 137 |
150 if (trial_run && state_ == STATE_AUTHENTICATED) | 138 if (trial_run && state_ == STATE_AUTHENTICATED) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 l10n_util::GetStringUTF16( | 215 l10n_util::GetStringUTF16( |
228 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); | 216 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); |
229 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != | 217 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != |
230 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | 218 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { |
231 screenlock_bridge_->lock_handler()->SetAuthType( | 219 screenlock_bridge_->lock_handler()->SetAuthType( |
232 user_email_, | 220 user_email_, |
233 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, | 221 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, |
234 base::string16()); | 222 base::string16()); |
235 } | 223 } |
236 } | 224 } |
OLD | NEW |