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

Side by Side Diff: chrome/browser/sync/sync_ui_util.cc

Issue 11886079: Revert 177136 due to memory error on Mac ASAN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/sync_ui_util.h ('k') | chrome/browser/sync/sync_ui_util_unittest.cc » ('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 (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
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) {
48 string16 username = UTF8ToUTF16(service.profile()->GetPrefs()->GetString( 51 string16 username = UTF8ToUTF16(service.profile()->GetPrefs()->GetString(
49 prefs::kGoogleServicesUsername)); 52 prefs::kGoogleServicesUsername));
50 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 53 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
51 if (link_label) 54 if (link_label)
52 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); 55 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL));
53 56
54 switch (auth_error.state()) { 57 switch (auth_error.state()) {
55 case AuthError::INVALID_GAIA_CREDENTIALS: 58 case AuthError::INVALID_GAIA_CREDENTIALS:
56 case AuthError::ACCOUNT_DELETED: 59 case AuthError::ACCOUNT_DELETED:
57 case AuthError::ACCOUNT_DISABLED: 60 case AuthError::ACCOUNT_DISABLED:
58 // If the user name is empty then the first login failed, otherwise the 61 // If the user name is empty then the first login failed, otherwise the
59 // credentials are out-of-date. 62 // credentials are out-of-date.
60 if (username.empty()) { 63 if (username.empty()) {
61 if (status_label) { 64 if (status_label) {
62 status_label->assign( 65 status_label->assign(
63 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); 66 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS));
64 } 67 }
65 } else { 68 } else {
66 if (status_label) { 69 if (status_label) {
67 status_label->assign( 70 status_label->assign(
68 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); 71 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE));
69 } 72 }
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 }
70 } 85 }
71 break; 86 break;
72 case AuthError::SERVICE_UNAVAILABLE: 87 case AuthError::SERVICE_UNAVAILABLE:
73 if (status_label) { 88 if (status_label) {
74 status_label->assign( 89 status_label->assign(
75 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); 90 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE));
76 } 91 }
77 if (link_label) 92 if (link_label)
78 link_label->clear(); 93 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 }
79 break; 106 break;
80 case AuthError::CONNECTION_FAILED: 107 case AuthError::CONNECTION_FAILED:
81 // Note that there is little the user can do if the server is not 108 // 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 109 // reachable. Since attempting to re-connect is done automatically by
83 // the Syncer, we do not show the (re)login link. 110 // the Syncer, we do not show the (re)login link.
84 if (status_label) { 111 if (status_label) {
85 status_label->assign( 112 status_label->assign(
86 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE, 113 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE,
87 product_name)); 114 product_name));
88 } 115 }
89 break; 116 break;
90 default: 117 default:
91 if (status_label) { 118 if (status_label) {
92 status_label->assign(l10n_util::GetStringUTF16( 119 status_label->assign(l10n_util::GetStringUTF16(
93 IDS_SYNC_ERROR_SIGNING_IN)); 120 IDS_SYNC_ERROR_SIGNING_IN));
94 } 121 }
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 }
95 break; 134 break;
96 } 135 }
97 } 136 }
98 137
99 // Returns the message that should be displayed when the user is authenticated 138 // 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 139 // and can connect to the sync server. If the user hasn't yet authenticated, an
101 // empty string is returned. 140 // empty string is returned.
102 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, 141 string16 GetSyncedStateStatusLabel(ProfileSyncService* service,
103 StatusLabelStyle style) { 142 StatusLabelStyle style) {
104 if (!service->sync_initialized()) 143 if (!service->sync_initialized())
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (status_label) { 229 if (status_label) {
191 status_label->assign( 230 status_label->assign(
192 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 231 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
193 } 232 }
194 return PRE_SYNCED; 233 return PRE_SYNCED;
195 } 234 }
196 235
197 // No auth in progress check for an auth error. 236 // No auth in progress check for an auth error.
198 if (auth_error.state() != AuthError::NONE) { 237 if (auth_error.state() != AuthError::NONE) {
199 if (status_label && link_label) { 238 if (status_label && link_label) {
200 GetStatusLabelsForAuthError( 239 GetStatusLabelsForAuthError(auth_error, *service,
201 auth_error, *service, status_label, link_label); 240 status_label, link_label, NULL, NULL, NULL);
202 } 241 }
203 return SYNC_ERROR; 242 return SYNC_ERROR;
204 } 243 }
205 244
206 // We dont have an auth error. Check for protocol error. 245 // We dont have an auth error. Check for protocol error.
207 if (ShouldShowActionOnUI(status.sync_protocol_error)) { 246 if (ShouldShowActionOnUI(status.sync_protocol_error)) {
208 if (status_label) { 247 if (status_label) {
209 GetStatusForActionableError(status.sync_protocol_error, 248 GetStatusForActionableError(status.sync_protocol_error,
210 status_label); 249 status_label);
211 } 250 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 286 }
248 if (signin.AuthInProgress()) { 287 if (signin.AuthInProgress()) {
249 if (status_label) { 288 if (status_label) {
250 status_label->assign( 289 status_label->assign(
251 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 290 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
252 } 291 }
253 } else if (auth_error.state() != AuthError::NONE && 292 } else if (auth_error.state() != AuthError::NONE &&
254 auth_error.state() != AuthError::TWO_FACTOR) { 293 auth_error.state() != AuthError::TWO_FACTOR) {
255 if (status_label) { 294 if (status_label) {
256 status_label->clear(); 295 status_label->clear();
257 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL); 296 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL,
297 NULL, NULL, NULL);
258 } 298 }
259 result_type = SYNC_ERROR; 299 result_type = SYNC_ERROR;
260 } 300 }
261 } else if (service->HasUnrecoverableError()) { 301 } else if (service->HasUnrecoverableError()) {
262 result_type = SYNC_ERROR; 302 result_type = SYNC_ERROR;
263 ProfileSyncService::Status status; 303 ProfileSyncService::Status status;
264 service->QueryDetailedSyncStatus(&status); 304 service->QueryDetailedSyncStatus(&status);
265 if (ShouldShowActionOnUI(status.sync_protocol_error)) { 305 if (ShouldShowActionOnUI(status.sync_protocol_error)) {
266 if (status_label) { 306 if (status_label) {
267 GetStatusForActionableError(status.sync_protocol_error, 307 GetStatusForActionableError(status.sync_protocol_error,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 string16* menu_label, 381 string16* menu_label,
342 string16* bubble_message, 382 string16* bubble_message,
343 string16* bubble_accept_label) { 383 string16* bubble_accept_label) {
344 DCHECK(menu_label); 384 DCHECK(menu_label);
345 DCHECK(bubble_message); 385 DCHECK(bubble_message);
346 DCHECK(bubble_accept_label); 386 DCHECK(bubble_accept_label);
347 *menu_label = string16(); 387 *menu_label = string16();
348 *bubble_message = string16(); 388 *bubble_message = string16();
349 *bubble_accept_label = string16(); 389 *bubble_accept_label = string16();
350 390
351 // Only display an error if we've completed sync setup.
352 if (!service->HasSyncSetupCompleted()) 391 if (!service->HasSyncSetupCompleted())
353 return; 392 return;
354 393
355 // Display a passphrase error if we have one. 394 MessageType status = GetStatus(service, signin);
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.
356 if (service->IsPassphraseRequired() && 407 if (service->IsPassphraseRequired() &&
357 service->IsPassphraseRequiredForDecryption()) { 408 service->IsPassphraseRequiredForDecryption()) {
358 // This is not the first machine so ask user to enter passphrase. 409 // This is not the first machine so ask user to enter passphrase.
359 *menu_label = l10n_util::GetStringUTF16( 410 *menu_label = l10n_util::GetStringUTF16(
360 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); 411 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM);
361 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 412 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
362 *bubble_message = l10n_util::GetStringFUTF16( 413 *bubble_message = l10n_util::GetStringFUTF16(
363 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); 414 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name);
364 *bubble_accept_label = l10n_util::GetStringUTF16( 415 *bubble_accept_label = l10n_util::GetStringUTF16(
365 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); 416 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT);
366 return; 417 return;
367 } 418 }
368 } 419 }
369 420
370 MessageType GetStatus( 421 MessageType GetStatus(
371 ProfileSyncService* service, const SigninManager& signin) { 422 ProfileSyncService* service, const SigninManager& signin) {
372 return sync_ui_util::GetStatusInfo(service, signin, WITH_HTML, NULL, NULL); 423 return sync_ui_util::GetStatusInfo(service, signin, WITH_HTML, NULL, NULL);
373 } 424 }
374 425
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
375 string16 ConstructTime(int64 time_in_int) { 438 string16 ConstructTime(int64 time_in_int) {
376 base::Time time = base::Time::FromInternalValue(time_in_int); 439 base::Time time = base::Time::FromInternalValue(time_in_int);
377 440
378 // If time is null the format function returns a time in 1969. 441 // If time is null the format function returns a time in 1969.
379 if (time.is_null()) 442 if (time.is_null())
380 return string16(); 443 return string16();
381 return base::TimeFormatFriendlyDateAndTime(time); 444 return base::TimeFormatFriendlyDateAndTime(time);
382 } 445 }
383 446
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
384 } // namespace sync_ui_util 464 } // namespace sync_ui_util
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_ui_util.h ('k') | chrome/browser/sync/sync_ui_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698