OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/signin/signin_global_error.h" |
14 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager.h" |
| 16 #include "chrome/browser/signin/signin_ui_util.h" |
15 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
16 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 21 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
20 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
24 #include "google_apis/gaia/google_service_auth_error.h" | 26 #include "google_apis/gaia/google_service_auth_error.h" |
25 #include "grit/browser_resources.h" | 27 #include "grit/browser_resources.h" |
26 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
27 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
28 #include "grit/locale_settings.h" | 30 #include "grit/locale_settings.h" |
29 #include "sync/internal_api/public/base/model_type.h" | 31 #include "sync/internal_api/public/base/model_type.h" |
30 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 32 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
31 #include "sync/protocol/proto_enum_conversions.h" | 33 #include "sync/protocol/proto_enum_conversions.h" |
32 #include "sync/protocol/sync_protocol_error.h" | 34 #include "sync/protocol/sync_protocol_error.h" |
33 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
34 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
35 | 37 |
36 typedef GoogleServiceAuthError AuthError; | 38 typedef GoogleServiceAuthError AuthError; |
37 | 39 |
38 namespace sync_ui_util { | 40 namespace sync_ui_util { |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 // Given an authentication state this helper function returns various labels | |
43 // that can be used to display information about the state. | |
44 void GetStatusLabelsForAuthError(const AuthError& auth_error, | |
45 const ProfileSyncService& service, | |
46 string16* status_label, | |
47 string16* link_label) { | |
48 string16 username = UTF8ToUTF16(service.profile()->GetPrefs()->GetString( | |
49 prefs::kGoogleServicesUsername)); | |
50 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | |
51 if (link_label) | |
52 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); | |
53 | |
54 switch (auth_error.state()) { | |
55 case AuthError::INVALID_GAIA_CREDENTIALS: | |
56 case AuthError::ACCOUNT_DELETED: | |
57 case AuthError::ACCOUNT_DISABLED: | |
58 // If the user name is empty then the first login failed, otherwise the | |
59 // credentials are out-of-date. | |
60 if (username.empty()) { | |
61 if (status_label) { | |
62 status_label->assign( | |
63 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); | |
64 } | |
65 } else { | |
66 if (status_label) { | |
67 status_label->assign( | |
68 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); | |
69 } | |
70 } | |
71 break; | |
72 case AuthError::SERVICE_UNAVAILABLE: | |
73 if (status_label) { | |
74 status_label->assign( | |
75 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); | |
76 } | |
77 if (link_label) | |
78 link_label->clear(); | |
79 break; | |
80 case AuthError::CONNECTION_FAILED: | |
81 // Note that there is little the user can do if the server is not | |
82 // reachable. Since attempting to re-connect is done automatically by | |
83 // the Syncer, we do not show the (re)login link. | |
84 if (status_label) { | |
85 status_label->assign( | |
86 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE, | |
87 product_name)); | |
88 } | |
89 break; | |
90 default: | |
91 if (status_label) { | |
92 status_label->assign(l10n_util::GetStringUTF16( | |
93 IDS_SYNC_ERROR_SIGNING_IN)); | |
94 } | |
95 break; | |
96 } | |
97 } | |
98 | |
99 // Returns the message that should be displayed when the user is authenticated | 44 // Returns the message that should be displayed when the user is authenticated |
100 // and can connect to the sync server. If the user hasn't yet authenticated, an | 45 // and can connect to the sync server. If the user hasn't yet authenticated, an |
101 // empty string is returned. | 46 // empty string is returned. |
102 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, | 47 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
| 48 const SigninManager& signin, |
103 StatusLabelStyle style) { | 49 StatusLabelStyle style) { |
104 if (!service->sync_initialized()) | 50 string16 user_name = UTF8ToUTF16(signin.GetAuthenticatedUsername()); |
| 51 |
| 52 if (!user_name.empty() && |
| 53 (!service || service->IsManaged())) { |
| 54 // User is signed in, but sync is disabled. |
| 55 return l10n_util::GetStringFUTF16(IDS_SIGNED_IN_WITH_SYNC_DISABLED, |
| 56 user_name); |
| 57 } |
| 58 |
| 59 if (!service || !service->sync_initialized()) { |
| 60 // User is not signed in, or sync is still initializing. |
105 return string16(); | 61 return string16(); |
| 62 } |
106 | 63 |
107 string16 user_name = UTF8ToUTF16(service->profile()->GetPrefs()->GetString( | |
108 prefs::kGoogleServicesUsername)); | |
109 DCHECK(!user_name.empty()); | 64 DCHECK(!user_name.empty()); |
110 | 65 |
111 // Message may also carry additional advice with an HTML link, if acceptable. | 66 // Message may also carry additional advice with an HTML link, if acceptable. |
112 switch (style) { | 67 switch (style) { |
113 case PLAIN_TEXT: | 68 case PLAIN_TEXT: |
114 return l10n_util::GetStringFUTF16( | 69 return l10n_util::GetStringFUTF16( |
115 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | 70 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, |
116 user_name); | 71 user_name); |
117 case WITH_HTML: | 72 case WITH_HTML: |
118 return l10n_util::GetStringFUTF16( | 73 return l10n_util::GetStringFUTF16( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // status_label and link_label must either be both NULL or both non-NULL. | 112 // status_label and link_label must either be both NULL or both non-NULL. |
158 MessageType GetStatusInfo(ProfileSyncService* service, | 113 MessageType GetStatusInfo(ProfileSyncService* service, |
159 const SigninManager& signin, | 114 const SigninManager& signin, |
160 StatusLabelStyle style, | 115 StatusLabelStyle style, |
161 string16* status_label, | 116 string16* status_label, |
162 string16* link_label) { | 117 string16* link_label) { |
163 DCHECK_EQ(status_label == NULL, link_label == NULL); | 118 DCHECK_EQ(status_label == NULL, link_label == NULL); |
164 | 119 |
165 MessageType result_type(SYNCED); | 120 MessageType result_type(SYNCED); |
166 | 121 |
167 if (!service) { | 122 if (signin.GetAuthenticatedUsername().empty()) |
168 return PRE_SYNCED; | 123 return PRE_SYNCED; |
169 } | |
170 | 124 |
171 if (service->HasSyncSetupCompleted()) { | 125 if (!service || service->IsManaged() || service->HasSyncSetupCompleted()) { |
172 ProfileSyncService::Status status; | |
173 service->QueryDetailedSyncStatus(&status); | |
174 const AuthError& auth_error = service->GetAuthError(); | |
175 | |
176 // The order or priority is going to be: 1. Unrecoverable errors. | 126 // The order or priority is going to be: 1. Unrecoverable errors. |
177 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. | 127 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. |
178 | 128 |
179 if (service->HasUnrecoverableError()) { | 129 if (service && service->HasUnrecoverableError()) { |
180 if (status_label) { | 130 if (status_label) { |
181 status_label->assign(l10n_util::GetStringFUTF16( | 131 status_label->assign(l10n_util::GetStringFUTF16( |
182 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR, | 132 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR, |
183 l10n_util::GetStringUTF16(IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL))); | 133 l10n_util::GetStringUTF16(IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL))); |
184 } | 134 } |
185 return SYNC_ERROR; | 135 return SYNC_ERROR; |
186 } | 136 } |
187 | 137 |
188 // For auth errors first check if an auth is in progress. | 138 // For auth errors first check if an auth is in progress. |
189 if (signin.AuthInProgress()) { | 139 if (signin.AuthInProgress()) { |
190 if (status_label) { | 140 if (status_label) { |
191 status_label->assign( | 141 status_label->assign( |
192 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 142 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
193 } | 143 } |
194 return PRE_SYNCED; | 144 return PRE_SYNCED; |
195 } | 145 } |
196 | 146 |
197 // No auth in progress check for an auth error. | 147 // No auth in progress check for an auth error. |
| 148 AuthError auth_error = signin.signin_global_error()->GetLastAuthError(); |
198 if (auth_error.state() != AuthError::NONE) { | 149 if (auth_error.state() != AuthError::NONE) { |
199 if (status_label && link_label) { | 150 if (status_label && link_label) |
200 GetStatusLabelsForAuthError( | 151 signin_ui_util::GetStatusLabelsForAuthError( |
201 auth_error, *service, status_label, link_label); | 152 signin, status_label, link_label); |
202 } | |
203 return SYNC_ERROR; | 153 return SYNC_ERROR; |
204 } | 154 } |
205 | 155 |
206 // We dont have an auth error. Check for protocol error. | 156 // We dont have an auth error. Check for sync errors if the sync service |
207 if (ShouldShowActionOnUI(status.sync_protocol_error)) { | 157 // is enabled. |
208 if (status_label) { | 158 if (service) { |
209 GetStatusForActionableError(status.sync_protocol_error, | 159 ProfileSyncService::Status status; |
210 status_label); | 160 service->QueryDetailedSyncStatus(&status); |
| 161 |
| 162 if (ShouldShowActionOnUI(status.sync_protocol_error)) { |
| 163 if (status_label) { |
| 164 GetStatusForActionableError(status.sync_protocol_error, |
| 165 status_label); |
| 166 } |
| 167 return SYNC_ERROR; |
211 } | 168 } |
212 return SYNC_ERROR; | |
213 } | |
214 | 169 |
215 // Now finally passphrase error. | 170 // Now finally passphrase error. |
216 if (service->IsPassphraseRequired()) { | 171 if (service->IsPassphraseRequired()) { |
217 if (service->IsPassphraseRequiredForDecryption()) { | 172 if (service->IsPassphraseRequiredForDecryption()) { |
218 // TODO(lipalani) : Ask tim if this is still needed. | 173 // TODO(lipalani) : Ask tim if this is still needed. |
219 // NOT first machine. | 174 // NOT first machine. |
220 // Show a link ("needs attention"), but still indicate the | 175 // Show a link ("needs attention"), but still indicate the |
221 // current synced status. Return SYNC_PROMO so that | 176 // current synced status. Return SYNC_PROMO so that |
222 // the configure link will still be shown. | 177 // the configure link will still be shown. |
223 if (status_label && link_label) { | 178 if (status_label && link_label) { |
224 status_label->assign(GetSyncedStateStatusLabel(service, style)); | 179 status_label->assign(GetSyncedStateStatusLabel( |
225 link_label->assign( | 180 service, signin, style)); |
226 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); | 181 link_label->assign( |
| 182 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); |
| 183 } |
| 184 return SYNC_PROMO; |
227 } | 185 } |
228 return SYNC_PROMO; | |
229 } | 186 } |
230 } | 187 } |
231 | 188 |
232 // There is no error. Display "Last synced..." message. | 189 // There is no error. Display "Last synced..." message. |
233 if (status_label) | 190 if (status_label) |
234 status_label->assign(GetSyncedStateStatusLabel(service, style)); | 191 status_label->assign(GetSyncedStateStatusLabel(service, signin, style)); |
235 return SYNCED; | 192 return SYNCED; |
236 } else { | 193 } else { |
237 // Either show auth error information with a link to re-login, auth in prog, | 194 // Either show auth error information with a link to re-login, auth in prog, |
238 // or provide a link to continue with setup. | 195 // or provide a link to continue with setup. |
239 result_type = PRE_SYNCED; | |
240 if (service->FirstSetupInProgress()) { | 196 if (service->FirstSetupInProgress()) { |
| 197 result_type = PRE_SYNCED; |
241 ProfileSyncService::Status status; | 198 ProfileSyncService::Status status; |
242 service->QueryDetailedSyncStatus(&status); | 199 service->QueryDetailedSyncStatus(&status); |
243 const AuthError& auth_error = service->GetAuthError(); | 200 AuthError auth_error = signin.signin_global_error()->GetLastAuthError(); |
244 if (status_label) { | 201 if (status_label) { |
245 status_label->assign( | 202 status_label->assign( |
246 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); | 203 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); |
247 } | 204 } |
248 if (signin.AuthInProgress()) { | 205 if (signin.AuthInProgress()) { |
249 if (status_label) { | 206 if (status_label) { |
250 status_label->assign( | 207 status_label->assign( |
251 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 208 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
252 } | 209 } |
253 } else if (auth_error.state() != AuthError::NONE && | 210 } else if (auth_error.state() != AuthError::NONE && |
254 auth_error.state() != AuthError::TWO_FACTOR) { | 211 auth_error.state() != AuthError::TWO_FACTOR) { |
255 if (status_label) { | 212 if (status_label) { |
256 status_label->clear(); | 213 status_label->clear(); |
257 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL); | 214 signin_ui_util::GetStatusLabelsForAuthError( |
| 215 signin, status_label, NULL); |
258 } | 216 } |
259 result_type = SYNC_ERROR; | 217 result_type = SYNC_ERROR; |
260 } | 218 } |
261 } else if (service->HasUnrecoverableError()) { | 219 } else if (service->HasUnrecoverableError()) { |
262 result_type = SYNC_ERROR; | 220 result_type = SYNC_ERROR; |
263 ProfileSyncService::Status status; | 221 ProfileSyncService::Status status; |
264 service->QueryDetailedSyncStatus(&status); | 222 service->QueryDetailedSyncStatus(&status); |
265 if (ShouldShowActionOnUI(status.sync_protocol_error)) { | 223 if (ShouldShowActionOnUI(status.sync_protocol_error)) { |
266 if (status_label) { | 224 if (status_label) { |
267 GetStatusForActionableError(status.sync_protocol_error, | 225 GetStatusForActionableError(status.sync_protocol_error, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 string16 ConstructTime(int64 time_in_int) { | 333 string16 ConstructTime(int64 time_in_int) { |
376 base::Time time = base::Time::FromInternalValue(time_in_int); | 334 base::Time time = base::Time::FromInternalValue(time_in_int); |
377 | 335 |
378 // If time is null the format function returns a time in 1969. | 336 // If time is null the format function returns a time in 1969. |
379 if (time.is_null()) | 337 if (time.is_null()) |
380 return string16(); | 338 return string16(); |
381 return base::TimeFormatFriendlyDateAndTime(time); | 339 return base::TimeFormatFriendlyDateAndTime(time); |
382 } | 340 } |
383 | 341 |
384 } // namespace sync_ui_util | 342 } // namespace sync_ui_util |
OLD | NEW |