Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync/sync_ui_util.h" | 5 #include "chrome/browser/sync/sync_ui_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
| 8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/browser/sync/protocol/proto_enum_conversions.h" | 15 #include "chrome/browser/sync/protocol/proto_enum_conversions.h" |
| 15 #include "chrome/browser/sync/protocol/sync_protocol_error.h" | 16 #include "chrome/browser/sync/protocol/sync_protocol_error.h" |
| 16 #include "chrome/browser/sync/syncable/model_type.h" | 17 #include "chrome/browser/sync/syncable/model_type.h" |
| 17 #include "chrome/browser/sync/sessions/session_state.h" | 18 #include "chrome/browser/sync/sessions/session_state.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
| 22 #include "chrome/common/net/gaia/google_service_auth_error.h" | 23 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 24 #include "chrome/common/pref_names.h" | |
| 23 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 24 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
| 25 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
| 26 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 27 #include "grit/locale_settings.h" | 29 #include "grit/locale_settings.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 30 | 32 |
| 31 typedef GoogleServiceAuthError AuthError; | 33 typedef GoogleServiceAuthError AuthError; |
| 32 | 34 |
| 33 namespace sync_ui_util { | 35 namespace sync_ui_util { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 // Given an authentication state this helper function returns various labels | 39 // Given an authentication state this helper function returns various labels |
| 38 // that can be used to display information about the state. | 40 // that can be used to display information about the state. |
| 39 void GetStatusLabelsForAuthError(const AuthError& auth_error, | 41 void GetStatusLabelsForAuthError(const AuthError& auth_error, |
| 40 const ProfileSyncService& service, | 42 const ProfileSyncService& service, |
| 41 string16* status_label, | 43 string16* status_label, |
| 42 string16* link_label, | 44 string16* link_label, |
| 43 string16* global_error_menu_label, | 45 string16* global_error_menu_label, |
| 44 string16* global_error_bubble_message, | 46 string16* global_error_bubble_message, |
| 45 string16* global_error_bubble_accept_label) { | 47 string16* global_error_bubble_accept_label) { |
| 48 string16 username = UTF8ToUTF16(service.profile()->GetPrefs()->GetString( | |
| 49 prefs::kGoogleServicesUsername)); | |
| 46 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 50 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| 47 if (link_label) | 51 if (link_label) |
| 48 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); | 52 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); |
| 49 | 53 |
| 50 switch (auth_error.state()) { | 54 switch (auth_error.state()) { |
| 51 case AuthError::INVALID_GAIA_CREDENTIALS: | 55 case AuthError::INVALID_GAIA_CREDENTIALS: |
| 52 case AuthError::ACCOUNT_DELETED: | 56 case AuthError::ACCOUNT_DELETED: |
| 53 case AuthError::ACCOUNT_DISABLED: | 57 case AuthError::ACCOUNT_DISABLED: |
| 54 // If the user name is empty then the first login failed, otherwise the | 58 // If the user name is empty then the first login failed, otherwise the |
| 55 // credentials are out-of-date. | 59 // credentials are out-of-date. |
| 56 if (service.GetAuthenticatedUsername().empty()) { | 60 if (username.empty()) { |
| 57 if (status_label) { | 61 if (status_label) { |
| 58 status_label->assign( | 62 status_label->assign( |
| 59 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); | 63 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); |
| 60 } | 64 } |
| 61 } else { | 65 } else { |
| 62 if (status_label) { | 66 if (status_label) { |
| 63 status_label->assign( | 67 status_label->assign( |
| 64 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); | 68 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); |
| 65 } | 69 } |
| 66 if (global_error_menu_label) { | 70 if (global_error_menu_label) { |
| 67 global_error_menu_label->assign(l10n_util::GetStringUTF16( | 71 global_error_menu_label->assign(l10n_util::GetStringUTF16( |
| 68 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM)); | 72 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM)); |
| 69 } | 73 } |
| 70 if (global_error_bubble_message) { | 74 if (global_error_bubble_message) { |
| 71 global_error_bubble_message->assign(l10n_util::GetStringFUTF16( | 75 global_error_bubble_message->assign(l10n_util::GetStringFUTF16( |
| 72 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name)); | 76 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name)); |
| 73 } | 77 } |
| 74 if (global_error_bubble_accept_label) { | 78 if (global_error_bubble_accept_label) { |
| 75 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( | 79 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( |
| 76 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); | 80 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); |
| 77 } | 81 } |
| 78 } | 82 } |
| 79 break; | 83 break; |
| 80 case AuthError::SERVICE_UNAVAILABLE: | 84 case AuthError::SERVICE_UNAVAILABLE: |
| 81 DCHECK(service.GetAuthenticatedUsername().empty()); | |
|
tim (not reviewing)
2011/11/23 20:13:42
AFAICT, this was a bogus dcheck (except in the ini
| |
| 82 if (status_label) { | 85 if (status_label) { |
| 83 status_label->assign( | 86 status_label->assign( |
| 84 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); | 87 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); |
| 85 } | 88 } |
| 86 if (link_label) | 89 if (link_label) |
| 87 link_label->clear(); | 90 link_label->clear(); |
| 88 if (global_error_menu_label) { | 91 if (global_error_menu_label) { |
| 89 global_error_menu_label->assign(l10n_util::GetStringUTF16( | 92 global_error_menu_label->assign(l10n_util::GetStringUTF16( |
| 90 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM)); | 93 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM)); |
| 91 } | 94 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 } | 130 } |
| 128 break; | 131 break; |
| 129 } | 132 } |
| 130 } | 133 } |
| 131 | 134 |
| 132 // Returns the message that should be displayed when the user is authenticated | 135 // Returns the message that should be displayed when the user is authenticated |
| 133 // and can connect to the sync server. If the user hasn't yet authenticated, an | 136 // and can connect to the sync server. If the user hasn't yet authenticated, an |
| 134 // empty string is returned. | 137 // empty string is returned. |
| 135 string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { | 138 string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { |
| 136 string16 label; | 139 string16 label; |
| 137 string16 user_name(service->GetAuthenticatedUsername()); | 140 if (!service->sync_initialized()) |
| 138 if (user_name.empty()) | 141 return string16(); |
| 139 return label; | |
| 140 | 142 |
| 143 string16 username = UTF8ToUTF16(service->profile()->GetPrefs()->GetString( | |
| 144 prefs::kGoogleServicesUsername)); | |
| 141 return l10n_util::GetStringFUTF16( | 145 return l10n_util::GetStringFUTF16( |
| 142 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | 146 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, |
| 143 user_name, | 147 username, |
| 144 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | 148 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); |
| 145 } | 149 } |
| 146 | 150 |
| 147 void GetStatusForActionableError( | 151 void GetStatusForActionableError( |
| 148 const browser_sync::SyncProtocolError& error, | 152 const browser_sync::SyncProtocolError& error, |
| 149 string16* status_label) { | 153 string16* status_label) { |
| 150 DCHECK(status_label); | 154 DCHECK(status_label); |
| 151 switch (error.action) { | 155 switch (error.action) { |
| 152 case browser_sync::STOP_AND_RESTART_SYNC: | 156 case browser_sync::STOP_AND_RESTART_SYNC: |
| 153 status_label->assign( | 157 status_label->assign( |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 } | 691 } |
| 688 } else { | 692 } else { |
| 689 version_modifier = " " + version_modifier; | 693 version_modifier = " " + version_modifier; |
| 690 } | 694 } |
| 691 return chrome_version.Name() + " " + chrome_version.OSType() + " " + | 695 return chrome_version.Name() + " " + chrome_version.OSType() + " " + |
| 692 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + | 696 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + |
| 693 version_modifier; | 697 version_modifier; |
| 694 } | 698 } |
| 695 | 699 |
| 696 } // namespace sync_ui_util | 700 } // namespace sync_ui_util |
| OLD | NEW |