Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/signin/easy_unlock_screenlock_state_handler.cc

Issue 628193003: [Easy Unlock] Update handling of the trial easy unlock/signin run (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/prefs/scoped_user_pref_update.h"
9 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/chromeos_utils.h" 13 #include "chrome/browser/chromeos/chromeos_utils.h"
12 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
13 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
15 17
16 namespace { 18 namespace {
17 19
18 ScreenlockBridge::UserPodCustomIcon GetIconForState( 20 ScreenlockBridge::UserPodCustomIcon GetIconForState(
19 EasyUnlockScreenlockStateHandler::State state) { 21 EasyUnlockScreenlockStateHandler::State state) {
20 switch (state) { 22 switch (state) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 64 }
63 } 65 }
64 66
65 bool TooltipContainsDeviceType(EasyUnlockScreenlockStateHandler::State state) { 67 bool TooltipContainsDeviceType(EasyUnlockScreenlockStateHandler::State state) {
66 return state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED || 68 return state == EasyUnlockScreenlockStateHandler::STATE_AUTHENTICATED ||
67 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE || 69 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNLOCKABLE ||
68 state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH || 70 state == EasyUnlockScreenlockStateHandler::STATE_NO_BLUETOOTH ||
69 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED; 71 state == EasyUnlockScreenlockStateHandler::STATE_PHONE_UNSUPPORTED;
70 } 72 }
71 73
74 bool IsLocaleEnUS() {
75 return g_browser_process->GetApplicationLocale() == "en-US";
76 }
77
72 } // namespace 78 } // namespace
73 79
74 80
75 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler( 81 EasyUnlockScreenlockStateHandler::EasyUnlockScreenlockStateHandler(
76 const std::string& user_email, 82 const std::string& user_email,
77 HardlockState initial_hardlock_state, 83 HardlockState initial_hardlock_state,
78 PrefService* pref_service, 84 PrefService* local_state,
79 ScreenlockBridge* screenlock_bridge) 85 ScreenlockBridge* screenlock_bridge)
80 : state_(STATE_INACTIVE), 86 : state_(STATE_INACTIVE),
81 user_email_(user_email), 87 user_email_(user_email),
82 pref_service_(pref_service), 88 local_state_(local_state),
83 screenlock_bridge_(screenlock_bridge), 89 screenlock_bridge_(screenlock_bridge),
84 hardlock_state_(initial_hardlock_state), 90 hardlock_state_(initial_hardlock_state),
85 hardlock_ui_shown_(false) { 91 hardlock_ui_shown_(false) {
86 DCHECK(screenlock_bridge_); 92 DCHECK(screenlock_bridge_);
87 screenlock_bridge_->AddObserver(this); 93 screenlock_bridge_->AddObserver(this);
88 } 94 }
89 95
90 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() { 96 EasyUnlockScreenlockStateHandler::~EasyUnlockScreenlockStateHandler() {
91 screenlock_bridge_->RemoveObserver(this); 97 screenlock_bridge_->RemoveObserver(this);
92 // Make sure the screenlock state set by this gets cleared. 98 // Make sure the screenlock state set by this gets cleared.
93 ChangeState(STATE_INACTIVE); 99 ChangeState(STATE_INACTIVE);
94 } 100 }
95 101
96 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) { 102 void EasyUnlockScreenlockStateHandler::ChangeState(State new_state) {
97 if (state_ == new_state) 103 if (state_ == new_state)
98 return; 104 return;
99 105
100 state_ = new_state; 106 state_ = new_state;
101 107
102 // If lock screen is not active or it forces offline password, just cache the 108 // If lock screen is not active or it forces offline password, just cache the
103 // current state. The screenlock state will get refreshed in |ScreenDidLock|. 109 // current state. The screenlock state will get refreshed in |ScreenDidLock|.
104 if (!screenlock_bridge_->IsLocked()) 110 if (!screenlock_bridge_->IsLocked())
105 return; 111 return;
106 112
107 const bool trial_run = IsTrialRun(); 113 const bool trial_run = IsTrialRun();
108 114
109 // No hardlock UI for trial run. 115 // Ignore NO_PAIRING hardlock state for trial run.
110 if (!trial_run && hardlock_state_ != NO_HARDLOCK) { 116 if (!(trial_run && hardlock_state_ == NO_PAIRING) &&
117 hardlock_state_ != NO_HARDLOCK) {
111 ShowHardlockUI(); 118 ShowHardlockUI();
112 return; 119 return;
113 } 120 }
114 121
115 UpdateScreenlockAuthType(); 122 UpdateScreenlockAuthType();
116 123
117 ScreenlockBridge::UserPodCustomIcon icon = GetIconForState(state_); 124 ScreenlockBridge::UserPodCustomIcon icon = GetIconForState(state_);
118 125
119 if (icon == ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) { 126 if (icon == ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE) {
120 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_); 127 screenlock_bridge_->lock_handler()->HideUserPodCustomIcon(user_email_);
121 return; 128 return;
122 } 129 }
123 130
124 ScreenlockBridge::UserPodCustomIconOptions icon_options; 131 ScreenlockBridge::UserPodCustomIconOptions icon_options;
125 icon_options.SetIcon(icon); 132 icon_options.SetIcon(icon);
126 133
127 // Don't hardlock on trial run.
128 if (!trial_run && HardlockOnClick(state_)) 134 if (!trial_run && HardlockOnClick(state_))
129 icon_options.SetHardlockOnClick(); 135 icon_options.SetHardlockOnClick();
130 136
131 UpdateTooltipOptions(trial_run, &icon_options); 137 UpdateTooltipOptions(trial_run, &icon_options);
132 138
133 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, 139 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_,
134 icon_options); 140 icon_options);
135 } 141 }
136 142
137 void EasyUnlockScreenlockStateHandler::SetHardlockState( 143 void EasyUnlockScreenlockStateHandler::SetHardlockState(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 hardlock_ui_shown_ = false; 200 hardlock_ui_shown_ = false;
195 return; 201 return;
196 } 202 }
197 203
198 if (hardlock_ui_shown_) 204 if (hardlock_ui_shown_)
199 return; 205 return;
200 206
201 ScreenlockBridge::UserPodCustomIconOptions icon_options; 207 ScreenlockBridge::UserPodCustomIconOptions icon_options;
202 icon_options.SetIcon(ScreenlockBridge::USER_POD_CUSTOM_ICON_HARDLOCKED); 208 icon_options.SetIcon(ScreenlockBridge::USER_POD_CUSTOM_ICON_HARDLOCKED);
203 209
204 base::string16 tooltip; 210 // TODO(tbarzic): Remove this condition for M-40.
205 if (hardlock_state_ == USER_HARDLOCK) { 211 if (IsLocaleEnUS()) {
206 tooltip = l10n_util::GetStringFUTF16( 212 base::string16 tooltip;
207 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_USER, GetDeviceName()); 213 if (hardlock_state_ == USER_HARDLOCK) {
208 } else if (hardlock_state_ == PAIRING_CHANGED) { 214 tooltip = l10n_util::GetStringFUTF16(
209 tooltip = l10n_util::GetStringUTF16( 215 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_USER, GetDeviceName());
210 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_CHANGED); 216 } else if (hardlock_state_ == PAIRING_CHANGED) {
211 } else { 217 tooltip = l10n_util::GetStringUTF16(
212 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_; 218 IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_HARDLOCK_PAIRING_CHANGED);
219 } else {
220 LOG(ERROR) << "Unknown hardlock state " << hardlock_state_;
221 }
222 icon_options.SetTooltip(tooltip, false /* don't autoshow */);
213 } 223 }
214 icon_options.SetTooltip(tooltip, false /* don't autoshow */);
215 224
216 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_, 225 screenlock_bridge_->lock_handler()->ShowUserPodCustomIcon(user_email_,
217 icon_options); 226 icon_options);
218 hardlock_ui_shown_ = true; 227 hardlock_ui_shown_ = true;
219 } 228 }
220 229
221 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions( 230 void EasyUnlockScreenlockStateHandler::UpdateTooltipOptions(
222 bool trial_run, 231 bool trial_run,
223 ScreenlockBridge::UserPodCustomIconOptions* icon_options) { 232 ScreenlockBridge::UserPodCustomIconOptions* icon_options) {
224 size_t resource_id = 0; 233 size_t resource_id = 0;
225 base::string16 device_name; 234 base::string16 device_name;
226 if (trial_run && state_ == STATE_AUTHENTICATED) { 235 if (trial_run && state_ == STATE_AUTHENTICATED) {
227 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL; 236 // TODO(tbarzic): Remove this condition for M-40 branch.
237 if (IsLocaleEnUS())
238 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_INITIAL_AUTHENTICATED;
239 else
240 resource_id = IDS_EASY_UNLOCK_SCREENLOCK_TOOLTIP_TUTORIAL;
228 } else { 241 } else {
229 resource_id = GetTooltipResourceId(state_); 242 resource_id = GetTooltipResourceId(state_);
230 if (TooltipContainsDeviceType(state_)) 243 if (TooltipContainsDeviceType(state_))
231 device_name = GetDeviceName(); 244 device_name = GetDeviceName();
232 } 245 }
233 246
234 if (!resource_id) 247 if (!resource_id)
235 return; 248 return;
236 249
237 base::string16 tooltip; 250 base::string16 tooltip;
238 if (device_name.empty()) { 251 if (device_name.empty()) {
239 tooltip = l10n_util::GetStringUTF16(resource_id); 252 tooltip = l10n_util::GetStringUTF16(resource_id);
240 } else { 253 } else {
241 tooltip = l10n_util::GetStringFUTF16(resource_id, device_name); 254 tooltip = l10n_util::GetStringFUTF16(resource_id, device_name);
242 } 255 }
243 256
244 if (tooltip.empty()) 257 if (tooltip.empty())
245 return; 258 return;
246 259
247 icon_options->SetTooltip( 260 icon_options->SetTooltip(tooltip, trial_run /* autoshow tooltip */);
248 tooltip,
249 state_ == STATE_AUTHENTICATED && trial_run /* autoshow tooltip */);
250 } 261 }
251 262
252 bool EasyUnlockScreenlockStateHandler::IsTrialRun() { 263 bool EasyUnlockScreenlockStateHandler::IsTrialRun() {
253 return pref_service_ && 264 if (!local_state_)
254 pref_service_->GetBoolean(prefs::kEasyUnlockShowTutorial); 265 return false;
266 const base::DictionaryValue* dict =
267 local_state_->GetDictionary(prefs::kEasyUnlockFirstRunComplete);
268 bool first_run_complete;
269 return !dict ||
270 !dict->GetBooleanWithoutPathExpansion(user_email_, &first_run_complete) ||
271 !first_run_complete;
255 } 272 }
256 273
257 void EasyUnlockScreenlockStateHandler::MarkTrialRunComplete() { 274 void EasyUnlockScreenlockStateHandler::MarkTrialRunComplete() {
258 if (!pref_service_) 275 DCHECK(!user_email_.empty());
276
277 if (!local_state_)
259 return; 278 return;
260 pref_service_->SetBoolean(prefs::kEasyUnlockShowTutorial, false); 279 DictionaryPrefUpdate update(local_state_, prefs::kEasyUnlockFirstRunComplete);
280 update->SetBooleanWithoutPathExpansion(user_email_, true);
261 } 281 }
262 282
263 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() { 283 base::string16 EasyUnlockScreenlockStateHandler::GetDeviceName() {
264 #if defined(OS_CHROMEOS) 284 #if defined(OS_CHROMEOS)
265 return chromeos::GetChromeDeviceType(); 285 return chromeos::GetChromeDeviceType();
266 #else 286 #else
267 // TODO(tbarzic): Figure out the name for non Chrome OS case. 287 // TODO(tbarzic): Figure out the name for non Chrome OS case.
268 return base::ASCIIToUTF16("Chrome"); 288 return base::ASCIIToUTF16("Chrome");
269 #endif 289 #endif
270 } 290 }
271 291
272 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() { 292 void EasyUnlockScreenlockStateHandler::UpdateScreenlockAuthType() {
273 if (!IsTrialRun() && hardlock_state_ != NO_HARDLOCK) 293 if (!IsTrialRun() && hardlock_state_ != NO_HARDLOCK)
274 return; 294 return;
275 295
276 if (state_ == STATE_AUTHENTICATED) { 296 if (state_ == STATE_AUTHENTICATED) {
277 screenlock_bridge_->lock_handler()->SetAuthType( 297 screenlock_bridge_->lock_handler()->SetAuthType(
278 user_email_, 298 user_email_,
279 ScreenlockBridge::LockHandler::USER_CLICK, 299 ScreenlockBridge::LockHandler::USER_CLICK,
280 l10n_util::GetStringUTF16( 300 l10n_util::GetStringUTF16(
281 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE)); 301 IDS_EASY_UNLOCK_SCREENLOCK_USER_POD_AUTH_VALUE));
282 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) != 302 } else if (screenlock_bridge_->lock_handler()->GetAuthType(user_email_) !=
283 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { 303 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) {
284 screenlock_bridge_->lock_handler()->SetAuthType( 304 screenlock_bridge_->lock_handler()->SetAuthType(
285 user_email_, 305 user_email_,
286 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD, 306 ScreenlockBridge::LockHandler::OFFLINE_PASSWORD,
287 base::string16()); 307 base::string16());
288 } 308 }
289 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698