| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Dev servers have more features than standard sync servers. | 94 // Dev servers have more features than standard sync servers. |
| 95 // Chrome stable and beta builds will go to the standard sync servers. | 95 // Chrome stable and beta builds will go to the standard sync servers. |
| 96 #if defined(GOOGLE_CHROME_BUILD) | 96 #if defined(GOOGLE_CHROME_BUILD) |
| 97 // For stable, this is "". For dev, this is "dev". For beta, this is "beta". | 97 // For stable, this is "". For dev, this is "dev". For beta, this is "beta". |
| 98 // For daily, this is "canary build". | 98 // For daily, this is "canary build". |
| 99 // For linux Chromium builds, this could be anything depending on the | 99 // For linux Chromium builds, this could be anything depending on the |
| 100 // distribution, so always direct those users to dev server urls. | 100 // distribution, so always direct those users to dev server urls. |
| 101 // If this is an official build, it will always be one of the above. | 101 // If this is an official build, it will always be one of the above. |
| 102 std::string channel = platform_util::GetVersionStringModifier(); | 102 std::string channel = platform_util::GetVersionStringModifier(); |
| 103 if (channel.empty() || channel == "beta") { | 103 if (channel.empty() || channel == "beta") { |
| 104 LOG(INFO) << "Detected official build, using official sync server."; | |
| 105 sync_service_url_ = GURL(kSyncServerUrl); | 104 sync_service_url_ = GURL(kSyncServerUrl); |
| 106 } else { | |
| 107 LOG(INFO) << "Detected official build, but using dev channel sync server."; | |
| 108 } | 105 } |
| 109 #else | |
| 110 LOG(INFO) << "Unofficial build, using dev channel sync server."; | |
| 111 #endif | 106 #endif |
| 112 } | 107 } |
| 113 | 108 |
| 114 ProfileSyncService::ProfileSyncService() | 109 ProfileSyncService::ProfileSyncService() |
| 115 : last_auth_error_(AuthError::None()), | 110 : last_auth_error_(AuthError::None()), |
| 116 factory_(NULL), | 111 factory_(NULL), |
| 117 profile_(NULL), | 112 profile_(NULL), |
| 118 sync_service_url_(kSyncServerUrl), | 113 sync_service_url_(kSyncServerUrl), |
| 119 backend_initialized_(false), | 114 backend_initialized_(false), |
| 120 is_auth_in_progress_(false), | 115 is_auth_in_progress_(false), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const std::string& token) { | 148 const std::string& token) { |
| 154 signin_.SetUsername(username); | 149 signin_.SetUsername(username); |
| 155 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); | 150 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); |
| 156 profile()->GetTokenService()->OnIssueAuthTokenSuccess( | 151 profile()->GetTokenService()->OnIssueAuthTokenSuccess( |
| 157 GaiaConstants::kSyncService, token); | 152 GaiaConstants::kSyncService, token); |
| 158 profile()->GetPrefs()->SetBoolean(prefs::kSyncCredentialsMigrated, true); | 153 profile()->GetPrefs()->SetBoolean(prefs::kSyncCredentialsMigrated, true); |
| 159 token_migrator_.reset(); | 154 token_migrator_.reset(); |
| 160 } | 155 } |
| 161 | 156 |
| 162 void ProfileSyncService::Initialize() { | 157 void ProfileSyncService::Initialize() { |
| 163 LOG(INFO) << "Starting ProfileSyncService."; | |
| 164 InitSettings(); | 158 InitSettings(); |
| 165 RegisterPreferences(); | 159 RegisterPreferences(); |
| 166 | 160 |
| 167 // Watch the preference that indicates sync is managed so we can take | 161 // Watch the preference that indicates sync is managed so we can take |
| 168 // appropriate action. | 162 // appropriate action. |
| 169 pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this); | 163 pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this); |
| 170 | 164 |
| 171 // For now, the only thing we can do through policy is to turn sync off. | 165 // For now, the only thing we can do through policy is to turn sync off. |
| 172 if (IsManaged()) { | 166 if (IsManaged()) { |
| 173 DisableForUser(); | 167 DisableForUser(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 GURL custom_sync_url(value); | 254 GURL custom_sync_url(value); |
| 261 if (custom_sync_url.is_valid()) { | 255 if (custom_sync_url.is_valid()) { |
| 262 sync_service_url_ = custom_sync_url; | 256 sync_service_url_ = custom_sync_url; |
| 263 } else { | 257 } else { |
| 264 LOG(WARNING) << "The following sync URL specified at the command-line " | 258 LOG(WARNING) << "The following sync URL specified at the command-line " |
| 265 << "is invalid: " << value; | 259 << "is invalid: " << value; |
| 266 } | 260 } |
| 267 } | 261 } |
| 268 } | 262 } |
| 269 | 263 |
| 270 LOG(INFO) << "Using " << sync_service_url_ << " for sync server URL."; | |
| 271 | |
| 272 // Override the notification server host from the command-line, if provided. | 264 // Override the notification server host from the command-line, if provided. |
| 273 if (command_line.HasSwitch(switches::kSyncNotificationHost)) { | 265 if (command_line.HasSwitch(switches::kSyncNotificationHost)) { |
| 274 std::string value(command_line.GetSwitchValueASCII( | 266 std::string value(command_line.GetSwitchValueASCII( |
| 275 switches::kSyncNotificationHost)); | 267 switches::kSyncNotificationHost)); |
| 276 if (!value.empty()) { | 268 if (!value.empty()) { |
| 277 notifier_options_.xmpp_host_port.set_host(value); | 269 notifier_options_.xmpp_host_port.set_host(value); |
| 278 notifier_options_.xmpp_host_port.set_port(notifier::kDefaultXmppPort); | 270 notifier_options_.xmpp_host_port.set_port(notifier::kDefaultXmppPort); |
| 279 } | 271 } |
| 280 LOG(INFO) << "Using " << notifier_options_.xmpp_host_port.ToString() | 272 LOG(INFO) << "Using " << notifier_options_.xmpp_host_port.ToString() |
| 281 << " for test sync notification server."; | 273 << " for test sync notification server."; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 380 |
| 389 void ProfileSyncService::StartUp() { | 381 void ProfileSyncService::StartUp() { |
| 390 // Don't start up multiple times. | 382 // Don't start up multiple times. |
| 391 if (backend_.get()) { | 383 if (backend_.get()) { |
| 392 LOG(INFO) << "Skipping bringing up backend host."; | 384 LOG(INFO) << "Skipping bringing up backend host."; |
| 393 return; | 385 return; |
| 394 } | 386 } |
| 395 | 387 |
| 396 DCHECK(AreCredentialsAvailable()); | 388 DCHECK(AreCredentialsAvailable()); |
| 397 | 389 |
| 398 LOG(INFO) << "ProfileSyncService bringing up backend host."; | |
| 399 | |
| 400 last_synced_time_ = base::Time::FromInternalValue( | 390 last_synced_time_ = base::Time::FromInternalValue( |
| 401 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); | 391 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); |
| 402 | 392 |
| 403 CreateBackend(); | 393 CreateBackend(); |
| 404 // Initialize the backend. Every time we start up a new SyncBackendHost, | 394 // Initialize the backend. Every time we start up a new SyncBackendHost, |
| 405 // we'll want to start from a fresh SyncDB, so delete any old one that might | 395 // we'll want to start from a fresh SyncDB, so delete any old one that might |
| 406 // be there. | 396 // be there. |
| 407 InitializeBackend(!HasSyncSetupCompleted()); | 397 InitializeBackend(!HasSyncSetupCompleted()); |
| 408 } | 398 } |
| 409 | 399 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 430 is_auth_in_progress_ = false; | 420 is_auth_in_progress_ = false; |
| 431 backend_initialized_ = false; | 421 backend_initialized_ = false; |
| 432 last_attempted_user_email_.clear(); | 422 last_attempted_user_email_.clear(); |
| 433 } | 423 } |
| 434 | 424 |
| 435 void ProfileSyncService::ClearServerData() { | 425 void ProfileSyncService::ClearServerData() { |
| 436 backend_->RequestClearServerData(); | 426 backend_->RequestClearServerData(); |
| 437 } | 427 } |
| 438 | 428 |
| 439 void ProfileSyncService::DisableForUser() { | 429 void ProfileSyncService::DisableForUser() { |
| 440 LOG(INFO) << "Disabling sync for user."; | |
| 441 | |
| 442 // Clear prefs (including SyncSetupHasCompleted) before shutting down so | 430 // Clear prefs (including SyncSetupHasCompleted) before shutting down so |
| 443 // PSS clients don't think we're set up while we're shutting down. | 431 // PSS clients don't think we're set up while we're shutting down. |
| 444 ClearPreferences(); | 432 ClearPreferences(); |
| 445 Shutdown(true); | 433 Shutdown(true); |
| 446 | 434 |
| 447 if (cros_user_.empty()) { | 435 if (cros_user_.empty()) { |
| 448 signin_.SignOut(); | 436 signin_.SignOut(); |
| 449 } | 437 } |
| 450 | 438 |
| 451 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); | 439 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 // is initialized, all enabled data types are consistent with one | 969 // is initialized, all enabled data types are consistent with one |
| 982 // another, and no unrecoverable error has transpired. | 970 // another, and no unrecoverable error has transpired. |
| 983 if (unrecoverable_error_detected_) | 971 if (unrecoverable_error_detected_) |
| 984 return false; | 972 return false; |
| 985 | 973 |
| 986 if (!data_type_manager_.get()) | 974 if (!data_type_manager_.get()) |
| 987 return false; | 975 return false; |
| 988 | 976 |
| 989 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 977 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 990 } | 978 } |
| OLD | NEW |