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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 2179283002: Refactored signin/sync error controllers for the avatar button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Uninitialized ptr Created 4 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
« no previous file with comments | « chrome/browser/ui/views/profiles/new_avatar_button.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/metrics/user_metrics.h" 8 #include "base/metrics/user_metrics.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/lifetime/application_lifetime.h" 11 #include "chrome/browser/lifetime/application_lifetime.h"
12 #include "chrome/browser/prefs/incognito_mode_prefs.h" 12 #include "chrome/browser/prefs/incognito_mode_prefs.h"
13 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 13 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/profiles/profile_metrics.h" 15 #include "chrome/browser/profiles/profile_metrics.h"
16 #include "chrome/browser/profiles/profile_window.h" 16 #include "chrome/browser/profiles/profile_window.h"
17 #include "chrome/browser/profiles/profiles_state.h" 17 #include "chrome/browser/profiles/profiles_state.h"
18 #include "chrome/browser/signin/chrome_signin_helper.h" 18 #include "chrome/browser/signin/chrome_signin_helper.h"
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
20 #include "chrome/browser/signin/signin_error_controller_factory.h" 20 #include "chrome/browser/signin/signin_error_controller_factory.h"
21 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/signin/signin_promo.h" 22 #include "chrome/browser/signin/signin_promo.h"
23 #include "chrome/browser/signin/signin_ui_util.h" 23 #include "chrome/browser/signin/signin_ui_util.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/sync/sync_ui_util.h"
25 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_commands.h" 27 #include "chrome/browser/ui/browser_commands.h"
27 #include "chrome/browser/ui/browser_dialogs.h" 28 #include "chrome/browser/ui/browser_dialogs.h"
28 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/chrome_pages.h" 30 #include "chrome/browser/ui/chrome_pages.h"
30 #include "chrome/browser/ui/singleton_tabs.h" 31 #include "chrome/browser/ui/singleton_tabs.h"
31 #include "chrome/browser/ui/user_manager.h" 32 #include "chrome/browser/ui/user_manager.h"
32 #include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views .h" 33 #include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views .h"
33 #include "chrome/browser/ui/views/profiles/user_manager_view.h" 34 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
34 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 35 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 if (has_button) 1470 if (has_button)
1470 layout->AddView(*button); 1471 layout->AddView(*button);
1471 else 1472 else
1472 layout->SkipColumns(1); 1473 layout->SkipColumns(1);
1473 } 1474 }
1474 1475
1475 return view; 1476 return view;
1476 } 1477 }
1477 1478
1478 views::View* ProfileChooserView::CreateSyncErrorViewIfNeeded() { 1479 views::View* ProfileChooserView::CreateSyncErrorViewIfNeeded() {
1479 ProfileSyncService* service = 1480 int content_string_id, button_string_id;
1480 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); 1481 views::LabelButton** button_out = nullptr;
1481 1482 sync_ui_util::AvatarSyncErrorType error =
1482 // The order or priority is going to be: 1. Unrecoverable errors. 1483 sync_ui_util::GetMessagesForAvatarSyncError(
1483 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. 1484 browser_->profile(), &content_string_id, &button_string_id);
1484 if (service && service->HasUnrecoverableError()) { 1485 switch (error) {
1485 // An unrecoverable error is sometimes accompanied by an actionable error. 1486 case sync_ui_util::MANAGED_USER_UNRECOVERABLE_ERROR:
1486 // If an actionable error is not set to be UPGRADE_CLIENT, then show a 1487 button_out = &sync_error_signout_button_;
1487 // generic unrecoverable error message. 1488 break;
1488 ProfileSyncService::Status status; 1489 case sync_ui_util::UNRECOVERABLE_ERROR:
1489 service->QueryDetailedSyncStatus(&status); 1490 button_out = &sync_error_signin_again_button_;
1490 if (status.sync_protocol_error.action != syncer::UPGRADE_CLIENT) { 1491 break;
1491 // Display different messages and buttons for managed accounts. 1492 case sync_ui_util::AUTH_ERROR:
1492 if (SigninManagerFactory::GetForProfile(browser_->profile()) 1493 button_out = &sync_error_signin_button_;
1493 ->IsSignoutProhibited()) { 1494 break;
1494 // For a managed user, the user is directed to the signout 1495 case sync_ui_util::UPGRADE_CLIENT_ERROR:
1495 // confirmation dialogue in the settings page. 1496 button_out = &sync_error_upgrade_button_;
1496 return CreateSyncErrorView(IDS_SYNC_ERROR_USER_MENU_SIGNOUT_MESSAGE, 1497 break;
1497 IDS_SYNC_ERROR_USER_MENU_SIGNOUT_BUTTON, 1498 case sync_ui_util::PASSPHRASE_ERROR:
1498 &sync_error_signout_button_); 1499 button_out = &sync_error_passphrase_button_;
1499 } 1500 break;
1500 // For a non-managed user, we sign out on the user's behalf and prompt 1501 case sync_ui_util::NO_SYNC_ERROR:
1501 // the user to sign in again. 1502 return nullptr;
1502 return CreateSyncErrorView(IDS_SYNC_ERROR_USER_MENU_SIGNIN_AGAIN_MESSAGE, 1503 default:
1503 IDS_SYNC_ERROR_USER_MENU_SIGNIN_AGAIN_BUTTON, 1504 NOTREACHED();
1504 &sync_error_signin_again_button_);
1505 }
1506 } 1505 }
1507 1506 return CreateSyncErrorView(content_string_id, button_string_id, button_out);
1508 // Check for an auth error.
1509 if (HasAuthError(browser_->profile())) {
1510 return CreateSyncErrorView(IDS_SYNC_ERROR_USER_MENU_SIGNIN_MESSAGE,
1511 IDS_SYNC_ERROR_USER_MENU_SIGNIN_BUTTON,
1512 &sync_error_signin_button_);
1513 }
1514
1515 // Check for sync errors if the sync service is enabled.
1516 if (service) {
1517 // Check for an actionable UPGRADE_CLIENT error.
1518 ProfileSyncService::Status status;
1519 service->QueryDetailedSyncStatus(&status);
1520 if (status.sync_protocol_error.action == syncer::UPGRADE_CLIENT) {
1521 return CreateSyncErrorView(IDS_SYNC_ERROR_USER_MENU_UPGRADE_MESSAGE,
1522 IDS_SYNC_ERROR_USER_MENU_UPGRADE_BUTTON,
1523 &sync_error_upgrade_button_);
1524 }
1525
1526 // Check for a sync passphrase error.
1527 SyncErrorController* sync_error_controller =
1528 service->sync_error_controller();
1529 if (sync_error_controller && sync_error_controller->HasError()) {
1530 return CreateSyncErrorView(IDS_SYNC_ERROR_USER_MENU_PASSPHRASE_MESSAGE,
1531 IDS_SYNC_ERROR_USER_MENU_PASSPHRASE_BUTTON,
1532 &sync_error_passphrase_button_);
1533 }
1534 }
1535
1536 // There is no error.
1537 return nullptr;
1538 } 1507 }
1539 1508
1540 views::View* ProfileChooserView::CreateSyncErrorView( 1509 views::View* ProfileChooserView::CreateSyncErrorView(
1541 const int content_string_id, 1510 const int content_string_id,
1542 const int button_string_id, 1511 const int button_string_id,
1543 views::LabelButton** button_out) { 1512 views::LabelButton** button_out) {
1544 // Sets an overall horizontal layout. 1513 // Sets an overall horizontal layout.
1545 views::View* view = new views::View(); 1514 views::View* view = new views::View();
1546 views::BoxLayout* layout = new views::BoxLayout( 1515 views::BoxLayout* layout = new views::BoxLayout(
1547 views::BoxLayout::kHorizontal, kMaterialMenuEdgeMargin, 1516 views::BoxLayout::kHorizontal, kMaterialMenuEdgeMargin,
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2294 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2326 IncognitoModePrefs::DISABLED; 2295 IncognitoModePrefs::DISABLED;
2327 return incognito_available && !browser_->profile()->IsGuestSession(); 2296 return incognito_available && !browser_->profile()->IsGuestSession();
2328 } 2297 }
2329 2298
2330 void ProfileChooserView::PostActionPerformed( 2299 void ProfileChooserView::PostActionPerformed(
2331 ProfileMetrics::ProfileDesktopMenu action_performed) { 2300 ProfileMetrics::ProfileDesktopMenu action_performed) {
2332 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 2301 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
2333 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 2302 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
2334 } 2303 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/new_avatar_button.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698