| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/histogram.h" | 15 #include "base/histogram.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/stl_util-inl.h" | 17 #include "base/stl_util-inl.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/task.h" | 19 #include "base/task.h" |
| 20 #include "chrome/browser/chrome_thread.h" | 20 #include "chrome/browser/chrome_thread.h" |
| 21 #include "chrome/browser/history/history_types.h" | 21 #include "chrome/browser/history/history_types.h" |
| 22 #include "chrome/browser/platform_util.h" | 22 #include "chrome/browser/platform_util.h" |
| 23 #include "chrome/browser/pref_service.h" | 23 #include "chrome/browser/pref_service.h" |
| 24 #include "chrome/browser/profile.h" | 24 #include "chrome/browser/profile.h" |
| 25 #include "chrome/browser/net/gaia/token_service.h" |
| 25 #include "chrome/browser/sync/engine/syncapi.h" | 26 #include "chrome/browser/sync/engine/syncapi.h" |
| 26 #include "chrome/browser/sync/glue/change_processor.h" | 27 #include "chrome/browser/sync/glue/change_processor.h" |
| 27 #include "chrome/browser/sync/glue/data_type_controller.h" | 28 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 28 #include "chrome/browser/sync/glue/data_type_manager.h" | 29 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 29 #include "chrome/browser/sync/profile_sync_factory.h" | 30 #include "chrome/browser/sync/profile_sync_factory.h" |
| 30 #include "chrome/browser/sync/syncable/directory_manager.h" | 31 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/notification_details.h" | 33 #include "chrome/common/notification_details.h" |
| 33 #include "chrome/common/notification_service.h" | 34 #include "chrome/common/notification_service.h" |
| 34 #include "chrome/common/notification_source.h" | 35 #include "chrome/common/notification_source.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 InitSettings(); | 126 InitSettings(); |
| 126 RegisterPreferences(); | 127 RegisterPreferences(); |
| 127 | 128 |
| 128 if (!profile()->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) { | 129 if (!profile()->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)) { |
| 129 DisableForUser(); // Clean up in case of previous crash / setup abort. | 130 DisableForUser(); // Clean up in case of previous crash / setup abort. |
| 130 | 131 |
| 131 // Automatically start sync in Chromium OS. | 132 // Automatically start sync in Chromium OS. |
| 132 if (bootstrap_sync_authentication_) { | 133 if (bootstrap_sync_authentication_) { |
| 133 // If the LSID is empty, we're in a CrOS UI test that is not testing sync | 134 // If the LSID is empty, we're in a CrOS UI test that is not testing sync |
| 134 // behavior, so we don't want the sync service to start. | 135 // behavior, so we don't want the sync service to start. |
| 135 if (GetLsidForAuthBootstraping().empty()) { | 136 if (profile()->GetTokenService() && |
| 137 !profile()->GetTokenService()->HasLsid()) { |
| 136 LOG(WARNING) << "Skipping CrOS sync startup, no LSID present."; | 138 LOG(WARNING) << "Skipping CrOS sync startup, no LSID present."; |
| 137 return; | 139 return; |
| 138 } | 140 } |
| 139 StartUp(); | 141 StartUp(); |
| 140 } | 142 } |
| 141 } else { | 143 } else { |
| 142 StartUp(); | 144 StartUp(); |
| 143 } | 145 } |
| 144 } | 146 } |
| 145 | 147 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 222 |
| 221 void ProfileSyncService::ClearPreferences() { | 223 void ProfileSyncService::ClearPreferences() { |
| 222 PrefService* pref_service = profile_->GetPrefs(); | 224 PrefService* pref_service = profile_->GetPrefs(); |
| 223 pref_service->ClearPref(prefs::kSyncLastSyncedTime); | 225 pref_service->ClearPref(prefs::kSyncLastSyncedTime); |
| 224 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 226 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
| 225 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 227 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
| 226 // Is that really what we want? | 228 // Is that really what we want? |
| 227 pref_service->ScheduleSavePersistentPrefs(); | 229 pref_service->ScheduleSavePersistentPrefs(); |
| 228 } | 230 } |
| 229 | 231 |
| 230 // The domain and name of the LSID cookie which we use to bootstrap the sync | |
| 231 // authentication in Chromium OS. | |
| 232 const char kLsidCookieDomain[] = "www.google.com"; | |
| 233 const char kLsidCookieName[] = "LSID"; | |
| 234 | |
| 235 std::string ProfileSyncService::GetLsidForAuthBootstraping() { | |
| 236 if (bootstrap_sync_authentication_ && profile()->GetRequestContext()) { | |
| 237 // If we're running inside Chromium OS, bootstrap the sync authentication by | |
| 238 // using the LSID cookie provided by the Chromium OS login manager. | |
| 239 net::CookieMonster::CookieList cookies = profile()->GetRequestContext()-> | |
| 240 GetCookieStore()->GetCookieMonster()->GetAllCookies(); | |
| 241 for (net::CookieMonster::CookieList::const_iterator it = cookies.begin(); | |
| 242 it != cookies.end(); ++it) { | |
| 243 if (kLsidCookieDomain == it->first) { | |
| 244 const net::CookieMonster::CanonicalCookie& cookie = it->second; | |
| 245 if (kLsidCookieName == cookie.Name()) { | |
| 246 return cookie.Value(); | |
| 247 } | |
| 248 } | |
| 249 } | |
| 250 } | |
| 251 return std::string(); | |
| 252 } | |
| 253 | |
| 254 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { | 232 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { |
| 255 if (!backend_.get()) { | 233 if (!backend_.get()) { |
| 256 NOTREACHED(); | 234 NOTREACHED(); |
| 257 return; | 235 return; |
| 258 } | 236 } |
| 259 | 237 |
| 260 bool invalidate_sync_login = false; | 238 bool invalidate_sync_login = false; |
| 261 bool invalidate_sync_xmpp_login = false; | 239 bool invalidate_sync_xmpp_login = false; |
| 262 #if !defined(NDEBUG) | 240 #if !defined(NDEBUG) |
| 263 invalidate_sync_login = CommandLine::ForCurrentProcess()->HasSwitch( | 241 invalidate_sync_login = CommandLine::ForCurrentProcess()->HasSwitch( |
| 264 switches::kInvalidateSyncLogin); | 242 switches::kInvalidateSyncLogin); |
| 265 invalidate_sync_xmpp_login = CommandLine::ForCurrentProcess()->HasSwitch( | 243 invalidate_sync_xmpp_login = CommandLine::ForCurrentProcess()->HasSwitch( |
| 266 switches::kInvalidateSyncXmppLogin); | 244 switches::kInvalidateSyncXmppLogin); |
| 267 #endif | 245 #endif |
| 268 | 246 |
| 269 syncable::ModelTypeSet types; | 247 syncable::ModelTypeSet types; |
| 270 // If sync setup hasn't finished, we don't want to initialize routing info | 248 // If sync setup hasn't finished, we don't want to initialize routing info |
| 271 // for any data types so that we don't download updates for types that the | 249 // for any data types so that we don't download updates for types that the |
| 272 // user chooses not to sync on the first DownloadUpdatesCommand. | 250 // user chooses not to sync on the first DownloadUpdatesCommand. |
| 273 if (HasSyncSetupCompleted()) | 251 if (HasSyncSetupCompleted()) |
| 274 GetPreferredDataTypes(&types); | 252 GetPreferredDataTypes(&types); |
| 275 backend_->Initialize(sync_service_url_, | 253 backend_->Initialize(sync_service_url_, |
| 276 types, | 254 types, |
| 277 profile_->GetRequestContext(), | 255 profile_->GetRequestContext(), |
| 278 GetLsidForAuthBootstraping(), | 256 profile_->GetTokenService()->GetLsid(), |
| 279 delete_sync_data_folder, | 257 delete_sync_data_folder, |
| 280 invalidate_sync_login, | 258 invalidate_sync_login, |
| 281 invalidate_sync_xmpp_login, | 259 invalidate_sync_xmpp_login, |
| 282 notification_method_); | 260 notification_method_); |
| 283 } | 261 } |
| 284 | 262 |
| 285 void ProfileSyncService::StartUp() { | 263 void ProfileSyncService::StartUp() { |
| 286 // Don't start up multiple times. | 264 // Don't start up multiple times. |
| 287 if (backend_.get()) { | 265 if (backend_.get()) { |
| 288 LOG(INFO) << "Skipping bringing up backend host."; | 266 LOG(INFO) << "Skipping bringing up backend host."; |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 // is initialized, all enabled data types are consistent with one | 759 // is initialized, all enabled data types are consistent with one |
| 782 // another, and no unrecoverable error has transpired. | 760 // another, and no unrecoverable error has transpired. |
| 783 if (unrecoverable_error_detected_) | 761 if (unrecoverable_error_detected_) |
| 784 return false; | 762 return false; |
| 785 | 763 |
| 786 if (!data_type_manager_.get()) | 764 if (!data_type_manager_.get()) |
| 787 return false; | 765 return false; |
| 788 | 766 |
| 789 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 767 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 790 } | 768 } |
| OLD | NEW |