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

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller.cc

Issue 3201003: Fixed error message bubbles according to the latest mocks (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Comments resolved Created 10 years, 4 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chromeos/login/existing_user_controller.h" 5 #include "chrome/browser/chromeos/login/existing_user_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 10
(...skipping 29 matching lines...) Expand all
40 40
41 namespace { 41 namespace {
42 42
43 // Max number of users we'll show. The true max is the min of this and the 43 // Max number of users we'll show. The true max is the min of this and the
44 // number of windows that fit on the screen. 44 // number of windows that fit on the screen.
45 const size_t kMaxUsers = 6; 45 const size_t kMaxUsers = 6;
46 46
47 // Used to indicate no user has been selected. 47 // Used to indicate no user has been selected.
48 const size_t kNotSelected = -1; 48 const size_t kNotSelected = -1;
49 49
50 // Offset of cursor in first position from edit left side. It's used to position
51 // info bubble arrow to cursor.
52 const int kCursorOffset = 5;
53
50 // Checks if display names are unique. If there are duplicates, enables 54 // Checks if display names are unique. If there are duplicates, enables
51 // tooltips with full emails to let users distinguish their accounts. 55 // tooltips with full emails to let users distinguish their accounts.
52 // Otherwise, disables the tooltips. 56 // Otherwise, disables the tooltips.
53 void EnableTooltipsIfNeeded(const std::vector<UserController*>& controllers) { 57 void EnableTooltipsIfNeeded(const std::vector<UserController*>& controllers) {
54 std::map<std::string, int> visible_display_names; 58 std::map<std::string, int> visible_display_names;
55 for (size_t i = 0; i + 1 < controllers.size(); ++i) { 59 for (size_t i = 0; i + 1 < controllers.size(); ++i) {
56 const std::string& display_name = 60 const std::string& display_name =
57 controllers[i]->user().GetDisplayName(); 61 controllers[i]->user().GetDisplayName();
58 ++visible_display_names[display_name]; 62 ++visible_display_names[display_name];
59 } 63 }
(...skipping 10 matching lines...) Expand all
70 ExistingUserController* 74 ExistingUserController*
71 ExistingUserController::delete_scheduled_instance_ = NULL; 75 ExistingUserController::delete_scheduled_instance_ = NULL;
72 76
73 ExistingUserController::ExistingUserController( 77 ExistingUserController::ExistingUserController(
74 const std::vector<UserManager::User>& users, 78 const std::vector<UserManager::User>& users,
75 const gfx::Rect& background_bounds) 79 const gfx::Rect& background_bounds)
76 : background_bounds_(background_bounds), 80 : background_bounds_(background_bounds),
77 background_window_(NULL), 81 background_window_(NULL),
78 background_view_(NULL), 82 background_view_(NULL),
79 selected_view_index_(kNotSelected), 83 selected_view_index_(kNotSelected),
84 num_login_attempts_(0),
80 bubble_(NULL) { 85 bubble_(NULL) {
81 if (delete_scheduled_instance_) 86 if (delete_scheduled_instance_)
82 delete_scheduled_instance_->Delete(); 87 delete_scheduled_instance_->Delete();
83 88
84 // Caclulate the max number of users from available screen size. 89 // Caclulate the max number of users from available screen size.
85 size_t max_users = kMaxUsers; 90 size_t max_users = kMaxUsers;
86 int screen_width = background_bounds.width(); 91 int screen_width = background_bounds.width();
87 if (screen_width > 0) { 92 if (screen_width > 0) {
88 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers, 93 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers,
89 static_cast<size_t>((screen_width - login::kUserImageSize) 94 static_cast<size_t>((screen_width - login::kUserImageSize)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 message.set_param(0, is_enabled); 187 message.set_param(0, is_enabled);
183 WmIpc::instance()->SendMessage(message); 188 WmIpc::instance()->SendMessage(message);
184 } 189 }
185 190
186 void ExistingUserController::Login(UserController* source, 191 void ExistingUserController::Login(UserController* source,
187 const string16& password) { 192 const string16& password) {
188 BootTimesLoader::Get()->RecordLoginAttempted(); 193 BootTimesLoader::Get()->RecordLoginAttempted();
189 std::vector<UserController*>::const_iterator i = 194 std::vector<UserController*>::const_iterator i =
190 std::find(controllers_.begin(), controllers_.end(), source); 195 std::find(controllers_.begin(), controllers_.end(), source);
191 DCHECK(i != controllers_.end()); 196 DCHECK(i != controllers_.end());
192 selected_view_index_ = i - controllers_.begin(); 197
198 if (selected_view_index_ == static_cast<size_t>(i - controllers_.begin())) {
199 num_login_attempts_++;
200 } else {
201 selected_view_index_ = i - controllers_.begin();
202 num_login_attempts_ = 0;
203 }
193 204
194 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); 205 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
195 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); 206 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile();
196 ChromeThread::PostTask( 207 ChromeThread::PostTask(
197 ChromeThread::UI, FROM_HERE, 208 ChromeThread::UI, FROM_HERE,
198 NewRunnableMethod(authenticator_.get(), 209 NewRunnableMethod(authenticator_.get(),
199 &Authenticator::AuthenticateToLogin, 210 &Authenticator::AuthenticateToLogin,
200 profile, 211 profile,
201 controllers_[selected_view_index_]->user().email(), 212 controllers_[selected_view_index_]->user().email(),
202 UTF16ToUTF8(password), 213 UTF16ToUTF8(password),
(...skipping 23 matching lines...) Expand all
226 237
227 void ExistingUserController::OnUserSelected(UserController* source) { 238 void ExistingUserController::OnUserSelected(UserController* source) {
228 std::vector<UserController*>::const_iterator i = 239 std::vector<UserController*>::const_iterator i =
229 std::find(controllers_.begin(), controllers_.end(), source); 240 std::find(controllers_.begin(), controllers_.end(), source);
230 DCHECK(i != controllers_.end()); 241 DCHECK(i != controllers_.end());
231 size_t new_selected_index = i - controllers_.begin(); 242 size_t new_selected_index = i - controllers_.begin();
232 if (new_selected_index != selected_view_index_ && 243 if (new_selected_index != selected_view_index_ &&
233 selected_view_index_ != kNotSelected) { 244 selected_view_index_ != kNotSelected) {
234 controllers_[selected_view_index_]->ClearAndEnableFields(); 245 controllers_[selected_view_index_]->ClearAndEnableFields();
235 ClearCaptchaState(); 246 ClearCaptchaState();
247 num_login_attempts_ = 0;
236 } 248 }
237 selected_view_index_ = new_selected_index; 249 selected_view_index_ = new_selected_index;
238 } 250 }
239 251
240 void ExistingUserController::ActivateWizard(const std::string& screen_name) { 252 void ExistingUserController::ActivateWizard(const std::string& screen_name) {
241 // WizardController takes care of deleting itself when done. 253 // WizardController takes care of deleting itself when done.
242 WizardController* controller = new WizardController(); 254 WizardController* controller = new WizardController();
243 255
244 // Give the background window to the controller. 256 // Give the background window to the controller.
245 controller->OwnBackground(background_window_, background_view_); 257 controller->OwnBackground(background_window_, background_view_);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 view->set_delegate(this); 317 view->set_delegate(this);
306 views::Window* window = views::Window::CreateChromeWindow( 318 views::Window* window = views::Window::CreateChromeWindow(
307 GetNativeWindow(), gfx::Rect(), view); 319 GetNativeWindow(), gfx::Rect(), view);
308 window->SetIsAlwaysOnTop(true); 320 window->SetIsAlwaysOnTop(true);
309 window->Show(); 321 window->Show();
310 } else { 322 } else {
311 LOG(WARNING) << "No captcha image url was found?"; 323 LOG(WARNING) << "No captcha image url was found?";
312 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error); 324 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error);
313 } 325 }
314 } else { 326 } else {
315 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error); 327 if (controllers_[selected_view_index_]->is_guest())
328 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error);
329 else
330 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error);
316 } 331 }
317 } 332 }
318 333
319 controllers_[selected_view_index_]->ClearAndEnablePassword(); 334 controllers_[selected_view_index_]->ClearAndEnablePassword();
320 335
321 // Reenable clicking on other windows. 336 // Reenable clicking on other windows.
322 SendSetLoginState(true); 337 SendSetLoginState(true);
323 } 338 }
324 339
325 void ExistingUserController::AppendStartUrlToCmdline() { 340 void ExistingUserController::AppendStartUrlToCmdline() {
(...skipping 12 matching lines...) Expand all
338 } 353 }
339 354
340 void ExistingUserController::ShowError(int error_id, 355 void ExistingUserController::ShowError(int error_id,
341 const std::string& details) { 356 const std::string& details) {
342 ClearErrors(); 357 ClearErrors();
343 std::wstring error_text = l10n_util::GetString(error_id); 358 std::wstring error_text = l10n_util::GetString(error_id);
344 // TODO(dpolukhin): show detailed error info. |details| string contains 359 // TODO(dpolukhin): show detailed error info. |details| string contains
345 // low level error info that is not localized and even is not user friendly. 360 // low level error info that is not localized and even is not user friendly.
346 // For now just ignore it because error_text contains all required information 361 // For now just ignore it because error_text contains all required information
347 // for end users, developers can see details string in Chrome logs. 362 // for end users, developers can see details string in Chrome logs.
363
364 gfx::Rect bounds = controllers_[selected_view_index_]->GetScreenBounds();
365 BubbleBorder::ArrowLocation arrow;
366 if (controllers_[selected_view_index_]->is_guest()) {
367 arrow = BubbleBorder::LEFT_TOP;
368 } else {
369 // Point info bubble arrow to cursor position (approximately).
370 bounds.set_width(kCursorOffset * 2);
371 arrow = BubbleBorder::BOTTOM_LEFT;
372 }
373 std::wstring help_link;
374 if (num_login_attempts_ > static_cast<size_t>(1))
375 help_link = l10n_util::GetString(IDS_CANT_ACCESS_ACCOUNT_BUTTON);
376
348 bubble_ = MessageBubble::Show( 377 bubble_ = MessageBubble::Show(
349 controllers_[selected_view_index_]->controls_window(), 378 controllers_[selected_view_index_]->controls_window(),
350 controllers_[selected_view_index_]->GetScreenBounds(), 379 bounds,
351 BubbleBorder::BOTTOM_LEFT, 380 arrow,
352 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), 381 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING),
353 error_text, 382 error_text,
383 help_link,
354 this); 384 this);
355 } 385 }
356 386
357 void ExistingUserController::OnLoginSuccess(const std::string& username, 387 void ExistingUserController::OnLoginSuccess(const std::string& username,
358 const GaiaAuthConsumer::ClientLoginResult& credentials) { 388 const GaiaAuthConsumer::ClientLoginResult& credentials) {
359 389
360 AppendStartUrlToCmdline(); 390 AppendStartUrlToCmdline();
361 if (selected_view_index_ + 1 == controllers_.size()) { 391 if (selected_view_index_ + 1 == controllers_.size()) {
362 // For new user login don't launch browser until we pass image screen. 392 // For new user login don't launch browser until we pass image screen.
363 LoginUtils::Get()->EnableBrowserLaunch(false); 393 LoginUtils::Get()->EnableBrowserLaunch(false);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 425
396 cached_credentials_ = credentials; 426 cached_credentials_ = credentials;
397 PasswordChangedView* view = new PasswordChangedView(this); 427 PasswordChangedView* view = new PasswordChangedView(this);
398 views::Window* window = views::Window::CreateChromeWindow(GetNativeWindow(), 428 views::Window* window = views::Window::CreateChromeWindow(GetNativeWindow(),
399 gfx::Rect(), 429 gfx::Rect(),
400 view); 430 view);
401 window->SetIsAlwaysOnTop(true); 431 window->SetIsAlwaysOnTop(true);
402 window->Show(); 432 window->Show();
403 } 433 }
404 434
435 void ExistingUserController::OnHelpLinkActivated() {
436 AddStartUrl(GetAccountRecoveryHelpUrl());
437 LoginOffTheRecord();
438 }
439
405 void ExistingUserController::OnCaptchaEntered(const std::string& captcha) { 440 void ExistingUserController::OnCaptchaEntered(const std::string& captcha) {
406 login_captcha_ = captcha; 441 login_captcha_ = captcha;
407 } 442 }
408 443
409 void ExistingUserController::RecoverEncryptedData( 444 void ExistingUserController::RecoverEncryptedData(
410 const std::string& old_password) { 445 const std::string& old_password) {
411 ChromeThread::PostTask( 446 ChromeThread::PostTask(
412 ChromeThread::UI, FROM_HERE, 447 ChromeThread::UI, FROM_HERE,
413 NewRunnableMethod(authenticator_.get(), 448 NewRunnableMethod(authenticator_.get(),
414 &Authenticator::RecoverEncryptedData, 449 &Authenticator::RecoverEncryptedData,
415 old_password, 450 old_password,
416 cached_credentials_)); 451 cached_credentials_));
417 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); 452 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult();
418 } 453 }
419 454
420 void ExistingUserController::ResyncEncryptedData() { 455 void ExistingUserController::ResyncEncryptedData() {
421 ChromeThread::PostTask( 456 ChromeThread::PostTask(
422 ChromeThread::UI, FROM_HERE, 457 ChromeThread::UI, FROM_HERE,
423 NewRunnableMethod(authenticator_.get(), 458 NewRunnableMethod(authenticator_.get(),
424 &Authenticator::ResyncEncryptedData, 459 &Authenticator::ResyncEncryptedData,
425 cached_credentials_)); 460 cached_credentials_));
426 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); 461 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult();
427 } 462 }
428 463
429 } // namespace chromeos 464 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/existing_user_controller.h ('k') | chrome/browser/chromeos/login/helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698