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

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

Issue 7906013: Show bubble and wrench menu item for sync error (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor into sync_ui_util Created 9 years, 3 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/ui/toolbar/wrench_menu_model.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) 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"
(...skipping 14 matching lines...) Expand all
25 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 28
29 typedef GoogleServiceAuthError AuthError; 29 typedef GoogleServiceAuthError AuthError;
30 30
31 namespace sync_ui_util { 31 namespace sync_ui_util {
32 32
33 namespace { 33 namespace {
34 34
35 // Given an authentication state, this helper function returns the appropriate 35 // Given an authentication state this hellper function returns various labels
tim (not reviewing) 2011/09/20 03:26:47 nit - helper
sail 2011/09/20 21:45:43 Done.
36 // status message and, if necessary, the text that should appear in the 36 // that can be used to display information about the state.
37 // re-login link.
38 void GetStatusLabelsForAuthError(const AuthError& auth_error, 37 void GetStatusLabelsForAuthError(const AuthError& auth_error,
39 ProfileSyncService* service, string16* status_label, 38 const ProfileSyncService& service,
40 string16* link_label) { 39 string16* status_label,
40 string16* link_label,
41 string16* global_error_menu_label,
42 string16* global_error_bubble_message,
43 string16* global_error_bubble_accept_label) {
44 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
41 if (link_label) 45 if (link_label)
42 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL)); 46 link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL));
43 if (auth_error.state() == AuthError::INVALID_GAIA_CREDENTIALS || 47
44 auth_error.state() == AuthError::ACCOUNT_DELETED || 48 switch (auth_error.state()) {
45 auth_error.state() == AuthError::ACCOUNT_DISABLED) { 49 case AuthError::INVALID_GAIA_CREDENTIALS:
46 // If the user name is empty then the first login failed, otherwise the 50 case AuthError::ACCOUNT_DELETED:
47 // credentials are out-of-date. 51 case AuthError::ACCOUNT_DISABLED:
48 if (service->GetAuthenticatedUsername().empty()) 52 // If the user name is empty then the first login failed, otherwise the
49 status_label->assign( 53 // credentials are out-of-date.
50 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS)); 54 if (service.GetAuthenticatedUsername().empty()) {
51 else 55 if (status_label) {
52 status_label->assign( 56 status_label->assign(
53 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE)); 57 l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS));
54 } else if (auth_error.state() == AuthError::SERVICE_UNAVAILABLE) { 58 }
55 DCHECK(service->GetAuthenticatedUsername().empty()); 59 } else {
56 status_label->assign( 60 if (status_label) {
57 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE)); 61 status_label->assign(
58 } else if (auth_error.state() == AuthError::CONNECTION_FAILED) { 62 l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE));
59 // Note that there is little the user can do if the server is not 63 }
60 // reachable. Since attempting to re-connect is done automatically by 64 if (global_error_menu_label) {
61 // the Syncer, we do not show the (re)login link. 65 global_error_menu_label->assign(l10n_util::GetStringUTF16(
62 status_label->assign( 66 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM));
63 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE, 67 }
64 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 68 if (global_error_bubble_message) {
65 if (link_label) 69 global_error_bubble_message->assign(l10n_util::GetStringFUTF16(
66 link_label->clear(); 70 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name));
67 } else { 71 }
68 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_ERROR_SIGNING_IN)); 72 if (global_error_bubble_accept_label) {
73 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16(
74 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT));
75 }
76 }
77 break;
78 case AuthError::SERVICE_UNAVAILABLE:
79 DCHECK(service.GetAuthenticatedUsername().empty());
80 if (status_label) {
81 status_label->assign(
82 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE));
83 }
84 if (link_label)
85 link_label->clear();
86 if (global_error_menu_label) {
87 global_error_menu_label->assign(l10n_util::GetStringUTF16(
88 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM));
89 }
90 if (global_error_bubble_message) {
91 global_error_bubble_message->assign(l10n_util::GetStringFUTF16(
92 IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_MESSAGE, product_name));
93 }
94 if (global_error_bubble_accept_label) {
95 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16(
96 IDS_SYNC_UNAVAILABLE_ERROR_BUBBLE_VIEW_ACCEPT));
97 }
98 break;
99 case AuthError::CONNECTION_FAILED:
100 // Note that there is little the user can do if the server is not
101 // reachable. Since attempting to re-connect is done automatically by
102 // the Syncer, we do not show the (re)login link.
103 if (status_label) {
104 status_label->assign(
105 l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE,
106 product_name));
107 }
108 break;
109 default:
110 if (status_label) {
111 status_label->assign(l10n_util::GetStringUTF16(
112 IDS_SYNC_ERROR_SIGNING_IN));
113 }
114 if (global_error_menu_label) {
115 global_error_menu_label->assign(l10n_util::GetStringUTF16(
116 IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM));
117 }
118 if (global_error_bubble_message) {
119 global_error_bubble_message->assign(l10n_util::GetStringFUTF16(
120 IDS_SYNC_OTHER_SIGN_IN_ERROR_BUBBLE_VIEW_MESSAGE, product_name));
121 }
122 if (global_error_bubble_accept_label) {
123 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16(
124 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT));
125 }
126 break;
69 } 127 }
70 } 128 }
71 129
72 // Returns the message that should be displayed when the user is authenticated 130 // Returns the message that should be displayed when the user is authenticated
73 // and can connect to the sync server. If the user hasn't yet authenticated, an 131 // and can connect to the sync server. If the user hasn't yet authenticated, an
74 // empty string is returned. 132 // empty string is returned.
75 string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { 133 string16 GetSyncedStateStatusLabel(ProfileSyncService* service) {
76 string16 label; 134 string16 label;
77 string16 user_name(service->GetAuthenticatedUsername()); 135 string16 user_name(service->GetAuthenticatedUsername());
78 if (user_name.empty()) 136 if (user_name.empty())
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if (status_label) { 197 if (status_label) {
140 status_label->assign( 198 status_label->assign(
141 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 199 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
142 } 200 }
143 return PRE_SYNCED; 201 return PRE_SYNCED;
144 } 202 }
145 203
146 // No auth in progress check for an auth error. 204 // No auth in progress check for an auth error.
147 if (auth_error.state() != AuthError::NONE) { 205 if (auth_error.state() != AuthError::NONE) {
148 if (status_label && link_label) { 206 if (status_label && link_label) {
149 GetStatusLabelsForAuthError(auth_error, service, 207 GetStatusLabelsForAuthError(auth_error, *service,
150 status_label, link_label); 208 status_label, link_label, NULL, NULL, NULL);
151 } 209 }
152 return SYNC_ERROR; 210 return SYNC_ERROR;
153 } 211 }
154 212
155 // We dont have an auth error. Check for protocol error. 213 // We dont have an auth error. Check for protocol error.
156 if (ShouldShowActionOnUI(status.sync_protocol_error)) { 214 if (ShouldShowActionOnUI(status.sync_protocol_error)) {
157 if (status_label) { 215 if (status_label) {
158 GetStatusForActionableError(status.sync_protocol_error, 216 GetStatusForActionableError(status.sync_protocol_error,
159 status_label); 217 status_label);
160 } 218 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 255 }
198 if (service->UIShouldDepictAuthInProgress()) { 256 if (service->UIShouldDepictAuthInProgress()) {
199 if (status_label) { 257 if (status_label) {
200 status_label->assign( 258 status_label->assign(
201 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 259 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
202 } 260 }
203 } else if (auth_error.state() != AuthError::NONE && 261 } else if (auth_error.state() != AuthError::NONE &&
204 auth_error.state() != AuthError::TWO_FACTOR) { 262 auth_error.state() != AuthError::TWO_FACTOR) {
205 if (status_label) { 263 if (status_label) {
206 status_label->clear(); 264 status_label->clear();
207 GetStatusLabelsForAuthError(auth_error, service, status_label, NULL); 265 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL,
266 NULL, NULL, NULL);
208 } 267 }
209 result_type = SYNC_ERROR; 268 result_type = SYNC_ERROR;
210 } else if (!status.authenticated) { 269 } else if (!status.authenticated) {
211 if (status_label) { 270 if (status_label) {
212 status_label->assign( 271 status_label->assign(
213 l10n_util::GetStringUTF16(IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED)); 272 l10n_util::GetStringUTF16(IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED));
214 } 273 }
215 } 274 }
216 } else if (service->unrecoverable_error_detected()) { 275 } else if (service->unrecoverable_error_detected()) {
217 result_type = SYNC_ERROR; 276 result_type = SYNC_ERROR;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 337
279 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, 338 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service,
280 string16* status_label, 339 string16* status_label,
281 string16* link_label) { 340 string16* link_label) {
282 DCHECK(status_label); 341 DCHECK(status_label);
283 DCHECK(link_label); 342 DCHECK(link_label);
284 return sync_ui_util::GetStatusInfoForNewTabPage( 343 return sync_ui_util::GetStatusInfoForNewTabPage(
285 service, status_label, link_label); 344 service, status_label, link_label);
286 } 345 }
287 346
347 MessageType GetStatusLabelsForSyncGlobalError(ProfileSyncService* service,
348 string16* menu_label,
349 string16* bubble_message,
350 string16* bubble_accept_label) {
351 if (!service->HasSyncSetupCompleted())
352 return PRE_SYNCED;
353 MessageType status = GetStatus(service);
354 if (status != SYNC_ERROR)
355 return status;
356
357 if (service->IsPassphraseRequired() &&
358 service->IsPassphraseRequiredForDecryption()) {
359 // This is not the first machine so ask user to enter passphrase.
360 if (menu_label) {
361 *menu_label = l10n_util::GetStringUTF16(
362 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM);
363 }
364 if (bubble_message) {
365 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
366 *bubble_message = l10n_util::GetStringFUTF16(
367 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name);
368 }
369 if (bubble_accept_label) {
370 *bubble_accept_label = l10n_util::GetStringUTF16(
371 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT);
372 }
373 return SYNC_ERROR;
374 }
375
376 const AuthError& auth_error = service->GetAuthError();
377 if (auth_error.state() != AuthError::NONE) {
378 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL,
379 menu_label, bubble_message, bubble_accept_label);
380 return SYNC_ERROR;
381 }
382
383 return SYNCED;
384 }
385
288 MessageType GetStatus(ProfileSyncService* service) { 386 MessageType GetStatus(ProfileSyncService* service) {
289 return sync_ui_util::GetStatusInfo(service, NULL, NULL); 387 return sync_ui_util::GetStatusInfo(service, NULL, NULL);
290 } 388 }
291 389
292 bool ShouldShowSyncErrorButton(ProfileSyncService* service) { 390 bool ShouldShowSyncErrorButton(ProfileSyncService* service) {
293 return service && 391 return service &&
294 ((!service->IsManaged() && 392 ((!service->IsManaged() &&
295 service->HasSyncSetupCompleted()) && 393 service->HasSyncSetupCompleted()) &&
296 (GetStatus(service) == sync_ui_util::SYNC_ERROR || 394 (GetStatus(service) == sync_ui_util::SYNC_ERROR ||
297 service->IsPassphraseRequired())); 395 service->IsPassphraseRequired()));
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 DictionaryValue* val = new DictionaryValue; 648 DictionaryValue* val = new DictionaryValue;
551 val->SetString("model_type", ModelTypeToString(it->first)); 649 val->SetString("model_type", ModelTypeToString(it->first));
552 val->SetString("group", ModelSafeGroupToString(it->second)); 650 val->SetString("group", ModelSafeGroupToString(it->second));
553 routing_info->Append(val); 651 routing_info->Append(val);
554 } 652 }
555 } 653 }
556 } 654 }
557 } 655 }
558 656
559 } // namespace sync_ui_util 657 } // namespace sync_ui_util
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_ui_util.h ('k') | chrome/browser/ui/toolbar/wrench_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698