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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 namespace sync_ui_util { | 38 namespace sync_ui_util { |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Given an authentication state this helper function returns various labels | 42 // Given an authentication state this helper function returns various labels |
43 // that can be used to display information about the state. | 43 // that can be used to display information about the state. |
44 void GetStatusLabelsForAuthError(const AuthError& auth_error, | 44 void GetStatusLabelsForAuthError(const AuthError& auth_error, |
45 const ProfileSyncService& service, | 45 const ProfileSyncService& service, |
46 string16* status_label, | 46 string16* status_label, |
47 string16* link_label, | 47 string16* link_label) { |
48 string16* global_error_menu_label, | |
49 string16* global_error_bubble_message, | |
50 string16* global_error_bubble_accept_label) { | |
51 string16 username = UTF8ToUTF16(service.profile()->GetPrefs()->GetString( | 48 string16 username = UTF8ToUTF16(service.profile()->GetPrefs()->GetString( |
52 prefs::kGoogleServicesUsername)); | 49 prefs::kGoogleServicesUsername)); |
53 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 50 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
54 if (link_label) | 51 if (link_label) |
55 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); | 52 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); |
56 | 53 |
57 switch (auth_error.state()) { | 54 switch (auth_error.state()) { |
58 case AuthError::INVALID_GAIA_CREDENTIALS: | 55 case AuthError::INVALID_GAIA_CREDENTIALS: |
59 case AuthError::ACCOUNT_DELETED: | 56 case AuthError::ACCOUNT_DELETED: |
60 case AuthError::ACCOUNT_DISABLED: | 57 case AuthError::ACCOUNT_DISABLED: |
61 // 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 |
62 // credentials are out-of-date. | 59 // credentials are out-of-date. |
63 if (username.empty()) { | 60 if (username.empty()) { |
64 if (status_label) { | 61 if (status_label) { |
65 status_label->assign( | 62 status_label->assign( |
66 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); | 63 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); |
67 } | 64 } |
68 } else { | 65 } else { |
69 if (status_label) { | 66 if (status_label) { |
70 status_label->assign( | 67 status_label->assign( |
71 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); | 68 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); |
72 } | 69 } |
73 if (global_error_menu_label) { | |
74 global_error_menu_label->assign(l10n_util::GetStringUTF16( | |
75 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM)); | |
76 } | |
77 if (global_error_bubble_message) { | |
78 global_error_bubble_message->assign(l10n_util::GetStringFUTF16( | |
79 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name)); | |
80 } | |
81 if (global_error_bubble_accept_label) { | |
82 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( | |
83 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); | |
84 } | |
85 } | 70 } |
86 break; | 71 break; |
87 case AuthError::SERVICE_UNAVAILABLE: | 72 case AuthError::SERVICE_UNAVAILABLE: |
88 if (status_label) { | 73 if (status_label) { |
89 status_label->assign( | 74 status_label->assign( |
90 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); | 75 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); |
91 } | 76 } |
92 if (link_label) | 77 if (link_label) |
93 link_label->clear(); | 78 link_label->clear(); |
94 if (global_error_menu_label) { | |
95 global_error_menu_label->assign(l10n_util::GetStringUTF16( | |
96 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM)); | |
97 } | |
98 if (global_error_bubble_message) { | |
99 global_error_bubble_message->assign(l10n_util::GetStringFUTF16( | |
100 IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_MESSAGE, product_name)); | |
101 } | |
102 if (global_error_bubble_accept_label) { | |
103 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( | |
104 IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_ACCEPT)); | |
105 } | |
106 break; | 79 break; |
107 case AuthError::CONNECTION_FAILED: | 80 case AuthError::CONNECTION_FAILED: |
108 // Note that there is little the user can do if the server is not | 81 // Note that there is little the user can do if the server is not |
109 // reachable. Since attempting to re-connect is done automatically by | 82 // reachable. Since attempting to re-connect is done automatically by |
110 // the Syncer, we do not show the (re)login link. | 83 // the Syncer, we do not show the (re)login link. |
111 if (status_label) { | 84 if (status_label) { |
112 status_label->assign( | 85 status_label->assign( |
113 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE, | 86 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE, |
114 product_name)); | 87 product_name)); |
115 } | 88 } |
116 break; | 89 break; |
117 default: | 90 default: |
118 if (status_label) { | 91 if (status_label) { |
119 status_label->assign(l10n_util::GetStringUTF16( | 92 status_label->assign(l10n_util::GetStringUTF16( |
120 IDS_SYNC_ERROR_SIGNING_IN)); | 93 IDS_SYNC_ERROR_SIGNING_IN)); |
121 } | 94 } |
122 if (global_error_menu_label) { | |
123 global_error_menu_label->assign(l10n_util::GetStringUTF16( | |
124 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM)); | |
125 } | |
126 if (global_error_bubble_message) { | |
127 global_error_bubble_message->assign(l10n_util::GetStringFUTF16( | |
128 IDS_SYNC_OTHER_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name)); | |
129 } | |
130 if (global_error_bubble_accept_label) { | |
131 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( | |
132 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); | |
133 } | |
134 break; | 95 break; |
135 } | 96 } |
136 } | 97 } |
137 | 98 |
138 // Returns the message that should be displayed when the user is authenticated | 99 // Returns the message that should be displayed when the user is authenticated |
139 // and can connect to the sync server. If the user hasn't yet authenticated, an | 100 // and can connect to the sync server. If the user hasn't yet authenticated, an |
140 // empty string is returned. | 101 // empty string is returned. |
141 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, | 102 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
142 StatusLabelStyle style) { | 103 StatusLabelStyle style) { |
143 if (!service->sync_initialized()) | 104 if (!service->sync_initialized()) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if (status_label) { | 190 if (status_label) { |
230 status_label->assign( | 191 status_label->assign( |
231 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 192 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
232 } | 193 } |
233 return PRE_SYNCED; | 194 return PRE_SYNCED; |
234 } | 195 } |
235 | 196 |
236 // No auth in progress check for an auth error. | 197 // No auth in progress check for an auth error. |
237 if (auth_error.state() != AuthError::NONE) { | 198 if (auth_error.state() != AuthError::NONE) { |
238 if (status_label && link_label) { | 199 if (status_label && link_label) { |
239 GetStatusLabelsForAuthError(auth_error, *service, | 200 GetStatusLabelsForAuthError( |
240 status_label, link_label, NULL, NULL, NULL); | 201 auth_error, *service, status_label, link_label); |
241 } | 202 } |
242 return SYNC_ERROR; | 203 return SYNC_ERROR; |
243 } | 204 } |
244 | 205 |
245 // We dont have an auth error. Check for protocol error. | 206 // We dont have an auth error. Check for protocol error. |
246 if (ShouldShowActionOnUI(status.sync_protocol_error)) { | 207 if (ShouldShowActionOnUI(status.sync_protocol_error)) { |
247 if (status_label) { | 208 if (status_label) { |
248 GetStatusForActionableError(status.sync_protocol_error, | 209 GetStatusForActionableError(status.sync_protocol_error, |
249 status_label); | 210 status_label); |
250 } | 211 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 247 } |
287 if (signin.AuthInProgress()) { | 248 if (signin.AuthInProgress()) { |
288 if (status_label) { | 249 if (status_label) { |
289 status_label->assign( | 250 status_label->assign( |
290 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 251 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
291 } | 252 } |
292 } else if (auth_error.state() != AuthError::NONE && | 253 } else if (auth_error.state() != AuthError::NONE && |
293 auth_error.state() != AuthError::TWO_FACTOR) { | 254 auth_error.state() != AuthError::TWO_FACTOR) { |
294 if (status_label) { | 255 if (status_label) { |
295 status_label->clear(); | 256 status_label->clear(); |
296 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL, | 257 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL); |
297 NULL, NULL, NULL); | |
298 } | 258 } |
299 result_type = SYNC_ERROR; | 259 result_type = SYNC_ERROR; |
300 } | 260 } |
301 } else if (service->HasUnrecoverableError()) { | 261 } else if (service->HasUnrecoverableError()) { |
302 result_type = SYNC_ERROR; | 262 result_type = SYNC_ERROR; |
303 ProfileSyncService::Status status; | 263 ProfileSyncService::Status status; |
304 service->QueryDetailedSyncStatus(&status); | 264 service->QueryDetailedSyncStatus(&status); |
305 if (ShouldShowActionOnUI(status.sync_protocol_error)) { | 265 if (ShouldShowActionOnUI(status.sync_protocol_error)) { |
306 if (status_label) { | 266 if (status_label) { |
307 GetStatusForActionableError(status.sync_protocol_error, | 267 GetStatusForActionableError(status.sync_protocol_error, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 string16* menu_label, | 341 string16* menu_label, |
382 string16* bubble_message, | 342 string16* bubble_message, |
383 string16* bubble_accept_label) { | 343 string16* bubble_accept_label) { |
384 DCHECK(menu_label); | 344 DCHECK(menu_label); |
385 DCHECK(bubble_message); | 345 DCHECK(bubble_message); |
386 DCHECK(bubble_accept_label); | 346 DCHECK(bubble_accept_label); |
387 *menu_label = string16(); | 347 *menu_label = string16(); |
388 *bubble_message = string16(); | 348 *bubble_message = string16(); |
389 *bubble_accept_label = string16(); | 349 *bubble_accept_label = string16(); |
390 | 350 |
| 351 // Only display an error if we've completed sync setup. |
391 if (!service->HasSyncSetupCompleted()) | 352 if (!service->HasSyncSetupCompleted()) |
392 return; | 353 return; |
393 | 354 |
394 MessageType status = GetStatus(service, signin); | 355 // Display a passphrase error if we have one. |
395 if (status == SYNC_ERROR) { | |
396 const AuthError& auth_error = service->GetAuthError(); | |
397 if (auth_error.state() != AuthError::NONE) { | |
398 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, | |
399 menu_label, bubble_message, bubble_accept_label); | |
400 // If we have an actionable auth error, display it. | |
401 if (!menu_label->empty()) | |
402 return; | |
403 } | |
404 } | |
405 | |
406 // No actionable auth error - display the passphrase error. | |
407 if (service->IsPassphraseRequired() && | 356 if (service->IsPassphraseRequired() && |
408 service->IsPassphraseRequiredForDecryption()) { | 357 service->IsPassphraseRequiredForDecryption()) { |
409 // This is not the first machine so ask user to enter passphrase. | 358 // This is not the first machine so ask user to enter passphrase. |
410 *menu_label = l10n_util::GetStringUTF16( | 359 *menu_label = l10n_util::GetStringUTF16( |
411 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); | 360 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); |
412 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 361 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
413 *bubble_message = l10n_util::GetStringFUTF16( | 362 *bubble_message = l10n_util::GetStringFUTF16( |
414 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); | 363 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); |
415 *bubble_accept_label = l10n_util::GetStringUTF16( | 364 *bubble_accept_label = l10n_util::GetStringUTF16( |
416 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); | 365 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); |
417 return; | 366 return; |
418 } | 367 } |
419 } | 368 } |
420 | 369 |
421 MessageType GetStatus( | 370 MessageType GetStatus( |
422 ProfileSyncService* service, const SigninManager& signin) { | 371 ProfileSyncService* service, const SigninManager& signin) { |
423 return sync_ui_util::GetStatusInfo(service, signin, WITH_HTML, NULL, NULL); | 372 return sync_ui_util::GetStatusInfo(service, signin, WITH_HTML, NULL, NULL); |
424 } | 373 } |
425 | 374 |
426 string16 GetSyncMenuLabel( | |
427 ProfileSyncService* service, const SigninManager& signin) { | |
428 MessageType type = GetStatus(service, signin); | |
429 | |
430 if (type == sync_ui_util::SYNCED) | |
431 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); | |
432 else if (type == sync_ui_util::SYNC_ERROR) | |
433 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | |
434 else | |
435 return l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); | |
436 } | |
437 | |
438 string16 ConstructTime(int64 time_in_int) { | 375 string16 ConstructTime(int64 time_in_int) { |
439 base::Time time = base::Time::FromInternalValue(time_in_int); | 376 base::Time time = base::Time::FromInternalValue(time_in_int); |
440 | 377 |
441 // If time is null the format function returns a time in 1969. | 378 // If time is null the format function returns a time in 1969. |
442 if (time.is_null()) | 379 if (time.is_null()) |
443 return string16(); | 380 return string16(); |
444 return base::TimeFormatFriendlyDateAndTime(time); | 381 return base::TimeFormatFriendlyDateAndTime(time); |
445 } | 382 } |
446 | 383 |
447 std::string MakeSyncAuthErrorText( | |
448 const GoogleServiceAuthError::State& state) { | |
449 switch (state) { | |
450 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: | |
451 case GoogleServiceAuthError::ACCOUNT_DELETED: | |
452 case GoogleServiceAuthError::ACCOUNT_DISABLED: | |
453 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: | |
454 return "INVALID_GAIA_CREDENTIALS"; | |
455 case GoogleServiceAuthError::USER_NOT_SIGNED_UP: | |
456 return "USER_NOT_SIGNED_UP"; | |
457 case GoogleServiceAuthError::CONNECTION_FAILED: | |
458 return "CONNECTION_FAILED"; | |
459 default: | |
460 return std::string(); | |
461 } | |
462 } | |
463 | |
464 } // namespace sync_ui_util | 384 } // namespace sync_ui_util |
OLD | NEW |