diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-26 19:13:41 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-26 19:13:41 +0000 |
commit | ebce09f8561211765ac3542e3c06f423280fbf14 (patch) | |
tree | 7e075007c75761be005d561df520ecdd5c6e00ae | |
parent | 578a05c290474305000848620939f02d3e3f214f (diff) | |
download | chromium_src-ebce09f8561211765ac3542e3c06f423280fbf14.zip chromium_src-ebce09f8561211765ac3542e3c06f423280fbf14.tar.gz chromium_src-ebce09f8561211765ac3542e3c06f423280fbf14.tar.bz2 |
Revert 94128 - [Sync] Refactor sync datatype error handling.
This introduces SyncError's, which are a convenient way of passing around an
error location, type, and message. All datatypes have been refactored to use
this, including in the AssociateModels code. A future change will use this
to add support for continuing sync even when a datatype fails to start.
In addition, eventually a future change will convert the UnrecoverableError
handler to use SyncError's as well as have the datatype controller's and
datatype manager surface SyncError's to the PSS.
BUG=87645
TEST=
Review URL: http://codereview.chromium.org/7453014
TBR=zea@chromium.org
Review URL: http://codereview.chromium.org/7497014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94143 0039d316-1c4b-4281-b951-d872f2087c98
59 files changed, 273 insertions, 777 deletions
diff --git a/chrome/browser/prefs/pref_model_associator.cc b/chrome/browser/prefs/pref_model_associator.cc index 88c9640..5c004a7b 100644 --- a/chrome/browser/prefs/pref_model_associator.cc +++ b/chrome/browser/prefs/pref_model_associator.cc @@ -116,7 +116,7 @@ void PrefModelAssociator::InitPrefAndAssociate( return; } -SyncError PrefModelAssociator::MergeDataAndStartSyncing( +bool PrefModelAssociator::MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, SyncChangeProcessor* sync_processor) { @@ -158,14 +158,9 @@ SyncError PrefModelAssociator::MergeDataAndStartSyncing( } // Push updates to sync. - SyncError error = - sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); - if (error.IsSet()) { - return error; - } - + sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); models_associated_ = true; - return SyncError(); + return true; } void PrefModelAssociator::StopSyncing(syncable::ModelType type) { @@ -311,15 +306,11 @@ SyncDataList PrefModelAssociator::GetAllSyncData(syncable::ModelType type) return current_data; } -SyncError PrefModelAssociator::ProcessSyncChanges( +void PrefModelAssociator::ProcessSyncChanges( const tracked_objects::Location& from_here, const SyncChangeList& change_list) { - if (!models_associated_) { - SyncError error(FROM_HERE, - "Models not yet associated.", - PREFERENCES); - return error; - } + if (!models_associated_) + return; AutoReset<bool> processing_changes(&processing_syncer_changes_, true); SyncChangeList::const_iterator iter; for (iter = change_list.begin(); iter != change_list.end(); ++iter) { @@ -368,7 +359,6 @@ SyncError PrefModelAssociator::ProcessSyncChanges( SendUpdateNotificationsIfNecessary(name); } - return SyncError(); } Value* PrefModelAssociator::ReadPreferenceSpecifics( @@ -442,9 +432,5 @@ void PrefModelAssociator::ProcessPrefChange(const std::string& name) { } changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); } - - SyncError error = - sync_processor_->ProcessSyncChanges(FROM_HERE, changes); - if (error.IsSet()) - StopSyncing(PREFERENCES); + sync_processor_->ProcessSyncChanges(FROM_HERE, changes); } diff --git a/chrome/browser/prefs/pref_model_associator.h b/chrome/browser/prefs/pref_model_associator.h index a185a78..1503153 100644 --- a/chrome/browser/prefs/pref_model_associator.h +++ b/chrome/browser/prefs/pref_model_associator.h @@ -37,10 +37,9 @@ class PrefModelAssociator // SyncableService implementation. virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; - virtual SyncError ProcessSyncChanges( - const tracked_objects::Location& from_here, - const SyncChangeList& change_list) OVERRIDE; - virtual SyncError MergeDataAndStartSyncing( + virtual void ProcessSyncChanges(const tracked_objects::Location& from_here, + const SyncChangeList& change_list) OVERRIDE; + virtual bool MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, SyncChangeProcessor* sync_processor) OVERRIDE; diff --git a/chrome/browser/sync/api/sync_change_processor.h b/chrome/browser/sync/api/sync_change_processor.h index edc7c0f..80be610 100644 --- a/chrome/browser/sync/api/sync_change_processor.h +++ b/chrome/browser/sync/api/sync_change_processor.h @@ -8,8 +8,6 @@ #include <vector> -#include "chrome/browser/sync/api/sync_error.h" - class SyncChange; namespace tracked_objects { @@ -22,15 +20,8 @@ typedef std::vector<SyncChange> SyncChangeList; class SyncChangeProcessor { public: // Process a list of SyncChanges. - // Returns: A default SyncError (IsSet() == false) if no errors were - // encountered, and a filled SyncError (IsSet() == true) - // otherwise. - // Inputs: - // |from_here|: allows tracking of where sync changes originate. - // |change_list|: is the list of sync changes in need of processing. - virtual SyncError ProcessSyncChanges( - const tracked_objects::Location& from_here, - const SyncChangeList& change_list) = 0; + virtual void ProcessSyncChanges(const tracked_objects::Location& from_here, + const SyncChangeList& change_list) = 0; protected: virtual ~SyncChangeProcessor(); }; diff --git a/chrome/browser/sync/api/sync_error.cc b/chrome/browser/sync/api/sync_error.cc deleted file mode 100644 index c916bae..0000000 --- a/chrome/browser/sync/api/sync_error.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2011 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.h" - -#include "base/logging.h" -#include "base/tracked.h" - -SyncError::SyncError() { - Clear(); -} - -SyncError::SyncError(const tracked_objects::Location& location, - const std::string& message, - syncable::ModelType type) { - Init(location, message, type); - PrintLogError(); -} - -SyncError::SyncError(const SyncError& other) { - Copy(other); -} - -SyncError& SyncError::operator=(const SyncError& other) { - if (this == &other) { - return *this; - } - Copy(other); - return *this; -} - -void SyncError::Copy(const SyncError& other) { - if (other.IsSet()) { - Init(other.location(), - other.message(), - other.type()); - } else { - Clear(); - } -} - -void SyncError::Clear() { - location_.reset(); - message_ = std::string(); - type_ = syncable::UNSPECIFIED; -} - -void SyncError::Reset(const tracked_objects::Location& location, - const std::string& message, - syncable::ModelType type) { - Init(location, message, type); - PrintLogError(); -} - -void SyncError::Init(const tracked_objects::Location& location, - const std::string& message, - syncable::ModelType type) { - location_.reset(new tracked_objects::Location(location)); - message_ = message; - type_ = type; -} - -bool SyncError::IsSet() const { - return location_.get() != NULL; -} - -const tracked_objects::Location& SyncError::location() const { - CHECK(IsSet()); - return *location_; -} - -const std::string& SyncError::message() const { - CHECK(IsSet()); - return message_; -} - -const syncable::ModelType SyncError::type() const { - CHECK(IsSet()); - return type_; -} - -void SyncError::PrintLogError() const { - LAZY_STREAM(logging::LogMessage(location_->file_name(), - location_->line_number(), - logging::LOG_ERROR).stream(), - LOG_IS_ON(ERROR)) - << syncable::ModelTypeToString(type_) << " Sync Error: " << message_; -} diff --git a/chrome/browser/sync/api/sync_error.h b/chrome/browser/sync/api/sync_error.h deleted file mode 100644 index 326e9d4..0000000 --- a/chrome/browser/sync/api/sync_error.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2011 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_H_ -#define CHROME_BROWSER_SYNC_API_SYNC_ERROR_H_ -#pragma once - -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/sync/syncable/model_type.h" - -namespace tracked_objects { -class Location; -} // namespace tracked_objects - -// Sync errors are used for debug purposes and handled internally and/or -// exposed through Chrome's "about:sync" internal page. They are considered -// unrecoverable for the datatype creating them, and should only be used as -// such. -// This class is copy-friendly and thread-safe. -class SyncError { - public: - // Default constructor refers to "no error", and IsSet() will return false. - SyncError(); - - // Create a new Sync error triggered by datatype |type| with debug message - // |message| from the specified location. IsSet() will return true. - // Will print the new error to LOG(ERROR). - SyncError(const tracked_objects::Location& location, - const std::string& message, - syncable::ModelType type); - - // Copy and assign via deep copy. - SyncError(const SyncError& other); - SyncError& operator=(const SyncError& other); - - // Reset the current error to a new error. May be called irrespective of - // whether IsSet() is true. After this is called, IsSet() will return true. - // Will print the new error to LOG(ERROR). - void Reset(const tracked_objects::Location& location, - const std::string& message, - syncable::ModelType type); - - // Whether this is a valid error or not. - bool IsSet() const; - - // These must only be called if IsSet() is true. - const tracked_objects::Location& location() const; - const std::string& message() const; - const syncable::ModelType type() const; - - private: - // Print error information to log. - void PrintLogError() const; - - // Make a copy of a SyncError. If other.IsSet() == false, this->IsSet() will - // now return false. - void Copy(const SyncError& other); - - // Initialize the local error data with the specified error data. After this - // is called, IsSet() will return true. - void Init(const tracked_objects::Location& location, - const std::string& message, - syncable::ModelType type); - - // Reset the error to it's default (unset) values. - void Clear(); - - // scoped_ptr is necessary because Location objects aren't assignable. - scoped_ptr<tracked_objects::Location> location_; - std::string message_; - syncable::ModelType type_; -}; - -#endif // CHROME_BROWSER_SYNC_API_SYNC_ERROR_H_ diff --git a/chrome/browser/sync/api/sync_error_unittest.cc b/chrome/browser/sync/api/sync_error_unittest.cc deleted file mode 100644 index 6e2d9a8..0000000 --- a/chrome/browser/sync/api/sync_error_unittest.cc +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2011 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.h" - -#include <string> - -#include "base/tracked.h" -#include "testing/gtest/include/gtest/gtest.h" - -using std::string; -using syncable::ModelType; - -namespace { - -typedef testing::Test SyncErrorTest; - -TEST_F(SyncErrorTest, Unset) { - SyncError error; - EXPECT_FALSE(error.IsSet()); -} - -TEST_F(SyncErrorTest, Default) { - tracked_objects::Location location = FROM_HERE; - std::string msg = "test"; - ModelType type = syncable::PREFERENCES; - SyncError error(location, msg, type); - EXPECT_TRUE(error.IsSet()); - EXPECT_EQ(location.line_number(), error.location().line_number()); - EXPECT_EQ(msg, error.message()); - EXPECT_EQ(type, error.type()); -} - -TEST_F(SyncErrorTest, Reset) { - tracked_objects::Location location = FROM_HERE; - std::string msg = "test"; - ModelType type = syncable::PREFERENCES; - - SyncError error; - EXPECT_FALSE(error.IsSet()); - - error.Reset(location, msg, type); - EXPECT_TRUE(error.IsSet()); - EXPECT_EQ(location.line_number(), error.location().line_number()); - EXPECT_EQ(msg, error.message()); - EXPECT_EQ(type, error.type()); - - tracked_objects::Location location2 = FROM_HERE; - std::string msg2 = "test"; - ModelType type2 = syncable::PREFERENCES; - error.Reset(location2, msg2, type2); - EXPECT_TRUE(error.IsSet()); - EXPECT_EQ(location2.line_number(), error.location().line_number()); - EXPECT_EQ(msg2, error.message()); - EXPECT_EQ(type2, error.type()); -} - -TEST_F(SyncErrorTest, Copy) { - tracked_objects::Location location = FROM_HERE; - std::string msg = "test"; - ModelType type = syncable::PREFERENCES; - - SyncError error1; - EXPECT_FALSE(error1.IsSet()); - SyncError error2(error1); - EXPECT_FALSE(error2.IsSet()); - - error1.Reset(location, msg, type); - EXPECT_TRUE(error1.IsSet()); - EXPECT_EQ(location.line_number(), error1.location().line_number()); - EXPECT_EQ(msg, error1.message()); - EXPECT_EQ(type, error1.type()); - - SyncError error3(error1); - EXPECT_TRUE(error3.IsSet()); - EXPECT_EQ(error1.location().line_number(), error3.location().line_number()); - EXPECT_EQ(error1.message(), error3.message()); - EXPECT_EQ(error1.type(), error3.type()); - - SyncError error4; - EXPECT_FALSE(error4.IsSet()); - SyncError error5(error4); - EXPECT_FALSE(error5.IsSet()); -} - -TEST_F(SyncErrorTest, Assign) { - tracked_objects::Location location = FROM_HERE; - std::string msg = "test"; - ModelType type = syncable::PREFERENCES; - - SyncError error1; - EXPECT_FALSE(error1.IsSet()); - SyncError error2; - error2 = error1; - EXPECT_FALSE(error2.IsSet()); - - error1.Reset(location, msg, type); - EXPECT_TRUE(error1.IsSet()); - EXPECT_EQ(location.line_number(), error1.location().line_number()); - EXPECT_EQ(msg, error1.message()); - EXPECT_EQ(type, error1.type()); - - error2 = error1; - EXPECT_TRUE(error2.IsSet()); - EXPECT_EQ(error1.location().line_number(), error2.location().line_number()); - EXPECT_EQ(error1.message(), error2.message()); - EXPECT_EQ(error1.type(), error2.type()); - - error2 = SyncError(); - EXPECT_FALSE(error2.IsSet()); -} - -} // namespace diff --git a/chrome/browser/sync/api/syncable_service.h b/chrome/browser/sync/api/syncable_service.h index 9d7ae62..3c40975 100644 --- a/chrome/browser/sync/api/syncable_service.h +++ b/chrome/browser/sync/api/syncable_service.h @@ -12,7 +12,6 @@ #include "chrome/browser/sync/syncable/model_type.h" #include "chrome/browser/sync/api/sync_change_processor.h" #include "chrome/browser/sync/api/sync_data.h" -#include "chrome/browser/sync/api/sync_error.h" class SyncData; @@ -26,10 +25,7 @@ class SyncableService : public SyncChangeProcessor { // two. After this, the SyncableService's local data should match the server // data, and the service should be ready to receive and process any further // SyncChange's as they occur. - // Returns: A default SyncError (IsSet() == false) if no errors were - // encountered, and a filled SyncError (IsSet() == true) - // otherwise. - virtual SyncError MergeDataAndStartSyncing( + virtual bool MergeDataAndStartSyncing( syncable::ModelType type, const SyncDataList& initial_sync_data, SyncChangeProcessor* sync_processor) = 0; @@ -44,10 +40,7 @@ class SyncableService : public SyncChangeProcessor { // SyncChangeProcessor interface. // Process a list of new SyncChanges and update the local data as necessary. - // Returns: A default SyncError (IsSet() == false) if no errors were - // encountered, and a filled SyncError (IsSet() == true) - // otherwise. - virtual SyncError ProcessSyncChanges( + virtual void ProcessSyncChanges( const tracked_objects::Location& from_here, const SyncChangeList& change_list) OVERRIDE = 0; diff --git a/chrome/browser/sync/api/syncable_service_mock.h b/chrome/browser/sync/api/syncable_service_mock.h index e1e6bf7..29c5e9b 100644 --- a/chrome/browser/sync/api/syncable_service_mock.h +++ b/chrome/browser/sync/api/syncable_service_mock.h @@ -16,15 +16,13 @@ class SyncableServiceMock : public SyncableService { SyncableServiceMock(); virtual ~SyncableServiceMock(); - MOCK_METHOD3(MergeDataAndStartSyncing, - SyncError(syncable::ModelType, - const SyncDataList&, - SyncChangeProcessor* sync_processor)); + MOCK_METHOD3(MergeDataAndStartSyncing, bool( + syncable::ModelType, const SyncDataList&, + SyncChangeProcessor* sync_processor)); MOCK_METHOD1(StopSyncing, void(syncable::ModelType)); - MOCK_CONST_METHOD1(GetAllSyncData, SyncDataList(syncable::ModelType type)); + MOCK_CONST_METHOD1(GetAllSyncData, SyncDataList(syncable::ModelType)); MOCK_METHOD2(ProcessSyncChanges, - SyncError(const tracked_objects::Location&, - const SyncChangeList&)); + void(const tracked_objects::Location&, const SyncChangeList&)); }; #endif // CHROME_BROWSER_SYNC_API_SYNCABLE_SERVICE_MOCK_H_ diff --git a/chrome/browser/sync/backend_migrator.cc b/chrome/browser/sync/backend_migrator.cc index cc0b613..4d8550f 100644 --- a/chrome/browser/sync/backend_migrator.cc +++ b/chrome/browser/sync/backend_migrator.cc @@ -121,8 +121,9 @@ void BackendMigrator::Observe(int type, if (state_ == IDLE) return; - const DataTypeManager::ConfigureResult* result = - Details<DataTypeManager::ConfigureResult>(details).ptr(); + DataTypeManager::ConfigureResultWithErrorLocation* result = + Details<DataTypeManager::ConfigureResultWithErrorLocation>( + details).ptr(); ModelTypeSet intersection; std::set_intersection(result->requested_types.begin(), @@ -150,7 +151,7 @@ void BackendMigrator::Observe(int type, return; } - if (result->status != DataTypeManager::OK) { + if (result->result != DataTypeManager::OK) { // If this fails, and we're disabling types, a type may or may not be // disabled until the user restarts the browser. If this wasn't an abort, // any failure will be reported as an unrecoverable error to the UI. If it diff --git a/chrome/browser/sync/backend_migrator_unittest.cc b/chrome/browser/sync/backend_migrator_unittest.cc index bd9677b..cdc2643 100644 --- a/chrome/browser/sync/backend_migrator_unittest.cc +++ b/chrome/browser/sync/backend_migrator_unittest.cc @@ -59,25 +59,15 @@ class BackendMigratorTest : public testing::Test { .WillOnce(Return(snap_.get())); } - void SendConfigureDone(DataTypeManager::ConfigureStatus status, + void SendConfigureDone(DataTypeManager::ConfigureResult result, const syncable::ModelTypeSet& types) { - if (status == DataTypeManager::OK) { - DataTypeManager::ConfigureResult result(status, types); - NotificationService::current()->Notify( - chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, - Source<DataTypeManager>(&manager_), - Details<const DataTypeManager::ConfigureResult>(&result)); - } else { - DataTypeManager::ConfigureResult result( - status, - types, - syncable::ModelTypeSet(), - FROM_HERE); - NotificationService::current()->Notify( - chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, - Source<DataTypeManager>(&manager_), - Details<const DataTypeManager::ConfigureResult>(&result)); - } + DataTypeManager::ConfigureResultWithErrorLocation result_with_location( + result, FROM_HERE, types); + NotificationService::current()->Notify( + chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, + Source<DataTypeManager>(&manager_), + Details<DataTypeManager::ConfigureResultWithErrorLocation>( + &result_with_location)); } ProfileSyncService* service() { return &service_; } diff --git a/chrome/browser/sync/glue/app_model_associator.cc b/chrome/browser/sync/glue/app_model_associator.cc index a0a566d..fd6dd24 100644 --- a/chrome/browser/sync/glue/app_model_associator.cc +++ b/chrome/browser/sync/glue/app_model_associator.cc @@ -7,7 +7,6 @@ #include "base/logging.h" #include "base/tracked.h" #include "chrome/browser/extensions/extension_sync_data.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/extension_sync_traits.h" #include "chrome/browser/sync/glue/extension_sync.h" @@ -32,24 +31,22 @@ AppModelAssociator::~AppModelAssociator() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -bool AppModelAssociator::AssociateModels(SyncError* error) { +bool AppModelAssociator::AssociateModels() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); ExtensionDataMap extension_data_map; if (!SlurpExtensionData( traits_, *extension_service_, user_share_, &extension_data_map)) { - error->Reset(FROM_HERE, "Failed to get app data.", model_type()); return false; } if (!FlushExtensionData( traits_, extension_data_map, extension_service_, user_share_)) { - error->Reset(FROM_HERE, "Failed to flush app data.", model_type()); return false; } return true; } -bool AppModelAssociator::DisassociateModels(SyncError* error) { +bool AppModelAssociator::DisassociateModels() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Nothing to do. return true; diff --git a/chrome/browser/sync/glue/app_model_associator.h b/chrome/browser/sync/glue/app_model_associator.h index 0d975cd..65c5d55 100644 --- a/chrome/browser/sync/glue/app_model_associator.h +++ b/chrome/browser/sync/glue/app_model_associator.h @@ -32,8 +32,8 @@ class AppModelAssociator : public AssociatorInterface { static syncable::ModelType model_type() { return syncable::APPS; } // AssociatorInterface implementation. - virtual bool AssociateModels(SyncError* error); - virtual bool DisassociateModels(SyncError* error); + virtual bool AssociateModels(); + virtual bool DisassociateModels(); virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); virtual void AbortAssociation(); virtual bool CryptoReadyIfNecessary(); diff --git a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc index c340190..51446bb 100644 --- a/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/autofill_data_type_controller_unittest.cc @@ -124,7 +124,7 @@ class AutofillDataTypeControllerTest : public testing::Test { WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillRepeatedly(Return(true)); EXPECT_CALL(service_, ActivateDataType(_, _)); EXPECT_CALL(*change_processor_, IsRunning()).WillRepeatedly(Return(true)); @@ -132,7 +132,7 @@ class AutofillDataTypeControllerTest : public testing::Test { void SetStopExpectations() { EXPECT_CALL(service_, DeactivateDataType(_, _)); - EXPECT_CALL(*model_associator_, DisassociateModels(_)); + EXPECT_CALL(*model_associator_, DisassociateModels()); } void WaitForEmptyDBMessageLoop() { @@ -259,7 +259,7 @@ TEST_F(AutofillDataTypeControllerTest, AbortWhileAssociatingActivated) { WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillRepeatedly(Return(true)); EXPECT_CALL(*change_processor_, IsRunning()).WillRepeatedly(Return(true)); diff --git a/chrome/browser/sync/glue/autofill_model_associator.cc b/chrome/browser/sync/glue/autofill_model_associator.cc index 73cff83..435cb1c 100644 --- a/chrome/browser/sync/glue/autofill_model_associator.cc +++ b/chrome/browser/sync/glue/autofill_model_associator.cc @@ -14,7 +14,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/autofill_change_processor.h" #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" @@ -137,7 +136,7 @@ bool AutofillModelAssociator::LoadAutofillData( return true; } -bool AutofillModelAssociator::AssociateModels(SyncError* error) { +bool AutofillModelAssociator::AssociateModels() { VLOG(1) << "Associating Autofill Models"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); { @@ -150,9 +149,7 @@ bool AutofillModelAssociator::AssociateModels(SyncError* error) { ScopedVector<AutofillProfile> profiles; if (!LoadAutofillData(&entries, &profiles.get())) { - error->Reset(FROM_HERE, - "Could not get the autofill data from WebDatabase.", - model_type()); + LOG(ERROR) << "Could not get the autofill data from WebDatabase."; return false; } @@ -162,16 +159,13 @@ bool AutofillModelAssociator::AssociateModels(SyncError* error) { sync_api::ReadNode autofill_root(&trans); if (!autofill_root.InitByTagLookup(kAutofillTag)) { - error->Reset(FROM_HERE, - "Server did not create the top-level autofill node. We " - "might be running against an out-of-date server.", - model_type()); + LOG(ERROR) << "Server did not create the top-level autofill node. We " + << "might be running against an out-of-date server."; return false; } if (!TraverseAndAssociateChromeAutofillEntries(&trans, autofill_root, entries, &bundle.current_entries, &bundle.new_entries)) { - error->Reset(FROM_HERE, "Failed to associate entries.", model_type()); return false; } @@ -180,7 +174,6 @@ bool AutofillModelAssociator::AssociateModels(SyncError* error) { autofill_root, &bundle, profiles.get())) { - error->Reset(FROM_HERE, "Failed to associate sync nodes.", model_type()); return false; } } @@ -191,7 +184,7 @@ bool AutofillModelAssociator::AssociateModels(SyncError* error) { // to worry about the sync model getting out of sync, because changes are // propagated to the ChangeProcessor on this thread. if (!SaveChangesToWebData(bundle)) { - error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); + LOG(ERROR) << "Failed to update autofill entries."; return false; } @@ -352,7 +345,7 @@ void AutofillModelAssociator::AddNativeProfileIfNeeded( } } -bool AutofillModelAssociator::DisassociateModels(SyncError* error) { +bool AutofillModelAssociator::DisassociateModels() { id_map_.clear(); id_map_inverse_.clear(); return true; diff --git a/chrome/browser/sync/glue/autofill_model_associator.h b/chrome/browser/sync/glue/autofill_model_associator.h index baffaa8..3eb9186 100644 --- a/chrome/browser/sync/glue/autofill_model_associator.h +++ b/chrome/browser/sync/glue/autofill_model_associator.h @@ -54,10 +54,10 @@ class AutofillModelAssociator // PerDataTypeAssociatorInterface implementation. // // Iterates through the sync model looking for matched pairs of items. - virtual bool AssociateModels(SyncError* error); + virtual bool AssociateModels(); // Clears all associations. - virtual bool DisassociateModels(SyncError* error); + virtual bool DisassociateModels(); // The has_nodes out param is true if the sync model has nodes other // than the permanent tagged nodes. diff --git a/chrome/browser/sync/glue/autofill_profile_model_associator.cc b/chrome/browser/sync/glue/autofill_profile_model_associator.cc index 9c2692b..ca01b08 100644 --- a/chrome/browser/sync/glue/autofill_profile_model_associator.cc +++ b/chrome/browser/sync/glue/autofill_profile_model_associator.cc @@ -6,7 +6,6 @@ #include "base/tracked.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/glue/autofill_profile_change_processor.h" #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h" #include "chrome/browser/sync/profile_sync_service.h" @@ -137,7 +136,7 @@ bool AutofillProfileModelAssociator::LoadAutofillData( return true; } -bool AutofillProfileModelAssociator::AssociateModels(SyncError* error) { +bool AutofillProfileModelAssociator::AssociateModels() { VLOG(1) << "Associating Autofill Models"; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); { @@ -148,9 +147,7 @@ bool AutofillProfileModelAssociator::AssociateModels(SyncError* error) { ScopedVector<AutofillProfile> profiles; if (!LoadAutofillData(&profiles.get())) { - error->Reset(FROM_HERE, - "Could not get the autofill data from WebDatabase.", - model_type()); + LOG(ERROR) << "Could not get the autofill data from WebDatabase."; return false; } @@ -165,10 +162,8 @@ bool AutofillProfileModelAssociator::AssociateModels(SyncError* error) { sync_api::ReadNode autofill_root(&trans); if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) { - error->Reset(FROM_HERE, - "Server did not create the top-level autofill node. We " - "might be running against an out-of-date server.", - model_type()); + LOG(ERROR) << "Server did not create the top-level autofill node. We " + << "might be running against an out-of-date server."; return false; } @@ -178,15 +173,12 @@ bool AutofillProfileModelAssociator::AssociateModels(SyncError* error) { &bundle.new_profiles, &bundle.profiles_to_delete) || !TraverseAndAssociateAllSyncNodes(&trans, autofill_root, &bundle)) { - error->Reset(FROM_HERE, - "Failed to associate all sync nodes.", - model_type()); return false; } } if (!SaveChangesToWebData(bundle)) { - error->Reset(FROM_HERE, "Failed to update webdata.", model_type()); + LOG(ERROR) << "Failed to update autofill entries."; return false; } @@ -195,7 +187,7 @@ bool AutofillProfileModelAssociator::AssociateModels(SyncError* error) { return true; } -bool AutofillProfileModelAssociator::DisassociateModels(SyncError* error) { +bool AutofillProfileModelAssociator::DisassociateModels() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); id_map_.clear(); id_map_inverse_.clear(); diff --git a/chrome/browser/sync/glue/autofill_profile_model_associator.h b/chrome/browser/sync/glue/autofill_profile_model_associator.h index 4b0b1a2..c8b99ac 100644 --- a/chrome/browser/sync/glue/autofill_profile_model_associator.h +++ b/chrome/browser/sync/glue/autofill_profile_model_associator.h @@ -59,10 +59,10 @@ class AutofillProfileModelAssociator // PerDataTypeAssociatorInterface implementation. // // Iterates through the sync model looking for matched pairs of items. - virtual bool AssociateModels(SyncError* error); + virtual bool AssociateModels(); // Clears all associations. - virtual bool DisassociateModels(SyncError* error); + virtual bool DisassociateModels(); // TODO(lipalani) Bug 64111. // The has_nodes out param is true if the sync model has nodes other diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc index 0c4bce0..d385e76c7 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc @@ -74,14 +74,14 @@ class BookmarkDataTypeControllerTest : public testing::Test { EXPECT_CALL(*profile_sync_factory_, CreateBookmarkSyncComponents(_, _)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillRepeatedly(Return(true)); EXPECT_CALL(service_, ActivateDataType(_, _)); } void SetStopExpectations() { EXPECT_CALL(service_, DeactivateDataType(_, _)); - EXPECT_CALL(*model_associator_, DisassociateModels(_)); + EXPECT_CALL(*model_associator_, DisassociateModels()); } MessageLoopForUI message_loop_; @@ -160,9 +160,8 @@ TEST_F(BookmarkDataTypeControllerTest, StartAssociationFailed) { WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). - WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::BOOKMARKS), - Return(false))); + EXPECT_CALL(*model_associator_, AssociateModels()). + WillRepeatedly(Return(false)); EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); bookmark_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc index 6e0ba5c..ec57895 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.cc +++ b/chrome/browser/sync/glue/bookmark_model_associator.cc @@ -14,7 +14,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/bookmark_change_processor.h" #include "chrome/browser/sync/syncable/nigori_util.h" @@ -45,9 +44,6 @@ namespace browser_sync { static const char kBookmarkBarTag[] = "bookmark_bar"; static const char kSyncedBookmarksTag[] = "synced_bookmarks"; static const char kOtherBookmarksTag[] = "other_bookmarks"; -static const char kServerError[] = - "Server did not create top-level nodes. Possibly we are running against " - "an out-of-date server?"; // Bookmark comparer for map of bookmark nodes. class BookmarkComparer { @@ -182,7 +178,7 @@ BookmarkModelAssociator::~BookmarkModelAssociator() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -bool BookmarkModelAssociator::DisassociateModels(SyncError* error) { +bool BookmarkModelAssociator::DisassociateModels() { id_map_.clear(); id_map_inverse_.clear(); dirty_associations_sync_ids_.clear(); @@ -319,20 +315,20 @@ bool BookmarkModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, return true; } -bool BookmarkModelAssociator::AssociateModels(SyncError* error) { +bool BookmarkModelAssociator::AssociateModels() { // Try to load model associations from persisted associations first. If that // succeeds, we don't need to run the complex model matching algorithm. if (LoadAssociations()) return true; - DisassociateModels(error); + DisassociateModels(); // We couldn't load model associations from persisted associations. So build // them. - return BuildAssociations(error); + return BuildAssociations(); } -bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { +bool BookmarkModelAssociator::BuildAssociations() { // Algorithm description: // Match up the roots and recursively do the following: // * For each sync node for the current sync parent node, find the best @@ -356,12 +352,14 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { // and Other Bookmarks. if (!AssociateTaggedPermanentNode(bookmark_model_->other_node(), kOtherBookmarksTag)) { - error->Reset(FROM_HERE, kServerError, model_type()); + LOG(ERROR) << "Server did not create top-level nodes. Possibly we " + << "are running against an out-of-date server?"; return false; } if (!AssociateTaggedPermanentNode(bookmark_model_->bookmark_bar_node(), kBookmarkBarTag)) { - error->Reset(FROM_HERE, kServerError, model_type()); + LOG(ERROR) << "Server did not create top-level nodes. Possibly we " + << "are running against an out-of-date server?"; return false; } if (!AssociateTaggedPermanentNode(bookmark_model_->synced_node(), @@ -370,7 +368,8 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { // server if the command line flag is set. CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableSyncedBookmarksFolder)) { - error->Reset(FROM_HERE, kServerError, model_type()); + LOG(ERROR) << "Server did not create top-level synced nodes. Possibly " + << "we are running against an out-of-date server?"; return false; } int64 bookmark_bar_sync_id = GetSyncIdFromChromeId( @@ -400,7 +399,6 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { sync_api::ReadNode sync_parent(&trans); if (!sync_parent.InitByIdLookup(sync_parent_id)) { - error->Reset(FROM_HERE, "Failed to lookup node.", model_type()); return false; } // Only folder nodes are pushed on to the stack. @@ -416,7 +414,6 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { while (sync_child_id != sync_api::kInvalidId) { sync_api::WriteNode sync_child_node(&trans); if (!sync_child_node.InitByIdLookup(sync_child_id)) { - error->Reset(FROM_HERE, "Failed to lookup node.", model_type()); return false; } diff --git a/chrome/browser/sync/glue/bookmark_model_associator.h b/chrome/browser/sync/glue/bookmark_model_associator.h index 27471c2..ac0da1c 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.h +++ b/chrome/browser/sync/glue/bookmark_model_associator.h @@ -52,9 +52,9 @@ class BookmarkModelAssociator // node. After successful completion, the models should be identical and // corresponding. Returns true on success. On failure of this step, we // should abort the sync operation and report an error to the user. - virtual bool AssociateModels(SyncError* error); + virtual bool AssociateModels(); - virtual bool DisassociateModels(SyncError* error); + virtual bool DisassociateModels(); // The has_nodes out param is true if the sync model has nodes other // than the permanent tagged nodes. @@ -111,7 +111,7 @@ class BookmarkModelAssociator // Matches up the bookmark model and the sync model to build model // associations. - bool BuildAssociations(SyncError* error); + bool BuildAssociations(); // Associate a top-level node of the bookmark model with a permanent node in // the sync domain. Such permanent nodes are identified by a tag that is diff --git a/chrome/browser/sync/glue/data_type_manager.cc b/chrome/browser/sync/glue/data_type_manager.cc index 186205a..45b836e 100644 --- a/chrome/browser/sync/glue/data_type_manager.cc +++ b/chrome/browser/sync/glue/data_type_manager.cc @@ -6,42 +6,12 @@ namespace browser_sync { -DataTypeManager::ConfigureResult::ConfigureResult() {} +DataTypeManager::ConfigureResultWithErrorLocation:: + ~ConfigureResultWithErrorLocation() {} -DataTypeManager::ConfigureResult::ConfigureResult(ConfigureStatus status, - TypeSet requested_types) - : status(status), - requested_types(requested_types) { - DCHECK_EQ(OK, status); -} - -DataTypeManager::ConfigureResult::ConfigureResult( - ConfigureStatus status, - TypeSet requested_types, - TypeSet failed_types, - const tracked_objects::Location& location) - : status(status), - requested_types(requested_types), - failed_types(failed_types), - location(location) { - DCHECK_NE(OK, status); -} - -// Static. -std::string DataTypeManager::ConfigureStatusToString(ConfigureStatus status) { - switch (status) { - case OK: - return "Ok"; - case ASSOCIATION_FAILED: - return "Association Failed"; - case ABORTED: - return "Aborted"; - case UNRECOVERABLE_ERROR: - return "Unrecoverable Error"; - default: - NOTREACHED(); - return std::string(); - } +DataTypeManager::ConfigureResultWithErrorLocation:: + ConfigureResultWithErrorLocation() + : result(OK) { } } // namespace browser_sync diff --git a/chrome/browser/sync/glue/data_type_manager.h b/chrome/browser/sync/glue/data_type_manager.h index a7ded22..eef71a1 100644 --- a/chrome/browser/sync/glue/data_type_manager.h +++ b/chrome/browser/sync/glue/data_type_manager.h @@ -7,7 +7,6 @@ #pragma once #include <set> -#include <string> #include "base/memory/scoped_ptr.h" #include "base/task.h" @@ -37,7 +36,7 @@ class DataTypeManager { // Update NotifyDone() in data_type_manager_impl.cc if you update // this. - enum ConfigureStatus { + enum ConfigureResult { OK, // Configuration finished without error. ASSOCIATION_FAILED, // An error occurred during model association. ABORTED, // Start was aborted by calling Stop() before @@ -48,25 +47,34 @@ class DataTypeManager { typedef std::set<syncable::ModelType> TypeSet; - // Note: location and failed_types are only filled when status is not OK. - struct ConfigureResult { - ConfigureResult(); - ConfigureResult(ConfigureStatus status, - TypeSet requested_types); - ConfigureResult(ConfigureStatus status, - TypeSet requested_types, - TypeSet failed_types, - const tracked_objects::Location& location); - ConfigureStatus status; + // In case of an error the location is filled with the location the + // error originated from. In case of a success the error location value + // is to be not used. + // TODO(tim): We should rename this / ConfigureResult to something more + // flexible like SyncConfigureDoneDetails. + struct ConfigureResultWithErrorLocation { + ConfigureResult result; TypeSet requested_types; - TypeSet failed_types; - tracked_objects::Location location; + scoped_ptr<tracked_objects::Location> location; + + ConfigureResultWithErrorLocation(); + ConfigureResultWithErrorLocation(const ConfigureResult& result, + const tracked_objects::Location& location, + const TypeSet& requested_types) + : result(result), + requested_types(requested_types) { + this->location.reset(new tracked_objects::Location( + location.function_name(), + location.file_name(), + location.line_number(), + location.program_counter())); + } + + ~ConfigureResultWithErrorLocation(); }; - virtual ~DataTypeManager() {} - // Convert a ConfigureStatus to string for debug purposes. - static std::string ConfigureStatusToString(ConfigureStatus status); + virtual ~DataTypeManager() {} // Begins asynchronous configuration of data types. Any currently // running data types that are not in the desired_types set will be diff --git a/chrome/browser/sync/glue/data_type_manager_impl.cc b/chrome/browser/sync/glue/data_type_manager_impl.cc index 5a7cf23a..ebafd82 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl.cc @@ -130,8 +130,7 @@ void DataTypeManagerImpl::ConfigureImpl(const TypeSet& desired_types, // If we're already configured and the types haven't changed, we can exit // out early. NotifyStart(); - ConfigureResult result(OK, last_requested_types_); - NotifyDone(result); + NotifyDone(OK, FROM_HERE); return; } @@ -222,7 +221,7 @@ void DataTypeManagerImpl::DownloadReady(bool success) { DCHECK(state_ == DOWNLOAD_PENDING); if (!success) { - Abort(UNRECOVERABLE_ERROR, FROM_HERE, needs_start_[0]->type()); + NotifyDone(UNRECOVERABLE_ERROR, FROM_HERE); return; } @@ -277,8 +276,7 @@ void DataTypeManagerImpl::StartNextType() { // If no more data types need starting, we're done. state_ = CONFIGURED; - ConfigureResult result(OK, last_requested_types_); - NotifyDone(result); + NotifyDone(OK, FROM_HERE); } void DataTypeManagerImpl::TypeStartCallback( @@ -293,7 +291,7 @@ void DataTypeManagerImpl::TypeStartCallback( // DataTypeManager::Stop() was called while the current data type // was starting. Now that it has finished starting, we can finish // stopping the DataTypeManager. This is considered an ABORT. - Abort(ABORTED, location, needs_start_[0]->type()); + FinishStopAndNotify(ABORTED, FROM_HERE); return; } else if (state_ == STOPPED) { // If our state_ is STOPPED, we have already stopped all of the data @@ -308,6 +306,8 @@ void DataTypeManagerImpl::TypeStartCallback( DCHECK_EQ(needs_start_[0], started_dtc); needs_start_.erase(needs_start_.begin()); + if (result == DataTypeController::NEEDS_CRYPTO) { + } // If the type started normally, continue to the next type. // If the type is waiting for the cryptographer, continue to the next type. // Once the cryptographer is ready, we'll attempt to restart this type. @@ -322,29 +322,22 @@ void DataTypeManagerImpl::TypeStartCallback( // managed to start up to this point and pass the result to the // callback. VLOG(0) << "Failed " << started_dtc->name(); - ConfigureStatus configure_status = DataTypeManager::ABORTED; + ConfigureResult configure_result = DataTypeManager::ABORTED; switch (result) { case DataTypeController::ABORTED: - configure_status = DataTypeManager::ABORTED; + configure_result = DataTypeManager::ABORTED; break; case DataTypeController::ASSOCIATION_FAILED: - configure_status = DataTypeManager::ASSOCIATION_FAILED; + configure_result = DataTypeManager::ASSOCIATION_FAILED; break; case DataTypeController::UNRECOVERABLE_ERROR: - configure_status = DataTypeManager::UNRECOVERABLE_ERROR; + configure_result = DataTypeManager::UNRECOVERABLE_ERROR; break; default: NOTREACHED(); break; } - - // TODO(sync): We currently only specify the last attempted type as the failed - // type. At some point we should allow a datatype to fail without preventing - // other datatypes from continuing. In that case we'll have to support - // multiple types failing. - Abort(configure_status, - location, - started_dtc->type()); + FinishStopAndNotify(configure_result, location); } void DataTypeManagerImpl::Stop() { @@ -375,10 +368,7 @@ void DataTypeManagerImpl::Stop() { // If Stop() is called while waiting for download, cancel all // outstanding tasks. weak_ptr_factory_.InvalidateWeakPtrs(); - syncable::ModelType type = syncable::UNSPECIFIED; - if (needs_start_.size() > 0) - type = needs_start_[0]->type(); - Abort(ABORTED, FROM_HERE, type); + FinishStopAndNotify(ABORTED, FROM_HERE); return; } @@ -400,20 +390,10 @@ void DataTypeManagerImpl::FinishStop() { state_ = STOPPED; } -void DataTypeManagerImpl::Abort( - ConfigureStatus status, - const tracked_objects::Location& location, - syncable::ModelType last_attempted_type) { - DCHECK_NE(OK, status); +void DataTypeManagerImpl::FinishStopAndNotify(ConfigureResult result, + const tracked_objects::Location& location) { FinishStop(); - TypeSet attempted_types; - if (syncable::IsRealDataType(last_attempted_type)) - attempted_types.insert(last_attempted_type); - ConfigureResult result(status, - last_requested_types_, - attempted_types, - location); - NotifyDone(result); + NotifyDone(result, location); } void DataTypeManagerImpl::NotifyStart() { @@ -423,12 +403,14 @@ void DataTypeManagerImpl::NotifyStart() { NotificationService::NoDetails()); } -void DataTypeManagerImpl::NotifyDone(const ConfigureResult& result) { +void DataTypeManagerImpl::NotifyDone(ConfigureResult result, + const tracked_objects::Location& location) { + ConfigureResultWithErrorLocation result_with_location(result, location, + last_requested_types_); AddToConfigureTime(); - VLOG(1) << "Total time spent configuring: " << configure_time_delta_.InSecondsF() << "s"; - switch (result.status) { + switch (result) { case DataTypeManager::OK: VLOG(1) << "NotifyDone called with result: OK"; UMA_HISTOGRAM_TIMES("Sync.ConfigureTime.OK", @@ -456,7 +438,7 @@ void DataTypeManagerImpl::NotifyDone(const ConfigureResult& result) { NotificationService::current()->Notify( chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, Source<DataTypeManager>(this), - Details<const ConfigureResult>(&result)); + Details<ConfigureResultWithErrorLocation>(&result_with_location)); } const DataTypeController::TypeMap& DataTypeManagerImpl::controllers() { diff --git a/chrome/browser/sync/glue/data_type_manager_impl.h b/chrome/browser/sync/glue/data_type_manager_impl.h index 65db005..8e8076f 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl.h +++ b/chrome/browser/sync/glue/data_type_manager_impl.h @@ -50,9 +50,8 @@ class DataTypeManagerImpl : public DataTypeManager { // Stops all data types. void FinishStop(); - void Abort(ConfigureStatus status, - const tracked_objects::Location& location, - syncable::ModelType last_attempted_type); + void FinishStopAndNotify(ConfigureResult result, + const tracked_objects::Location& location); // Returns true if any last_requested_types_ currently needs to start model // association. If non-null, fills |needs_start| with all such controllers. @@ -62,7 +61,8 @@ class DataTypeManagerImpl : public DataTypeManager { void Restart(sync_api::ConfigureReason reason, bool enable_nigori); void DownloadReady(bool success); void NotifyStart(); - void NotifyDone(const ConfigureResult& result); + void NotifyDone(ConfigureResult result, + const tracked_objects::Location& location); void SetBlockedAndNotify(); // Add to |configure_time_delta_| the time since we last called diff --git a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc index e21e680..24dbe9c 100644 --- a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc +++ b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc @@ -53,12 +53,12 @@ ACTION_P2(InvokeCallbackPointer, callback, argument) { delete callback; } -DataTypeManager::ConfigureStatus GetStatus( +DataTypeManager::ConfigureResult GetResult( const NotificationDetails& details) { - const DataTypeManager::ConfigureResult* result = - Details<const DataTypeManager::ConfigureResult>( + DataTypeManager::ConfigureResultWithErrorLocation* result_with_location = + Details<DataTypeManager::ConfigureResultWithErrorLocation>( details).ptr(); - return result->status; + return result_with_location->result; } class DataTypeManagerImplTest : public testing::Test { @@ -149,11 +149,11 @@ class DataTypeManagerImplTest : public testing::Test { } - void SetConfigureDoneExpectation(DataTypeManager::ConfigureStatus status) { + void SetConfigureDoneExpectation(DataTypeManager::ConfigureResult result) { EXPECT_CALL( observer_, Observe(int(chrome::NOTIFICATION_SYNC_CONFIGURE_DONE), _, - ::testing::ResultOf(&GetStatus, status))); + ::testing::ResultOf(&GetResult, result))); } MessageLoopForUI message_loop_; diff --git a/chrome/browser/sync/glue/data_type_manager_mock.cc b/chrome/browser/sync/glue/data_type_manager_mock.cc index fa088ff..a530d51 100644 --- a/chrome/browser/sync/glue/data_type_manager_mock.cc +++ b/chrome/browser/sync/glue/data_type_manager_mock.cc @@ -9,7 +9,7 @@ namespace browser_sync { DataTypeManagerMock::DataTypeManagerMock() - : result_(OK, syncable::ModelTypeSet()) { + : result_(OK, FROM_HERE, syncable::ModelTypeSet()) { // By default, calling Configure will send a SYNC_CONFIGURE_START // and SYNC_CONFIGURE_DONE notification with a DataTypeManager::OK diff --git a/chrome/browser/sync/glue/data_type_manager_mock.h b/chrome/browser/sync/glue/data_type_manager_mock.h index 4e110ed..be45d9f 100644 --- a/chrome/browser/sync/glue/data_type_manager_mock.h +++ b/chrome/browser/sync/glue/data_type_manager_mock.h @@ -17,7 +17,7 @@ ACTION_P3(NotifyFromDataTypeManagerWithResult, dtm, type, result) { NotificationService::current()->Notify( type, Source<browser_sync::DataTypeManager>(dtm), - Details<const browser_sync::DataTypeManager::ConfigureResult>( + Details<browser_sync::DataTypeManager::ConfigureResultWithErrorLocation>( result)); } @@ -42,7 +42,7 @@ class DataTypeManagerMock : public DataTypeManager { MOCK_METHOD0(state, State()); private: - browser_sync::DataTypeManager::ConfigureResult result_; + browser_sync::DataTypeManager::ConfigureResultWithErrorLocation result_; }; } // namespace browser_sync diff --git a/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc b/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc index 5c4fb18..4a6953c 100644 --- a/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/extension_data_type_controller_unittest.cc @@ -59,7 +59,7 @@ class ExtensionDataTypeControllerTest : public testing::Test { WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillRepeatedly(Return(true)); } @@ -69,7 +69,7 @@ class ExtensionDataTypeControllerTest : public testing::Test { void SetStopExpectations() { EXPECT_CALL(service_, DeactivateDataType(_, _)); - EXPECT_CALL(*model_associator_, DisassociateModels(_)); + EXPECT_CALL(*model_associator_, DisassociateModels()); } MessageLoopForUI message_loop_; @@ -117,9 +117,8 @@ TEST_F(ExtensionDataTypeControllerTest, StartOk) { TEST_F(ExtensionDataTypeControllerTest, StartAssociationFailed) { SetStartExpectations(); SetAssociateExpectations(); - EXPECT_CALL(*model_associator_, AssociateModels(_)). - WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::EXTENSIONS), - Return(false))); + EXPECT_CALL(*model_associator_, AssociateModels()). + WillRepeatedly(Return(false)); EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); extension_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); diff --git a/chrome/browser/sync/glue/extension_model_associator.cc b/chrome/browser/sync/glue/extension_model_associator.cc index fbe0e0d..46594b6 100644 --- a/chrome/browser/sync/glue/extension_model_associator.cc +++ b/chrome/browser/sync/glue/extension_model_associator.cc @@ -32,24 +32,22 @@ ExtensionModelAssociator::~ExtensionModelAssociator() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -bool ExtensionModelAssociator::AssociateModels(SyncError* error) { +bool ExtensionModelAssociator::AssociateModels() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); ExtensionDataMap extension_data_map; if (!SlurpExtensionData( traits_, *extension_service_, user_share_, &extension_data_map)) { - error->Reset(FROM_HERE, "Failed to get extension data.", model_type()); return false; } if (!FlushExtensionData( traits_, extension_data_map, extension_service_, user_share_)) { - error->Reset(FROM_HERE, "Failed to flush extension data.", model_type()); return false; } return true; } -bool ExtensionModelAssociator::DisassociateModels(SyncError* error) { +bool ExtensionModelAssociator::DisassociateModels() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Nothing to do. return true; diff --git a/chrome/browser/sync/glue/extension_model_associator.h b/chrome/browser/sync/glue/extension_model_associator.h index 48f51b2..b71a281 100644 --- a/chrome/browser/sync/glue/extension_model_associator.h +++ b/chrome/browser/sync/glue/extension_model_associator.h @@ -7,7 +7,6 @@ #pragma once #include "base/basictypes.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/glue/extension_sync_traits.h" #include "chrome/browser/sync/glue/model_associator.h" #include "chrome/browser/sync/syncable/model_type.h" @@ -33,8 +32,8 @@ class ExtensionModelAssociator : public AssociatorInterface { static syncable::ModelType model_type() { return syncable::EXTENSIONS; } // AssociatorInterface implementation. - virtual bool AssociateModels(SyncError* error); - virtual bool DisassociateModels(SyncError* error); + virtual bool AssociateModels(); + virtual bool DisassociateModels(); virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); virtual void AbortAssociation(); virtual bool CryptoReadyIfNecessary(); diff --git a/chrome/browser/sync/glue/frontend_data_type_controller.cc b/chrome/browser/sync/glue/frontend_data_type_controller.cc index 6d99787..9a22cb8 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/frontend_data_type_controller.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/model_associator.h" #include "chrome/browser/sync/profile_sync_factory.h" @@ -93,11 +92,10 @@ bool FrontendDataTypeController::Associate() { } base::TimeTicks start_time = base::TimeTicks::Now(); - SyncError error; - bool merge_success = model_associator()->AssociateModels(&error); + bool merge_success = model_associator()->AssociateModels(); RecordAssociationTime(base::TimeTicks::Now() - start_time); if (!merge_success) { - StartFailed(ASSOCIATION_FAILED, error.location()); + StartFailed(ASSOCIATION_FAILED, FROM_HERE); return false; } @@ -107,8 +105,7 @@ bool FrontendDataTypeController::Associate() { return true; } -void FrontendDataTypeController::StartFailed( - StartResult result, +void FrontendDataTypeController::StartFailed(StartResult result, const tracked_objects::Location& location) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CleanUpState(); @@ -121,12 +118,10 @@ void FrontendDataTypeController::StartFailed( // invoking the callback will trigger a call to STOP(), which will get // confused by the non-NULL start_callback_. scoped_ptr<StartCallback> callback(start_callback_.release()); - // TODO(zea): Send the full SyncError on failure and handle it higher up. callback->Run(result, location); } -void FrontendDataTypeController::FinishStart( - StartResult result, +void FrontendDataTypeController::FinishStart(StartResult result, const tracked_objects::Location& location) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -154,10 +149,8 @@ void FrontendDataTypeController::Stop() { if (change_processor_.get()) sync_service_->DeactivateDataType(this, change_processor_.get()); - if (model_associator()) { - SyncError error; - model_associator()->DisassociateModels(&error); - } + if (model_associator()) + model_associator()->DisassociateModels(); set_model_associator(NULL); change_processor_.reset(); diff --git a/chrome/browser/sync/glue/frontend_data_type_controller.h b/chrome/browser/sync/glue/frontend_data_type_controller.h index a1a7b01..86c3e60 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller.h +++ b/chrome/browser/sync/glue/frontend_data_type_controller.h @@ -15,7 +15,6 @@ class Profile; class ProfileSyncService; class ProfileSyncFactory; -class SyncError; namespace base { class TimeDelta; } namespace browser_sync { @@ -85,11 +84,11 @@ class FrontendDataTypeController : public DataTypeController { // Cleans up state and calls callback when start fails. virtual void StartFailed(StartResult result, - const tracked_objects::Location& location); + const tracked_objects::Location& from_here); // Helper method to run the stashed start callback with a given result. virtual void FinishStart(StartResult result, - const tracked_objects::Location& location); + const tracked_objects::Location& from_here); // DataType specific histogram methods. Because histograms use static's, the // specific datatype controllers must implement this themselves. diff --git a/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc b/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc index 2f90f9f..ee3f42f 100644 --- a/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/frontend_data_type_controller_unittest.cc @@ -111,7 +111,7 @@ class FrontendDataTypeControllerTest : public testing::Test { WillOnce(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillOnce(Return(true)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); } @@ -124,7 +124,7 @@ class FrontendDataTypeControllerTest : public testing::Test { void SetStopExpectations() { EXPECT_CALL(*dtc_mock_, CleanUpState()); EXPECT_CALL(service_, DeactivateDataType(_, _)); - EXPECT_CALL(*model_associator_, DisassociateModels(_)); + EXPECT_CALL(*model_associator_, DisassociateModels()); } void SetStartFailExpectations(DataTypeController::StartResult result) { @@ -160,7 +160,7 @@ TEST_F(FrontendDataTypeControllerTest, StartFirstRun) { WillOnce(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillOnce(DoAll(SetArgumentPointee<0>(false), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillOnce(Return(true)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); SetActivateExpectations(DataTypeController::OK_FIRST_RUN); @@ -185,9 +185,8 @@ TEST_F(FrontendDataTypeControllerTest, StartAssociationFailed) { WillOnce(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). - WillOnce(DoAll(browser_sync::SetSyncError(syncable::PREFERENCES), - Return(false))); + EXPECT_CALL(*model_associator_, AssociateModels()). + WillOnce(Return(false)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); // Set up association to fail with an association failed error. diff --git a/chrome/browser/sync/glue/generic_change_processor.cc b/chrome/browser/sync/glue/generic_change_processor.cc index d24d477..6c85de9 100644 --- a/chrome/browser/sync/glue/generic_change_processor.cc +++ b/chrome/browser/sync/glue/generic_change_processor.cc @@ -7,7 +7,6 @@ #include "base/tracked.h" #include "chrome/browser/sync/api/syncable_service.h" #include "chrome/browser/sync/api/sync_change.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/syncable/nigori_util.h" @@ -70,45 +69,37 @@ void GenericChangeProcessor::CommitChangesFromSyncModel() { return; if (syncer_changes_.empty()) return; - SyncError error = local_service_->ProcessSyncChanges(FROM_HERE, - syncer_changes_); + local_service_->ProcessSyncChanges(FROM_HERE, syncer_changes_); syncer_changes_.clear(); - if (error.IsSet()) { - error_handler()->OnUnrecoverableError(error.location(), error.message()); - } } -SyncError GenericChangeProcessor::GetSyncDataForType( +bool GenericChangeProcessor::GetSyncDataForType( syncable::ModelType type, SyncDataList* current_sync_data) { std::string type_name = syncable::ModelTypeToString(type); sync_api::ReadTransaction trans(FROM_HERE, share_handle()); sync_api::ReadNode root(&trans); if (!root.InitByTagLookup(syncable::ModelTypeToRootTag(type))) { - SyncError error(FROM_HERE, - "Server did not create the top-level " + type_name + - " node. We might be running against an out-of-date server.", - type); - return error; + LOG(ERROR) << "Server did not create the top-level " + type_name + " node." + << " We might be running against an out-of-date server."; + return false; } int64 sync_child_id = root.GetFirstChildId(); while (sync_child_id != sync_api::kInvalidId) { sync_api::ReadNode sync_child_node(&trans); if (!sync_child_node.InitByIdLookup(sync_child_id)) { - SyncError error(FROM_HERE, - "Failed to fetch child node for type " + type_name + ".", - type); - return error; + LOG(ERROR) << "Failed to fetch child node for type " + type_name + "."; + return false; } current_sync_data->push_back(SyncData::CreateRemoteData( sync_child_node.GetEntitySpecifics())); sync_child_id = sync_child_node.GetSuccessorId(); } - return SyncError(); + return true; } -SyncError GenericChangeProcessor::ProcessSyncChanges( +void GenericChangeProcessor::ProcessSyncChanges( const tracked_objects::Location& from_here, const SyncChangeList& list_of_changes) { sync_api::WriteTransaction trans(from_here, share_handle()); @@ -118,20 +109,17 @@ SyncError GenericChangeProcessor::ProcessSyncChanges( ++iter) { const SyncChange& change = *iter; DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); - syncable::ModelType type = change.sync_data().GetDataType(); - std::string type_str = syncable::ModelTypeToString(type); + std::string type_str = syncable::ModelTypeToString( + change.sync_data().GetDataType()); sync_api::WriteNode sync_node(&trans); if (change.change_type() == SyncChange::ACTION_DELETE) { if (change.sync_data().GetTag() == "" || !sync_node.InitByClientTagLookup(change.sync_data().GetDataType(), change.sync_data().GetTag())) { NOTREACHED(); - SyncError error(FROM_HERE, - "Failed to delete " + type_str + " node.", - type); - error_handler()->OnUnrecoverableError(error.location(), - error.message()); - return error; + error_handler()->OnUnrecoverableError(FROM_HERE, + "Failed to delete " + type_str + " node."); + return; } sync_node.Remove(); } else if (change.change_type() == SyncChange::ACTION_ADD) { @@ -141,23 +129,16 @@ SyncError GenericChangeProcessor::ProcessSyncChanges( if (!root_node.InitByTagLookup( syncable::ModelTypeToRootTag(change.sync_data().GetDataType()))) { NOTREACHED(); - SyncError error(FROM_HERE, - "Failed to look up root node for type " + type_str, - type); - error_handler()->OnUnrecoverableError(error.location(), - error.message()); - return error; + error_handler()->OnUnrecoverableError(FROM_HERE, + "Failed to look up root node for type " + type_str); + return; } if (!sync_node.InitUniqueByCreation(change.sync_data().GetDataType(), root_node, change.sync_data().GetTag())) { - NOTREACHED(); - SyncError error(FROM_HERE, - "Failed to create " + type_str + " node.", - type); - error_handler()->OnUnrecoverableError(error.location(), - error.message()); - return error; + error_handler()->OnUnrecoverableError(FROM_HERE, + "Failed to create " + type_str + " node."); + return; } sync_node.SetTitle(UTF8ToWide(change.sync_data().GetTitle())); sync_node.SetEntitySpecifics(change.sync_data().GetSpecifics()); @@ -166,12 +147,9 @@ SyncError GenericChangeProcessor::ProcessSyncChanges( !sync_node.InitByClientTagLookup(change.sync_data().GetDataType(), change.sync_data().GetTag())) { NOTREACHED(); - SyncError error(FROM_HERE, - "Failed to update " + type_str + " node.", - type); - error_handler()->OnUnrecoverableError(error.location(), - error.message()); - return error; + error_handler()->OnUnrecoverableError(FROM_HERE, + "Failed to update " + type_str + " node"); + return; } sync_node.SetTitle(UTF8ToWide(change.sync_data().GetTitle())); sync_node.SetEntitySpecifics(change.sync_data().GetSpecifics()); @@ -179,15 +157,11 @@ SyncError GenericChangeProcessor::ProcessSyncChanges( // successor, parent, etc.). } else { NOTREACHED(); - SyncError error(FROM_HERE, - "Received unset SyncChange in the change processor.", - type); - error_handler()->OnUnrecoverableError(error.location(), - error.message()); - return error; + error_handler()->OnUnrecoverableError(FROM_HERE, + "Received unset SyncChange in the change processor."); + return; } } - return SyncError(); } bool GenericChangeProcessor::SyncModelHasUserCreatedNodes( diff --git a/chrome/browser/sync/glue/generic_change_processor.h b/chrome/browser/sync/glue/generic_change_processor.h index 4864360..d3176e5 100644 --- a/chrome/browser/sync/glue/generic_change_processor.h +++ b/chrome/browser/sync/glue/generic_change_processor.h @@ -45,13 +45,12 @@ class GenericChangeProcessor : public ChangeProcessor, virtual void CommitChangesFromSyncModel() OVERRIDE; // SyncChangeProcessor implementation. - virtual SyncError ProcessSyncChanges( - const tracked_objects::Location& from_here, - const SyncChangeList& change_list) OVERRIDE; + virtual void ProcessSyncChanges(const tracked_objects::Location& from_here, + const SyncChangeList& change_list) OVERRIDE; // Fills |current_sync_data| with all the syncer data for the specified type. - virtual SyncError GetSyncDataForType(syncable::ModelType type, - SyncDataList* current_sync_data); + virtual bool GetSyncDataForType(syncable::ModelType type, + SyncDataList* current_sync_data); // Generic versions of AssociatorInterface methods. Called by // SyncableServiceAdapter. diff --git a/chrome/browser/sync/glue/model_associator.h b/chrome/browser/sync/glue/model_associator.h index eb65aab..eaa2a45 100644 --- a/chrome/browser/sync/glue/model_associator.h +++ b/chrome/browser/sync/glue/model_associator.h @@ -9,8 +9,6 @@ #include "base/basictypes.h" #include "chrome/browser/sync/syncable/model_type.h" -class SyncError; - namespace sync_api { class BaseNode; } @@ -29,12 +27,10 @@ class AssociatorInterface { // should be identical and corresponding. Returns true on // success. On failure of this step, we should abort the sync // operation and report an error to the user. - // TODO(zea): return a SyncError instead of passing one in. - virtual bool AssociateModels(SyncError* error) = 0; + virtual bool AssociateModels() = 0; // Clears all the associations between the chrome and sync models. - // TODO(zea): return a SyncError instead of passing one in. - virtual bool DisassociateModels(SyncError* error) = 0; + virtual bool DisassociateModels() = 0; // The has_nodes out parameter is set to true if the sync model has // nodes other than the permanent tagged nodes. The method may diff --git a/chrome/browser/sync/glue/model_associator_mock.h b/chrome/browser/sync/glue/model_associator_mock.h index 3474eff..51cb7c4 100644 --- a/chrome/browser/sync/glue/model_associator_mock.h +++ b/chrome/browser/sync/glue/model_associator_mock.h @@ -6,24 +6,18 @@ #define CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATOR_MOCK_H__ #pragma once -#include "base/tracked.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/glue/model_associator.h" #include "testing/gmock/include/gmock/gmock.h" namespace browser_sync { -ACTION_P(SetSyncError, type) { - arg0->Reset(FROM_HERE, "test", type); -} - class ModelAssociatorMock : public AssociatorInterface { public: ModelAssociatorMock(); virtual ~ModelAssociatorMock(); - MOCK_METHOD1(AssociateModels, bool(SyncError* error)); - MOCK_METHOD1(DisassociateModels, bool(SyncError* error)); + MOCK_METHOD0(AssociateModels, bool()); + MOCK_METHOD0(DisassociateModels, bool()); MOCK_METHOD1(SyncModelHasUserCreatedNodes, bool(bool* has_nodes)); MOCK_METHOD0(AbortAssociation, void()); MOCK_METHOD0(CryptoReadyIfNecessary, bool()); diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc index 96d6843..5200f5d 100644 --- a/chrome/browser/sync/glue/non_frontend_data_type_controller.cc +++ b/chrome/browser/sync/glue/non_frontend_data_type_controller.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/glue/change_processor.h" #include "chrome/browser/sync/glue/model_associator.h" #include "chrome/browser/sync/profile_sync_factory.h" @@ -105,11 +104,10 @@ void NonFrontendDataTypeController::StartAssociation() { } base::TimeTicks start_time = base::TimeTicks::Now(); - SyncError error; - bool merge_success = model_associator_->AssociateModels(&error); + bool merge_success = model_associator_->AssociateModels(); RecordAssociationTime(base::TimeTicks::Now() - start_time); if (!merge_success) { - StartFailed(ASSOCIATION_FAILED, error.location()); + StartFailed(ASSOCIATION_FAILED, FROM_HERE); return; } @@ -117,13 +115,11 @@ void NonFrontendDataTypeController::StartAssociation() { StartDone(!sync_has_nodes ? OK_FIRST_RUN : OK, RUNNING, FROM_HERE); } -void NonFrontendDataTypeController::StartFailed( - StartResult result, +void NonFrontendDataTypeController::StartFailed(StartResult result, const tracked_objects::Location& location) { DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); model_associator_.reset(); change_processor_.reset(); - // TODO(zea): Send the full SyncError on failure and handle it higher up. StartDone(result, NOT_RUNNING, location); } @@ -220,10 +216,8 @@ void NonFrontendDataTypeController::StopModels() { void NonFrontendDataTypeController::StopAssociation() { DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (model_associator_.get()) { - SyncError error; - model_associator_->DisassociateModels(&error); - } + if (model_associator_.get()) + model_associator_->DisassociateModels(); model_associator_.reset(); change_processor_.reset(); datatype_stopped_.Signal(); @@ -243,7 +237,7 @@ void NonFrontendDataTypeController::OnUnrecoverableError( const std::string& message) { DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); RecordUnrecoverableError(from_here, message); - BrowserThread::PostTask(BrowserThread::UI, from_here, NewRunnableMethod(this, + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(this, &NonFrontendDataTypeController::OnUnrecoverableErrorImpl, from_here, message)); } diff --git a/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc b/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc index e1fc3dd..eeda4c4 100644 --- a/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/non_frontend_data_type_controller_unittest.cc @@ -152,7 +152,7 @@ class NonFrontendDataTypeControllerTest : public testing::Test { WillOnce(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillOnce(Return(true)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); } @@ -166,7 +166,7 @@ class NonFrontendDataTypeControllerTest : public testing::Test { EXPECT_CALL(*dtc_mock_, StopAssociationAsync()); EXPECT_CALL(*dtc_mock_, StopModels()); EXPECT_CALL(service_, DeactivateDataType(_, _)); - EXPECT_CALL(*model_associator_, DisassociateModels(_)); + EXPECT_CALL(*model_associator_, DisassociateModels()); } void SetStartFailExpectations(DataTypeController::StartResult result) { @@ -222,7 +222,7 @@ TEST_F(NonFrontendDataTypeControllerTest, StartFirstRun) { WillOnce(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillOnce(DoAll(SetArgumentPointee<0>(false), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillOnce(Return(true)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); SetActivateExpectations(DataTypeController::OK_FIRST_RUN); @@ -250,9 +250,8 @@ TEST_F(NonFrontendDataTypeControllerTest, StartAssociationFailed) { WillOnce(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). - WillOnce(DoAll(browser_sync::SetSyncError(syncable::AUTOFILL), - Return(false))); + EXPECT_CALL(*model_associator_, AssociateModels()). + WillOnce(Return(false)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); // Set up association to fail with an association failed error. @@ -309,7 +308,7 @@ TEST_F(NonFrontendDataTypeControllerTest, AbortDuringAssociationInactive) { Return(true))); EXPECT_CALL(*model_associator_, AbortAssociation()).WillOnce( SignalEvent(&pause_db_thread)); - EXPECT_CALL(*model_associator_, AssociateModels(_)).WillOnce(Return(true)); + EXPECT_CALL(*model_associator_, AssociateModels()).WillOnce(Return(true)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); EXPECT_CALL(service_, ActivateDataType(_, _)); EXPECT_CALL(start_callback_, Run(DataTypeController::ABORTED,_)); @@ -338,7 +337,7 @@ TEST_F(NonFrontendDataTypeControllerTest, AbortDuringAssociationActivated) { Return(true))); EXPECT_CALL(*model_associator_, AbortAssociation()).WillOnce( SignalEvent(&pause_db_thread)); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillOnce(Return(true)); EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); EXPECT_CALL(service_, ActivateDataType(_, _)).WillOnce(DoAll( diff --git a/chrome/browser/sync/glue/password_model_associator.cc b/chrome/browser/sync/glue/password_model_associator.cc index 6d96186..1a1ca01 100644 --- a/chrome/browser/sync/glue/password_model_associator.cc +++ b/chrome/browser/sync/glue/password_model_associator.cc @@ -10,7 +10,6 @@ #include "base/tracked.h" #include "base/utf_string_conversions.h" #include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/protocol/password_specifics.pb.h" @@ -40,7 +39,7 @@ PasswordModelAssociator::PasswordModelAssociator( PasswordModelAssociator::~PasswordModelAssociator() {} -bool PasswordModelAssociator::AssociateModels(SyncError* error) { +bool PasswordModelAssociator::AssociateModels() { DCHECK(expected_loop_ == MessageLoop::current()); { base::AutoLock lock(abort_association_pending_lock_); @@ -54,9 +53,7 @@ bool PasswordModelAssociator::AssociateModels(SyncError* error) { if (!password_store_->FillAutofillableLogins(&passwords) || !password_store_->FillBlacklistLogins(&passwords)) { STLDeleteElements(&passwords); - error->Reset(FROM_HERE, - "Could not get the password entries.", - model_type()); + LOG(ERROR) << "Could not get the password entries."; return false; } @@ -67,20 +64,16 @@ bool PasswordModelAssociator::AssociateModels(SyncError* error) { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode password_root(&trans); if (!password_root.InitByTagLookup(kPasswordTag)) { - error->Reset(FROM_HERE, - "Server did not create the top-level password node. We " - "might be running against an out-of-date server.", - model_type()); + LOG(ERROR) << "Server did not create the top-level password node. We " + << "might be running against an out-of-date server."; return false; } for (std::vector<webkit_glue::PasswordForm*>::iterator ix = passwords.begin(); ix != passwords.end(); ++ix) { - if (IsAbortPending()) { - error->Reset(FROM_HERE, "Abort pending", model_type()); + if (IsAbortPending()) return false; - } std::string tag = MakeTag(**ix); sync_api::ReadNode node(&trans); @@ -95,9 +88,7 @@ bool PasswordModelAssociator::AssociateModels(SyncError* error) { sync_api::WriteNode write_node(&trans); if (!write_node.InitByClientTagLookup(syncable::PASSWORDS, tag)) { STLDeleteElements(&passwords); - error->Reset(FROM_HERE, - "Failed to edit password sync node.", - model_type()); + LOG(ERROR) << "Failed to edit password sync node."; return false; } WriteToSyncNode(new_password, &write_node); @@ -110,9 +101,7 @@ bool PasswordModelAssociator::AssociateModels(SyncError* error) { if (!node.InitUniqueByCreation(syncable::PASSWORDS, password_root, tag)) { STLDeleteElements(&passwords); - error->Reset(FROM_HERE, - "Failed to create password sync node.", - model_type()); + LOG(ERROR) << "Failed to create password sync node."; return false; } @@ -130,7 +119,7 @@ bool PasswordModelAssociator::AssociateModels(SyncError* error) { while (sync_child_id != sync_api::kInvalidId) { sync_api::ReadNode sync_child_node(&trans); if (!sync_child_node.InitByIdLookup(sync_child_id)) { - error->Reset(FROM_HERE, "Failed to fetch child node.", model_type()); + LOG(ERROR) << "Failed to fetch child node."; return false; } const sync_pb::PasswordSpecificsData& password = @@ -155,7 +144,7 @@ bool PasswordModelAssociator::AssociateModels(SyncError* error) { // store, as it can post tasks to the UI thread which can itself be blocked // on our transaction, resulting in deadlock. (http://crbug.com/70658) if (!WriteToPasswordStore(&new_passwords, &updated_passwords, NULL)) { - error->Reset(FROM_HERE, "Failed to write passwords.", model_type()); + LOG(ERROR) << "Failed to write passwords."; return false; } @@ -180,7 +169,7 @@ bool PasswordModelAssociator::DeleteAllNodes( return true; } -bool PasswordModelAssociator::DisassociateModels(SyncError* error) { +bool PasswordModelAssociator::DisassociateModels() { id_map_.clear(); id_map_inverse_.clear(); return true; diff --git a/chrome/browser/sync/glue/password_model_associator.h b/chrome/browser/sync/glue/password_model_associator.h index d612c03..0b3bac5 100644 --- a/chrome/browser/sync/glue/password_model_associator.h +++ b/chrome/browser/sync/glue/password_model_associator.h @@ -56,13 +56,13 @@ class PasswordModelAssociator // PerDataTypeAssociatorInterface implementation. // // Iterates through the sync model looking for matched pairs of items. - virtual bool AssociateModels(SyncError* error); + virtual bool AssociateModels(); // Delete all password nodes. bool DeleteAllNodes(sync_api::WriteTransaction* trans); // Clears all associations. - virtual bool DisassociateModels(SyncError* error); + virtual bool DisassociateModels(); // The has_nodes out param is true if the sync model has nodes other // than the permanent tagged nodes. diff --git a/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc b/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc index 3bca18b..ba436d9 100644 --- a/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/preference_data_type_controller_unittest.cc @@ -61,7 +61,7 @@ class PreferenceDataTypeControllerTest : public testing::Test { WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillRepeatedly(Return(true)); } @@ -71,7 +71,7 @@ class PreferenceDataTypeControllerTest : public testing::Test { void SetStopExpectations() { EXPECT_CALL(service_, DeactivateDataType(_, _)); - EXPECT_CALL(*model_associator_, DisassociateModels(_)); + EXPECT_CALL(*model_associator_, DisassociateModels()); } MessageLoopForUI message_loop_; @@ -119,9 +119,8 @@ TEST_F(PreferenceDataTypeControllerTest, StartOk) { TEST_F(PreferenceDataTypeControllerTest, StartAssociationFailed) { SetStartExpectations(); SetAssociateExpectations(); - EXPECT_CALL(*model_associator_, AssociateModels(_)). - WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::PREFERENCES), - Return(false))); + EXPECT_CALL(*model_associator_, AssociateModels()). + WillRepeatedly(Return(false)); EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); preference_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc index 5811049..a923081 100644 --- a/chrome/browser/sync/glue/session_model_associator.cc +++ b/chrome/browser/sync/glue/session_model_associator.cc @@ -14,7 +14,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/restore_tab_helper.h" #include "chrome/browser/sessions/session_service_factory.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/glue/synced_window_delegate.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/syncable/syncable.h" @@ -408,7 +407,7 @@ void SessionModelAssociator::Disassociate(int64 sync_id) { // TODO(zea): we will need this once we support deleting foreign sessions. } -bool SessionModelAssociator::AssociateModels(SyncError* error) { +bool SessionModelAssociator::AssociateModels() { DCHECK(CalledOnValidThread()); // Ensure that we disassociated properly, otherwise memory might leak. @@ -424,7 +423,7 @@ bool SessionModelAssociator::AssociateModels(SyncError* error) { sync_api::ReadNode root(&trans); if (!root.InitByTagLookup(kSessionsTag)) { - error->Reset(FROM_HERE, kNoSessionsFolderError, model_type()); + LOG(ERROR) << kNoSessionsFolderError; return false; } @@ -439,9 +438,7 @@ bool SessionModelAssociator::AssociateModels(SyncError* error) { sync_api::WriteNode write_node(&trans); if (!write_node.InitUniqueByCreation(syncable::SESSIONS, root, current_machine_tag_)) { - error->Reset(FROM_HERE, - "Failed to create sessions header sync node.", - model_type()); + LOG(ERROR) << "Failed to create sessions header sync node."; return false; } write_node.SetTitle(UTF8ToWide(current_machine_tag_)); @@ -457,7 +454,7 @@ bool SessionModelAssociator::AssociateModels(SyncError* error) { return true; } -bool SessionModelAssociator::DisassociateModels(SyncError* error) { +bool SessionModelAssociator::DisassociateModels() { DCHECK(CalledOnValidThread()); synced_session_tracker_.clear(); tab_map_.clear(); diff --git a/chrome/browser/sync/glue/session_model_associator.h b/chrome/browser/sync/glue/session_model_associator.h index 486b49f..72fa1e4 100644 --- a/chrome/browser/sync/glue/session_model_associator.h +++ b/chrome/browser/sync/glue/session_model_associator.h @@ -116,7 +116,7 @@ class SessionModelAssociator // with local client data. Processes/reuses any sync nodes owned by this // client and creates any further sync nodes needed to store local header and // tab info. - virtual bool AssociateModels(SyncError* error); + virtual bool AssociateModels(); // Initializes the given sync node from the given chrome node id. // Returns false if no sync node was found for the given chrome node id or @@ -126,7 +126,7 @@ class SessionModelAssociator // Clear local sync data buffers. Does not delete sync nodes to avoid // tombstones. TODO(zea): way to eventually delete orphaned nodes. - virtual bool DisassociateModels(SyncError* error); + virtual bool DisassociateModels(); // Returns the tag used to uniquely identify this machine's session in the // sync model. diff --git a/chrome/browser/sync/glue/syncable_service_adapter.cc b/chrome/browser/sync/glue/syncable_service_adapter.cc index 88b6ab1..68dcfae 100644 --- a/chrome/browser/sync/glue/syncable_service_adapter.cc +++ b/chrome/browser/sync/glue/syncable_service_adapter.cc @@ -30,26 +30,18 @@ SyncableServiceAdapter::~SyncableServiceAdapter() { } } -bool SyncableServiceAdapter::AssociateModels(SyncError* error) { +bool SyncableServiceAdapter::AssociateModels() { syncing_ = true; SyncDataList initial_sync_data; - SyncError temp_error = - sync_processor_->GetSyncDataForType(type_, &initial_sync_data); - if (temp_error.IsSet()) { - *error = temp_error; + if (!sync_processor_->GetSyncDataForType(type_, &initial_sync_data)) { return false; } - temp_error = service_->MergeDataAndStartSyncing(type_, - initial_sync_data, - sync_processor_); - if (temp_error.IsSet()) { - *error = temp_error; - return false; - } - return true; + return service_->MergeDataAndStartSyncing(type_, + initial_sync_data, + sync_processor_); } -bool SyncableServiceAdapter::DisassociateModels(SyncError* error) { +bool SyncableServiceAdapter::DisassociateModels() { service_->StopSyncing(type_); syncing_ = false; return true; diff --git a/chrome/browser/sync/glue/syncable_service_adapter.h b/chrome/browser/sync/glue/syncable_service_adapter.h index 7390f1c..b19a867 100644 --- a/chrome/browser/sync/glue/syncable_service_adapter.h +++ b/chrome/browser/sync/glue/syncable_service_adapter.h @@ -29,8 +29,8 @@ class SyncableServiceAdapter : public AssociatorInterface { virtual ~SyncableServiceAdapter(); // AssociatorInterface implementation. - virtual bool AssociateModels(SyncError* error) OVERRIDE; - virtual bool DisassociateModels(SyncError* error) OVERRIDE; + virtual bool AssociateModels() OVERRIDE; + virtual bool DisassociateModels() OVERRIDE; virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) OVERRIDE; virtual void AbortAssociation() OVERRIDE; virtual bool CryptoReadyIfNecessary() OVERRIDE; diff --git a/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc b/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc index 1c89cbb..4d2a1ad 100644 --- a/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/theme_data_type_controller_unittest.cc @@ -58,7 +58,7 @@ class ThemeDataTypeControllerTest : public testing::Test { WillRepeatedly(Return(true)); EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)). WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true))); - EXPECT_CALL(*model_associator_, AssociateModels(_)). + EXPECT_CALL(*model_associator_, AssociateModels()). WillRepeatedly(Return(true)); } @@ -68,7 +68,7 @@ class ThemeDataTypeControllerTest : public testing::Test { void SetStopExpectations() { EXPECT_CALL(service_, DeactivateDataType(_, _)); - EXPECT_CALL(*model_associator_, DisassociateModels(_)); + EXPECT_CALL(*model_associator_, DisassociateModels()); } MessageLoopForUI message_loop_; @@ -116,9 +116,8 @@ TEST_F(ThemeDataTypeControllerTest, StartOk) { TEST_F(ThemeDataTypeControllerTest, StartAssociationFailed) { SetStartExpectations(); SetAssociateExpectations(); - EXPECT_CALL(*model_associator_, AssociateModels(_)). - WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::THEMES), - Return(false))); + EXPECT_CALL(*model_associator_, AssociateModels()). + WillRepeatedly(Return(false)); EXPECT_CALL(start_callback_, Run(DataTypeController::ASSOCIATION_FAILED, _)); theme_dtc_->Start(NewCallback(&start_callback_, &StartCallback::Run)); diff --git a/chrome/browser/sync/glue/theme_model_associator.cc b/chrome/browser/sync/glue/theme_model_associator.cc index 5638bad..e53b021 100644 --- a/chrome/browser/sync/glue/theme_model_associator.cc +++ b/chrome/browser/sync/glue/theme_model_associator.cc @@ -8,7 +8,6 @@ #include "base/logging.h" #include "base/tracked.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/sync_backend_host.h" #include "chrome/browser/sync/glue/theme_util.h" @@ -36,11 +35,11 @@ ThemeModelAssociator::ThemeModelAssociator( ThemeModelAssociator::~ThemeModelAssociator() {} -bool ThemeModelAssociator::AssociateModels(SyncError* error) { +bool ThemeModelAssociator::AssociateModels() { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode root(&trans); if (!root.InitByTagLookup(kThemesTag)) { - error->Reset(FROM_HERE, kNoThemesFolderError, model_type()); + LOG(ERROR) << kNoThemesFolderError; return false; } @@ -63,9 +62,7 @@ bool ThemeModelAssociator::AssociateModels(SyncError* error) { sync_api::WriteNode node(&trans); if (!node.InitUniqueByCreation(syncable::THEMES, root, kCurrentThemeClientTag)) { - error->Reset(FROM_HERE, - "Could not create current theme node.", - model_type()); + LOG(ERROR) << "Could not create current theme node."; return false; } node.SetIsFolder(false); @@ -77,7 +74,7 @@ bool ThemeModelAssociator::AssociateModels(SyncError* error) { return true; } -bool ThemeModelAssociator::DisassociateModels(SyncError* error) { +bool ThemeModelAssociator::DisassociateModels() { // We don't maintain any association state, so nothing to do. return true; } diff --git a/chrome/browser/sync/glue/theme_model_associator.h b/chrome/browser/sync/glue/theme_model_associator.h index 357c7b6..e76b5bd 100644 --- a/chrome/browser/sync/glue/theme_model_associator.h +++ b/chrome/browser/sync/glue/theme_model_associator.h @@ -27,8 +27,8 @@ class ThemeModelAssociator : public AssociatorInterface { static syncable::ModelType model_type() { return syncable::THEMES; } // AssociatorInterface implementation. - virtual bool AssociateModels(SyncError* error); - virtual bool DisassociateModels(SyncError* error); + virtual bool AssociateModels(); + virtual bool DisassociateModels(); virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); virtual void AbortAssociation() { // No implementation needed, this associator runs on the main diff --git a/chrome/browser/sync/glue/typed_url_model_associator.cc b/chrome/browser/sync/glue/typed_url_model_associator.cc index 961f2b9..4aad3e5 100644 --- a/chrome/browser/sync/glue/typed_url_model_associator.cc +++ b/chrome/browser/sync/glue/typed_url_model_associator.cc @@ -11,7 +11,6 @@ #include "base/tracked.h" #include "base/utf_string_conversions.h" #include "chrome/browser/history/history_backend.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" @@ -47,15 +46,13 @@ TypedUrlModelAssociator::TypedUrlModelAssociator( TypedUrlModelAssociator::~TypedUrlModelAssociator() {} -bool TypedUrlModelAssociator::AssociateModels(SyncError* error) { +bool TypedUrlModelAssociator::AssociateModels() { VLOG(1) << "Associating TypedUrl Models"; DCHECK(expected_loop_ == MessageLoop::current()); std::vector<history::URLRow> typed_urls; if (!history_backend_->GetAllTypedURLs(&typed_urls)) { - error->Reset(FROM_HERE, - "Could not get the typed_url entries.", - model_type()); + LOG(ERROR) << "Could not get the typed_url entries."; return false; } @@ -65,7 +62,7 @@ bool TypedUrlModelAssociator::AssociateModels(SyncError* error) { ix != typed_urls.end(); ++ix) { if (!history_backend_->GetVisitsForURL(ix->id(), &(visit_vectors[ix->id()]))) { - error->Reset(FROM_HERE, "Could not get the url's visits.", model_type()); + LOG(ERROR) << "Could not get the url's visits."; return false; } // Sometimes (due to a bug elsewhere in the history or sync code, or due to @@ -90,10 +87,8 @@ bool TypedUrlModelAssociator::AssociateModels(SyncError* error) { sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); sync_api::ReadNode typed_url_root(&trans); if (!typed_url_root.InitByTagLookup(kTypedUrlTag)) { - error->Reset(FROM_HERE, - "Server did not create the top-level typed_url node. We " - "might be running against an out-of-date server.", - model_type()); + LOG(ERROR) << "Server did not create the top-level typed_url node. We " + << "might be running against an out-of-date server."; return false; } @@ -125,9 +120,7 @@ bool TypedUrlModelAssociator::AssociateModels(SyncError* error) { if (difference & DIFF_UPDATE_NODE) { sync_api::WriteNode write_node(&trans); if (!write_node.InitByClientTagLookup(syncable::TYPED_URLS, tag)) { - error->Reset(FROM_HERE, - "Failed to edit typed_url sync node.", - model_type()); + LOG(ERROR) << "Failed to edit typed_url sync node."; return false; } // We don't want to resurrect old visits that have been aged out by @@ -166,9 +159,7 @@ bool TypedUrlModelAssociator::AssociateModels(SyncError* error) { sync_api::WriteNode node(&trans); if (!node.InitUniqueByCreation(syncable::TYPED_URLS, typed_url_root, tag)) { - error->Reset(FROM_HERE, - "Failed to create typed_url sync node.", - model_type()); + LOG(ERROR) << "Failed to create typed_url sync node."; return false; } @@ -188,7 +179,7 @@ bool TypedUrlModelAssociator::AssociateModels(SyncError* error) { while (sync_child_id != sync_api::kInvalidId) { sync_api::ReadNode sync_child_node(&trans); if (!sync_child_node.InitByIdLookup(sync_child_id)) { - error->Reset(FROM_HERE, "Failed to fetch child node.", model_type()); + LOG(ERROR) << "Failed to fetch child node."; return false; } const sync_pb::TypedUrlSpecifics& typed_url( @@ -237,9 +228,7 @@ bool TypedUrlModelAssociator::AssociateModels(SyncError* error) { ++it) { sync_api::WriteNode sync_node(&trans); if (!sync_node.InitByIdLookup(*it)) { - error->Reset(FROM_HERE, - "Failed to fetch obsolete node.", - model_type()); + LOG(ERROR) << "Failed to fetch obsolete node."; return false; } sync_node.Remove(); @@ -277,7 +266,7 @@ bool TypedUrlModelAssociator::DeleteAllNodes( return true; } -bool TypedUrlModelAssociator::DisassociateModels(SyncError* error) { +bool TypedUrlModelAssociator::DisassociateModels() { id_map_.clear(); id_map_inverse_.clear(); return true; diff --git a/chrome/browser/sync/glue/typed_url_model_associator.h b/chrome/browser/sync/glue/typed_url_model_associator.h index ae4c5c1..fb75550 100644 --- a/chrome/browser/sync/glue/typed_url_model_associator.h +++ b/chrome/browser/sync/glue/typed_url_model_associator.h @@ -61,13 +61,13 @@ class TypedUrlModelAssociator // PerDataTypeAssociatorInterface implementation. // // Iterates through the sync model looking for matched pairs of items. - virtual bool AssociateModels(SyncError* error); + virtual bool AssociateModels(); // Delete all typed url nodes. bool DeleteAllNodes(sync_api::WriteTransaction* trans); // Clears all associations. - virtual bool DisassociateModels(SyncError* error); + virtual bool DisassociateModels(); // The has_nodes out param is true if the sync model has nodes other // than the permanent tagged nodes. diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index f0b3a64..e9625e6 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -1263,12 +1263,13 @@ void ProfileSyncService::Observe(int type, break; } case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: { - DataTypeManager::ConfigureResult* result = - Details<DataTypeManager::ConfigureResult>(details).ptr(); + DataTypeManager::ConfigureResultWithErrorLocation* result_with_location = + Details<DataTypeManager::ConfigureResultWithErrorLocation>( + details).ptr(); - DataTypeManager::ConfigureStatus status = result->status; - VLOG(1) << "PSS SYNC_CONFIGURE_DONE called with status: " << status; - if (status == DataTypeManager::ABORTED && + DataTypeManager::ConfigureResult result = result_with_location->result; + VLOG(1) << "PSS SYNC_CONFIGURE_DONE called with result: " << result; + if (result == DataTypeManager::ABORTED && expect_sync_configuration_aborted_) { VLOG(0) << "ProfileSyncService::Observe Sync Configure aborted"; expect_sync_configuration_aborted_ = false; @@ -1276,13 +1277,11 @@ void ProfileSyncService::Observe(int type, } // Clear out the gaia password if it is already there. gaia_password_ = std::string(); - if (status != DataTypeManager::OK) { + if (result != DataTypeManager::OK) { VLOG(0) << "ProfileSyncService::Observe: Unrecoverable error detected"; - std::string message = - "Sync Configuration failed while configuring " + - syncable::ModelTypeSetToString(result->failed_types) + - ": " + DataTypeManager::ConfigureStatusToString(status); - OnUnrecoverableError(result->location, message); + std::string message = StringPrintf("Sync Configuration failed with %d", + result); + OnUnrecoverableError(*(result_with_location->location), message); cached_passphrase_ = CachedPassphrase(); return; } diff --git a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc index 7f36c97..1d05bc6 100644 --- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc @@ -21,7 +21,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/sync/abstract_profile_sync_service_test.h" -#include "chrome/browser/sync/api/sync_error.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/bookmark_change_processor.h" #include "chrome/browser/sync/glue/bookmark_model_associator.h" @@ -326,8 +325,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test { profile_.GetBookmarkModel(), test_user_share_.user_share(), &mock_unrecoverable_error_handler_)); - SyncError error; - EXPECT_TRUE(model_associator_->AssociateModels(&error)); + EXPECT_TRUE(model_associator_->AssociateModels()); MessageLoop::current()->RunAllPending(); // Set up change processor. @@ -340,8 +338,8 @@ class ProfileSyncServiceBookmarkTest : public testing::Test { void StopSync() { change_processor_->Stop(); change_processor_.reset(); - SyncError error; - EXPECT_TRUE(model_associator_->DisassociateModels(&error)); + + EXPECT_TRUE(model_associator_->DisassociateModels()); model_associator_.reset(); message_loop_.RunAllPending(); diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc index 652230e..322f33c 100644 --- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc @@ -275,13 +275,10 @@ TEST_F(ProfileSyncServiceStartupTest, ClearServerData) { TEST_F(ProfileSyncServiceStartupTest, StartFailure) { DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); - DataTypeManager::ConfigureStatus status = + DataTypeManager::ConfigureResult configure_result = DataTypeManager::ASSOCIATION_FAILED; - browser_sync::DataTypeManager::ConfigureResult result( - status, - syncable::ModelTypeSet(), - syncable::ModelTypeSet(), - FROM_HERE); + browser_sync::DataTypeManager::ConfigureResultWithErrorLocation result( + configure_result, FROM_HERE, syncable::ModelTypeSet()); EXPECT_CALL(*data_type_manager, Configure(_, _)). WillRepeatedly( DoAll( diff --git a/chrome/browser/sync/syncable/model_type.cc b/chrome/browser/sync/syncable/model_type.cc index 28bafef..868b43c 100644 --- a/chrome/browser/sync/syncable/model_type.cc +++ b/chrome/browser/sync/syncable/model_type.cc @@ -543,8 +543,4 @@ bool intToRealModelType(const std::string& notification_type, return false; } -bool IsRealDataType(ModelType model_type) { - return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; -} - } // namespace syncable diff --git a/chrome/browser/sync/syncable/model_type.h b/chrome/browser/sync/syncable/model_type.h index e15da9e..d8582a3 100644 --- a/chrome/browser/sync/syncable/model_type.h +++ b/chrome/browser/sync/syncable/model_type.h @@ -162,9 +162,6 @@ bool RealModelTypeToint(ModelType model_type, bool intToRealModelType(const std::string& notification_type, ModelType* model_type); -// Returns true if |model_type| is a real datatype -bool IsRealDataType(ModelType model_type); - } // namespace syncable #endif // CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ diff --git a/chrome/browser/sync/syncable/model_type_unittest.cc b/chrome/browser/sync/syncable/model_type_unittest.cc index 5461f76..f946f95 100644 --- a/chrome/browser/sync/syncable/model_type_unittest.cc +++ b/chrome/browser/sync/syncable/model_type_unittest.cc @@ -78,14 +78,5 @@ TEST_F(ModelTypeTest, ModelTypeBitSetFromString) { EXPECT_FALSE(ModelTypeBitSetFromString(input_string, &output)); } -TEST_F(ModelTypeTest, IsRealDataType) { - EXPECT_FALSE(IsRealDataType(UNSPECIFIED)); - EXPECT_FALSE(IsRealDataType(MODEL_TYPE_COUNT)); - EXPECT_FALSE(IsRealDataType(TOP_LEVEL_FOLDER)); - EXPECT_TRUE(IsRealDataType(FIRST_REAL_MODEL_TYPE)); - EXPECT_TRUE(IsRealDataType(BOOKMARKS)); - EXPECT_TRUE(IsRealDataType(APPS)); -} - } // namespace } // namespace syncable diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 8b28b7d..647ad32 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -581,8 +581,6 @@ 'browser/sync/api/sync_change.cc', 'browser/sync/api/sync_change_processor.h', 'browser/sync/api/sync_change_processor.cc', - 'browser/sync/api/sync_error.h', - 'browser/sync/api/sync_error.cc', ], 'include_dirs': [ '..', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 904afe7..414e187 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -3304,8 +3304,6 @@ 'sources': [ '<(protoc_out_dir)/chrome/browser/sync/protocol/test.pb.cc', 'app/breakpad_mac_stubs.mm', - 'browser/sync/api/sync_change_unittest.cc', - 'browser/sync/api/sync_error_unittest.cc', 'browser/sync/engine/apply_updates_command_unittest.cc', 'browser/sync/engine/build_commit_command_unittest.cc', 'browser/sync/engine/clear_data_command_unittest.cc', @@ -3348,6 +3346,7 @@ 'browser/sync/syncable/syncable_enum_conversions_unittest.cc', 'browser/sync/syncable/syncable_id_unittest.cc', 'browser/sync/syncable/syncable_unittest.cc', + 'browser/sync/api/sync_change_unittest.cc', 'browser/sync/util/data_encryption_unittest.cc', 'browser/sync/util/extensions_activity_monitor_unittest.cc', 'browser/sync/util/protobuf_unittest.cc', |