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()); | |
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 StatusLabelStyle style) { | 139 StatusLabelStyle style) { |
137 string16 label; | 140 string16 label; |
Andrew T Wilson (Slow)
2011/12/01 23:08:07
Do we still need label?
| |
138 string16 user_name(service->GetAuthenticatedUsername()); | 141 if (!service->sync_initialized()) |
139 if (user_name.empty()) | 142 return string16(); |
140 return label; | 143 |
144 string16 user_name = UTF8ToUTF16(service->profile()->GetPrefs()->GetString( | |
145 prefs::kGoogleServicesUsername)); | |
Andrew T Wilson (Slow)
2011/12/01 23:08:07
Might want to DCHECK(!user_name.empty())
| |
141 | 146 |
142 // Message may also carry additional advice with an HTML link, if acceptable. | 147 // Message may also carry additional advice with an HTML link, if acceptable. |
143 switch (style) { | 148 switch (style) { |
144 case PLAIN_TEXT: | 149 case PLAIN_TEXT: |
145 return l10n_util::GetStringFUTF16( | 150 return l10n_util::GetStringFUTF16( |
146 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | 151 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, |
147 user_name); | 152 user_name); |
148 case WITH_HTML: | 153 case WITH_HTML: |
149 return l10n_util::GetStringFUTF16( | 154 return l10n_util::GetStringFUTF16( |
150 IDS_SYNC_ACCOUNT_SYNCING_TO_USER_WITH_MANAGE_LINK, | 155 IDS_SYNC_ACCOUNT_SYNCING_TO_USER_WITH_MANAGE_LINK, |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 } | 706 } |
702 } else { | 707 } else { |
703 version_modifier = " " + version_modifier; | 708 version_modifier = " " + version_modifier; |
704 } | 709 } |
705 return chrome_version.Name() + " " + chrome_version.OSType() + " " + | 710 return chrome_version.Name() + " " + chrome_version.OSType() + " " + |
706 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + | 711 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + |
707 version_modifier; | 712 version_modifier; |
708 } | 713 } |
709 | 714 |
710 } // namespace sync_ui_util | 715 } // namespace sync_ui_util |
OLD | NEW |