summaryrefslogtreecommitdiffstats
path: root/components/sync_driver
diff options
context:
space:
mode:
authormaniscalco <maniscalco@chromium.org>2014-09-17 12:04:25 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-17 19:04:37 +0000
commitf513c50252f0f2ee326db80c63e9be4378003bea (patch)
tree3b32332ddff223eca66e4febce432f48bebc0976 /components/sync_driver
parent41fb084a9cac7aa51fb472bc6c96b73a2eee6617 (diff)
downloadchromium_src-f513c50252f0f2ee326db80c63e9be4378003bea.zip
chromium_src-f513c50252f0f2ee326db80c63e9be4378003bea.tar.gz
chromium_src-f513c50252f0f2ee326db80c63e9be4378003bea.tar.bz2
Make GenericChangeProcessor know its ModelType.
An instance of GenericChangeProcessor is effectively bound to a single ModelType, however, prior to this change GenericChangeProcessor didn't know its ModelType. It now has a ModelType data member. Motivation: In a future CL, GCP will be responsible for starting attachment uploads shortly after initialization. GCP will need to consult the Directory to get a list of attachment ids it needs to upload. To get the list from Directory, GCP needs to know the ModelType it is responsible for. Many of GenericChangeProcessor's public methods take a ModelType. DCHECK that the passed in ModelType matches the data member. BUG= Review URL: https://codereview.chromium.org/570193002 Cr-Commit-Position: refs/heads/master@{#295316}
Diffstat (limited to 'components/sync_driver')
-rw-r--r--components/sync_driver/fake_generic_change_processor.cc19
-rw-r--r--components/sync_driver/fake_generic_change_processor.h16
-rw-r--r--components/sync_driver/generic_change_processor.cc100
-rw-r--r--components/sync_driver/generic_change_processor.h24
-rw-r--r--components/sync_driver/generic_change_processor_factory.cc2
-rw-r--r--components/sync_driver/generic_change_processor_factory.h2
-rw-r--r--components/sync_driver/generic_change_processor_unittest.cc70
-rw-r--r--components/sync_driver/shared_change_processor.cc14
-rw-r--r--components/sync_driver/ui_data_type_controller_unittest.cc2
9 files changed, 132 insertions, 117 deletions
diff --git a/components/sync_driver/fake_generic_change_processor.cc b/components/sync_driver/fake_generic_change_processor.cc
index 91cfbf1..5c7c3ff4 100644
--- a/components/sync_driver/fake_generic_change_processor.cc
+++ b/components/sync_driver/fake_generic_change_processor.cc
@@ -12,15 +12,18 @@
namespace sync_driver {
FakeGenericChangeProcessor::FakeGenericChangeProcessor(
+ syncer::ModelType type,
SyncApiComponentFactory* sync_factory)
- : GenericChangeProcessor(NULL,
+ : GenericChangeProcessor(type,
+ NULL,
base::WeakPtr<syncer::SyncableService>(),
base::WeakPtr<syncer::SyncMergeResult>(),
NULL,
sync_factory,
scoped_refptr<syncer::AttachmentStore>()),
sync_model_has_user_created_nodes_(true),
- sync_model_has_user_created_nodes_success_(true) {}
+ sync_model_has_user_created_nodes_success_(true) {
+}
FakeGenericChangeProcessor::~FakeGenericChangeProcessor() {}
@@ -40,28 +43,25 @@ syncer::SyncError FakeGenericChangeProcessor::ProcessSyncChanges(
}
syncer::SyncError FakeGenericChangeProcessor::GetAllSyncDataReturnError(
- syncer::ModelType type, syncer::SyncDataList* current_sync_data) const {
+ syncer::SyncDataList* current_sync_data) const {
return syncer::SyncError();
}
bool FakeGenericChangeProcessor::GetDataTypeContext(
- syncer::ModelType type,
std::string* context) const {
return false;
}
-int FakeGenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) {
+int FakeGenericChangeProcessor::GetSyncCount() {
return 0;
}
-bool FakeGenericChangeProcessor::SyncModelHasUserCreatedNodes(
- syncer::ModelType type, bool* has_nodes) {
+bool FakeGenericChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) {
*has_nodes = sync_model_has_user_created_nodes_;
return sync_model_has_user_created_nodes_success_;
}
-bool FakeGenericChangeProcessor::CryptoReadyIfNecessary(
- syncer::ModelType type) {
+bool FakeGenericChangeProcessor::CryptoReadyIfNecessary() {
return true;
}
@@ -73,6 +73,7 @@ FakeGenericChangeProcessorFactory::~FakeGenericChangeProcessorFactory() {}
scoped_ptr<GenericChangeProcessor>
FakeGenericChangeProcessorFactory::CreateGenericChangeProcessor(
+ syncer::ModelType type,
syncer::UserShare* user_share,
DataTypeErrorHandler* error_handler,
const base::WeakPtr<syncer::SyncableService>& local_service,
diff --git a/components/sync_driver/fake_generic_change_processor.h b/components/sync_driver/fake_generic_change_processor.h
index 671e0fc..faae4bc 100644
--- a/components/sync_driver/fake_generic_change_processor.h
+++ b/components/sync_driver/fake_generic_change_processor.h
@@ -10,13 +10,15 @@
#include "components/sync_driver/generic_change_processor_factory.h"
#include "components/sync_driver/sync_api_component_factory.h"
#include "sync/api/sync_error.h"
+#include "sync/internal_api/public/base/model_type.h"
namespace sync_driver {
// A fake GenericChangeProcessor that can return arbitrary values.
class FakeGenericChangeProcessor : public GenericChangeProcessor {
public:
- FakeGenericChangeProcessor(SyncApiComponentFactory* sync_factory);
+ FakeGenericChangeProcessor(syncer::ModelType type,
+ SyncApiComponentFactory* sync_factory);
virtual ~FakeGenericChangeProcessor();
// Setters for GenericChangeProcessor implementation results.
@@ -28,14 +30,11 @@ class FakeGenericChangeProcessor : public GenericChangeProcessor {
const tracked_objects::Location& from_here,
const syncer::SyncChangeList& change_list) OVERRIDE;
virtual syncer::SyncError GetAllSyncDataReturnError(
- syncer::ModelType type,
syncer::SyncDataList* data) const OVERRIDE;
- virtual bool GetDataTypeContext(syncer::ModelType type,
- std::string* context) const OVERRIDE;
- virtual int GetSyncCountForType(syncer::ModelType type) OVERRIDE;
- virtual bool SyncModelHasUserCreatedNodes(syncer::ModelType type,
- bool* has_nodes) OVERRIDE;
- virtual bool CryptoReadyIfNecessary(syncer::ModelType type) OVERRIDE;
+ virtual bool GetDataTypeContext(std::string* context) const OVERRIDE;
+ virtual int GetSyncCount() OVERRIDE;
+ virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) OVERRIDE;
+ virtual bool CryptoReadyIfNecessary() OVERRIDE;
private:
bool sync_model_has_user_created_nodes_;
@@ -49,6 +48,7 @@ class FakeGenericChangeProcessorFactory : public GenericChangeProcessorFactory {
scoped_ptr<FakeGenericChangeProcessor> processor);
virtual ~FakeGenericChangeProcessorFactory();
virtual scoped_ptr<GenericChangeProcessor> CreateGenericChangeProcessor(
+ syncer::ModelType type,
syncer::UserShare* user_share,
DataTypeErrorHandler* error_handler,
const base::WeakPtr<syncer::SyncableService>& local_service,
diff --git a/components/sync_driver/generic_change_processor.cc b/components/sync_driver/generic_change_processor.cc
index 9bfd0c2..08238e5 100644
--- a/components/sync_driver/generic_change_processor.cc
+++ b/components/sync_driver/generic_change_processor.cc
@@ -88,6 +88,7 @@ syncer::SyncData BuildRemoteSyncData(
} // namespace
GenericChangeProcessor::GenericChangeProcessor(
+ syncer::ModelType type,
DataTypeErrorHandler* error_handler,
const base::WeakPtr<syncer::SyncableService>& local_service,
const base::WeakPtr<syncer::SyncMergeResult>& merge_result,
@@ -95,11 +96,13 @@ GenericChangeProcessor::GenericChangeProcessor(
SyncApiComponentFactory* sync_factory,
const scoped_refptr<syncer::AttachmentStore>& attachment_store)
: ChangeProcessor(error_handler),
+ type_(type),
local_service_(local_service),
merge_result_(merge_result),
share_handle_(user_share),
weak_ptr_factory_(this) {
DCHECK(CalledOnValidThread());
+ DCHECK_NE(type_, syncer::UNSPECIFIED);
if (attachment_store.get()) {
attachment_service_ = sync_factory->CreateAttachmentService(
attachment_store, *user_share, this);
@@ -192,9 +195,10 @@ void GenericChangeProcessor::CommitChangesFromSyncModel() {
syncer::SyncDataList GenericChangeProcessor::GetAllSyncData(
syncer::ModelType type) const {
+ DCHECK_EQ(type_, type);
// This is slow / memory intensive. Should be used sparingly by datatypes.
syncer::SyncDataList data;
- GetAllSyncDataReturnError(type, &data);
+ GetAllSyncDataReturnError(&data);
return data;
}
@@ -203,6 +207,7 @@ syncer::SyncError GenericChangeProcessor::UpdateDataTypeContext(
syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status,
const std::string& context) {
DCHECK(syncer::ProtocolTypes().Has(type));
+ DCHECK_EQ(type_, type);
if (context.size() > static_cast<size_t>(kContextSizeLimit)) {
return syncer::SyncError(FROM_HERE,
@@ -227,24 +232,23 @@ void GenericChangeProcessor::OnAttachmentUploaded(
}
syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError(
- syncer::ModelType type,
syncer::SyncDataList* current_sync_data) const {
DCHECK(CalledOnValidThread());
- std::string type_name = syncer::ModelTypeToString(type);
+ std::string type_name = syncer::ModelTypeToString(type_);
syncer::ReadTransaction trans(FROM_HERE, share_handle());
syncer::ReadNode root(&trans);
- if (root.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) {
+ if (root.InitTypeRoot(type_) != syncer::BaseNode::INIT_OK) {
syncer::SyncError error(FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
"Server did not create the top-level " + type_name +
" node. We might be running against an out-of-"
"date server.",
- type);
+ type_);
return error;
}
// TODO(akalin): We'll have to do a tree traversal for bookmarks.
- DCHECK_NE(type, syncer::BOOKMARKS);
+ DCHECK_NE(type_, syncer::BOOKMARKS);
std::vector<int64> child_ids;
root.GetChildIds(&child_ids);
@@ -254,11 +258,11 @@ syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError(
syncer::ReadNode sync_child_node(&trans);
if (sync_child_node.InitByIdLookup(*it) !=
syncer::BaseNode::INIT_OK) {
- syncer::SyncError error(FROM_HERE,
- syncer::SyncError::DATATYPE_ERROR,
- "Failed to fetch child node for type " +
- type_name + ".",
- type);
+ syncer::SyncError error(
+ FROM_HERE,
+ syncer::SyncError::DATATYPE_ERROR,
+ "Failed to fetch child node for type " + type_name + ".",
+ type_);
return error;
}
current_sync_data->push_back(BuildRemoteSyncData(
@@ -267,25 +271,24 @@ syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError(
return syncer::SyncError();
}
-bool GenericChangeProcessor::GetDataTypeContext(syncer::ModelType type,
- std::string* context) const {
+bool GenericChangeProcessor::GetDataTypeContext(std::string* context) const {
syncer::ReadTransaction trans(FROM_HERE, share_handle());
sync_pb::DataTypeContext context_proto;
- trans.GetDataTypeContext(type, &context_proto);
+ trans.GetDataTypeContext(type_, &context_proto);
if (!context_proto.has_context())
return false;
- DCHECK_EQ(type,
+ DCHECK_EQ(type_,
syncer::GetModelTypeFromSpecificsFieldNumber(
context_proto.data_type_id()));
*context = context_proto.context();
return true;
}
-int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) {
+int GenericChangeProcessor::GetSyncCount() {
syncer::ReadTransaction trans(FROM_HERE, share_handle());
syncer::ReadNode root(&trans);
- if (root.InitTypeRoot(type) != syncer::BaseNode::INIT_OK)
+ if (root.InitTypeRoot(type_) != syncer::BaseNode::INIT_OK)
return 0;
// Subtract one to account for type's root node.
@@ -409,19 +412,16 @@ syncer::SyncError GenericChangeProcessor::ProcessSyncChanges(
syncer::WriteTransaction trans(from_here, share_handle());
- syncer::ModelType type = syncer::UNSPECIFIED;
-
for (syncer::SyncChangeList::const_iterator iter = list_of_changes.begin();
iter != list_of_changes.end();
++iter) {
const syncer::SyncChange& change = *iter;
- DCHECK_NE(change.sync_data().GetDataType(), syncer::UNSPECIFIED);
- type = change.sync_data().GetDataType();
- std::string type_str = syncer::ModelTypeToString(type);
+ DCHECK_EQ(change.sync_data().GetDataType(), type_);
+ std::string type_str = syncer::ModelTypeToString(type_);
syncer::WriteNode sync_node(&trans);
if (change.change_type() == syncer::SyncChange::ACTION_DELETE) {
syncer::SyncError error =
- AttemptDelete(change, type, type_str, &sync_node, error_handler());
+ AttemptDelete(change, type_, type_str, &sync_node, error_handler());
if (error.IsSet()) {
NOTREACHED();
return error;
@@ -432,13 +432,13 @@ syncer::SyncError GenericChangeProcessor::ProcessSyncChanges(
}
} else if (change.change_type() == syncer::SyncChange::ACTION_ADD) {
syncer::SyncError error = HandleActionAdd(
- change, type_str, type, trans, &sync_node, &new_attachments);
+ change, type_str, trans, &sync_node, &new_attachments);
if (error.IsSet()) {
return error;
}
} else if (change.change_type() == syncer::SyncChange::ACTION_UPDATE) {
syncer::SyncError error = HandleActionUpdate(
- change, type_str, type, trans, &sync_node, &new_attachments);
+ change, type_str, trans, &sync_node, &new_attachments);
if (error.IsSet()) {
return error;
}
@@ -448,7 +448,7 @@ syncer::SyncError GenericChangeProcessor::ProcessSyncChanges(
syncer::SyncError::DATATYPE_ERROR,
"Received unset SyncChange in the change processor, " +
change.location().ToString(),
- type);
+ type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
NOTREACHED();
LOG(ERROR) << "Unset sync change.";
@@ -460,13 +460,12 @@ syncer::SyncError GenericChangeProcessor::ProcessSyncChanges(
// If datatype uses attachments it should have supplied attachment store
// which would initialize attachment_service_. Fail if it isn't so.
if (!attachment_service_.get()) {
- DCHECK_NE(type, syncer::UNSPECIFIED);
syncer::SyncError error(
FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
"Datatype performs attachment operation without initializing "
"attachment store",
- type);
+ type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
NOTREACHED();
return error;
@@ -484,7 +483,6 @@ syncer::SyncError GenericChangeProcessor::ProcessSyncChanges(
syncer::SyncError GenericChangeProcessor::HandleActionAdd(
const syncer::SyncChange& change,
const std::string& type_str,
- const syncer::ModelType& type,
const syncer::WriteTransaction& trans,
syncer::WriteNode* sync_node,
syncer::AttachmentIdList* new_attachments) {
@@ -497,7 +495,7 @@ syncer::SyncError GenericChangeProcessor::HandleActionAdd(
syncer::SyncError error(FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
"Failed to look up root node for type " + type_str,
- type);
+ type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
NOTREACHED();
LOG(ERROR) << "Create: no root node.";
@@ -512,21 +510,21 @@ syncer::SyncError GenericChangeProcessor::HandleActionAdd(
switch (result) {
case syncer::WriteNode::INIT_FAILED_EMPTY_TAG: {
syncer::SyncError error;
- error.Reset(FROM_HERE, error_prefix + "empty tag", type);
+ error.Reset(FROM_HERE, error_prefix + "empty tag", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Create: Empty tag.";
return error;
}
case syncer::WriteNode::INIT_FAILED_ENTRY_ALREADY_EXISTS: {
syncer::SyncError error;
- error.Reset(FROM_HERE, error_prefix + "entry already exists", type);
+ error.Reset(FROM_HERE, error_prefix + "entry already exists", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Create: Entry exists.";
return error;
}
case syncer::WriteNode::INIT_FAILED_COULD_NOT_CREATE_ENTRY: {
syncer::SyncError error;
- error.Reset(FROM_HERE, error_prefix + "failed to create entry", type);
+ error.Reset(FROM_HERE, error_prefix + "failed to create entry", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Create: Could not create entry.";
return error;
@@ -534,14 +532,14 @@ syncer::SyncError GenericChangeProcessor::HandleActionAdd(
case syncer::WriteNode::INIT_FAILED_SET_PREDECESSOR: {
syncer::SyncError error;
error.Reset(
- FROM_HERE, error_prefix + "failed to set predecessor", type);
+ FROM_HERE, error_prefix + "failed to set predecessor", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Create: Bad predecessor.";
return error;
}
default: {
syncer::SyncError error;
- error.Reset(FROM_HERE, error_prefix + "unknown error", type);
+ error.Reset(FROM_HERE, error_prefix + "unknown error", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Create: Unknown error.";
return error;
@@ -569,7 +567,6 @@ syncer::SyncError GenericChangeProcessor::HandleActionAdd(
syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
const syncer::SyncChange& change,
const std::string& type_str,
- const syncer::ModelType& type,
const syncer::WriteTransaction& trans,
syncer::WriteNode* sync_node,
syncer::AttachmentIdList* new_attachments) {
@@ -584,19 +581,19 @@ syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
change.location().ToString() + ", ";
if (result == syncer::BaseNode::INIT_FAILED_PRECONDITION) {
syncer::SyncError error;
- error.Reset(FROM_HERE, error_prefix + "empty tag", type);
+ error.Reset(FROM_HERE, error_prefix + "empty tag", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Update: Empty tag.";
return error;
} else if (result == syncer::BaseNode::INIT_FAILED_ENTRY_NOT_GOOD) {
syncer::SyncError error;
- error.Reset(FROM_HERE, error_prefix + "bad entry", type);
+ error.Reset(FROM_HERE, error_prefix + "bad entry", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Update: bad entry.";
return error;
} else if (result == syncer::BaseNode::INIT_FAILED_ENTRY_IS_DEL) {
syncer::SyncError error;
- error.Reset(FROM_HERE, error_prefix + "deleted entry", type);
+ error.Reset(FROM_HERE, error_prefix + "deleted entry", type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Update: deleted entry.";
return error;
@@ -607,14 +604,14 @@ syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
sync_node->GetEntry()->GetSpecifics();
CHECK(specifics.has_encrypted());
const bool can_decrypt = crypto->CanDecrypt(specifics.encrypted());
- const bool agreement = encrypted_types.Has(type);
+ const bool agreement = encrypted_types.Has(type_);
if (!agreement && !can_decrypt) {
syncer::SyncError error;
error.Reset(FROM_HERE,
"Failed to load encrypted entry, missing key and "
"nigori mismatch for " +
type_str + ".",
- type);
+ type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Update: encr case 1.";
return error;
@@ -624,7 +621,7 @@ syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
"Failed to load encrypted entry, we have the key "
"and the nigori matches (?!) for " +
type_str + ".",
- type);
+ type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Update: encr case 2.";
return error;
@@ -634,7 +631,7 @@ syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
"Failed to load encrypted entry, missing key and "
"the nigori matches for " +
type_str + ".",
- type);
+ type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Update: encr case 3.";
return error;
@@ -644,7 +641,7 @@ syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
"Failed to load encrypted entry, we have the key"
"(?!) and nigori mismatch for " +
type_str + ".",
- type);
+ type_);
error_handler()->OnSingleDataTypeUnrecoverableError(error);
LOG(ERROR) << "Update: encr case 4.";
return error;
@@ -670,19 +667,16 @@ syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
return syncer::SyncError();
}
-bool GenericChangeProcessor::SyncModelHasUserCreatedNodes(
- syncer::ModelType type,
- bool* has_nodes) {
+bool GenericChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) {
DCHECK(CalledOnValidThread());
DCHECK(has_nodes);
- DCHECK_NE(type, syncer::UNSPECIFIED);
- std::string type_name = syncer::ModelTypeToString(type);
+ std::string type_name = syncer::ModelTypeToString(type_);
std::string err_str = "Server did not create the top-level " + type_name +
" node. We might be running against an out-of-date server.";
*has_nodes = false;
syncer::ReadTransaction trans(FROM_HERE, share_handle());
syncer::ReadNode type_root_node(&trans);
- if (type_root_node.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) {
+ if (type_root_node.InitTypeRoot(type_) != syncer::BaseNode::INIT_OK) {
LOG(ERROR) << err_str;
return false;
}
@@ -693,14 +687,12 @@ bool GenericChangeProcessor::SyncModelHasUserCreatedNodes(
return true;
}
-bool GenericChangeProcessor::CryptoReadyIfNecessary(syncer::ModelType type) {
+bool GenericChangeProcessor::CryptoReadyIfNecessary() {
DCHECK(CalledOnValidThread());
- DCHECK_NE(type, syncer::UNSPECIFIED);
// We only access the cryptographer while holding a transaction.
syncer::ReadTransaction trans(FROM_HERE, share_handle());
const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
- return !encrypted_types.Has(type) ||
- trans.GetCryptographer()->is_ready();
+ return !encrypted_types.Has(type_) || trans.GetCryptographer()->is_ready();
}
void GenericChangeProcessor::StartImpl() {
diff --git a/components/sync_driver/generic_change_processor.h b/components/sync_driver/generic_change_processor.h
index f76fba5e..05a7368 100644
--- a/components/sync_driver/generic_change_processor.h
+++ b/components/sync_driver/generic_change_processor.h
@@ -44,10 +44,11 @@ class GenericChangeProcessor : public ChangeProcessor,
public syncer::AttachmentService::Delegate,
public base::NonThreadSafe {
public:
- // Create a change processor and connect it to the syncer.
+ // Create a change processor for |type| and connect it to the syncer.
// |attachment_store| can be NULL which means that datatype will not use sync
// attachments.
GenericChangeProcessor(
+ syncer::ModelType type,
DataTypeErrorHandler* error_handler,
const base::WeakPtr<syncer::SyncableService>& local_service,
const base::WeakPtr<syncer::SyncMergeResult>& merge_result,
@@ -84,23 +85,20 @@ class GenericChangeProcessor : public ChangeProcessor,
// Similar to above, but returns a SyncError for use by direct clients
// of GenericChangeProcessor that may need more error visibility.
virtual syncer::SyncError GetAllSyncDataReturnError(
- syncer::ModelType type,
syncer::SyncDataList* data) const;
- // If a datatype context associated with |type| exists, fills |context| and
- // returns true. Otheriwse, if there has not been a context set, returns
- // false.
- virtual bool GetDataTypeContext(syncer::ModelType type,
- std::string* context) const;
+ // If a datatype context associated with this GenericChangeProcessor's type
+ // exists, fills |context| and returns true. Otheriwse, if there has not been
+ // a context set, returns false.
+ virtual bool GetDataTypeContext(std::string* context) const;
// Returns the number of items for this type.
- virtual int GetSyncCountForType(syncer::ModelType type);
+ virtual int GetSyncCount();
// Generic versions of AssociatorInterface methods. Called by
// syncer::SyncableServiceAdapter or the DataTypeController.
- virtual bool SyncModelHasUserCreatedNodes(syncer::ModelType type,
- bool* has_nodes);
- virtual bool CryptoReadyIfNecessary(syncer::ModelType type);
+ virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes);
+ virtual bool CryptoReadyIfNecessary();
protected:
// ChangeProcessor interface.
@@ -114,7 +112,6 @@ class GenericChangeProcessor : public ChangeProcessor,
// that need to be stored. This method will append to it.
syncer::SyncError HandleActionAdd(const syncer::SyncChange& change,
const std::string& type_str,
- const syncer::ModelType& type,
const syncer::WriteTransaction& trans,
syncer::WriteNode* sync_node,
syncer::AttachmentIdList* new_attachments);
@@ -126,7 +123,6 @@ class GenericChangeProcessor : public ChangeProcessor,
syncer::SyncError HandleActionUpdate(
const syncer::SyncChange& change,
const std::string& type_str,
- const syncer::ModelType& type,
const syncer::WriteTransaction& trans,
syncer::WriteNode* sync_node,
syncer::AttachmentIdList* new_attachments);
@@ -137,6 +133,8 @@ class GenericChangeProcessor : public ChangeProcessor,
// AttachmentStore.
void UploadAttachments(const syncer::AttachmentIdList& attachment_ids);
+ const syncer::ModelType type_;
+
// The SyncableService this change processor will forward changes on to.
const base::WeakPtr<syncer::SyncableService> local_service_;
diff --git a/components/sync_driver/generic_change_processor_factory.cc b/components/sync_driver/generic_change_processor_factory.cc
index 501e699..1a7a8d9 100644
--- a/components/sync_driver/generic_change_processor_factory.cc
+++ b/components/sync_driver/generic_change_processor_factory.cc
@@ -16,6 +16,7 @@ GenericChangeProcessorFactory::~GenericChangeProcessorFactory() {}
scoped_ptr<GenericChangeProcessor>
GenericChangeProcessorFactory::CreateGenericChangeProcessor(
+ syncer::ModelType type,
syncer::UserShare* user_share,
DataTypeErrorHandler* error_handler,
const base::WeakPtr<syncer::SyncableService>& local_service,
@@ -23,6 +24,7 @@ GenericChangeProcessorFactory::CreateGenericChangeProcessor(
SyncApiComponentFactory* sync_factory) {
DCHECK(user_share);
return make_scoped_ptr(new GenericChangeProcessor(
+ type,
error_handler,
local_service,
merge_result,
diff --git a/components/sync_driver/generic_change_processor_factory.h b/components/sync_driver/generic_change_processor_factory.h
index 5ed06a5..0407eb0 100644
--- a/components/sync_driver/generic_change_processor_factory.h
+++ b/components/sync_driver/generic_change_processor_factory.h
@@ -6,6 +6,7 @@
#define COMPONENTS_SYNC_DRIVER_GENERIC_CHANGE_PROCESSOR_FACTORY_H_
#include "base/memory/weak_ptr.h"
+#include "sync/internal_api/public/base/model_type.h"
namespace syncer {
class AttachmentService;
@@ -34,6 +35,7 @@ class GenericChangeProcessorFactory {
GenericChangeProcessorFactory();
virtual ~GenericChangeProcessorFactory();
virtual scoped_ptr<GenericChangeProcessor> CreateGenericChangeProcessor(
+ syncer::ModelType type,
syncer::UserShare* user_share,
DataTypeErrorHandler* error_handler,
const base::WeakPtr<syncer::SyncableService>& local_service,
diff --git a/components/sync_driver/generic_change_processor_unittest.cc b/components/sync_driver/generic_change_processor_unittest.cc
index ce20575..623a509 100644
--- a/components/sync_driver/generic_change_processor_unittest.cc
+++ b/components/sync_driver/generic_change_processor_unittest.cc
@@ -102,24 +102,46 @@ class MockSyncApiComponentFactory : public SyncApiComponentFactory {
class SyncGenericChangeProcessorTest : public testing::Test {
public:
- // It doesn't matter which type we use. Just pick one.
+ // Most test cases will use this type. For those that need a
+ // GenericChangeProcessor for a different type, use |InitializeForType|.
static const syncer::ModelType kType = syncer::PREFERENCES;
SyncGenericChangeProcessorTest()
- : sync_merge_result_(kType),
- merge_result_ptr_factory_(&sync_merge_result_),
- syncable_service_ptr_factory_(&fake_syncable_service_),
+ : syncable_service_ptr_factory_(&fake_syncable_service_),
mock_attachment_service_(NULL) {}
virtual void SetUp() OVERRIDE {
- test_user_share_.SetUp();
+ // Use kType by default, but allow test cases to re-initialize with whatever
+ // type they choose. Therefore, it's important that all type dependent
+ // initialization occurs in InitializeForType.
+ InitializeForType(kType);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ mock_attachment_service_ = NULL;
+ if (test_user_share_) {
+ test_user_share_->TearDown();
+ }
+ }
+
+ // Initialize GenericChangeProcessor and related classes for testing with
+ // model type |type|.
+ void InitializeForType(syncer::ModelType type) {
+ TearDown();
+ test_user_share_.reset(new syncer::TestUserShare);
+ test_user_share_->SetUp();
+ sync_merge_result_.reset(new syncer::SyncMergeResult(type));
+ merge_result_ptr_factory_.reset(
+ new base::WeakPtrFactory<syncer::SyncMergeResult>(
+ sync_merge_result_.get()));
+
syncer::ModelTypeSet types = syncer::ProtocolTypes();
for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good();
iter.Inc()) {
syncer::TestUserShare::CreateRoot(iter.Get(),
- test_user_share_.user_share());
+ test_user_share_->user_share());
}
- test_user_share_.encryption_handler()->Init();
+ test_user_share_->encryption_handler()->Init();
scoped_refptr<syncer::AttachmentStore> attachment_store(
new syncer::FakeAttachmentStore(base::MessageLoopProxy::current()));
@@ -133,26 +155,22 @@ class SyncGenericChangeProcessorTest : public testing::Test {
sync_factory_.reset(new MockSyncApiComponentFactory(
mock_attachment_service.PassAs<syncer::AttachmentService>()));
change_processor_.reset(
- new GenericChangeProcessor(&data_type_error_handler_,
+ new GenericChangeProcessor(type,
+ &data_type_error_handler_,
syncable_service_ptr_factory_.GetWeakPtr(),
- merge_result_ptr_factory_.GetWeakPtr(),
- test_user_share_.user_share(),
+ merge_result_ptr_factory_->GetWeakPtr(),
+ test_user_share_->user_share(),
sync_factory_.get(),
attachment_store));
}
- virtual void TearDown() OVERRIDE {
- mock_attachment_service_ = NULL;
- test_user_share_.TearDown();
- }
-
- void BuildChildNodes(int n) {
+ void BuildChildNodes(syncer::ModelType type, int n) {
syncer::WriteTransaction trans(FROM_HERE, user_share());
syncer::ReadNode root(&trans);
- ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(kType));
+ ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(type));
for (int i = 0; i < n; ++i) {
syncer::WriteNode node(&trans);
- node.InitUniqueByCreation(kType, root, base::StringPrintf("node%05d", i));
+ node.InitUniqueByCreation(type, root, base::StringPrintf("node%05d", i));
}
}
@@ -161,7 +179,7 @@ class SyncGenericChangeProcessorTest : public testing::Test {
}
syncer::UserShare* user_share() {
- return test_user_share_.user_share();
+ return test_user_share_->user_share();
}
MockAttachmentService* mock_attachment_service() {
@@ -176,15 +194,16 @@ class SyncGenericChangeProcessorTest : public testing::Test {
private:
base::MessageLoopForUI loop_;
- syncer::SyncMergeResult sync_merge_result_;
- base::WeakPtrFactory<syncer::SyncMergeResult> merge_result_ptr_factory_;
+ scoped_ptr<syncer::SyncMergeResult> sync_merge_result_;
+ scoped_ptr<base::WeakPtrFactory<syncer::SyncMergeResult> >
+ merge_result_ptr_factory_;
syncer::FakeSyncableService fake_syncable_service_;
base::WeakPtrFactory<syncer::FakeSyncableService>
syncable_service_ptr_factory_;
DataTypeErrorHandlerMock data_type_error_handler_;
- syncer::TestUserShare test_user_share_;
+ scoped_ptr<syncer::TestUserShare> test_user_share_;
MockAttachmentService* mock_attachment_service_;
scoped_ptr<SyncApiComponentFactory> sync_factory_;
@@ -197,7 +216,7 @@ TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) {
const int kNumChildNodes = 1000;
const int kRepeatCount = 1;
- ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kNumChildNodes));
+ ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kType, kNumChildNodes));
for (int i = 0; i < kRepeatCount; ++i) {
syncer::SyncDataList sync_data =
@@ -209,6 +228,7 @@ TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) {
}
TEST_F(SyncGenericChangeProcessorTest, SetGetPasswords) {
+ InitializeForType(syncer::PASSWORDS);
const int kNumPasswords = 10;
sync_pb::PasswordSpecificsData password_data;
password_data.set_username_value("user");
@@ -266,6 +286,7 @@ TEST_F(SyncGenericChangeProcessorTest, SetGetPasswords) {
}
TEST_F(SyncGenericChangeProcessorTest, UpdatePasswords) {
+ InitializeForType(syncer::PASSWORDS);
const int kNumPasswords = 10;
sync_pb::PasswordSpecificsData password_data;
password_data.set_username_value("user");
@@ -420,8 +441,7 @@ TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) {
change_processor()->OnAttachmentUploaded(attachment_id);
syncer::ReadTransaction read_transaction(FROM_HERE, user_share());
syncer::ReadNode node(&read_transaction);
- ASSERT_EQ(node.InitByClientTagLookup(syncer::PREFERENCES, tag),
- syncer::BaseNode::INIT_OK);
+ ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK);
attachment_ids = node.GetAttachmentIds();
EXPECT_EQ(1U, attachment_ids.size());
}
diff --git a/components/sync_driver/shared_change_processor.cc b/components/sync_driver/shared_change_processor.cc
index 945f9c6..c1cf407 100644
--- a/components/sync_driver/shared_change_processor.cc
+++ b/components/sync_driver/shared_change_processor.cc
@@ -67,7 +67,8 @@ base::WeakPtr<syncer::SyncableService> SharedChangeProcessor::Connect(
}
generic_change_processor_ =
- processor_factory->CreateGenericChangeProcessor(user_share,
+ processor_factory->CreateGenericChangeProcessor(type,
+ user_share,
error_handler,
local_service,
merge_result,
@@ -97,7 +98,7 @@ int SharedChangeProcessor::GetSyncCount() {
LOG(ERROR) << "Change processor disconnected.";
return 0;
}
- return generic_change_processor_->GetSyncCountForType(type_);
+ return generic_change_processor_->GetSyncCount();
}
syncer::SyncError SharedChangeProcessor::ProcessSyncChanges(
@@ -139,7 +140,7 @@ syncer::SyncError SharedChangeProcessor::GetAllSyncDataReturnError(
type_);
return error;
}
- return generic_change_processor_->GetAllSyncDataReturnError(type, data);
+ return generic_change_processor_->GetAllSyncDataReturnError(data);
}
syncer::SyncError SharedChangeProcessor::UpdateDataTypeContext(
@@ -168,8 +169,7 @@ bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) {
LOG(ERROR) << "Change processor disconnected.";
return false;
}
- return generic_change_processor_->SyncModelHasUserCreatedNodes(
- type_, has_nodes);
+ return generic_change_processor_->SyncModelHasUserCreatedNodes(has_nodes);
}
bool SharedChangeProcessor::CryptoReadyIfNecessary() {
@@ -180,7 +180,7 @@ bool SharedChangeProcessor::CryptoReadyIfNecessary() {
LOG(ERROR) << "Change processor disconnected.";
return true; // Otherwise we get into infinite spin waiting.
}
- return generic_change_processor_->CryptoReadyIfNecessary(type_);
+ return generic_change_processor_->CryptoReadyIfNecessary();
}
bool SharedChangeProcessor::GetDataTypeContext(std::string* context) const {
@@ -191,7 +191,7 @@ bool SharedChangeProcessor::GetDataTypeContext(std::string* context) const {
LOG(ERROR) << "Change processor disconnected.";
return false;
}
- return generic_change_processor_->GetDataTypeContext(type_, context);
+ return generic_change_processor_->GetDataTypeContext(context);
}
syncer::SyncError SharedChangeProcessor::CreateAndUploadError(
diff --git a/components/sync_driver/ui_data_type_controller_unittest.cc b/components/sync_driver/ui_data_type_controller_unittest.cc
index e34dce2..da61cb7 100644
--- a/components/sync_driver/ui_data_type_controller_unittest.cc
+++ b/components/sync_driver/ui_data_type_controller_unittest.cc
@@ -65,7 +65,7 @@ class SyncUIDataTypeControllerTest : public testing::Test,
protected:
void SetStartExpectations() {
scoped_ptr<FakeGenericChangeProcessor> p(
- new FakeGenericChangeProcessor(this));
+ new FakeGenericChangeProcessor(type_, this));
change_processor_ = p.get();
scoped_ptr<GenericChangeProcessorFactory> f(
new FakeGenericChangeProcessorFactory(p.Pass()));