| 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 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/chrome_thread.h" | 22 #include "chrome/browser/chrome_thread.h" |
| 23 #include "chrome/browser/history/history_types.h" | 23 #include "chrome/browser/history/history_types.h" |
| 24 #include "chrome/browser/platform_util.h" | 24 #include "chrome/browser/platform_util.h" |
| 25 #include "chrome/browser/pref_service.h" | 25 #include "chrome/browser/pref_service.h" |
| 26 #include "chrome/browser/profile.h" | 26 #include "chrome/browser/profile.h" |
| 27 #include "chrome/browser/net/gaia/token_service.h" | 27 #include "chrome/browser/net/gaia/token_service.h" |
| 28 #include "chrome/browser/sync/engine/syncapi.h" | 28 #include "chrome/browser/sync/engine/syncapi.h" |
| 29 #include "chrome/browser/sync/glue/change_processor.h" | 29 #include "chrome/browser/sync/glue/change_processor.h" |
| 30 #include "chrome/browser/sync/glue/data_type_controller.h" | 30 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 31 #include "chrome/browser/sync/glue/data_type_manager.h" | 31 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 32 #include "chrome/browser/sync/glue/session_data_type_controller.h" | |
| 33 #include "chrome/browser/sync/profile_sync_factory.h" | 32 #include "chrome/browser/sync/profile_sync_factory.h" |
| 34 #include "chrome/browser/sync/syncable/directory_manager.h" | 33 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 35 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/notification_details.h" | 35 #include "chrome/common/notification_details.h" |
| 37 #include "chrome/common/notification_service.h" | 36 #include "chrome/common/notification_service.h" |
| 38 #include "chrome/common/notification_source.h" | 37 #include "chrome/common/notification_source.h" |
| 39 #include "chrome/common/notification_type.h" | 38 #include "chrome/common/notification_type.h" |
| 40 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 41 #include "chrome/common/time_format.h" | 40 #include "chrome/common/time_format.h" |
| 42 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 162 } |
| 164 } | 163 } |
| 165 | 164 |
| 166 void ProfileSyncService::RegisterDataTypeController( | 165 void ProfileSyncService::RegisterDataTypeController( |
| 167 DataTypeController* data_type_controller) { | 166 DataTypeController* data_type_controller) { |
| 168 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 167 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
| 169 data_type_controllers_[data_type_controller->type()] = | 168 data_type_controllers_[data_type_controller->type()] = |
| 170 data_type_controller; | 169 data_type_controller; |
| 171 } | 170 } |
| 172 | 171 |
| 173 browser_sync::SessionModelAssociator* | |
| 174 ProfileSyncService::GetSessionModelAssociator() { | |
| 175 if (data_type_controllers_.find(syncable::SESSIONS) == | |
| 176 data_type_controllers_.end() || | |
| 177 data_type_controllers_.find(syncable::SESSIONS)->second->state() != | |
| 178 DataTypeController::RUNNING) { | |
| 179 return NULL; | |
| 180 } | |
| 181 return static_cast<browser_sync::SessionDataTypeController*>( | |
| 182 data_type_controllers_.find( | |
| 183 syncable::SESSIONS)->second.get())->GetModelAssociator(); | |
| 184 } | |
| 185 | |
| 186 void ProfileSyncService::GetDataTypeControllerStates( | 172 void ProfileSyncService::GetDataTypeControllerStates( |
| 187 browser_sync::DataTypeController::StateMap* state_map) const { | 173 browser_sync::DataTypeController::StateMap* state_map) const { |
| 188 browser_sync::DataTypeController::TypeMap::const_iterator iter | 174 browser_sync::DataTypeController::TypeMap::const_iterator iter |
| 189 = data_type_controllers_.begin(); | 175 = data_type_controllers_.begin(); |
| 190 for ( ; iter != data_type_controllers_.end(); ++iter ) { | 176 for ( ; iter != data_type_controllers_.end(); ++iter ) { |
| 191 (*state_map)[iter->first] = iter->second.get()->state(); | 177 (*state_map)[iter->first] = iter->second.get()->state(); |
| 192 } | 178 } |
| 193 } | 179 } |
| 194 | 180 |
| 195 void ProfileSyncService::InitSettings() { | 181 void ProfileSyncService::InitSettings() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 #endif | 233 #endif |
| 248 | 234 |
| 249 pref_service->RegisterBooleanPref(prefs::kSyncBookmarks, true); | 235 pref_service->RegisterBooleanPref(prefs::kSyncBookmarks, true); |
| 250 pref_service->RegisterBooleanPref(prefs::kSyncPasswords, enable_by_default); | 236 pref_service->RegisterBooleanPref(prefs::kSyncPasswords, enable_by_default); |
| 251 pref_service->RegisterBooleanPref(prefs::kSyncPreferences, enable_by_default); | 237 pref_service->RegisterBooleanPref(prefs::kSyncPreferences, enable_by_default); |
| 252 pref_service->RegisterBooleanPref(prefs::kSyncAutofill, enable_by_default); | 238 pref_service->RegisterBooleanPref(prefs::kSyncAutofill, enable_by_default); |
| 253 pref_service->RegisterBooleanPref(prefs::kSyncThemes, enable_by_default); | 239 pref_service->RegisterBooleanPref(prefs::kSyncThemes, enable_by_default); |
| 254 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls, enable_by_default); | 240 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls, enable_by_default); |
| 255 pref_service->RegisterBooleanPref(prefs::kSyncExtensions, enable_by_default); | 241 pref_service->RegisterBooleanPref(prefs::kSyncExtensions, enable_by_default); |
| 256 pref_service->RegisterBooleanPref(prefs::kSyncApps, enable_by_default); | 242 pref_service->RegisterBooleanPref(prefs::kSyncApps, enable_by_default); |
| 257 pref_service->RegisterBooleanPref(prefs::kSyncSessions, enable_by_default); | 243 |
| 258 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, | 244 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, |
| 259 enable_by_default); | 245 enable_by_default); |
| 246 |
| 260 pref_service->RegisterBooleanPref(prefs::kSyncManaged, false); | 247 pref_service->RegisterBooleanPref(prefs::kSyncManaged, false); |
| 261 } | 248 } |
| 262 | 249 |
| 263 void ProfileSyncService::ClearPreferences() { | 250 void ProfileSyncService::ClearPreferences() { |
| 264 PrefService* pref_service = profile_->GetPrefs(); | 251 PrefService* pref_service = profile_->GetPrefs(); |
| 265 pref_service->ClearPref(prefs::kSyncLastSyncedTime); | 252 pref_service->ClearPref(prefs::kSyncLastSyncedTime); |
| 266 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 253 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
| 267 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 254 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
| 268 // Is that really what we want? | 255 // Is that really what we want? |
| 269 pref_service->ScheduleSavePersistentPrefs(); | 256 pref_service->ScheduleSavePersistentPrefs(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); | 314 profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); |
| 328 | 315 |
| 329 CreateBackend(); | 316 CreateBackend(); |
| 330 // Initialize the backend. Every time we start up a new SyncBackendHost, | 317 // Initialize the backend. Every time we start up a new SyncBackendHost, |
| 331 // we'll want to start from a fresh SyncDB, so delete any old one that might | 318 // we'll want to start from a fresh SyncDB, so delete any old one that might |
| 332 // be there. | 319 // be there. |
| 333 InitializeBackend(!HasSyncSetupCompleted()); | 320 InitializeBackend(!HasSyncSetupCompleted()); |
| 334 } | 321 } |
| 335 | 322 |
| 336 void ProfileSyncService::Shutdown(bool sync_disabled) { | 323 void ProfileSyncService::Shutdown(bool sync_disabled) { |
| 337 // Stop all data type controllers, if needed. | 324 |
| 325 // Stop all data type controllers, if needed. |
| 338 if (data_type_manager_.get() && | 326 if (data_type_manager_.get() && |
| 339 data_type_manager_->state() != DataTypeManager::STOPPED) { | 327 data_type_manager_->state() != DataTypeManager::STOPPED) { |
| 340 data_type_manager_->Stop(); | 328 data_type_manager_->Stop(); |
| 341 } | 329 } |
| 342 | 330 |
| 343 data_type_manager_.reset(); | 331 data_type_manager_.reset(); |
| 344 | 332 |
| 345 // Move aside the backend so nobody else tries to use it while we are | 333 // Move aside the backend so nobody else tries to use it while we are |
| 346 // shutting it down. | 334 // shutting it down. |
| 347 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); | 335 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 case syncable::AUTOFILL: | 402 case syncable::AUTOFILL: |
| 415 return prefs::kSyncAutofill; | 403 return prefs::kSyncAutofill; |
| 416 case syncable::THEMES: | 404 case syncable::THEMES: |
| 417 return prefs::kSyncThemes; | 405 return prefs::kSyncThemes; |
| 418 case syncable::TYPED_URLS: | 406 case syncable::TYPED_URLS: |
| 419 return prefs::kSyncTypedUrls; | 407 return prefs::kSyncTypedUrls; |
| 420 case syncable::EXTENSIONS: | 408 case syncable::EXTENSIONS: |
| 421 return prefs::kSyncExtensions; | 409 return prefs::kSyncExtensions; |
| 422 case syncable::APPS: | 410 case syncable::APPS: |
| 423 return prefs::kSyncApps; | 411 return prefs::kSyncApps; |
| 424 case syncable::SESSIONS: | |
| 425 return prefs::kSyncSessions; | |
| 426 default: | 412 default: |
| 427 NOTREACHED(); | 413 NOTREACHED(); |
| 428 return NULL; | 414 return NULL; |
| 429 } | 415 } |
| 430 } | 416 } |
| 431 | 417 |
| 432 // An invariant has been violated. Transition to an error state where we try | 418 // An invariant has been violated. Transition to an error state where we try |
| 433 // to do as little work as possible, to avoid further corruption or crashes. | 419 // to do as little work as possible, to avoid further corruption or crashes. |
| 434 void ProfileSyncService::OnUnrecoverableError( | 420 void ProfileSyncService::OnUnrecoverableError( |
| 435 const tracked_objects::Location& from_here, | 421 const tracked_objects::Location& from_here, |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 // is initialized, all enabled data types are consistent with one | 843 // is initialized, all enabled data types are consistent with one |
| 858 // another, and no unrecoverable error has transpired. | 844 // another, and no unrecoverable error has transpired. |
| 859 if (unrecoverable_error_detected_) | 845 if (unrecoverable_error_detected_) |
| 860 return false; | 846 return false; |
| 861 | 847 |
| 862 if (!data_type_manager_.get()) | 848 if (!data_type_manager_.get()) |
| 863 return false; | 849 return false; |
| 864 | 850 |
| 865 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 851 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
| 866 } | 852 } |
| OLD | NEW |