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

Unified Diff: chrome/browser/sync/sync_ui_util.cc

Issue 12077030: Allow signin to continue even if sync is disabled by policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows sync integration test failure Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/profile_sync_service_mock.h ('k') | chrome/browser/sync/sync_ui_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/sync_ui_util.cc
diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc
index 43db6f66faf507af2eb6a6647ffef957fdd810e7..a41619e52c3bff2d6fe67488c97f76295b9180f9 100644
--- a/chrome/browser/sync/sync_ui_util.cc
+++ b/chrome/browser/sync/sync_ui_util.cc
@@ -11,7 +11,9 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/signin/signin_global_error.h"
#include "chrome/browser/signin/signin_manager.h"
+#include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
@@ -39,73 +41,26 @@ namespace sync_ui_util {
namespace {
-// Given an authentication state this helper function returns various labels
-// that can be used to display information about the state.
-void GetStatusLabelsForAuthError(const AuthError& auth_error,
- const ProfileSyncService& service,
- string16* status_label,
- string16* link_label) {
- string16 username = UTF8ToUTF16(service.profile()->GetPrefs()->GetString(
- prefs::kGoogleServicesUsername));
- string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
- if (link_label)
- link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL));
-
- switch (auth_error.state()) {
- case AuthError::INVALID_GAIA_CREDENTIALS:
- case AuthError::ACCOUNT_DELETED:
- case AuthError::ACCOUNT_DISABLED:
- // If the user name is empty then the first login failed, otherwise the
- // credentials are out-of-date.
- if (username.empty()) {
- if (status_label) {
- status_label->assign(
- l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS));
- }
- } else {
- if (status_label) {
- status_label->assign(
- l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_INFO_OUT_OF_DATE));
- }
- }
- break;
- case AuthError::SERVICE_UNAVAILABLE:
- if (status_label) {
- status_label->assign(
- l10n_util::GetStringUTF16(IDS_SYNC_SERVICE_UNAVAILABLE));
- }
- if (link_label)
- link_label->clear();
- break;
- case AuthError::CONNECTION_FAILED:
- // Note that there is little the user can do if the server is not
- // reachable. Since attempting to re-connect is done automatically by
- // the Syncer, we do not show the (re)login link.
- if (status_label) {
- status_label->assign(
- l10n_util::GetStringFUTF16(IDS_SYNC_SERVER_IS_UNREACHABLE,
- product_name));
- }
- break;
- default:
- if (status_label) {
- status_label->assign(l10n_util::GetStringUTF16(
- IDS_SYNC_ERROR_SIGNING_IN));
- }
- break;
- }
-}
-
// Returns the message that should be displayed when the user is authenticated
// and can connect to the sync server. If the user hasn't yet authenticated, an
// empty string is returned.
string16 GetSyncedStateStatusLabel(ProfileSyncService* service,
+ const SigninManager& signin,
StatusLabelStyle style) {
- if (!service->sync_initialized())
+ string16 user_name = UTF8ToUTF16(signin.GetAuthenticatedUsername());
+
+ if (!user_name.empty() &&
+ (!service || service->IsManaged())) {
+ // User is signed in, but sync is disabled.
+ return l10n_util::GetStringFUTF16(IDS_SIGNED_IN_WITH_SYNC_DISABLED,
+ user_name);
+ }
+
+ if (!service || !service->sync_initialized()) {
+ // User is not signed in, or sync is still initializing.
return string16();
+ }
- string16 user_name = UTF8ToUTF16(service->profile()->GetPrefs()->GetString(
- prefs::kGoogleServicesUsername));
DCHECK(!user_name.empty());
// Message may also carry additional advice with an HTML link, if acceptable.
@@ -164,19 +119,14 @@ MessageType GetStatusInfo(ProfileSyncService* service,
MessageType result_type(SYNCED);
- if (!service) {
+ if (signin.GetAuthenticatedUsername().empty())
return PRE_SYNCED;
- }
-
- if (service->HasSyncSetupCompleted()) {
- ProfileSyncService::Status status;
- service->QueryDetailedSyncStatus(&status);
- const AuthError& auth_error = service->GetAuthError();
+ if (!service || service->IsManaged() || service->HasSyncSetupCompleted()) {
// The order or priority is going to be: 1. Unrecoverable errors.
// 2. Auth errors. 3. Protocol errors. 4. Passphrase errors.
- if (service->HasUnrecoverableError()) {
+ if (service && service->HasUnrecoverableError()) {
if (status_label) {
status_label->assign(l10n_util::GetStringFUTF16(
IDS_SYNC_STATUS_UNRECOVERABLE_ERROR,
@@ -195,52 +145,59 @@ MessageType GetStatusInfo(ProfileSyncService* service,
}
// No auth in progress check for an auth error.
+ AuthError auth_error = signin.signin_global_error()->GetLastAuthError();
if (auth_error.state() != AuthError::NONE) {
- if (status_label && link_label) {
- GetStatusLabelsForAuthError(
- auth_error, *service, status_label, link_label);
- }
+ if (status_label && link_label)
+ signin_ui_util::GetStatusLabelsForAuthError(
+ signin, status_label, link_label);
return SYNC_ERROR;
}
- // We dont have an auth error. Check for protocol error.
- if (ShouldShowActionOnUI(status.sync_protocol_error)) {
- if (status_label) {
- GetStatusForActionableError(status.sync_protocol_error,
- status_label);
+ // We dont have an auth error. Check for sync errors if the sync service
+ // is enabled.
+ if (service) {
+ ProfileSyncService::Status status;
+ service->QueryDetailedSyncStatus(&status);
+
+ if (ShouldShowActionOnUI(status.sync_protocol_error)) {
+ if (status_label) {
+ GetStatusForActionableError(status.sync_protocol_error,
+ status_label);
+ }
+ return SYNC_ERROR;
}
- return SYNC_ERROR;
- }
- // Now finally passphrase error.
- if (service->IsPassphraseRequired()) {
- if (service->IsPassphraseRequiredForDecryption()) {
- // TODO(lipalani) : Ask tim if this is still needed.
- // NOT first machine.
- // Show a link ("needs attention"), but still indicate the
- // current synced status. Return SYNC_PROMO so that
- // the configure link will still be shown.
- if (status_label && link_label) {
- status_label->assign(GetSyncedStateStatusLabel(service, style));
- link_label->assign(
- l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION));
+ // Now finally passphrase error.
+ if (service->IsPassphraseRequired()) {
+ if (service->IsPassphraseRequiredForDecryption()) {
+ // TODO(lipalani) : Ask tim if this is still needed.
+ // NOT first machine.
+ // Show a link ("needs attention"), but still indicate the
+ // current synced status. Return SYNC_PROMO so that
+ // the configure link will still be shown.
+ if (status_label && link_label) {
+ status_label->assign(GetSyncedStateStatusLabel(
+ service, signin, style));
+ link_label->assign(
+ l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION));
+ }
+ return SYNC_PROMO;
}
- return SYNC_PROMO;
}
}
// There is no error. Display "Last synced..." message.
if (status_label)
- status_label->assign(GetSyncedStateStatusLabel(service, style));
+ status_label->assign(GetSyncedStateStatusLabel(service, signin, style));
return SYNCED;
} else {
// Either show auth error information with a link to re-login, auth in prog,
// or provide a link to continue with setup.
- result_type = PRE_SYNCED;
if (service->FirstSetupInProgress()) {
+ result_type = PRE_SYNCED;
ProfileSyncService::Status status;
service->QueryDetailedSyncStatus(&status);
- const AuthError& auth_error = service->GetAuthError();
+ AuthError auth_error = signin.signin_global_error()->GetLastAuthError();
if (status_label) {
status_label->assign(
l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS));
@@ -254,7 +211,8 @@ MessageType GetStatusInfo(ProfileSyncService* service,
auth_error.state() != AuthError::TWO_FACTOR) {
if (status_label) {
status_label->clear();
- GetStatusLabelsForAuthError(auth_error, *service, status_label, NULL);
+ signin_ui_util::GetStatusLabelsForAuthError(
+ signin, status_label, NULL);
}
result_type = SYNC_ERROR;
}
« no previous file with comments | « chrome/browser/sync/profile_sync_service_mock.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