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

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

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