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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 bool ShouldShowActionOnUI( | 179 bool ShouldShowActionOnUI( |
180 const syncer::SyncProtocolError& error) { | 180 const syncer::SyncProtocolError& error) { |
181 return (error.action != syncer::UNKNOWN_ACTION && | 181 return (error.action != syncer::UNKNOWN_ACTION && |
182 error.action != syncer::DISABLE_SYNC_ON_CLIENT && | 182 error.action != syncer::DISABLE_SYNC_ON_CLIENT && |
183 error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT); | 183 error.action != syncer::STOP_SYNC_FOR_DISABLED_ACCOUNT); |
184 } | 184 } |
185 | 185 |
186 ProfileSyncService::ProfileSyncService( | 186 ProfileSyncService::ProfileSyncService( |
187 ProfileSyncComponentsFactory* factory, | 187 ProfileSyncComponentsFactory* factory, |
188 Profile* profile, | 188 Profile* profile, |
189 ManagedUserSigninManagerWrapper* signin_wrapper, | 189 scoped_ptr<ManagedUserSigninManagerWrapper> signin_wrapper, |
190 ProfileOAuth2TokenService* oauth2_token_service, | 190 ProfileOAuth2TokenService* oauth2_token_service, |
191 ProfileSyncServiceStartBehavior start_behavior) | 191 ProfileSyncServiceStartBehavior start_behavior) |
192 : OAuth2TokenService::Consumer("sync"), | 192 : OAuth2TokenService::Consumer("sync"), |
193 last_auth_error_(AuthError::AuthErrorNone()), | 193 last_auth_error_(AuthError::AuthErrorNone()), |
194 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), | 194 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), |
195 factory_(factory), | 195 factory_(factory), |
196 profile_(profile), | 196 profile_(profile), |
197 sync_prefs_(profile_->GetPrefs()), | 197 sync_prefs_(profile_->GetPrefs()), |
198 sync_service_url_(kDevServerUrl), | 198 sync_service_url_(GetSyncServiceURL(*CommandLine::ForCurrentProcess())), |
199 is_first_time_sync_configure_(false), | 199 is_first_time_sync_configure_(false), |
200 backend_initialized_(false), | 200 backend_initialized_(false), |
201 sync_disabled_by_admin_(false), | 201 sync_disabled_by_admin_(false), |
202 is_auth_in_progress_(false), | 202 is_auth_in_progress_(false), |
203 signin_(signin_wrapper), | 203 signin_(signin_wrapper.Pass()), |
204 unrecoverable_error_reason_(ERROR_REASON_UNSET), | 204 unrecoverable_error_reason_(ERROR_REASON_UNSET), |
205 expect_sync_configuration_aborted_(false), | 205 expect_sync_configuration_aborted_(false), |
206 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), | 206 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), |
207 encrypt_everything_(false), | 207 encrypt_everything_(false), |
208 encryption_pending_(false), | 208 encryption_pending_(false), |
209 configure_status_(DataTypeManager::UNKNOWN), | 209 configure_status_(DataTypeManager::UNKNOWN), |
210 oauth2_token_service_(oauth2_token_service), | 210 oauth2_token_service_(oauth2_token_service), |
211 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), | 211 request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), |
212 weak_factory_(this), | 212 weak_factory_(this), |
213 startup_controller_weak_factory_(this), | 213 startup_controller_weak_factory_(this), |
214 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), | 214 connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), |
215 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), | 215 last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), |
216 network_resources_(new syncer::HttpBridgeNetworkResources), | 216 network_resources_(new syncer::HttpBridgeNetworkResources), |
217 startup_controller_( | 217 startup_controller_( |
218 start_behavior, | 218 start_behavior, |
219 oauth2_token_service, | 219 oauth2_token_service, |
220 &sync_prefs_, | 220 &sync_prefs_, |
221 signin_wrapper, | 221 signin_.get(), |
222 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | 222 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, |
223 startup_controller_weak_factory_.GetWeakPtr(), | 223 startup_controller_weak_factory_.GetWeakPtr(), |
224 SYNC)), | 224 SYNC)), |
225 backup_rollback_controller_( | 225 backup_rollback_controller_( |
226 &sync_prefs_, signin_wrapper, | 226 &sync_prefs_, |
| 227 signin_.get(), |
227 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | 228 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, |
228 startup_controller_weak_factory_.GetWeakPtr(), | 229 startup_controller_weak_factory_.GetWeakPtr(), |
229 BACKUP), | 230 BACKUP), |
230 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, | 231 base::Bind(&ProfileSyncService::StartUpSlowBackendComponents, |
231 startup_controller_weak_factory_.GetWeakPtr(), | 232 startup_controller_weak_factory_.GetWeakPtr(), |
232 ROLLBACK)), | 233 ROLLBACK)), |
233 backend_mode_(IDLE), | 234 backend_mode_(IDLE), |
234 backup_start_delay_(base::TimeDelta::FromSeconds(kBackupStartDelay)), | 235 backup_start_delay_(base::TimeDelta::FromSeconds(kBackupStartDelay)), |
235 clear_browsing_data_(base::Bind(&ClearBrowsingData)) { | 236 clear_browsing_data_(base::Bind(&ClearBrowsingData)) { |
236 DCHECK(profile); | 237 DCHECK(profile); |
237 // By default, dev, canary, and unbranded Chromium users will go to the | |
238 // development servers. Development servers have more features than standard | |
239 // sync servers. Users with officially-branded Chrome stable and beta builds | |
240 // will go to the standard sync servers. | |
241 // | |
242 // GetChannel hits the registry on Windows. See http://crbug.com/70380. | |
243 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
244 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
245 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | |
246 channel == chrome::VersionInfo::CHANNEL_BETA) { | |
247 sync_service_url_ = GURL(kSyncServerUrl); | |
248 } | |
249 | |
250 syncer::SyncableService::StartSyncFlare flare( | 238 syncer::SyncableService::StartSyncFlare flare( |
251 sync_start_util::GetFlareForSyncableService(profile->GetPath())); | 239 sync_start_util::GetFlareForSyncableService(profile->GetPath())); |
252 scoped_ptr<browser_sync::LocalSessionEventRouter> router( | 240 scoped_ptr<browser_sync::LocalSessionEventRouter> router( |
253 new NotificationServiceSessionsRouter(profile, flare)); | 241 new NotificationServiceSessionsRouter(profile, flare)); |
254 sessions_sync_manager_.reset( | 242 sessions_sync_manager_.reset( |
255 new SessionsSyncManager(profile, this, router.Pass())); | 243 new SessionsSyncManager(profile, this, router.Pass())); |
256 } | 244 } |
257 | 245 |
258 ProfileSyncService::~ProfileSyncService() { | 246 ProfileSyncService::~ProfileSyncService() { |
259 sync_prefs_.RemoveSyncPrefObserver(this); | 247 sync_prefs_.RemoveSyncPrefObserver(this); |
(...skipping 12 matching lines...) Expand all Loading... |
272 | 260 |
273 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { | 261 bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { |
274 if (!oauth2_token_service_) | 262 if (!oauth2_token_service_) |
275 return false; | 263 return false; |
276 | 264 |
277 return oauth2_token_service_->RefreshTokenIsAvailable( | 265 return oauth2_token_service_->RefreshTokenIsAvailable( |
278 signin_->GetAccountIdToUse()); | 266 signin_->GetAccountIdToUse()); |
279 } | 267 } |
280 | 268 |
281 void ProfileSyncService::Initialize() { | 269 void ProfileSyncService::Initialize() { |
282 InitSettings(); | |
283 | |
284 // We clear this here (vs Shutdown) because we want to remember that an error | 270 // We clear this here (vs Shutdown) because we want to remember that an error |
285 // happened on shutdown so we can display details (message, location) about it | 271 // happened on shutdown so we can display details (message, location) about it |
286 // in about:sync. | 272 // in about:sync. |
287 ClearStaleErrors(); | 273 ClearStaleErrors(); |
288 | 274 |
289 sync_prefs_.AddSyncPrefObserver(this); | 275 sync_prefs_.AddSyncPrefObserver(this); |
290 | 276 |
291 // For now, the only thing we can do through policy is to turn sync off. | 277 // For now, the only thing we can do through policy is to turn sync off. |
292 if (IsManaged()) { | 278 if (IsManaged()) { |
293 DisableForUser(); | 279 DisableForUser(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 495 |
510 void ProfileSyncService::GetDataTypeControllerStates( | 496 void ProfileSyncService::GetDataTypeControllerStates( |
511 browser_sync::DataTypeController::StateMap* state_map) const { | 497 browser_sync::DataTypeController::StateMap* state_map) const { |
512 for (browser_sync::DataTypeController::TypeMap::const_iterator iter = | 498 for (browser_sync::DataTypeController::TypeMap::const_iterator iter = |
513 directory_data_type_controllers_.begin(); | 499 directory_data_type_controllers_.begin(); |
514 iter != directory_data_type_controllers_.end(); | 500 iter != directory_data_type_controllers_.end(); |
515 ++iter) | 501 ++iter) |
516 (*state_map)[iter->first] = iter->second.get()->state(); | 502 (*state_map)[iter->first] = iter->second.get()->state(); |
517 } | 503 } |
518 | 504 |
519 void ProfileSyncService::InitSettings() { | |
520 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
521 | |
522 // Override the sync server URL from the command-line, if sync server | |
523 // command-line argument exists. | |
524 if (command_line.HasSwitch(switches::kSyncServiceURL)) { | |
525 std::string value(command_line.GetSwitchValueASCII( | |
526 switches::kSyncServiceURL)); | |
527 if (!value.empty()) { | |
528 GURL custom_sync_url(value); | |
529 if (custom_sync_url.is_valid()) { | |
530 sync_service_url_ = custom_sync_url; | |
531 } else { | |
532 LOG(WARNING) << "The following sync URL specified at the command-line " | |
533 << "is invalid: " << value; | |
534 } | |
535 } | |
536 } | |
537 } | |
538 | |
539 SyncCredentials ProfileSyncService::GetCredentials() { | 505 SyncCredentials ProfileSyncService::GetCredentials() { |
540 SyncCredentials credentials; | 506 SyncCredentials credentials; |
541 if (backend_mode_ == SYNC) { | 507 if (backend_mode_ == SYNC) { |
542 credentials.email = signin_->GetEffectiveUsername(); | 508 credentials.email = signin_->GetEffectiveUsername(); |
543 DCHECK(!credentials.email.empty()); | 509 DCHECK(!credentials.email.empty()); |
544 credentials.sync_token = access_token_; | 510 credentials.sync_token = access_token_; |
545 | 511 |
546 if (credentials.sync_token.empty()) | 512 if (credentials.sync_token.empty()) |
547 credentials.sync_token = "credentials_lost"; | 513 credentials.sync_token = "credentials_lost"; |
548 } | 514 } |
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2552 if (first_sync_time.is_null()) | 2518 if (first_sync_time.is_null()) |
2553 return; | 2519 return; |
2554 | 2520 |
2555 clear_browsing_data_.Run(profile_, first_sync_time, base::Time::Now()); | 2521 clear_browsing_data_.Run(profile_, first_sync_time, base::Time::Now()); |
2556 } | 2522 } |
2557 | 2523 |
2558 void ProfileSyncService::SetClearingBrowseringDataForTesting( | 2524 void ProfileSyncService::SetClearingBrowseringDataForTesting( |
2559 base::Callback<void(Profile*, base::Time, base::Time)> c) { | 2525 base::Callback<void(Profile*, base::Time, base::Time)> c) { |
2560 clear_browsing_data_ = c; | 2526 clear_browsing_data_ = c; |
2561 } | 2527 } |
| 2528 |
| 2529 GURL ProfileSyncService::GetSyncServiceURL( |
| 2530 const base::CommandLine& command_line) { |
| 2531 // By default, dev, canary, and unbranded Chromium users will go to the |
| 2532 // development servers. Development servers have more features than standard |
| 2533 // sync servers. Users with officially-branded Chrome stable and beta builds |
| 2534 // will go to the standard sync servers. |
| 2535 GURL result(kDevServerUrl); |
| 2536 |
| 2537 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 2538 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 2539 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 2540 result = GURL(kSyncServerUrl); |
| 2541 } |
| 2542 |
| 2543 // Override the sync server URL from the command-line, if sync server |
| 2544 // command-line argument exists. |
| 2545 if (command_line.HasSwitch(switches::kSyncServiceURL)) { |
| 2546 std::string value(command_line.GetSwitchValueASCII( |
| 2547 switches::kSyncServiceURL)); |
| 2548 if (!value.empty()) { |
| 2549 GURL custom_sync_url(value); |
| 2550 if (custom_sync_url.is_valid()) { |
| 2551 result = custom_sync_url; |
| 2552 } else { |
| 2553 LOG(WARNING) << "The following sync URL specified at the command-line " |
| 2554 << "is invalid: " << value; |
| 2555 } |
| 2556 } |
| 2557 } |
| 2558 return result; |
| 2559 } |
OLD | NEW |