| OLD | NEW |
| 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" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/signin/signin_manager.h" |
| 14 #include "chrome/browser/sync/profile_sync_service.h" | 15 #include "chrome/browser/sync/profile_sync_service.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 16 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 19 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 19 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 20 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
| 22 #include "chrome/common/net/gaia/google_service_auth_error.h" | 23 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 break; | 214 break; |
| 214 default: | 215 default: |
| 215 NOTREACHED(); | 216 NOTREACHED(); |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| 219 // TODO(akalin): Write unit tests for these three functions below. | 220 // TODO(akalin): Write unit tests for these three functions below. |
| 220 | 221 |
| 221 // status_label and link_label must either be both NULL or both non-NULL. | 222 // status_label and link_label must either be both NULL or both non-NULL. |
| 222 MessageType GetStatusInfo(ProfileSyncService* service, | 223 MessageType GetStatusInfo(ProfileSyncService* service, |
| 224 const SigninManager& signin, |
| 223 StatusLabelStyle style, | 225 StatusLabelStyle style, |
| 224 string16* status_label, | 226 string16* status_label, |
| 225 string16* link_label) { | 227 string16* link_label) { |
| 226 DCHECK_EQ(status_label == NULL, link_label == NULL); | 228 DCHECK_EQ(status_label == NULL, link_label == NULL); |
| 227 | 229 |
| 228 MessageType result_type(SYNCED); | 230 MessageType result_type(SYNCED); |
| 229 | 231 |
| 230 if (!service) { | 232 if (!service) { |
| 231 return PRE_SYNCED; | 233 return PRE_SYNCED; |
| 232 } | 234 } |
| 233 | 235 |
| 234 if (service->HasSyncSetupCompleted()) { | 236 if (service->HasSyncSetupCompleted()) { |
| 235 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); | 237 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
| 236 const AuthError& auth_error = service->GetAuthError(); | 238 const AuthError& auth_error = service->GetAuthError(); |
| 237 | 239 |
| 238 // The order or priority is going to be: 1. Unrecoverable errors. | 240 // The order or priority is going to be: 1. Unrecoverable errors. |
| 239 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. | 241 // 2. Auth errors. 3. Protocol errors. 4. Passphrase errors. |
| 240 | 242 |
| 241 if (service->unrecoverable_error_detected()) { | 243 if (service->unrecoverable_error_detected()) { |
| 242 if (status_label) { | 244 if (status_label) { |
| 243 status_label->assign(l10n_util::GetStringFUTF16( | 245 status_label->assign(l10n_util::GetStringFUTF16( |
| 244 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR, | 246 IDS_SYNC_STATUS_UNRECOVERABLE_ERROR, |
| 245 l10n_util::GetStringUTF16(IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL))); | 247 l10n_util::GetStringUTF16(IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL))); |
| 246 } | 248 } |
| 247 return SYNC_ERROR; | 249 return SYNC_ERROR; |
| 248 } | 250 } |
| 249 | 251 |
| 250 // For auth errors first check if an auth is in progress. | 252 // For auth errors first check if an auth is in progress. |
| 251 if (service->UIShouldDepictAuthInProgress()) { | 253 if (signin.AuthInProgress()) { |
| 252 if (status_label) { | 254 if (status_label) { |
| 253 status_label->assign( | 255 status_label->assign( |
| 254 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 256 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
| 255 } | 257 } |
| 256 return PRE_SYNCED; | 258 return PRE_SYNCED; |
| 257 } | 259 } |
| 258 | 260 |
| 259 // No auth in progress check for an auth error. | 261 // No auth in progress check for an auth error. |
| 260 if (auth_error.state() != AuthError::NONE) { | 262 if (auth_error.state() != AuthError::NONE) { |
| 261 if (status_label && link_label) { | 263 if (status_label && link_label) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 // Either show auth error information with a link to re-login, auth in prog, | 301 // Either show auth error information with a link to re-login, auth in prog, |
| 300 // or provide a link to continue with setup. | 302 // or provide a link to continue with setup. |
| 301 result_type = PRE_SYNCED; | 303 result_type = PRE_SYNCED; |
| 302 if (service->FirstSetupInProgress()) { | 304 if (service->FirstSetupInProgress()) { |
| 303 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); | 305 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
| 304 const AuthError& auth_error = service->GetAuthError(); | 306 const AuthError& auth_error = service->GetAuthError(); |
| 305 if (status_label) { | 307 if (status_label) { |
| 306 status_label->assign( | 308 status_label->assign( |
| 307 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); | 309 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS)); |
| 308 } | 310 } |
| 309 if (service->UIShouldDepictAuthInProgress()) { | 311 if (signin.AuthInProgress()) { |
| 310 if (status_label) { | 312 if (status_label) { |
| 311 status_label->assign( | 313 status_label->assign( |
| 312 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 314 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
| 313 } | 315 } |
| 314 } else if (auth_error.state() != AuthError::NONE && | 316 } else if (auth_error.state() != AuthError::NONE && |
| 315 auth_error.state() != AuthError::TWO_FACTOR) { | 317 auth_error.state() != AuthError::TWO_FACTOR) { |
| 316 if (status_label) { | 318 if (status_label) { |
| 317 status_label->clear(); | 319 status_label->clear(); |
| 318 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL, | 320 GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL, |
| 319 NULL, NULL, NULL); | 321 NULL, NULL, NULL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 332 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); | 334 status_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_SETUP_ERROR)); |
| 333 } | 335 } |
| 334 } | 336 } |
| 335 } | 337 } |
| 336 return result_type; | 338 return result_type; |
| 337 } | 339 } |
| 338 | 340 |
| 339 // Returns the status info for use on the new tab page, where we want slightly | 341 // Returns the status info for use on the new tab page, where we want slightly |
| 340 // different information than in the settings panel. | 342 // different information than in the settings panel. |
| 341 MessageType GetStatusInfoForNewTabPage(ProfileSyncService* service, | 343 MessageType GetStatusInfoForNewTabPage(ProfileSyncService* service, |
| 344 const SigninManager& signin, |
| 342 string16* status_label, | 345 string16* status_label, |
| 343 string16* link_label) { | 346 string16* link_label) { |
| 344 DCHECK(status_label); | 347 DCHECK(status_label); |
| 345 DCHECK(link_label); | 348 DCHECK(link_label); |
| 346 | 349 |
| 347 if (service->HasSyncSetupCompleted() && | 350 if (service->HasSyncSetupCompleted() && |
| 348 service->IsPassphraseRequired()) { | 351 service->IsPassphraseRequired()) { |
| 349 if (service->passphrase_required_reason() == sync_api::REASON_ENCRYPTION) { | 352 if (service->passphrase_required_reason() == sync_api::REASON_ENCRYPTION) { |
| 350 // First machine migrating to passwords. Show as a promotion. | 353 // First machine migrating to passwords. Show as a promotion. |
| 351 if (status_label && link_label) { | 354 if (status_label && link_label) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 363 if (status_label && link_label) { | 366 if (status_label && link_label) { |
| 364 status_label->assign(string16()); | 367 status_label->assign(string16()); |
| 365 link_label->assign( | 368 link_label->assign( |
| 366 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); | 369 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); |
| 367 } | 370 } |
| 368 return SYNC_ERROR; | 371 return SYNC_ERROR; |
| 369 } | 372 } |
| 370 } | 373 } |
| 371 | 374 |
| 372 // Fallback to default. | 375 // Fallback to default. |
| 373 return GetStatusInfo(service, WITH_HTML, status_label, link_label); | 376 return GetStatusInfo(service, signin, WITH_HTML, status_label, link_label); |
| 374 } | 377 } |
| 375 | 378 |
| 376 } // namespace | 379 } // namespace |
| 377 | 380 |
| 378 MessageType GetStatusLabels(ProfileSyncService* service, | 381 MessageType GetStatusLabels(ProfileSyncService* service, |
| 382 const SigninManager& signin, |
| 379 StatusLabelStyle style, | 383 StatusLabelStyle style, |
| 380 string16* status_label, | 384 string16* status_label, |
| 381 string16* link_label) { | 385 string16* link_label) { |
| 382 DCHECK(status_label); | 386 DCHECK(status_label); |
| 383 DCHECK(link_label); | 387 DCHECK(link_label); |
| 384 return sync_ui_util::GetStatusInfo(service, style, status_label, link_label); | 388 return sync_ui_util::GetStatusInfo( |
| 389 service, signin, style, status_label, link_label); |
| 385 } | 390 } |
| 386 | 391 |
| 387 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, | 392 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, |
| 393 const SigninManager& signin, |
| 388 string16* status_label, | 394 string16* status_label, |
| 389 string16* link_label) { | 395 string16* link_label) { |
| 390 DCHECK(status_label); | 396 DCHECK(status_label); |
| 391 DCHECK(link_label); | 397 DCHECK(link_label); |
| 392 return sync_ui_util::GetStatusInfoForNewTabPage( | 398 return sync_ui_util::GetStatusInfoForNewTabPage( |
| 393 service, status_label, link_label); | 399 service, signin, status_label, link_label); |
| 394 } | 400 } |
| 395 | 401 |
| 396 void GetStatusLabelsForSyncGlobalError(ProfileSyncService* service, | 402 void GetStatusLabelsForSyncGlobalError(ProfileSyncService* service, |
| 403 const SigninManager& signin, |
| 397 string16* menu_label, | 404 string16* menu_label, |
| 398 string16* bubble_message, | 405 string16* bubble_message, |
| 399 string16* bubble_accept_label) { | 406 string16* bubble_accept_label) { |
| 400 DCHECK(menu_label); | 407 DCHECK(menu_label); |
| 401 DCHECK(bubble_message); | 408 DCHECK(bubble_message); |
| 402 DCHECK(bubble_accept_label); | 409 DCHECK(bubble_accept_label); |
| 403 *menu_label = string16(); | 410 *menu_label = string16(); |
| 404 *bubble_message = string16(); | 411 *bubble_message = string16(); |
| 405 *bubble_accept_label = string16(); | 412 *bubble_accept_label = string16(); |
| 406 | 413 |
| 407 if (!service->HasSyncSetupCompleted()) | 414 if (!service->HasSyncSetupCompleted()) |
| 408 return; | 415 return; |
| 409 | 416 |
| 410 if (service->IsPassphraseRequired() && | 417 if (service->IsPassphraseRequired() && |
| 411 service->IsPassphraseRequiredForDecryption()) { | 418 service->IsPassphraseRequiredForDecryption()) { |
| 412 // This is not the first machine so ask user to enter passphrase. | 419 // This is not the first machine so ask user to enter passphrase. |
| 413 *menu_label = l10n_util::GetStringUTF16( | 420 *menu_label = l10n_util::GetStringUTF16( |
| 414 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); | 421 IDS_SYNC_PASSPHRASE_ERROR_WRENCH_MENU_ITEM); |
| 415 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 422 string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| 416 *bubble_message = l10n_util::GetStringFUTF16( | 423 *bubble_message = l10n_util::GetStringFUTF16( |
| 417 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); | 424 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_MESSAGE, product_name); |
| 418 *bubble_accept_label = l10n_util::GetStringUTF16( | 425 *bubble_accept_label = l10n_util::GetStringUTF16( |
| 419 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); | 426 IDS_SYNC_PASSPHRASE_ERROR_BUBBLE_VIEW_ACCEPT); |
| 420 return; | 427 return; |
| 421 } | 428 } |
| 422 | 429 |
| 423 MessageType status = GetStatus(service); | 430 MessageType status = GetStatus(service, signin); |
| 424 if (status != SYNC_ERROR) | 431 if (status != SYNC_ERROR) |
| 425 return; | 432 return; |
| 426 | 433 |
| 427 const AuthError& auth_error = service->GetAuthError(); | 434 const AuthError& auth_error = service->GetAuthError(); |
| 428 if (auth_error.state() != AuthError::NONE) { | 435 if (auth_error.state() != AuthError::NONE) { |
| 429 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, | 436 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, |
| 430 menu_label, bubble_message, bubble_accept_label); | 437 menu_label, bubble_message, bubble_accept_label); |
| 431 } | 438 } |
| 432 } | 439 } |
| 433 | 440 |
| 434 MessageType GetStatus(ProfileSyncService* service) { | 441 MessageType GetStatus( |
| 435 return sync_ui_util::GetStatusInfo(service, WITH_HTML, NULL, NULL); | 442 ProfileSyncService* service, const SigninManager& signin) { |
| 443 return sync_ui_util::GetStatusInfo(service, signin, WITH_HTML, NULL, NULL); |
| 436 } | 444 } |
| 437 | 445 |
| 438 string16 GetSyncMenuLabel(ProfileSyncService* service) { | 446 string16 GetSyncMenuLabel( |
| 439 MessageType type = GetStatus(service); | 447 ProfileSyncService* service, const SigninManager& signin) { |
| 448 MessageType type = GetStatus(service, signin); |
| 440 | 449 |
| 441 if (type == sync_ui_util::SYNCED) | 450 if (type == sync_ui_util::SYNCED) |
| 442 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); | 451 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); |
| 443 else if (type == sync_ui_util::SYNC_ERROR) | 452 else if (type == sync_ui_util::SYNC_ERROR) |
| 444 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | 453 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); |
| 445 else | 454 else |
| 446 return l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); | 455 return l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); |
| 447 } | 456 } |
| 448 | 457 |
| 449 void AddBoolSyncDetail(ListValue* details, | 458 void AddBoolSyncDetail(ListValue* details, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 } | 733 } |
| 725 } else { | 734 } else { |
| 726 version_modifier = " " + version_modifier; | 735 version_modifier = " " + version_modifier; |
| 727 } | 736 } |
| 728 return chrome_version.Name() + " " + chrome_version.OSType() + " " + | 737 return chrome_version.Name() + " " + chrome_version.OSType() + " " + |
| 729 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + | 738 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + |
| 730 version_modifier; | 739 version_modifier; |
| 731 } | 740 } |
| 732 | 741 |
| 733 } // namespace sync_ui_util | 742 } // namespace sync_ui_util |
| OLD | NEW |