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

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

Issue 2457483002: [MD Settings][Sync Settings] Updates sync status messages (Closed)
Patch Set: Created 4 years, 1 month 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 return l10n_util::GetStringFUTF16( 91 return l10n_util::GetStringFUTF16(
92 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK, 92 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK,
93 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); 93 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL));
94 default: 94 default:
95 NOTREACHED(); 95 NOTREACHED();
96 return NULL; 96 return NULL;
97 } 97 }
98 } 98 }
99 99
100 void GetStatusForActionableError( 100 void GetStatusForActionableError(const syncer::SyncProtocolError& error,
101 const syncer::SyncProtocolError& error, 101 base::string16* status_label,
102 base::string16* status_label) { 102 ActionType* action_type) {
103 DCHECK(status_label); 103 DCHECK(status_label);
104 switch (error.action) { 104 switch (error.action) {
105 case syncer::STOP_AND_RESTART_SYNC:
106 status_label->assign(
107 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC));
108 break;
109 case syncer::UPGRADE_CLIENT: 105 case syncer::UPGRADE_CLIENT:
110 status_label->assign( 106 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_UPGRADE_CLIENT));
111 l10n_util::GetStringFUTF16(IDS_SYNC_UPGRADE_CLIENT, 107 *action_type = UPGRADE_CLIENT;
112 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
113 break; 108 break;
114 case syncer::ENABLE_SYNC_ON_ACCOUNT: 109 case syncer::ENABLE_SYNC_ON_ACCOUNT:
115 status_label->assign( 110 status_label->assign(
116 l10n_util::GetStringUTF16(IDS_SYNC_ENABLE_SYNC_ON_ACCOUNT)); 111 l10n_util::GetStringUTF16(IDS_SYNC_ENABLE_SYNC_ON_ACCOUNT));
117 break;
118 case syncer::CLEAR_USER_DATA_AND_RESYNC:
119 status_label->assign(
120 l10n_util::GetStringUTF16(IDS_SYNC_CLEAR_USER_DATA));
121 break; 112 break;
122 default: 113 default:
123 NOTREACHED(); 114 NOTREACHED();
124 } 115 }
125 } 116 }
126 117
118 void GetStatusForUnrecoverableError(Profile* profile,
119 ProfileSyncService* service,
120 base::string16* status_label,
121 ActionType* action_type) {
122 // Unrecoverable error is sometimes accompanied by actionable error.
123 // If actionable error is set then display corresponding message,
124 // otherwise show generic unrecoverable error message.
125 ProfileSyncService::Status status;
126 service->QueryDetailedSyncStatus(&status);
127 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) {
tommycli 2016/10/28 21:21:09 Hmm this looks odd to read, since ShouldShowAction
Moe 2016/11/01 19:44:01 Here's my interpretation: in the new design, the R
128 GetStatusForActionableError(status.sync_protocol_error, status_label,
129 action_type);
130 } else {
131 *action_type = REAUTHENTICATE;
132
133 #if !defined(OS_CHROMEOS)
tommycli 2016/10/28 21:21:09 this can be an #if, #else, #endif
Moe 2016/11/01 19:44:01 Done.
134 status_label->assign(l10n_util::GetStringUTF16(
135 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR));
136 // The message for managed accounts is the same as that of the cros.
137 if (SigninManagerFactory::GetForProfile(profile)->IsSignoutProhibited()) {
138 status_label->assign(l10n_util::GetStringUTF16(
139 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR_CROS));
140 }
141 #endif
142 #if defined(OS_CHROMEOS)
143 status_label->assign(l10n_util::GetStringUTF16(
144 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR_CROS));
145 #endif
146 }
147 }
148
149 // Depending on the authentication state, returns labels to be used to display
150 // information about the sync status.
151 void GetStatusForAuthError(Profile* profile,
152 const SigninManagerBase& signin_manager,
153 base::string16* status_label,
154 base::string16* link_label,
155 ActionType* action_type) {
156 DCHECK(status_label);
157 DCHECK(link_label);
158 const GoogleServiceAuthError::State state =
159 SigninErrorControllerFactory::GetForProfile(profile)->
160 auth_error().state();
161 switch (state) {
162 case GoogleServiceAuthError::SERVICE_UNAVAILABLE:
163 status_label->assign(
164 l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE));
165 break;
166 case GoogleServiceAuthError::CONNECTION_FAILED:
167 status_label->assign(
168 l10n_util::GetStringUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE));
169 // Note that there is little the user can do if the server is not
170 // reachable. Since attempting to re-connect is done automatically by
171 // the Syncer, we do not show the (re)login link.
172 break;
173 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS:
174 case GoogleServiceAuthError::SERVICE_ERROR:
175 case GoogleServiceAuthError::ACCOUNT_DELETED:
176 case GoogleServiceAuthError::ACCOUNT_DISABLED:
177 default:
178 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_ERROR));
179 link_label->assign(
180 l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL));
181 *action_type = REAUTHENTICATE;
182 break;
183 }
184 }
185
127 // TODO(akalin): Write unit tests for these three functions below. 186 // TODO(akalin): Write unit tests for these three functions below.
128 187
129 // status_label and link_label must either be both NULL or both non-NULL. 188 // status_label and link_label must either be both NULL or both non-NULL.
130 MessageType GetStatusInfo(Profile* profile, 189 MessageType GetStatusInfo(Profile* profile,
131 ProfileSyncService* service, 190 ProfileSyncService* service,
132 const SigninManagerBase& signin, 191 const SigninManagerBase& signin,
133 StatusLabelStyle style, 192 StatusLabelStyle style,
134 base::string16* status_label, 193 base::string16* status_label,
135 base::string16* link_label) { 194 base::string16* link_label,
195 ActionType* action_type) {
136 DCHECK_EQ(status_label == NULL, link_label == NULL); 196 DCHECK_EQ(status_label == NULL, link_label == NULL);
137 197
138 MessageType result_type(SYNCED); 198 MessageType result_type(SYNCED);
139 199
140 if (!signin.IsAuthenticated()) 200 if (!signin.IsAuthenticated())
141 return PRE_SYNCED; 201 return PRE_SYNCED;
142 202
143 if (!service || service->IsManaged() || service->IsFirstSetupComplete() || 203 if (!service || service->IsManaged() || service->IsFirstSetupComplete() ||
144 !service->IsSyncRequested()) { 204 !service->IsSyncRequested()) {
145 // The order or priority is going to be: 1. Unrecoverable errors. 205 // The order or priority is going to be: 1. Unrecoverable errors.
146 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. 206 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors.
147 207
148 if (service && service->HasUnrecoverableError()) { 208 if (service && service->HasUnrecoverableError()) {
149 if (status_label) { 209 GetStatusForUnrecoverableError(profile, service, status_label,
150 // Unrecoverable error is sometimes accompanied by actionable error. 210 action_type);
151 // If actionable error is set then display corresponding message,
152 // otherwise show generic unrecoverable error message.
153 ProfileSyncService::Status status;
154 service->QueryDetailedSyncStatus(&status);
155 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) {
156 GetStatusForActionableError(status.sync_protocol_error, status_label);
157 } else {
158 status_label->assign(l10n_util::GetStringFUTF16(
159 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR,
160 l10n_util::GetStringUTF16(
161 IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL)));
162 }
163 }
164 return SYNC_ERROR; 211 return SYNC_ERROR;
165 } 212 }
166 213
167 // For auth errors first check if an auth is in progress. 214 // For auth errors first check if an auth is in progress.
168 if (signin.AuthInProgress()) { 215 if (signin.AuthInProgress()) {
169 if (status_label) { 216 if (status_label) {
170 status_label->assign( 217 status_label->assign(
171 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 218 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
172 } 219 }
173 return PRE_SYNCED; 220 return PRE_SYNCED;
174 } 221 }
175 222
176 // Check for sync errors if the sync service is enabled. 223 // Check for sync errors if the sync service is enabled.
177 if (service) { 224 if (service) {
178 // Since there is no auth in progress, check for an auth error first. 225 // Since there is no auth in progress, check for an auth error first.
179 AuthError auth_error = 226 AuthError auth_error =
180 SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); 227 SigninErrorControllerFactory::GetForProfile(profile)->auth_error();
181 if (auth_error.state() != AuthError::NONE) { 228 if (auth_error.state() != AuthError::NONE) {
182 if (status_label && link_label) 229 if (status_label && link_label)
183 signin_ui_util::GetStatusLabelsForAuthError(profile, signin, 230 GetStatusForAuthError(profile, signin, status_label, link_label,
184 status_label, link_label); 231 action_type);
185 return SYNC_ERROR; 232 return SYNC_ERROR;
186 } 233 }
187 234
188 // We don't have an auth error. Check for an actionable error. 235 // We don't have an auth error. Check for an actionable error.
189 ProfileSyncService::Status status; 236 ProfileSyncService::Status status;
190 service->QueryDetailedSyncStatus(&status); 237 service->QueryDetailedSyncStatus(&status);
191 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { 238 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) {
192 if (status_label) { 239 if (status_label) {
193 GetStatusForActionableError(status.sync_protocol_error, 240 GetStatusForActionableError(status.sync_protocol_error, status_label,
194 status_label); 241 action_type);
195 } 242 }
196 return SYNC_ERROR; 243 return SYNC_ERROR;
197 } 244 }
198 245
199 // Check for a passphrase error. 246 // Check for a passphrase error.
200 if (service->IsPassphraseRequired()) { 247 if (service->IsPassphraseRequired() &&
201 if (service->IsPassphraseRequiredForDecryption()) { 248 service->IsPassphraseRequiredForDecryption()) {
202 // TODO(lipalani) : Ask tim if this is still needed. 249 if (status_label && link_label) {
203 // NOT first machine. 250 status_label->assign(
204 // Show a link ("needs attention"), but still indicate the 251 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION));
205 // current synced status. Return SYNC_PROMO so that 252 link_label->assign(
206 // the configure link will still be shown. 253 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_LINK_LABEL));
207 if (status_label && link_label) { 254 *action_type = ENTER_PASSPHRASE;
208 status_label->assign(GetSyncedStateStatusLabel(
209 service, signin, style));
210 link_label->assign(
211 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION));
212 }
213 return SYNC_PROMO;
214 } 255 }
256 return SYNC_ERROR;
215 } 257 }
216 258
217 // Check to see if sync has been disabled via the dasboard and needs to be 259 // Check to see if sync has been disabled via the dasboard and needs to be
218 // set up once again. 260 // set up once again.
219 if (!service->IsSyncRequested() && 261 if (!service->IsSyncRequested() &&
220 status.sync_protocol_error.error_type == syncer::NOT_MY_BIRTHDAY) { 262 status.sync_protocol_error.error_type == syncer::NOT_MY_BIRTHDAY) {
221 if (status_label) { 263 if (status_label) {
222 status_label->assign(GetSyncedStateStatusLabel(service, 264 status_label->assign(GetSyncedStateStatusLabel(service,
223 signin, 265 signin,
224 style)); 266 style));
(...skipping 21 matching lines...) Expand all
246 } 288 }
247 if (signin.AuthInProgress()) { 289 if (signin.AuthInProgress()) {
248 if (status_label) { 290 if (status_label) {
249 status_label->assign( 291 status_label->assign(
250 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); 292 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL));
251 } 293 }
252 } else if (auth_error.state() != AuthError::NONE && 294 } else if (auth_error.state() != AuthError::NONE &&
253 auth_error.state() != AuthError::TWO_FACTOR) { 295 auth_error.state() != AuthError::TWO_FACTOR) {
254 if (status_label && link_label) { 296 if (status_label && link_label) {
255 status_label->clear(); 297 status_label->clear();
256 signin_ui_util::GetStatusLabelsForAuthError(profile, signin, 298 GetStatusForAuthError(profile, signin, status_label, link_label,
257 status_label, link_label); 299 action_type);
258 } 300 }
259 result_type = SYNC_ERROR; 301 result_type = SYNC_ERROR;
260 } 302 }
261 } else if (service->HasUnrecoverableError()) { 303 } else if (service->HasUnrecoverableError()) {
262 result_type = SYNC_ERROR; 304 result_type = SYNC_ERROR;
263 ProfileSyncService::Status status; 305 if (status_label) {
264 service->QueryDetailedSyncStatus(&status); 306 GetStatusForUnrecoverableError(profile, service, status_label,
265 if (browser_sync::ShouldShowActionOnUI(status.sync_protocol_error)) { 307 action_type);
266 if (status_label) {
267 GetStatusForActionableError(status.sync_protocol_error,
268 status_label);
269 }
270 } else if (status_label) {
271 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR));
272 } 308 }
273 } else if (signin.IsAuthenticated()) { 309 } else if (signin.IsAuthenticated()) {
274 // The user is signed in, but sync has been stopped. 310 // The user is signed in, but sync has been stopped.
311 result_type = PRE_SYNCED;
275 if (status_label) { 312 if (status_label) {
276 base::string16 label = l10n_util::GetStringUTF16( 313 status_label->assign(
277 IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED); 314 l10n_util::GetStringUTF16(IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED));
278 status_label->assign(label);
279 result_type = PRE_SYNCED;
280 } 315 }
281 } 316 }
282 } 317 }
283 return result_type; 318 return result_type;
284 } 319 }
285 320
286 // Returns the status info for use on the new tab page, where we want slightly 321 // Returns the status info for use on the new tab page, where we want slightly
287 // different information than in the settings panel. 322 // different information than in the settings panel.
288 MessageType GetStatusInfoForNewTabPage(Profile* profile, 323 MessageType GetStatusInfoForNewTabPage(Profile* profile,
289 ProfileSyncService* service, 324 ProfileSyncService* service,
(...skipping 21 matching lines...) Expand all
311 if (status_label && link_label) { 346 if (status_label && link_label) {
312 status_label->assign(base::string16()); 347 status_label->assign(base::string16());
313 link_label->assign( 348 link_label->assign(
314 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); 349 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION));
315 } 350 }
316 return SYNC_ERROR; 351 return SYNC_ERROR;
317 } 352 }
318 } 353 }
319 354
320 // Fallback to default. 355 // Fallback to default.
356 ActionType actionType(sync_ui_util::NO_ACTION);
321 return GetStatusInfo(profile, service, signin, WITH_HTML, status_label, 357 return GetStatusInfo(profile, service, signin, WITH_HTML, status_label,
322 link_label); 358 link_label, &actionType);
323 } 359 }
324 360
325 } // namespace 361 } // namespace
326 362
327 MessageType GetStatusLabels(Profile* profile, 363 MessageType GetStatusLabels(Profile* profile,
328 ProfileSyncService* service, 364 ProfileSyncService* service,
329 const SigninManagerBase& signin, 365 const SigninManagerBase& signin,
330 StatusLabelStyle style, 366 StatusLabelStyle style,
331 base::string16* status_label, 367 base::string16* status_label,
332 base::string16* link_label) { 368 base::string16* link_label,
369 ActionType* action_type) {
333 DCHECK(status_label); 370 DCHECK(status_label);
334 DCHECK(link_label); 371 DCHECK(link_label);
335 return sync_ui_util::GetStatusInfo(profile, service, signin, style, 372 return sync_ui_util::GetStatusInfo(profile, service, signin, style,
336 status_label, link_label); 373 status_label, link_label, action_type);
337 } 374 }
338 375
339 MessageType GetStatusLabelsForNewTabPage(Profile* profile, 376 MessageType GetStatusLabelsForNewTabPage(Profile* profile,
340 ProfileSyncService* service, 377 ProfileSyncService* service,
341 const SigninManagerBase& signin, 378 const SigninManagerBase& signin,
342 base::string16* status_label, 379 base::string16* status_label,
343 base::string16* link_label) { 380 base::string16* link_label) {
344 DCHECK(status_label); 381 DCHECK(status_label);
345 DCHECK(link_label); 382 DCHECK(link_label);
346 return sync_ui_util::GetStatusInfoForNewTabPage(profile, service, signin, 383 return sync_ui_util::GetStatusInfoForNewTabPage(profile, service, signin,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 485 }
449 486
450 // There is no error. 487 // There is no error.
451 return NO_SYNC_ERROR; 488 return NO_SYNC_ERROR;
452 } 489 }
453 #endif 490 #endif
454 491
455 MessageType GetStatus(Profile* profile, 492 MessageType GetStatus(Profile* profile,
456 ProfileSyncService* service, 493 ProfileSyncService* service,
457 const SigninManagerBase& signin) { 494 const SigninManagerBase& signin) {
495 ActionType actionType(sync_ui_util::NO_ACTION);
458 return sync_ui_util::GetStatusInfo(profile, service, signin, WITH_HTML, 496 return sync_ui_util::GetStatusInfo(profile, service, signin, WITH_HTML,
459 nullptr, nullptr); 497 nullptr, nullptr, &actionType);
460 } 498 }
461 499
462 base::string16 ConstructTime(int64_t time_in_int) { 500 base::string16 ConstructTime(int64_t time_in_int) {
463 base::Time time = base::Time::FromInternalValue(time_in_int); 501 base::Time time = base::Time::FromInternalValue(time_in_int);
464 502
465 // If time is null the format function returns a time in 1969. 503 // If time is null the format function returns a time in 1969.
466 if (time.is_null()) 504 if (time.is_null())
467 return base::string16(); 505 return base::string16();
468 return base::TimeFormatFriendlyDateAndTime(time); 506 return base::TimeFormatFriendlyDateAndTime(time);
469 } 507 }
470 508
471 } // namespace sync_ui_util 509 } // namespace sync_ui_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698