Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/string16.h" | 19 #include "base/string16.h" |
| 20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
| 21 #include "base/task.h" | 21 #include "base/task.h" |
| 22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 23 #include "chrome/browser/about_flags.h" | 23 #include "chrome/browser/about_flags.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 25 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 26 #include "chrome/browser/net/gaia/token_service.h" | 26 #include "chrome/browser/net/gaia/token_service.h" |
| 27 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/sync/backend_migrator.h" | |
| 30 #include "chrome/browser/sync/glue/change_processor.h" | 29 #include "chrome/browser/sync/glue/change_processor.h" |
| 31 #include "chrome/browser/sync/glue/data_type_controller.h" | 30 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 32 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 31 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 33 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" | 32 #include "chrome/browser/sync/glue/typed_url_data_type_controller.h" |
| 34 #include "chrome/browser/sync/glue/data_type_manager.h" | 33 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 35 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 34 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
| 36 #include "chrome/browser/sync/internal_api/configure_reason.h" | 35 #include "chrome/browser/sync/internal_api/configure_reason.h" |
| 37 #include "chrome/browser/sync/internal_api/sync_manager.h" | 36 #include "chrome/browser/sync/internal_api/sync_manager.h" |
| 38 #include "chrome/browser/sync/js/js_arg_list.h" | 37 #include "chrome/browser/sync/js/js_arg_list.h" |
| 39 #include "chrome/browser/sync/js/js_event_details.h" | 38 #include "chrome/browser/sync/js/js_event_details.h" |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 backend_->Initialize( | 384 backend_->Initialize( |
| 386 this, | 385 this, |
| 387 WeakHandle<JsEventHandler>(sync_js_controller_.AsWeakPtr()), | 386 WeakHandle<JsEventHandler>(sync_js_controller_.AsWeakPtr()), |
| 388 sync_service_url_, | 387 sync_service_url_, |
| 389 initial_types, | 388 initial_types, |
| 390 credentials, | 389 credentials, |
| 391 delete_sync_data_folder); | 390 delete_sync_data_folder); |
| 392 } | 391 } |
| 393 | 392 |
| 394 void ProfileSyncService::CreateBackend() { | 393 void ProfileSyncService::CreateBackend() { |
| 395 backend_.reset(new SyncBackendHost(profile_)); | 394 backend_.reset(new SyncBackendHost(profile_->GetDebugName(), profile_)); |
| 396 } | 395 } |
| 397 | 396 |
| 398 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { | 397 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { |
| 399 if (HasPendingEncryptedTypes()) | 398 if (HasPendingEncryptedTypes()) |
| 400 return true; | 399 return true; |
| 401 syncable::ModelTypeSet preferred_types; | 400 syncable::ModelTypeSet preferred_types; |
| 402 GetPreferredDataTypes(&preferred_types); | 401 GetPreferredDataTypes(&preferred_types); |
| 403 syncable::ModelTypeSet encrypted_types; | 402 syncable::ModelTypeSet encrypted_types; |
| 404 GetEncryptedDataTypes(&encrypted_types); | 403 GetEncryptedDataTypes(&encrypted_types); |
| 405 syncable::ModelTypeBitSet preferred_types_bitset = | 404 syncable::ModelTypeBitSet preferred_types_bitset = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 chrome::NOTIFICATION_SYNC_CONFIGURE_START, | 440 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
| 442 Source<DataTypeManager>(data_type_manager_.get())); | 441 Source<DataTypeManager>(data_type_manager_.get())); |
| 443 registrar_.Remove(this, | 442 registrar_.Remove(this, |
| 444 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 443 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 445 Source<DataTypeManager>(data_type_manager_.get())); | 444 Source<DataTypeManager>(data_type_manager_.get())); |
| 446 data_type_manager_.reset(); | 445 data_type_manager_.reset(); |
| 447 } | 446 } |
| 448 | 447 |
| 449 // Shutdown the migrator before the backend to ensure it doesn't pull a null | 448 // Shutdown the migrator before the backend to ensure it doesn't pull a null |
| 450 // snapshot. | 449 // snapshot. |
| 450 if (migrator_.get()) { | |
| 451 migrator_->RemoveMigrationObserver(this); | |
|
tim (not reviewing)
2011/09/01 01:50:56
hm, I thought we discussed just having the harness
akalin
2011/09/01 02:19:40
Okay, I guess that requires plumbing the migrator
akalin
2011/09/01 03:39:50
Exposed migrator via GetBackendMigratorForTest().
| |
| 452 } | |
| 451 migrator_.reset(); | 453 migrator_.reset(); |
| 452 sync_js_controller_.AttachJsBackend(WeakHandle<JsBackend>()); | 454 sync_js_controller_.AttachJsBackend(WeakHandle<JsBackend>()); |
| 453 | 455 |
| 454 // Move aside the backend so nobody else tries to use it while we are | 456 // Move aside the backend so nobody else tries to use it while we are |
| 455 // shutting it down. | 457 // shutting it down. |
| 456 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); | 458 scoped_ptr<SyncBackendHost> doomed_backend(backend_.release()); |
| 457 if (doomed_backend.get()) { | 459 if (doomed_backend.get()) { |
| 458 doomed_backend->Shutdown(sync_disabled); | 460 doomed_backend->Shutdown(sync_disabled); |
| 459 | 461 |
| 460 doomed_backend.reset(); | 462 doomed_backend.reset(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 unrecoverable_error_location_.reset( | 599 unrecoverable_error_location_.reset( |
| 598 new tracked_objects::Location(from_here.function_name(), | 600 new tracked_objects::Location(from_here.function_name(), |
| 599 from_here.file_name(), | 601 from_here.file_name(), |
| 600 from_here.line_number(), | 602 from_here.line_number(), |
| 601 from_here.program_counter())); | 603 from_here.program_counter())); |
| 602 | 604 |
| 603 // Tell the wizard so it can inform the user only if it is already open. | 605 // Tell the wizard so it can inform the user only if it is already open. |
| 604 wizard_.Step(SyncSetupWizard::FATAL_ERROR); | 606 wizard_.Step(SyncSetupWizard::FATAL_ERROR); |
| 605 | 607 |
| 606 NotifyObservers(); | 608 NotifyObservers(); |
| 607 LOG(ERROR) << "Unrecoverable error detected -- ProfileSyncService unusable." | |
| 608 << message; | |
| 609 std::string location; | 609 std::string location; |
| 610 from_here.Write(true, true, &location); | 610 from_here.Write(true, true, &location); |
| 611 LOG(ERROR) << location; | 611 LOG(ERROR) |
| 612 << "Unrecoverable error detected at " << location | |
| 613 << " -- ProfileSyncService unusable: " << message; | |
| 612 | 614 |
| 613 // Shut all data types down. | 615 // Shut all data types down. |
| 614 MessageLoop::current()->PostTask(FROM_HERE, | 616 MessageLoop::current()->PostTask(FROM_HERE, |
| 615 scoped_runnable_method_factory_.NewRunnableMethod( | 617 scoped_runnable_method_factory_.NewRunnableMethod( |
| 616 &ProfileSyncService::Shutdown, true)); | 618 &ProfileSyncService::Shutdown, true)); |
| 617 } | 619 } |
| 618 | 620 |
| 621 void ProfileSyncService::OnMigrationStateChange() { | |
| 622 // Needed by migration integration tests. | |
| 623 NotifyObservers(); | |
| 624 } | |
| 625 | |
| 619 void ProfileSyncService::OnBackendInitialized( | 626 void ProfileSyncService::OnBackendInitialized( |
| 620 const WeakHandle<JsBackend>& js_backend, bool success) { | 627 const WeakHandle<JsBackend>& js_backend, bool success) { |
| 621 if (!success) { | 628 if (!success) { |
| 622 // If backend initialization failed, abort. We only want to blow away | 629 // If backend initialization failed, abort. We only want to blow away |
| 623 // state (DBs, etc) if this was a first-time scenario that failed. | 630 // state (DBs, etc) if this was a first-time scenario that failed. |
| 624 wizard_.Step(SyncSetupWizard::FATAL_ERROR); | 631 wizard_.Step(SyncSetupWizard::FATAL_ERROR); |
| 625 Shutdown(!HasSyncSetupCompleted()); | 632 Shutdown(!HasSyncSetupCompleted()); |
| 626 return; | 633 return; |
| 627 } | 634 } |
| 628 | 635 |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 &data_type_controllers_)); | 1227 &data_type_controllers_)); |
| 1221 registrar_.Add(this, | 1228 registrar_.Add(this, |
| 1222 chrome::NOTIFICATION_SYNC_CONFIGURE_START, | 1229 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
| 1223 Source<DataTypeManager>(data_type_manager_.get())); | 1230 Source<DataTypeManager>(data_type_manager_.get())); |
| 1224 registrar_.Add(this, | 1231 registrar_.Add(this, |
| 1225 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 1232 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 1226 Source<DataTypeManager>(data_type_manager_.get())); | 1233 Source<DataTypeManager>(data_type_manager_.get())); |
| 1227 | 1234 |
| 1228 // We create the migrator at the same time. | 1235 // We create the migrator at the same time. |
| 1229 migrator_.reset( | 1236 migrator_.reset( |
| 1230 new browser_sync::BackendMigrator(this, data_type_manager_.get())); | 1237 new browser_sync::BackendMigrator( |
| 1238 profile_->GetDebugName(), GetUserShare(), | |
| 1239 this, data_type_manager_.get())); | |
| 1240 migrator_->AddMigrationObserver(this); | |
| 1231 } | 1241 } |
| 1232 | 1242 |
| 1233 syncable::ModelTypeSet types; | 1243 syncable::ModelTypeSet types; |
| 1234 GetPreferredDataTypes(&types); | 1244 GetPreferredDataTypes(&types); |
| 1235 if (IsPassphraseRequiredForDecryption()) { | 1245 if (IsPassphraseRequiredForDecryption()) { |
| 1236 if (IsEncryptedDatatypeEnabled()) { | 1246 if (IsEncryptedDatatypeEnabled()) { |
| 1237 // We need a passphrase still. We don't bother to attempt to configure | 1247 // We need a passphrase still. We don't bother to attempt to configure |
| 1238 // until we receive an OnPassphraseAccepted (which triggers a configure). | 1248 // until we receive an OnPassphraseAccepted (which triggers a configure). |
| 1239 VLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " | 1249 VLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " |
| 1240 << "because a passphrase required"; | 1250 << "because a passphrase required"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1294 } | 1304 } |
| 1295 VLOG(level) << "Unsynced items not printed because backend is not " | 1305 VLOG(level) << "Unsynced items not printed because backend is not " |
| 1296 << "initialized"; | 1306 << "initialized"; |
| 1297 } | 1307 } |
| 1298 | 1308 |
| 1299 bool ProfileSyncService::HasPendingBackendMigration() const { | 1309 bool ProfileSyncService::HasPendingBackendMigration() const { |
| 1300 return migrator_.get() && | 1310 return migrator_.get() && |
| 1301 migrator_->state() != browser_sync::BackendMigrator::IDLE; | 1311 migrator_->state() != browser_sync::BackendMigrator::IDLE; |
| 1302 } | 1312 } |
| 1303 | 1313 |
| 1314 syncable::ModelTypeSet | |
| 1315 ProfileSyncService::GetPendingMigrationTypesForTest() const { | |
| 1316 return | |
| 1317 migrator_.get() ? | |
| 1318 migrator_->GetPendingMigrationTypesForTest() : | |
| 1319 syncable::ModelTypeSet(); | |
| 1320 } | |
| 1321 | |
| 1304 void ProfileSyncService::GetModelSafeRoutingInfo( | 1322 void ProfileSyncService::GetModelSafeRoutingInfo( |
| 1305 browser_sync::ModelSafeRoutingInfo* out) const { | 1323 browser_sync::ModelSafeRoutingInfo* out) const { |
| 1306 if (backend_.get() && backend_initialized_) { | 1324 if (backend_.get() && backend_initialized_) { |
| 1307 backend_->GetModelSafeRoutingInfo(out); | 1325 backend_->GetModelSafeRoutingInfo(out); |
| 1308 } else { | 1326 } else { |
| 1309 NOTREACHED(); | 1327 NOTREACHED(); |
| 1310 } | 1328 } |
| 1311 } | 1329 } |
| 1312 | 1330 |
| 1313 void ProfileSyncService::ActivateDataType( | 1331 void ProfileSyncService::ActivateDataType( |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1574 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); | 1592 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); |
| 1575 syncable::ModelTypeSet registered; | 1593 syncable::ModelTypeSet registered; |
| 1576 GetRegisteredDataTypes(®istered); | 1594 GetRegisteredDataTypes(®istered); |
| 1577 syncable::ModelTypeBitSet registered_bit_set = | 1595 syncable::ModelTypeBitSet registered_bit_set = |
| 1578 syncable::ModelTypeBitSetFromSet(registered); | 1596 syncable::ModelTypeBitSetFromSet(registered); |
| 1579 unacknowledged = registered_bit_set & ~acknowledged; | 1597 unacknowledged = registered_bit_set & ~acknowledged; |
| 1580 } | 1598 } |
| 1581 return unacknowledged; | 1599 return unacknowledged; |
| 1582 } | 1600 } |
| 1583 | 1601 |
| OLD | NEW |