diff options
author | lipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 20:12:28 +0000 |
---|---|---|
committer | lipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 20:12:28 +0000 |
commit | 5d36e05c6ca86090652af10f08881677ee25775d (patch) | |
tree | 207b2224d01b974d0556caed3e8384e2abd83378 /chrome/browser | |
parent | 6b5071c252b83d1bc4186fa3b503c0a1de95a109 (diff) | |
download | chromium_src-5d36e05c6ca86090652af10f08881677ee25775d.zip chromium_src-5d36e05c6ca86090652af10f08881677ee25775d.tar.gz chromium_src-5d36e05c6ca86090652af10f08881677ee25775d.tar.bz2 |
Make the Datatypes using new syncapi upload unrecoverable errors to breakpad.
BUG=
TEST=
Review URL: http://codereview.chromium.org/10061002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133251 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
40 files changed, 522 insertions, 175 deletions
diff --git a/chrome/browser/extensions/app_notification_manager.cc b/chrome/browser/extensions/app_notification_manager.cc index c9aca6b..453e0cc 100644 --- a/chrome/browser/extensions/app_notification_manager.cc +++ b/chrome/browser/extensions/app_notification_manager.cc @@ -13,6 +13,7 @@ #include "base/stl_util.h" #include "base/time.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" #include "content/public/browser/notification_service.h" @@ -305,9 +306,11 @@ SyncError AppNotificationManager::ProcessSyncChanges( const SyncChangeList& change_list) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(loaded()); - if (!models_associated_) - return SyncError(FROM_HERE, "Models not yet associated.", - syncable::APP_NOTIFICATIONS); + if (!models_associated_) { + return sync_error_factory_->CreateAndUploadError( + FROM_HERE, + "Models not yet associated."); + } AutoReset<bool> processing_changes(&processing_syncer_changes_, true); @@ -328,10 +331,10 @@ SyncError AppNotificationManager::ProcessSyncChanges( new_notif->extension_id(), new_notif->guid()); if (existing_notif && existing_notif->is_local()) { NOTREACHED() << "Matched with notification marked as local"; - error = SyncError(FROM_HERE, + error = sync_error_factory_->CreateAndUploadError( + FROM_HERE, "ProcessSyncChanges received a local only notification" + - SyncChange::ChangeTypeToString(change_type), - syncable::APP_NOTIFICATIONS); + SyncChange::ChangeTypeToString(change_type)); continue; } @@ -382,7 +385,8 @@ SyncError AppNotificationManager::ProcessSyncChanges( SyncError AppNotificationManager::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // AppNotificationDataTypeController ensures that modei is fully should before // this method is called by waiting until the load notification is received @@ -391,7 +395,9 @@ SyncError AppNotificationManager::MergeDataAndStartSyncing( DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); DCHECK(!sync_processor_.get()); DCHECK(sync_processor.get()); + DCHECK(sync_error_factory.get()); sync_processor_ = sync_processor.Pass(); + sync_error_factory_ = sync_error_factory.Pass(); // We may add, or remove notifications here, so ensure we don't step on // our own toes. @@ -415,10 +421,10 @@ SyncError AppNotificationManager::MergeDataAndStartSyncing( // Local notification should always match with sync notification as // notifications are immutable. if (local_notif->is_local() || !sync_notif->Equals(*local_notif)) { - return SyncError(FROM_HERE, + return sync_error_factory_->CreateAndUploadError( + FROM_HERE, "MergeDataAndStartSyncing failed: local notification and sync " - "notification have same guid but different data.", - syncable::APP_NOTIFICATIONS); + "notification have same guid but different data."); } } else { // Sync model has a notification that local model does not, add it. @@ -444,6 +450,7 @@ void AppNotificationManager::StopSyncing(syncable::ModelType type) { DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); models_associated_ = false; sync_processor_.reset(); + sync_error_factory_.reset(); } void AppNotificationManager::SyncAddChange(const AppNotification& notif) { diff --git a/chrome/browser/extensions/app_notification_manager.h b/chrome/browser/extensions/app_notification_manager.h index fae3b9e..44bdd9b 100644 --- a/chrome/browser/extensions/app_notification_manager.h +++ b/chrome/browser/extensions/app_notification_manager.h @@ -24,6 +24,7 @@ class PerfTimer; class Profile; +class SyncErrorFactory; // This class keeps track of notifications for installed apps. class AppNotificationManager @@ -73,7 +74,8 @@ class AppNotificationManager virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; private: @@ -156,6 +158,10 @@ class AppNotificationManager // Sync change processor we use to push all our changes. scoped_ptr<SyncChangeProcessor> sync_processor_; + + // Sync error handler that we use to create errors from. + scoped_ptr<SyncErrorFactory> sync_error_factory_; + // Whether the sync model is associated with the local model. // In other words, whether we are ready to apply sync changes. bool models_associated_; diff --git a/chrome/browser/extensions/app_notification_manager_sync_unittest.cc b/chrome/browser/extensions/app_notification_manager_sync_unittest.cc index 6a498f4..d311360c 100644 --- a/chrome/browser/extensions/app_notification_manager_sync_unittest.cc +++ b/chrome/browser/extensions/app_notification_manager_sync_unittest.cc @@ -8,6 +8,8 @@ #include "base/string_number_conversions.h" #include "chrome/browser/extensions/app_notification.h" #include "chrome/browser/extensions/app_notification_manager.h" +#include "chrome/browser/sync/api/sync_error_factory.h" +#include "chrome/browser/sync/api/sync_error_factory_mock.h" #include "chrome/test/base/testing_profile.h" #include "content/test/test_browser_thread.h" #include "sync/protocol/app_notification_specifics.pb.h" @@ -15,6 +17,8 @@ #include "testing/gtest/include/gtest/gtest.h" using content::BrowserThread; +using ::testing::_; +using ::testing::Return; namespace { @@ -303,7 +307,8 @@ TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), // Empty. - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); EXPECT_EQ(0U, processor()->change_list_size()); @@ -320,7 +325,8 @@ TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, initial_data, - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); // Model should all of the initial sync data. @@ -357,7 +363,8 @@ TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyNoOverlap) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, initial_data, - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); for (SyncDataList::const_iterator iter = initial_data.begin(); @@ -408,7 +415,8 @@ TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptySomeOverlap) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, initial_data, - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); for (SyncDataList::const_iterator iter = initial_data.begin(); @@ -453,10 +461,16 @@ TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { initial_data.push_back( AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); + scoped_ptr<SyncErrorFactoryMock> error_handler(new SyncErrorFactoryMock()); + EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). + WillOnce( + Return(SyncError(FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); + SyncError sync_error = model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, initial_data, - PassProcessor()); + PassProcessor(), + error_handler.PassAs<SyncErrorFactory>()); EXPECT_TRUE(sync_error.IsSet()); EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); @@ -477,10 +491,16 @@ TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { initial_data.push_back( AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); + scoped_ptr<SyncErrorFactoryMock> error_handler(new SyncErrorFactoryMock()); + EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). + WillOnce( + Return(SyncError(FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); + SyncError sync_error = model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, initial_data, - PassProcessor()); + PassProcessor(), + error_handler.PassAs<SyncErrorFactory>()); EXPECT_TRUE(sync_error.IsSet()); EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); @@ -493,7 +513,8 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Set up a bunch of ADDs. SyncChangeList changes; @@ -519,7 +540,8 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Some adds and some deletes. SyncChangeList changes; @@ -544,7 +566,8 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Some adds and some deletes. SyncChangeList changes; @@ -567,7 +590,8 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Some adds and some deletes. SyncChangeList changes; @@ -590,7 +614,8 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Some adds and some deletes. SyncChangeList changes; @@ -614,7 +639,8 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); for (unsigned int i = 0; i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { SyncChangeList changes; @@ -636,17 +662,6 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { } } -// Process sync changes should return error if model association is not done. -TEST_F(AppNotificationManagerSyncTest, - ProcessSyncChangesErrorModelAssocNotDone) { - SyncChangeList changes; - - SyncError sync_error = model()->ProcessSyncChanges(FROM_HERE, changes); - EXPECT_TRUE(sync_error.IsSet()); - EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); - EXPECT_EQ(0U, processor()->change_list_size()); -} - // Stop syncing sets state correctly. TEST_F(AppNotificationManagerSyncTest, StopSyncing) { EXPECT_FALSE(model()->sync_processor_.get()); @@ -655,7 +670,8 @@ TEST_F(AppNotificationManagerSyncTest, StopSyncing) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_TRUE(model()->sync_processor_.get()); EXPECT_TRUE(model()->models_associated_); @@ -670,7 +686,8 @@ TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, SyncDataList(), - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); AppNotification* n1 = CreateNotification(1); model()->Add(n1); @@ -707,7 +724,8 @@ TEST_F(AppNotificationManagerSyncTest, ClearAllGetsSynced) { model()->MergeDataAndStartSyncing( syncable::APP_NOTIFICATIONS, initial_data, - PassProcessor()); + PassProcessor(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); model()->ClearAll(ext_id); diff --git a/chrome/browser/extensions/app_sync_bundle.cc b/chrome/browser/extensions/app_sync_bundle.cc index 43ceb98..29f508b 100644 --- a/chrome/browser/extensions/app_sync_bundle.cc +++ b/chrome/browser/extensions/app_sync_bundle.cc @@ -8,6 +8,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_sorting.h" #include "chrome/browser/sync/api/sync_change_processor.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_set.h" @@ -20,8 +21,10 @@ AppSyncBundle::AppSyncBundle(ExtensionService* extension_service) AppSyncBundle::~AppSyncBundle() {} void AppSyncBundle::SetupSync(SyncChangeProcessor* sync_change_processor, + SyncErrorFactory* sync_error_factory, const SyncDataList& initial_sync_data) { sync_processor_.reset(sync_change_processor); + sync_error_factory_.reset(sync_error_factory); for (SyncDataList::const_iterator i = initial_sync_data.begin(); i != initial_sync_data.end(); @@ -34,6 +37,7 @@ void AppSyncBundle::SetupSync(SyncChangeProcessor* sync_change_processor, void AppSyncBundle::Reset() { sync_processor_.reset(); + sync_error_factory_.reset(); synced_apps_.clear(); pending_sync_data_.clear(); } diff --git a/chrome/browser/extensions/app_sync_bundle.h b/chrome/browser/extensions/app_sync_bundle.h index 9872e9d..5d840c7 100644 --- a/chrome/browser/extensions/app_sync_bundle.h +++ b/chrome/browser/extensions/app_sync_bundle.h @@ -20,6 +20,7 @@ class SyncChangeProcessor; class Extension; class ExtensionService; class ExtensionSet; +class SyncErrorFactory; namespace extensions { @@ -31,6 +32,7 @@ class AppSyncBundle { // Setup this bundle to be sync application data. void SetupSync(SyncChangeProcessor* sync_proccessor, + SyncErrorFactory* sync_error_factory, const SyncDataList& initial_sync_data); // Resets this class back to it default values, which will disable all syncing @@ -89,6 +91,7 @@ class AppSyncBundle { ExtensionService* extension_service_; // Own us. scoped_ptr<SyncChangeProcessor> sync_processor_; + scoped_ptr<SyncErrorFactory> sync_error_factory_; std::set<std::string> synced_apps_; std::map<std::string, AppSyncData> pending_sync_data_; diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 0b78711..75e5405 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -75,6 +75,7 @@ #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/sync/api/sync_change.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/browser.h" @@ -1277,17 +1278,22 @@ void ExtensionService::CheckForUpdatesSoon() { SyncError ExtensionService::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { CHECK(sync_processor.get()); + CHECK(sync_error_factory.get()); switch (type) { case syncable::EXTENSIONS: extension_sync_bundle_.SetupSync(sync_processor.release(), + sync_error_factory.release(), initial_sync_data); break; case syncable::APPS: - app_sync_bundle_.SetupSync(sync_processor.release(), initial_sync_data); + app_sync_bundle_.SetupSync(sync_processor.release(), + sync_error_factory.release(), + initial_sync_data); break; default: diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index 7ce5e8b..68e2e5f 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -66,6 +66,7 @@ class GURL; class PendingExtensionManager; class Profile; class SyncData; +class SyncErrorFactory; class Version; namespace chromeos { @@ -425,7 +426,8 @@ class ExtensionService virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; virtual SyncError ProcessSyncChanges( diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index a4925b2..00a7c70 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -52,6 +52,8 @@ #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/pref_service_mock_builder.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" +#include "chrome/browser/sync/api/sync_error_factory.h" +#include "chrome/browser/sync/api/sync_error_factory_mock.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_notification_types.h" @@ -4005,7 +4007,8 @@ TEST_F(ExtensionServiceTest, GetSyncData) { ASSERT_TRUE(extension); service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); ASSERT_EQ(list.size(), 1U); @@ -4028,7 +4031,8 @@ TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); ASSERT_EQ(list.size(), 1U); @@ -4050,7 +4054,8 @@ TEST_F(ExtensionServiceTest, GetSyncDataFilter) { TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); ASSERT_EQ(list.size(), 0U); @@ -4064,7 +4069,8 @@ TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) { TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); { SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); @@ -4111,7 +4117,8 @@ TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) { TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); StringOrdinal initial_ordinal = StringOrdinal::CreateInitialOrdinal(); { @@ -4159,7 +4166,8 @@ TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) { TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); service_->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); { @@ -4197,9 +4205,11 @@ TEST_F(ExtensionServiceTest, GetSyncDataList) { TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); service_->DisableExtension(page_action, Extension::DISABLE_USER_ACTION); TerminateExtension(theme2_crx); @@ -4212,7 +4222,8 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { InitializeEmptyExtensionService(); TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); sync_pb::EntitySpecifics specifics; sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); @@ -4287,7 +4298,8 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { InitializeExtensionProcessManager(); TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); @@ -4341,7 +4353,8 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { InitializeExtensionServiceWithUpdater(); TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); TerminateExtension(good_crx); @@ -4372,7 +4385,8 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { InitializeRequestContext(); TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); @@ -4429,7 +4443,8 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { InitializeRequestContext(); TestSyncProcessorStub processor; service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), - scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub)); + scoped_ptr<SyncChangeProcessor>(new TestSyncProcessorStub), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); sync_pb::EntitySpecifics specifics; sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); diff --git a/chrome/browser/extensions/extension_sync_bundle.cc b/chrome/browser/extensions/extension_sync_bundle.cc index d4f5f5b..017915e 100644 --- a/chrome/browser/extensions/extension_sync_bundle.cc +++ b/chrome/browser/extensions/extension_sync_bundle.cc @@ -8,6 +8,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_sorting.h" #include "chrome/browser/sync/api/sync_change_processor.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_set.h" @@ -19,8 +20,10 @@ ExtensionSyncBundle::ExtensionSyncBundle(ExtensionService* extension_service) ExtensionSyncBundle::~ExtensionSyncBundle() {} void ExtensionSyncBundle::SetupSync(SyncChangeProcessor* sync_processor, + SyncErrorFactory* sync_error_factory, const SyncDataList& initial_sync_data) { sync_processor_.reset(sync_processor); + sync_error_factory_.reset(sync_error_factory); for (SyncDataList::const_iterator i = initial_sync_data.begin(); i != initial_sync_data.end(); @@ -33,6 +36,7 @@ void ExtensionSyncBundle::SetupSync(SyncChangeProcessor* sync_processor, void ExtensionSyncBundle::Reset() { sync_processor_.reset(); + sync_error_factory_.reset(); synced_extensions_.clear(); pending_sync_data_.clear(); } diff --git a/chrome/browser/extensions/extension_sync_bundle.h b/chrome/browser/extensions/extension_sync_bundle.h index 9c79eb8..1ee248d 100644 --- a/chrome/browser/extensions/extension_sync_bundle.h +++ b/chrome/browser/extensions/extension_sync_bundle.h @@ -20,6 +20,7 @@ class SyncChangeProcessor; class Extension; class ExtensionService; class ExtensionSet; +class SyncErrorFactory; namespace extensions { @@ -31,6 +32,7 @@ class ExtensionSyncBundle { // Setup this bundle to be sync extension data. void SetupSync(SyncChangeProcessor* sync_processor, + SyncErrorFactory* sync_error_factory, const SyncDataList& initial_sync_data); // Resets this class back to it default values, which will disable all syncing @@ -89,6 +91,7 @@ class ExtensionSyncBundle { ExtensionService* extension_service_; // Owns us. scoped_ptr<SyncChangeProcessor> sync_processor_; + scoped_ptr<SyncErrorFactory> sync_error_factory_; std::set<std::string> synced_extensions_; std::map<std::string, ExtensionSyncData> pending_sync_data_; diff --git a/chrome/browser/extensions/settings/settings_apitest.cc b/chrome/browser/extensions/settings/settings_apitest.cc index 2bfa7be..1db2c80 100644 --- a/chrome/browser/extensions/settings/settings_apitest.cc +++ b/chrome/browser/extensions/settings/settings_apitest.cc @@ -14,6 +14,8 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/api/sync_change.h" #include "chrome/browser/sync/api/sync_change_processor.h" +#include "chrome/browser/sync/api/sync_error_factory.h" +#include "chrome/browser/sync/api/sync_error_factory_mock.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/ui_test_utils.h" @@ -162,7 +164,9 @@ class ExtensionSettingsApiTest : public ExtensionApiTest { kModelType, SyncDataList(), scoped_ptr<SyncChangeProcessor>( - new SyncChangeProcessorDelegate(sync_processor))).IsSet()); + new SyncChangeProcessorDelegate(sync_processor)), + scoped_ptr<SyncErrorFactory>( + new SyncErrorFactoryMock())).IsSet()); } void SendChangesToSyncableService( diff --git a/chrome/browser/extensions/settings/settings_backend.cc b/chrome/browser/extensions/settings/settings_backend.cc index c13186d..a20a842 100644 --- a/chrome/browser/extensions/settings/settings_backend.cc +++ b/chrome/browser/extensions/settings/settings_backend.cc @@ -16,6 +16,7 @@ #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h" #include "chrome/browser/extensions/settings/settings_sync_processor.h" #include "chrome/browser/extensions/settings/settings_sync_util.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/common/extensions/extension.h" #include "content/public/browser/browser_thread.h" @@ -172,16 +173,19 @@ SyncDataList SettingsBackend::GetAllSyncData( SyncError SettingsBackend::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); DCHECK(type == syncable::EXTENSION_SETTINGS || type == syncable::APP_SETTINGS); DCHECK_EQ(sync_type_, syncable::UNSPECIFIED); DCHECK(!sync_processor_.get()); DCHECK(sync_processor.get()); + DCHECK(sync_error_factory.get()); sync_type_ = type; sync_processor_ = sync_processor.Pass(); + sync_error_factory_ = sync_error_factory.Pass(); // Group the initial sync data by extension id. std::map<std::string, linked_ptr<DictionaryValue> > grouped_sync_data; @@ -275,6 +279,7 @@ void SettingsBackend::StopSyncing(syncable::ModelType type) { sync_type_ = syncable::UNSPECIFIED; sync_processor_.reset(); + sync_error_factory_.reset(); } scoped_ptr<SettingsSyncProcessor> SettingsBackend::CreateSettingsSyncProcessor( diff --git a/chrome/browser/extensions/settings/settings_backend.h b/chrome/browser/extensions/settings/settings_backend.h index 493d81a..0c5015f 100644 --- a/chrome/browser/extensions/settings/settings_backend.h +++ b/chrome/browser/extensions/settings/settings_backend.h @@ -17,6 +17,8 @@ #include "chrome/browser/extensions/settings/syncable_settings_storage.h" #include "chrome/browser/sync/api/syncable_service.h" +class SyncErrorFactory; + namespace extensions { // Manages SettingsStorage objects for extensions, including routing @@ -48,7 +50,8 @@ class SettingsBackend : public SyncableService { virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual SyncError ProcessSyncChanges( const tracked_objects::Location& from_here, const SyncChangeList& change_list) OVERRIDE; @@ -94,6 +97,9 @@ class SettingsBackend : public SyncableService { // Current sync processor, if any. scoped_ptr<SyncChangeProcessor> sync_processor_; + // Current sync error handler if any. + scoped_ptr<SyncErrorFactory> sync_error_factory_; + DISALLOW_COPY_AND_ASSIGN(SettingsBackend); }; diff --git a/chrome/browser/extensions/settings/settings_sync_unittest.cc b/chrome/browser/extensions/settings/settings_sync_unittest.cc index 175d18f..f19c91dd 100644 --- a/chrome/browser/extensions/settings/settings_sync_unittest.cc +++ b/chrome/browser/extensions/settings/settings_sync_unittest.cc @@ -18,6 +18,8 @@ #include "chrome/browser/extensions/settings/syncable_settings_storage.h" #include "chrome/browser/extensions/settings/testing_settings_storage.h" #include "chrome/browser/sync/api/sync_change_processor.h" +#include "chrome/browser/sync/api/sync_error_factory.h" +#include "chrome/browser/sync/api/sync_error_factory_mock.h" #include "content/test/test_browser_thread.h" using content::BrowserThread; @@ -281,7 +283,8 @@ TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); AddExtensionAndGetStorage("s2", type); EXPECT_EQ(0u, GetAllSyncData(model_type).size()); @@ -322,7 +325,8 @@ TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, sync_data, - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Already in sync, so no changes. EXPECT_EQ(0u, sync_processor_->changes().size()); @@ -358,7 +362,8 @@ TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // All settings should have been pushed to sync. EXPECT_EQ(2u, sync_processor_->changes().size()); @@ -395,7 +400,8 @@ TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) { "s2", "bar", value2, model_type)); GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, sync_data, - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); expected1.Set("foo", value1.DeepCopy()); expected2.Set("bar", value2.DeepCopy()); @@ -436,7 +442,8 @@ TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, sync_data, - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); expected2.Set("bar", value2.DeepCopy()); // Make sync add some settings. @@ -509,7 +516,8 @@ TEST_F(ExtensionSettingsSyncTest, PushToSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, sync_data, - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Add something locally. storage1->Set(DEFAULTS, "bar", value2); @@ -658,7 +666,8 @@ TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) { GetSyncableService(syncable::EXTENSION_SETTINGS)->MergeDataAndStartSyncing( syncable::EXTENSION_SETTINGS, sync_data, - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); GetSyncableService(syncable::EXTENSION_SETTINGS)-> StopSyncing(syncable::EXTENSION_SETTINGS); EXPECT_EQ(0u, sync_processor_->changes().size()); @@ -672,7 +681,8 @@ TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) { GetSyncableService(syncable::APP_SETTINGS)->MergeDataAndStartSyncing( syncable::APP_SETTINGS, sync_data, - app_settings_delegate_.PassAs<SyncChangeProcessor>()); + app_settings_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); GetSyncableService(syncable::APP_SETTINGS)-> StopSyncing(syncable::APP_SETTINGS); EXPECT_EQ(0u, sync_processor_->changes().size()); @@ -706,7 +716,8 @@ TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, sync_data, - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); } testing_factory->GetExisting("bad")->SetFailAllRequests(false); @@ -823,7 +834,8 @@ TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Local settings will have been pushed to sync, since it's empty (in this // test; presumably it wouldn't be live, since we've been getting changes). @@ -900,7 +912,8 @@ TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, sync_data, - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); } EXPECT_EQ(0u, sync_processor_->changes().size()); @@ -1005,7 +1018,8 @@ TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ( SyncChange::ACTION_ADD, @@ -1051,7 +1065,8 @@ TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); testing_factory->GetExisting("bad")->SetFailAllRequests(false); EXPECT_EQ( @@ -1102,7 +1117,8 @@ TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ( SyncChange::ACTION_ADD, @@ -1152,7 +1168,8 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); sync_processor_->SetFailAllRequests(false); // Changes from good will be send to sync, changes from bad won't. @@ -1195,7 +1212,8 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ( SyncChange::ACTION_ADD, @@ -1238,7 +1256,8 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // bad will fail to send changes. good->Set(DEFAULTS, "foo", fooValue); @@ -1291,7 +1310,8 @@ TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); EXPECT_EQ( SyncChange::ACTION_ADD, @@ -1332,7 +1352,8 @@ TEST_F(ExtensionSettingsSyncTest, GetSyncableService(model_type)->MergeDataAndStartSyncing( model_type, SyncDataList(), - sync_processor_delegate_.PassAs<SyncChangeProcessor>()); + sync_processor_delegate_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); // Large local change rejected and doesn't get sent out. SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type); diff --git a/chrome/browser/extensions/test_extension_service.cc b/chrome/browser/extensions/test_extension_service.cc index 76d50cd..7ac2abe 100644 --- a/chrome/browser/extensions/test_extension_service.cc +++ b/chrome/browser/extensions/test_extension_service.cc @@ -5,6 +5,7 @@ #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_sync_data.h" #include "chrome/browser/extensions/test_extension_service.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "testing/gtest/include/gtest/gtest.h" TestExtensionService::~TestExtensionService() {} @@ -73,7 +74,8 @@ void TestExtensionService::CheckForUpdatesSoon() { SyncError TestExtensionService::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { ADD_FAILURE(); return SyncError(); } diff --git a/chrome/browser/extensions/test_extension_service.h b/chrome/browser/extensions/test_extension_service.h index afbe71e..3a80d67 100644 --- a/chrome/browser/extensions/test_extension_service.h +++ b/chrome/browser/extensions/test_extension_service.h @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/extension_service.h" class CrxInstaller; +class SyncErrorFactory; // Implemention of ExtensionServiceInterface with default // implementations for methods that add failures. You should subclass @@ -47,7 +48,8 @@ class TestExtensionService : public ExtensionServiceInterface { virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; virtual SyncError ProcessSyncChanges( diff --git a/chrome/browser/prefs/pref_model_associator.cc b/chrome/browser/prefs/pref_model_associator.cc index b70302a..16dc0c3 100644 --- a/chrome/browser/prefs/pref_model_associator.cc +++ b/chrome/browser/prefs/pref_model_associator.cc @@ -12,6 +12,7 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/sync/api/sync_change.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "sync/protocol/preference_specifics.pb.h" @@ -107,13 +108,16 @@ void PrefModelAssociator::InitPrefAndAssociate( SyncError PrefModelAssociator::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { DCHECK_EQ(type, PREFERENCES); DCHECK(CalledOnValidThread()); DCHECK(pref_service_); DCHECK(!sync_processor_.get()); DCHECK(sync_processor.get()); + DCHECK(sync_error_factory.get()); sync_processor_ = sync_processor.Pass(); + sync_error_factory_ = sync_error_factory.Pass(); SyncChangeList new_changes; std::set<std::string> remaining_preferences = registered_preferences_; @@ -161,6 +165,7 @@ void PrefModelAssociator::StopSyncing(syncable::ModelType type) { DCHECK_EQ(type, PREFERENCES); models_associated_ = false; sync_processor_.reset(); + sync_error_factory_.reset(); } Value* PrefModelAssociator::MergePreference( diff --git a/chrome/browser/prefs/pref_model_associator.h b/chrome/browser/prefs/pref_model_associator.h index de4b645..6d0bb52 100644 --- a/chrome/browser/prefs/pref_model_associator.h +++ b/chrome/browser/prefs/pref_model_associator.h @@ -43,7 +43,8 @@ class PrefModelAssociator virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; // Returns the list of preference names that are registered as syncable, and @@ -143,6 +144,9 @@ class PrefModelAssociator // Sync's SyncChange handler. We push all our changes through this. scoped_ptr<SyncChangeProcessor> sync_processor_; + // Sync's error handler. We use this to create sync errors. + scoped_ptr<SyncErrorFactory> sync_error_factory_; + DISALLOW_COPY_AND_ASSIGN(PrefModelAssociator); }; diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc index fb6f31e..a2f99ae4 100644 --- a/chrome/browser/search_engines/template_url_service.cc +++ b/chrome/browser/search_engines/template_url_service.cc @@ -34,6 +34,7 @@ #include "chrome/browser/search_engines/template_url_service_observer.h" #include "chrome/browser/search_engines/util.h" #include "chrome/browser/sync/api/sync_change.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/env_vars.h" @@ -846,9 +847,10 @@ SyncError TemplateURLService::ProcessSyncChanges( // . Trying to DELETE or UPDATE a non-existent search engine. // . Trying to ADD a search engine that already exists. NOTREACHED() << "Unexpected sync change state."; - error = SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + - SyncChange::ChangeTypeToString(iter->change_type()), - syncable::SEARCH_ENGINES); + error = sync_error_factory_->CreateAndUploadError( + FROM_HERE, + "ProcessSyncChanges failed on ChangeType " + + SyncChange::ChangeTypeToString(iter->change_type())); } } @@ -865,12 +867,15 @@ SyncError TemplateURLService::ProcessSyncChanges( SyncError TemplateURLService::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { DCHECK(loaded()); DCHECK_EQ(type, syncable::SEARCH_ENGINES); DCHECK(!sync_processor_.get()); DCHECK(sync_processor.get()); + DCHECK(sync_error_factory.get()); sync_processor_ = sync_processor.Pass(); + sync_error_factory_ = sync_error_factory.Pass(); // We just started syncing, so set our wait-for-default flag if we are // expecting a default from Sync. @@ -972,6 +977,7 @@ void TemplateURLService::StopSyncing(syncable::ModelType type) { DCHECK_EQ(type, syncable::SEARCH_ENGINES); models_associated_ = false; sync_processor_.reset(); + sync_error_factory_.reset(); } void TemplateURLService::ProcessTemplateURLChange( diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h index 067bceb..476797e 100644 --- a/chrome/browser/search_engines/template_url_service.h +++ b/chrome/browser/search_engines/template_url_service.h @@ -32,6 +32,7 @@ class Profile; class SearchHostToURLsMap; class SearchTermsData; class SyncData; +class SyncErrorFactory; class TemplateURLServiceObserver; namespace history { @@ -280,7 +281,8 @@ class TemplateURLService : public WebDataServiceConsumer, virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; // Processes a local TemplateURL change for Sync. |turl| is the TemplateURL @@ -598,6 +600,9 @@ class TemplateURLService : public WebDataServiceConsumer, // Sync's SyncChange handler. We push all our changes through this. scoped_ptr<SyncChangeProcessor> sync_processor_; + // Sync's error handler. We use it to create a sync error. + scoped_ptr<SyncErrorFactory> sync_error_factory_; + // Whether or not we are waiting on the default search provider to come in // from Sync. This is to facilitate the fact that changes to the value of // prefs::kSyncedDefaultSearchProviderGUID do not always come before the diff --git a/chrome/browser/search_engines/template_url_service_sync_unittest.cc b/chrome/browser/search_engines/template_url_service_sync_unittest.cc index 9fb42a4..a7ba778 100644 --- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc +++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc @@ -10,6 +10,8 @@ #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_test_util.h" +#include "chrome/browser/sync/api/sync_error_factory.h" +#include "chrome/browser/sync/api/sync_error_factory_mock.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_pref_service.h" @@ -179,6 +181,7 @@ class TemplateURLServiceSyncTest : public testing::Test { TestingProfile* profile_a() { return test_util_a_.profile(); } TestChangeProcessor* processor() { return sync_processor_.get(); } scoped_ptr<SyncChangeProcessor> PassProcessor(); + scoped_ptr<SyncErrorFactory> CreateAndPassSyncErrorFactory(); // Create a TemplateURL with some test values. The caller owns the returned // TemplateURL*. @@ -251,6 +254,11 @@ scoped_ptr<SyncChangeProcessor> TemplateURLServiceSyncTest::PassProcessor() { return sync_processor_delegate_.PassAs<SyncChangeProcessor>(); } +scoped_ptr<SyncErrorFactory> TemplateURLServiceSyncTest:: + CreateAndPassSyncErrorFactory() { + return scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock()); +} + TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL( const string16& keyword, const std::string& url, @@ -574,8 +582,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeSyncAndLocalURLDuplicates) { } TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, SyncDataList(), - PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, SyncDataList(), + PassProcessor(), + CreateAndPassSyncErrorFactory()); EXPECT_EQ(0U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); EXPECT_EQ(0U, processor()->change_list_size()); @@ -583,8 +593,11 @@ TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) { TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) { SyncDataList initial_data = CreateInitialSyncData(); - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, - PassProcessor()); + + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); // We expect the model to have accepted all of the initial sync data. Search @@ -607,8 +620,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) { "http://bing.com", "xyz")); SyncDataList initial_data = CreateInitialSyncData(); - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, - PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); EXPECT_EQ(6U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); // We expect the model to have accepted all of the initial sync data. Search @@ -640,8 +655,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) { model()->Add(converted); } - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, - PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); for (SyncDataList::const_iterator iter = initial_data.begin(); @@ -673,8 +690,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) { initial_data.push_back( TemplateURLService::CreateSyncDataFromTemplateURL(*turl2_older)); - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, - PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); // Both were local updates, so we expect the same count. EXPECT_EQ(2U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); @@ -704,8 +723,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) { model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com", "ccc")); // add - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, CreateInitialSyncData(), + PassProcessor(), + CreateAndPassSyncErrorFactory()); // The dupe results in a merge. The other two should be added to the model. EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); @@ -762,8 +783,11 @@ TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { model()->Add(CreateTestTemplateURL(ASCIIToUTF16("unique"), "http://unique.com", "ccc", 10)); // add - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), + PassProcessor(), + CreateAndPassSyncErrorFactory()); // The dupe results in a merge. The other two should be added to the model. EXPECT_EQ(5U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); @@ -801,8 +825,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) { TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { // We initially have no data. - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, SyncDataList(), - PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, SyncDataList(), + PassProcessor(), + CreateAndPassSyncErrorFactory()); // Set up a bunch of ADDs. SyncChangeList changes; @@ -823,8 +849,10 @@ TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) { } TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) { - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); // Process different types of changes, without conflicts. SyncChangeList changes; @@ -852,8 +880,10 @@ TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) { } TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); // Process different types of changes, with conflicts. Note that all this data // has a newer timestamp, so Sync will win in these scenarios. @@ -888,8 +918,10 @@ TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsSyncWins) { } TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) { - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); // Process different types of changes, with conflicts. Note that all this data // has an older timestamp, so the local data will win in these scenarios. @@ -935,8 +967,10 @@ TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithConflictsLocalWins) { TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { // Ensure that ProcessTemplateURLChange is called and pushes the correct // changes to Sync whenever local changes are made to TemplateURLs. - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); // Add a new search engine. TemplateURL* new_turl = @@ -970,8 +1004,10 @@ TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) { TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { // Start off B with some empty data. - model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model_b()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); // Merge A and B. All of B's data should transfer over to A, which initially // has no data. @@ -979,7 +1015,8 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { new SyncChangeProcessorDelegate(model_b())); model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), - delegate_b.PassAs<SyncChangeProcessor>()); + delegate_b.PassAs<SyncChangeProcessor>(), + CreateAndPassSyncErrorFactory()); // They should be consistent. AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), @@ -988,8 +1025,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) { TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { // Start off B with some empty data. - model_b()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + model_b()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); // Set up A so we have some interesting duplicates and conflicts. model_a()->Add(CreateTestTemplateURL(ASCIIToUTF16("key4"), "http://key4.com", @@ -1004,9 +1043,11 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { // Merge A and B. scoped_ptr<SyncChangeProcessorDelegate> delegate_b( new SyncChangeProcessorDelegate(model_b())); - model_a()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, + model_a()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, model_b()->GetAllSyncData(syncable::SEARCH_ENGINES), - delegate_b.PassAs<SyncChangeProcessor>()); + delegate_b.PassAs<SyncChangeProcessor>(), + CreateAndPassSyncErrorFactory()); // They should be consistent. AssertEquals(model_a()->GetAllSyncData(syncable::SEARCH_ENGINES), @@ -1014,8 +1055,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) { } TEST_F(TemplateURLServiceSyncTest, StopSyncing) { - SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + SyncError error = model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); ASSERT_FALSE(error.IsSet()); model()->StopSyncing(syncable::SEARCH_ENGINES); @@ -1033,8 +1076,10 @@ TEST_F(TemplateURLServiceSyncTest, StopSyncing) { TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) { processor()->set_erroneous(true); - SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + SyncError error = model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); EXPECT_TRUE(error.IsSet()); // Ensure that if the initial merge was erroneous, then subsequence attempts @@ -1056,8 +1101,10 @@ TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) { TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) { // Ensure that if the SyncProcessor succeeds in the initial merge, but fails // in future ProcessSyncChanges, we still return an error. - SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + SyncError error = model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + CreateInitialSyncData(), PassProcessor(), + CreateAndPassSyncErrorFactory()); ASSERT_FALSE(error.IsSet()); SyncChangeList changes; @@ -1078,8 +1125,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { model()->Add(CreateTestTemplateURL(ASCIIToUTF16("key1"), "http://key1.com", "key1", 10)); // earlier - SyncError error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - initial_data, PassProcessor()); + SyncError error = model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + initial_data, PassProcessor(), + CreateAndPassSyncErrorFactory()); ASSERT_FALSE(error.IsSet()); // We should have updated the original TemplateURL with Sync's version. @@ -1104,8 +1153,10 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) { model()->StopSyncing(syncable::SEARCH_ENGINES); sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( sync_processor_.get())); - error = model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - initial_data, PassProcessor()); + error = model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + initial_data, PassProcessor(), + CreateAndPassSyncErrorFactory()); ASSERT_FALSE(error.IsSet()); // Check that the TemplateURL was not modified. @@ -1120,8 +1171,10 @@ TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) { scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com/{searchTerms}", "key2", 90)); initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, - PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); @@ -1186,8 +1239,11 @@ TEST_F(TemplateURLServiceSyncTest, SyncedDefaultArrivesAfterStartup) { scoped_ptr<TemplateURL> turl(CreateTestTemplateURL(ASCIIToUTF16("key2"), "http://key2.com/{searchTerms}", "key2", 90)); initial_data[1] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, - PassProcessor()); + + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); // Ensure that the new default has been set. EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); @@ -1214,8 +1270,11 @@ TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) { EXPECT_EQ(default_search, model()->GetDefaultSearchProvider()); // Now sync the initial data. - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + SyncDataList initial_data = CreateInitialSyncData(); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); // Ensure that the new entries were added and the default has not changed. EXPECT_EQ(4U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); @@ -1225,8 +1284,11 @@ TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) { TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) { // First start off with a few entries and make sure we can set an unmanaged // default search provider. - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - CreateInitialSyncData(), PassProcessor()); + SyncDataList initial_data = CreateInitialSyncData(); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, initial_data, + PassProcessor(), + CreateAndPassSyncErrorFactory()); model()->SetDefaultSearchProvider(model()->GetTemplateURLForGUID("key2")); EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); @@ -1287,8 +1349,10 @@ TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) { "http://key1.com/{searchTerms}", "key1", 90)); initial_data[0] = TemplateURLService::CreateSyncDataFromTemplateURL(*turl); - model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, - initial_data, PassProcessor()); + model()->MergeDataAndStartSyncing( + syncable::SEARCH_ENGINES, + initial_data, PassProcessor(), + CreateAndPassSyncErrorFactory()); EXPECT_EQ(3U, model()->GetAllSyncData(syncable::SEARCH_ENGINES).size()); EXPECT_FALSE(model()->GetTemplateURLForGUID("whateverguid")); @@ -1309,7 +1373,8 @@ TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) { // Now try to sync the data locally. model()->MergeDataAndStartSyncing(syncable::SEARCH_ENGINES, initial_data, - PassProcessor()); + PassProcessor(), + CreateAndPassSyncErrorFactory()); // Nothing should have been added, and both bogus entries should be marked for // deletion. diff --git a/chrome/browser/sync/api/fake_syncable_service.cc b/chrome/browser/sync/api/fake_syncable_service.cc index 2f7d948..7082577 100644 --- a/chrome/browser/sync/api/fake_syncable_service.cc +++ b/chrome/browser/sync/api/fake_syncable_service.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/sync/api/fake_syncable_service.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "base/location.h" @@ -30,7 +31,8 @@ bool FakeSyncableService::syncing() const { SyncError FakeSyncableService::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { sync_processor_ = sync_processor.Pass(); type_ = type; if (!merge_data_and_start_syncing_error_.IsSet()) { diff --git a/chrome/browser/sync/api/fake_syncable_service.h b/chrome/browser/sync/api/fake_syncable_service.h index 724985c..3080a630 100644 --- a/chrome/browser/sync/api/fake_syncable_service.h +++ b/chrome/browser/sync/api/fake_syncable_service.h @@ -8,6 +8,8 @@ #include "chrome/browser/sync/api/syncable_service.h" +class SyncErrorFactory; + // A fake SyncableService that can return arbitrary values and maintains the // syncing status. class FakeSyncableService : public SyncableService { @@ -27,7 +29,8 @@ class FakeSyncableService : public SyncableService { virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; virtual SyncError ProcessSyncChanges( diff --git a/chrome/browser/sync/api/sync_error_factory.cc b/chrome/browser/sync/api/sync_error_factory.cc new file mode 100644 index 0000000..efc3627 --- /dev/null +++ b/chrome/browser/sync/api/sync_error_factory.cc @@ -0,0 +1,11 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/api/sync_error_factory.h" + +SyncErrorFactory::SyncErrorFactory() { +} + +SyncErrorFactory::~SyncErrorFactory() { +} diff --git a/chrome/browser/sync/api/sync_error_factory.h b/chrome/browser/sync/api/sync_error_factory.h new file mode 100644 index 0000000..05ea918 --- /dev/null +++ b/chrome/browser/sync/api/sync_error_factory.h @@ -0,0 +1,26 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_SYNC_API_SYNC_ERROR_FACTORY_H_ +#define CHROME_BROWSER_SYNC_API_SYNC_ERROR_FACTORY_H_ +#pragma once + +#include <string> + +#include "base/location.h" +#include "chrome/browser/sync/api/sync_error.h" + +class SyncErrorFactory { + public: + SyncErrorFactory(); + virtual ~SyncErrorFactory(); + + // Creates a SyncError object and uploads this call stack to breakpad. + virtual SyncError CreateAndUploadError( + const tracked_objects::Location& location, + const std::string& message) = 0; +}; + +#endif // CHROME_BROWSER_SYNC_API_SYNC_ERROR_FACTORY_H_ + diff --git a/chrome/browser/sync/api/sync_error_factory_mock.cc b/chrome/browser/sync/api/sync_error_factory_mock.cc new file mode 100644 index 0000000..edb1092 --- /dev/null +++ b/chrome/browser/sync/api/sync_error_factory_mock.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/api/sync_error_factory_mock.h" + +SyncErrorFactoryMock::SyncErrorFactoryMock() { +} + +SyncErrorFactoryMock::~SyncErrorFactoryMock() { +} + diff --git a/chrome/browser/sync/api/sync_error_factory_mock.h b/chrome/browser/sync/api/sync_error_factory_mock.h new file mode 100644 index 0000000..555b7b9 --- /dev/null +++ b/chrome/browser/sync/api/sync_error_factory_mock.h @@ -0,0 +1,23 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_SYNC_API_SYNC_ERROR_FACTORY_MOCK_H_ +#define CHROME_BROWSER_SYNC_API_SYNC_ERROR_FACTORY_MOCK_H_ +#pragma once + +#include "chrome/browser/sync/api/sync_error_factory.h" + +#include "testing/gmock/include/gmock/gmock.h" + +class SyncErrorFactoryMock : public SyncErrorFactory { + public: + SyncErrorFactoryMock(); + virtual ~SyncErrorFactoryMock(); + + MOCK_METHOD2(CreateAndUploadError, SyncError( + const tracked_objects::Location& location, + const std::string& message)); +}; + +#endif // CHROME_BROWSER_SYNC_API_SYNC_ERROR_FACTORY_MOCK_H_ diff --git a/chrome/browser/sync/api/syncable_service.h b/chrome/browser/sync/api/syncable_service.h index 1e1e6a2..800bdc3 100644 --- a/chrome/browser/sync/api/syncable_service.h +++ b/chrome/browser/sync/api/syncable_service.h @@ -16,6 +16,8 @@ #include "chrome/browser/sync/api/sync_error.h" #include "sync/syncable/model_type.h" +class SyncErrorFactory; + typedef std::vector<SyncData> SyncDataList; // TODO(zea): remove SupportsWeakPtr in favor of having all SyncableService @@ -36,7 +38,8 @@ class SyncableService : public SyncChangeProcessor, virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) = 0; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> error_handler) = 0; // Stop syncing the specified type and reset state. virtual void StopSyncing(syncable::ModelType type) = 0; diff --git a/chrome/browser/sync/glue/data_type_controller.h b/chrome/browser/sync/glue/data_type_controller.h index 5ae667d..81f7c68 100644 --- a/chrome/browser/sync/glue/data_type_controller.h +++ b/chrome/browser/sync/glue/data_type_controller.h @@ -98,6 +98,7 @@ class DataTypeController virtual State state() const = 0; // Partial implementation of DataTypeErrorHandler. + // This is thread safe. virtual SyncError CreateAndUploadError( const tracked_objects::Location& location, const std::string& message, diff --git a/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc b/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc index 3b7ec84..4741682 100644 --- a/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/new_non_frontend_data_type_controller.cc @@ -129,6 +129,8 @@ void NewNonFrontendDataTypeController:: type(), initial_sync_data, scoped_ptr<SyncChangeProcessor>( + new SharedChangeProcessorRef(shared_change_processor)), + scoped_ptr<SyncErrorFactory>( new SharedChangeProcessorRef(shared_change_processor))); RecordAssociationTime(base::TimeTicks::Now() - start_time); if (error.IsSet()) { diff --git a/chrome/browser/sync/glue/shared_change_processor.cc b/chrome/browser/sync/glue/shared_change_processor.cc index e803586..2eed84a7 100644 --- a/chrome/browser/sync/glue/shared_change_processor.cc +++ b/chrome/browser/sync/glue/shared_change_processor.cc @@ -19,7 +19,8 @@ SharedChangeProcessor::SharedChangeProcessor() : disconnected_(false), type_(syncable::UNSPECIFIED), sync_service_(NULL), - generic_change_processor_(NULL) { + generic_change_processor_(NULL), + error_handler_(NULL) { // We're always created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } @@ -59,6 +60,7 @@ base::WeakPtr<SyncableService> SharedChangeProcessor::Connect( return base::WeakPtr<SyncableService>(); type_ = type; sync_service_ = sync_service; + error_handler_ = error_handler; base::WeakPtr<SyncableService> local_service = sync_factory->GetSyncableServiceForType(type); if (!local_service.get()) { @@ -79,6 +81,7 @@ bool SharedChangeProcessor::Disconnect() { AutoLock lock(monitor_lock_); bool was_connected = !disconnected_; disconnected_ = true; + error_handler_ = NULL; return was_connected; } @@ -147,4 +150,15 @@ void SharedChangeProcessor::ActivateDataType( generic_change_processor_); } +SyncError SharedChangeProcessor::CreateAndUploadError( + const tracked_objects::Location& location, + const std::string& message) { + AutoLock lock(monitor_lock_); + if (!disconnected_) { + return error_handler_->CreateAndUploadError(location, message, type_); + } else { + return SyncError(location, message, type_); + } +} + } // namespace browser_sync diff --git a/chrome/browser/sync/glue/shared_change_processor.h b/chrome/browser/sync/glue/shared_change_processor.h index b87e1f9..17e24a1 100644 --- a/chrome/browser/sync/glue/shared_change_processor.h +++ b/chrome/browser/sync/glue/shared_change_processor.h @@ -13,6 +13,7 @@ #include "base/synchronization/lock.h" #include "chrome/browser/sync/api/sync_change_processor.h" #include "chrome/browser/sync/api/sync_error.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/browser/sync/glue/data_type_error_handler.h" #include "sync/engine/model_safe_worker.h" @@ -86,6 +87,10 @@ class SharedChangeProcessor // Does nothing if |disconnected_| is true. virtual void ActivateDataType(browser_sync::ModelSafeGroup model_safe_group); + virtual SyncError CreateAndUploadError( + const tracked_objects::Location& location, + const std::string& message); + protected: friend class base::RefCountedThreadSafe<SharedChangeProcessor>; virtual ~SharedChangeProcessor(); @@ -112,6 +117,8 @@ class SharedChangeProcessor // Used only on |backend_loop_|. GenericChangeProcessor* generic_change_processor_; + DataTypeErrorHandler* error_handler_; + DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); }; diff --git a/chrome/browser/sync/glue/shared_change_processor_ref.cc b/chrome/browser/sync/glue/shared_change_processor_ref.cc index e0b2a52..153eee0 100644 --- a/chrome/browser/sync/glue/shared_change_processor_ref.cc +++ b/chrome/browser/sync/glue/shared_change_processor_ref.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,4 +20,10 @@ SyncError SharedChangeProcessorRef::ProcessSyncChanges( return change_processor_->ProcessSyncChanges(from_here, change_list); } +SyncError SharedChangeProcessorRef::CreateAndUploadError( + const tracked_objects::Location& from_here, + const std::string& message) { + return change_processor_->CreateAndUploadError(from_here, message); +} + } // namespace browser_sync diff --git a/chrome/browser/sync/glue/shared_change_processor_ref.h b/chrome/browser/sync/glue/shared_change_processor_ref.h index 4c73bac..6b79769 100644 --- a/chrome/browser/sync/glue/shared_change_processor_ref.h +++ b/chrome/browser/sync/glue/shared_change_processor_ref.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,13 +9,15 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "chrome/browser/sync/api/sync_change_processor.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/browser/sync/glue/shared_change_processor.h" namespace browser_sync { // A SyncChangeProcessor stub for interacting with a refcounted // SharedChangeProcessor. -class SharedChangeProcessorRef : public SyncChangeProcessor { +class SharedChangeProcessorRef : public SyncChangeProcessor, + public SyncErrorFactory { public: SharedChangeProcessorRef( const scoped_refptr<browser_sync::SharedChangeProcessor>& @@ -27,6 +29,11 @@ class SharedChangeProcessorRef : public SyncChangeProcessor { const tracked_objects::Location& from_here, const SyncChangeList& change_list) OVERRIDE; + // SyncErrorFactory implementation. + virtual SyncError CreateAndUploadError( + const tracked_objects::Location& from_here, + const std::string& message) OVERRIDE; + // Default copy and assign welcome (and safe due to refcounted-ness). private: diff --git a/chrome/browser/sync/glue/ui_data_type_controller.cc b/chrome/browser/sync/glue/ui_data_type_controller.cc index 01aa1f7..9066034 100644 --- a/chrome/browser/sync/glue/ui_data_type_controller.cc +++ b/chrome/browser/sync/glue/ui_data_type_controller.cc @@ -131,6 +131,8 @@ void UIDataTypeController::Associate() { type(), initial_sync_data, scoped_ptr<SyncChangeProcessor>( + new SharedChangeProcessorRef(shared_change_processor_)), + scoped_ptr<SyncErrorFactory>( new SharedChangeProcessorRef(shared_change_processor_))); RecordAssociationTime(base::TimeTicks::Now() - start_time); if (error.IsSet()) { diff --git a/chrome/browser/webdata/autocomplete_syncable_service.cc b/chrome/browser/webdata/autocomplete_syncable_service.cc index 7c5678c..fc9fe10 100644 --- a/chrome/browser/webdata/autocomplete_syncable_service.cc +++ b/chrome/browser/webdata/autocomplete_syncable_service.cc @@ -10,6 +10,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/api/sync_error.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/browser/webdata/autofill_table.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/browser/webdata/web_database.h" @@ -110,17 +111,20 @@ AutocompleteSyncableService::AutocompleteSyncableService() SyncError AutocompleteSyncableService::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> error_handler) { DCHECK(CalledOnValidThread()); DCHECK(!sync_processor_.get()); DCHECK(sync_processor.get()); + DCHECK(error_handler.get()); VLOG(1) << "Associating Autocomplete: MergeDataAndStartSyncing"; + error_handler_ = error_handler.Pass(); std::vector<AutofillEntry> entries; if (!LoadAutofillData(&entries)) { - return SyncError( - FROM_HERE, "Could not get the autocomplete data from WebDatabase.", - model_type()); + return error_handler_->CreateAndUploadError( + FROM_HERE, + "Could not get the autocomplete data from WebDatabase."); } AutocompleteEntryMap new_db_entries; @@ -145,8 +149,11 @@ SyncError AutocompleteSyncableService::MergeDataAndStartSyncing( // Check if newly received items need culling. bool need_to_cull_data = !synced_expired_entries.empty(); - if (!SaveChangesToWebData(new_synced_entries)) - return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); + if (!SaveChangesToWebData(new_synced_entries)) { + return error_handler_->CreateAndUploadError( + FROM_HERE, + "Failed to update webdata."); + } WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); keys_to_ignore_.clear(); @@ -198,6 +205,7 @@ void AutocompleteSyncableService::StopSyncing(syncable::ModelType type) { DCHECK_EQ(syncable::AUTOFILL, type); sync_processor_.reset(NULL); + error_handler_.reset(); } SyncDataList AutocompleteSyncableService::GetAllSyncData( @@ -248,10 +256,9 @@ SyncError AutocompleteSyncableService::ProcessSyncChanges( case SyncChange::ACTION_UPDATE: if (!db_entries.get()) { if (!LoadAutofillData(&entries)) { - return SyncError( + return error_handler_->CreateAndUploadError( FROM_HERE, - "Could not get the autocomplete data from WebDatabase.", - model_type()); + "Could not get the autocomplete data from WebDatabase."); } db_entries.reset(new AutocompleteEntryMap); for (std::vector<AutofillEntry>::iterator it = entries.begin(); @@ -277,14 +284,18 @@ SyncError AutocompleteSyncableService::ProcessSyncChanges( } break; default: NOTREACHED() << "Unexpected sync change state."; - return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + - SyncChange::ChangeTypeToString(i->change_type()), - syncable::AUTOFILL); + return error_handler_->CreateAndUploadError( + FROM_HERE, + "ProcessSyncChanges failed on ChangeType " + + SyncChange::ChangeTypeToString(i->change_type())); } } - if (!SaveChangesToWebData(new_entries)) - return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); + if (!SaveChangesToWebData(new_entries)) { + return error_handler_->CreateAndUploadError( + FROM_HERE, + "Failed to update webdata."); + } // Remove already expired data. for (size_t i = 0; i < ignored_entries.size(); ++i) { @@ -416,9 +427,9 @@ SyncError AutocompleteSyncableService::AutofillEntryDelete( const sync_pb::AutofillSpecifics& autofill) { if (!web_data_service_->GetDatabase()->GetAutofillTable()->RemoveFormElement( UTF8ToUTF16(autofill.name()), UTF8ToUTF16(autofill.value()))) { - return SyncError(FROM_HERE, - "Could not remove autocomplete entry from WebDatabase.", - model_type()); + return error_handler_->CreateAndUploadError( + FROM_HERE, + "Could not remove autocomplete entry from WebDatabase."); } return SyncError(); } diff --git a/chrome/browser/webdata/autocomplete_syncable_service.h b/chrome/browser/webdata/autocomplete_syncable_service.h index f13873d..84d35fa 100644 --- a/chrome/browser/webdata/autocomplete_syncable_service.h +++ b/chrome/browser/webdata/autocomplete_syncable_service.h @@ -25,6 +25,7 @@ #include "content/public/browser/notification_registrar.h" class ProfileSyncServiceAutofillTest; +class SyncErrorFactory; namespace sync_pb { class AutofillSpecifics; @@ -51,7 +52,8 @@ class AutocompleteSyncableService virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> error_handler) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; virtual SyncError ProcessSyncChanges( @@ -137,6 +139,10 @@ class AutocompleteSyncableService // destroy it in StopSyncing(). scoped_ptr<SyncChangeProcessor> sync_processor_; + // We receive ownership of |error_handler_| in MergeDataAndStartSyncing() and + // destroy it in StopSyncing(). + scoped_ptr<SyncErrorFactory> error_handler_; + DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncableService); }; diff --git a/chrome/browser/webdata/autofill_profile_syncable_service.cc b/chrome/browser/webdata/autofill_profile_syncable_service.cc index fe1222d..f65327a 100644 --- a/chrome/browser/webdata/autofill_profile_syncable_service.cc +++ b/chrome/browser/webdata/autofill_profile_syncable_service.cc @@ -11,6 +11,7 @@ #include "chrome/browser/autofill/form_group.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/api/sync_error.h" +#include "chrome/browser/sync/api/sync_error_factory.h" #include "chrome/browser/webdata/autofill_table.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/browser/webdata/web_database.h" @@ -59,16 +60,18 @@ AutofillProfileSyncableService::AutofillProfileSyncableService() SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) { + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) { DCHECK(CalledOnValidThread()); DCHECK(!sync_processor_.get()); DCHECK(sync_processor.get()); + DCHECK(sync_error_factory.get()); DVLOG(1) << "Associating Autofill: MergeDataAndStartSyncing"; + sync_error_factory_ = sync_error_factory.Pass(); if (!LoadAutofillData(&profiles_.get())) { - return SyncError( - FROM_HERE, "Could not get the autofill data from WebDatabase.", - model_type()); + return sync_error_factory_->CreateAndUploadError( + FROM_HERE, "Could not get the autofill data from WebDatabase."); } if (DLOG_IS_ON(INFO)) { @@ -126,8 +129,11 @@ SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing( } } - if (!SaveChangesToWebData(bundle)) - return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); + if (!SaveChangesToWebData(bundle)) { + return sync_error_factory_->CreateAndUploadError( + FROM_HERE, + "Failed to update webdata."); + } SyncChangeList new_changes; for (GUIDToProfileMap::iterator i = remaining_profiles.begin(); @@ -157,6 +163,7 @@ void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) { DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); sync_processor_.reset(); + sync_error_factory_.reset(); profiles_.reset(); profiles_map_.clear(); } @@ -204,14 +211,18 @@ SyncError AutofillProfileSyncableService::ProcessSyncChanges( } break; default: NOTREACHED() << "Unexpected sync change state."; - return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + - SyncChange::ChangeTypeToString(i->change_type()), - syncable::AUTOFILL_PROFILE); + return sync_error_factory_->CreateAndUploadError( + FROM_HERE, + "ProcessSyncChanges failed on ChangeType " + + SyncChange::ChangeTypeToString(i->change_type())); } } - if (!SaveChangesToWebData(bundle)) - return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); + if (!SaveChangesToWebData(bundle)) { + return sync_error_factory_->CreateAndUploadError( + FROM_HERE, + "Failed to update webdata."); + } WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); diff --git a/chrome/browser/webdata/autofill_profile_syncable_service.h b/chrome/browser/webdata/autofill_profile_syncable_service.h index 59c1e4a..db3aa5c 100644 --- a/chrome/browser/webdata/autofill_profile_syncable_service.h +++ b/chrome/browser/webdata/autofill_profile_syncable_service.h @@ -51,7 +51,8 @@ class AutofillProfileSyncableService virtual SyncError MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, - scoped_ptr<SyncChangeProcessor> sync_processor) OVERRIDE; + scoped_ptr<SyncChangeProcessor> sync_processor, + scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; virtual void StopSyncing(syncable::ModelType type) OVERRIDE; virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; virtual SyncError ProcessSyncChanges( @@ -164,6 +165,8 @@ class AutofillProfileSyncableService scoped_ptr<SyncChangeProcessor> sync_processor_; + scoped_ptr<SyncErrorFactory> sync_error_factory_; + DISALLOW_COPY_AND_ASSIGN(AutofillProfileSyncableService); }; diff --git a/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc b/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc index 11a4dc3..5c88795 100644 --- a/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc +++ b/chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc @@ -6,6 +6,8 @@ #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/autofill/autofill_profile.h" +#include "chrome/browser/sync/api/sync_error_factory.h" +#include "chrome/browser/sync/api/sync_error_factory_mock.h" #include "chrome/browser/sync/internal_api/read_node_mock.h" #include "chrome/browser/webdata/autofill_change.h" #include "chrome/browser/webdata/autofill_profile_syncable_service.h" @@ -170,7 +172,8 @@ TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) { // Takes ownership of sync_processor_. autofill_syncable_service_.MergeDataAndStartSyncing( syncable::AUTOFILL_PROFILE, data_list, - sync_processor_.PassAs<SyncChangeProcessor>()); + sync_processor_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE); } @@ -201,7 +204,8 @@ TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { // Takes ownership of sync_processor_. autofill_syncable_service_.MergeDataAndStartSyncing( syncable::AUTOFILL_PROFILE, data_list, - sync_processor_.PassAs<SyncChangeProcessor>()); + sync_processor_.PassAs<SyncChangeProcessor>(), + scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); SyncDataList data = autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE); |