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

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: Address review comments 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 helper function returns various labels
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (status_label) { 195 if (status_label) {
138 status_label->assign( 196 status_label->assign(
139 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 197 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
140 } 198 }
141 return PRE_SYNCED; 199 return PRE_SYNCED;
142 } 200 }
143 201
144 // No auth in progress check for an auth error. 202 // No auth in progress check for an auth error.
145 if (auth_error.state() != AuthError::NONE) { 203 if (auth_error.state() != AuthError::NONE) {
146 if (status_label && link_label) { 204 if (status_label && link_label) {
147 GetStatusLabelsForAuthError(auth_error, service, 205 GetStatusLabelsForAuthError(auth_error, *service,
148 status_label, link_label); 206 status_label, link_label, NULL, NULL, NULL);
149 } 207 }
150 return SYNC_ERROR; 208 return SYNC_ERROR;
151 } 209 }
152 210
153 // We dont have an auth error. Check for protocol error. 211 // We dont have an auth error. Check for protocol error.
154 if (ShouldShowActionOnUI(status.sync_protocol_error)) { 212 if (ShouldShowActionOnUI(status.sync_protocol_error)) {
155 if (status_label) { 213 if (status_label) {
156 GetStatusForActionableError(status.sync_protocol_error, 214 GetStatusForActionableError(status.sync_protocol_error,
157 status_label); 215 status_label);
158 } 216 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 253 }
196 if (service->UIShouldDepictAuthInProgress()) { 254 if (service->UIShouldDepictAuthInProgress()) {
197 if (status_label) { 255 if (status_label) {
198 status_label->assign( 256 status_label->assign(
199 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 257 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
200 } 258 }
201 } else if (auth_error.state() != AuthError::NONE && 259 } else if (auth_error.state() != AuthError::NONE &&
202 auth_error.state() != AuthError::TWO_FACTOR) { 260 auth_error.state() != AuthError::TWO_FACTOR) {
203 if (status_label) { 261 if (status_label) {
204 status_label->clear(); 262 status_label->clear();
205 GetStatusLabelsForAuthError(auth_error, service, status_label, NULL); 263 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL,
264 NULL, NULL, NULL);
206 } 265 }
207 result_type = SYNC_ERROR; 266 result_type = SYNC_ERROR;
208 } else if (!status.authenticated) { 267 } else if (!status.authenticated) {
209 if (status_label) { 268 if (status_label) {
210 status_label->assign( 269 status_label->assign(
211 l10n_util::GetStringUTF16(IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED)); 270 l10n_util::GetStringUTF16(IDS_SYNC_ACCOUNT_DETAILS_NOT_ENTERED));
212 } 271 }
213 } 272 }
214 } else if (service->unrecoverable_error_detected()) { 273 } else if (service->unrecoverable_error_detected()) {
215 result_type = SYNC_ERROR; 274 result_type = SYNC_ERROR;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 335
277 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, 336 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service,
278 string16* status_label, 337 string16* status_label,
279 string16* link_label) { 338 string16* link_label) {
280 DCHECK(status_label); 339 DCHECK(status_label);
281 DCHECK(link_label); 340 DCHECK(link_label);
282 return sync_ui_util::GetStatusInfoForNewTabPage( 341 return sync_ui_util::GetStatusInfoForNewTabPage(
283 service, status_label, link_label); 342 service, status_label, link_label);
284 } 343 }
285 344
345 MessageType GetStatusLabelsForSyncGlobalError(ProfileSyncService* service,
346 string16* menu_label,
347 string16* bubble_message,
348 string16* bubble_accept_label) {
349 if (!service->HasSyncSetupCompleted())
350 return PRE_SYNCED;
351 MessageType status = GetStatus(service);
352 if (status != SYNC_ERROR)
353 return status;
354
355 if (service->IsPassphraseRequired() &&
356 service->IsPassphraseRequiredForDecryption()) {
357 // This is not the first machine so ask user to enter passphrase.
358 if (menu_label) {
359 *menu_label = l10n_util::GetStringUTF16(
360 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM);
361 }
362 if (bubble_message) {
363 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
364 *bubble_message = l10n_util::GetStringFUTF16(
365 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name);
366 }
367 if (bubble_accept_label) {
368 *bubble_accept_label = l10n_util::GetStringUTF16(
369 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT);
370 }
371 return SYNC_ERROR;
372 }
373
374 const AuthError& auth_error = service->GetAuthError();
375 if (auth_error.state() != AuthError::NONE) {
376 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL,
377 menu_label, bubble_message, bubble_accept_label);
378 return SYNC_ERROR;
379 }
380
381 return SYNCED;
382 }
383
286 MessageType GetStatus(ProfileSyncService* service) { 384 MessageType GetStatus(ProfileSyncService* service) {
287 return sync_ui_util::GetStatusInfo(service, NULL, NULL); 385 return sync_ui_util::GetStatusInfo(service, NULL, NULL);
288 } 386 }
289 387
290 bool ShouldShowSyncErrorButton(ProfileSyncService* service) { 388 bool ShouldShowSyncErrorButton(ProfileSyncService* service) {
291 return service && 389 return service &&
292 ((!service->IsManaged() && 390 ((!service->IsManaged() &&
293 service->HasSyncSetupCompleted()) && 391 service->HasSyncSetupCompleted()) &&
294 (GetStatus(service) == sync_ui_util::SYNC_ERROR || 392 (GetStatus(service) == sync_ui_util::SYNC_ERROR ||
295 service->IsPassphraseRequired())); 393 service->IsPassphraseRequired()));
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 DictionaryValue* val = new DictionaryValue; 646 DictionaryValue* val = new DictionaryValue;
549 val->SetString("model_type", ModelTypeToString(it->first)); 647 val->SetString("model_type", ModelTypeToString(it->first));
550 val->SetString("group", ModelSafeGroupToString(it->second)); 648 val->SetString("group", ModelSafeGroupToString(it->second));
551 routing_info->Append(val); 649 routing_info->Append(val);
552 } 650 }
553 } 651 }
554 } 652 }
555 } 653 }
556 654
557 } // namespace sync_ui_util 655 } // 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