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/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 for (int i = 0; i < kRelevantTokenServicesCount; ++i) { | 124 for (int i = 0; i < kRelevantTokenServicesCount; ++i) { |
125 if (service == kRelevantTokenServices[i]) | 125 if (service == kRelevantTokenServices[i]) |
126 return true; | 126 return true; |
127 } | 127 } |
128 return false; | 128 return false; |
129 } | 129 } |
130 | 130 |
131 bool ShouldShowActionOnUI( | 131 bool ShouldShowActionOnUI( |
132 const syncer::SyncProtocolError& error) { | 132 const syncer::SyncProtocolError& error) { |
133 return (error.action != syncer::UNKNOWN_ACTION && | 133 return (error.action != syncer::UNKNOWN_ACTION && |
134 error.action != syncer::DISABLE_SYNC_ON_CLIENT); | 134 error.action != syncer::DISABLE_SYNC_ON_CLIENT && |
| 135 error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT); |
135 } | 136 } |
136 | 137 |
137 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, | 138 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, |
138 Profile* profile, | 139 Profile* profile, |
139 SigninManagerBase* signin_manager, | 140 SigninManagerBase* signin_manager, |
140 StartBehavior start_behavior) | 141 StartBehavior start_behavior) |
141 : last_auth_error_(AuthError::AuthErrorNone()), | 142 : last_auth_error_(AuthError::AuthErrorNone()), |
142 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), | 143 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), |
143 factory_(factory), | 144 factory_(factory), |
144 profile_(profile), | 145 profile_(profile), |
145 // |profile| may be NULL in unit tests. | 146 // |profile| may be NULL in unit tests. |
146 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), | 147 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), |
147 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL), | 148 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL), |
148 sync_service_url_(kDevServerUrl), | 149 sync_service_url_(kDevServerUrl), |
149 data_type_requested_sync_startup_(false), | 150 data_type_requested_sync_startup_(false), |
150 is_first_time_sync_configure_(false), | 151 is_first_time_sync_configure_(false), |
151 backend_initialized_(false), | 152 backend_initialized_(false), |
| 153 sync_disabled_by_admin_(false), |
152 is_auth_in_progress_(false), | 154 is_auth_in_progress_(false), |
153 signin_(signin_manager), | 155 signin_(signin_manager), |
154 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 156 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
155 weak_factory_(this), | 157 weak_factory_(this), |
156 expect_sync_configuration_aborted_(false), | 158 expect_sync_configuration_aborted_(false), |
157 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 159 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
158 encrypt_everything_(false), | 160 encrypt_everything_(false), |
159 encryption_pending_(false), | 161 encryption_pending_(false), |
160 auto_start_enabled_(start_behavior == AUTO_START), | 162 auto_start_enabled_(start_behavior == AUTO_START), |
161 failed_datatypes_handler_(this), | 163 failed_datatypes_handler_(this), |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 OnInternalUnrecoverableError(FROM_HERE, | 1218 OnInternalUnrecoverableError(FROM_HERE, |
1217 last_actionable_error_.error_description, | 1219 last_actionable_error_.error_description, |
1218 true, | 1220 true, |
1219 ERROR_REASON_ACTIONABLE_ERROR); | 1221 ERROR_REASON_ACTIONABLE_ERROR); |
1220 break; | 1222 break; |
1221 case syncer::DISABLE_SYNC_ON_CLIENT: | 1223 case syncer::DISABLE_SYNC_ON_CLIENT: |
1222 OnStopSyncingPermanently(); | 1224 OnStopSyncingPermanently(); |
1223 // TODO(rsimha): Re-evaluate whether to also sign out the user here after | 1225 // TODO(rsimha): Re-evaluate whether to also sign out the user here after |
1224 // a dashboard clear. See http://crbug.com/240436. | 1226 // a dashboard clear. See http://crbug.com/240436. |
1225 break; | 1227 break; |
| 1228 case syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT: |
| 1229 // Sync disabled by domain admin. we should stop syncing until next |
| 1230 // restart. |
| 1231 sync_disabled_by_admin_ = true; |
| 1232 ShutdownImpl(true); |
| 1233 break; |
1226 default: | 1234 default: |
1227 NOTREACHED(); | 1235 NOTREACHED(); |
1228 } | 1236 } |
1229 NotifyObservers(); | 1237 NotifyObservers(); |
1230 } | 1238 } |
1231 | 1239 |
1232 void ProfileSyncService::OnConfigureBlocked() { | 1240 void ProfileSyncService::OnConfigureBlocked() { |
1233 NotifyObservers(); | 1241 NotifyObservers(); |
1234 } | 1242 } |
1235 | 1243 |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1972 break; | 1980 break; |
1973 } | 1981 } |
1974 case chrome::NOTIFICATION_TOKENS_CLEARED: { | 1982 case chrome::NOTIFICATION_TOKENS_CLEARED: { |
1975 // GetCredentials() will generate invalid credentials to cause the backend | 1983 // GetCredentials() will generate invalid credentials to cause the backend |
1976 // to generate an auth error. | 1984 // to generate an auth error. |
1977 if (backend_) | 1985 if (backend_) |
1978 backend_->UpdateCredentials(GetCredentials()); | 1986 backend_->UpdateCredentials(GetCredentials()); |
1979 break; | 1987 break; |
1980 } | 1988 } |
1981 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: | 1989 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: |
1982 // Disable sync if the user is signed out. | 1990 sync_disabled_by_admin_ = false; |
1983 DisableForUser(); | 1991 DisableForUser(); |
1984 break; | 1992 break; |
1985 default: { | 1993 default: { |
1986 NOTREACHED(); | 1994 NOTREACHED(); |
1987 } | 1995 } |
1988 } | 1996 } |
1989 } | 1997 } |
1990 | 1998 |
1991 void ProfileSyncService::AddObserver(Observer* observer) { | 1999 void ProfileSyncService::AddObserver(Observer* observer) { |
1992 observers_.AddObserver(observer); | 2000 observers_.AddObserver(observer); |
(...skipping 16 matching lines...) Expand all Loading... |
2009 } | 2017 } |
2010 | 2018 |
2011 // static | 2019 // static |
2012 bool ProfileSyncService::IsSyncEnabled() { | 2020 bool ProfileSyncService::IsSyncEnabled() { |
2013 // We have switches::kEnableSync just in case we need to change back to | 2021 // We have switches::kEnableSync just in case we need to change back to |
2014 // sync-disabled-by-default on a platform. | 2022 // sync-disabled-by-default on a platform. |
2015 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync); | 2023 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync); |
2016 } | 2024 } |
2017 | 2025 |
2018 bool ProfileSyncService::IsManaged() const { | 2026 bool ProfileSyncService::IsManaged() const { |
2019 return sync_prefs_.IsManaged(); | 2027 return sync_prefs_.IsManaged() || sync_disabled_by_admin_; |
2020 } | 2028 } |
2021 | 2029 |
2022 bool ProfileSyncService::ShouldPushChanges() { | 2030 bool ProfileSyncService::ShouldPushChanges() { |
2023 // True only after all bootstrapping has succeeded: the sync backend | 2031 // True only after all bootstrapping has succeeded: the sync backend |
2024 // is initialized, all enabled data types are consistent with one | 2032 // is initialized, all enabled data types are consistent with one |
2025 // another, and no unrecoverable error has transpired. | 2033 // another, and no unrecoverable error has transpired. |
2026 if (HasUnrecoverableError()) | 2034 if (HasUnrecoverableError()) |
2027 return false; | 2035 return false; |
2028 | 2036 |
2029 if (!data_type_manager_) | 2037 if (!data_type_manager_) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2104 #if defined(ENABLE_MANAGED_USERS) | 2112 #if defined(ENABLE_MANAGED_USERS) |
2105 if (ManagedUserService::ProfileIsManaged(profile_)) { | 2113 if (ManagedUserService::ProfileIsManaged(profile_)) { |
2106 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); | 2114 DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername()); |
2107 return ManagedUserService::GetManagedUserPseudoEmail(); | 2115 return ManagedUserService::GetManagedUserPseudoEmail(); |
2108 } | 2116 } |
2109 #endif | 2117 #endif |
2110 | 2118 |
2111 return signin_->GetAuthenticatedUsername(); | 2119 return signin_->GetAuthenticatedUsername(); |
2112 } | 2120 } |
2113 | 2121 |
OLD | NEW |