Commit dc4d0153 authored by thestig@chromium.org's avatar thestig@chromium.org

Revert of sync: Add non-blocking type encryption support...

Revert of sync: Add non-blocking type encryption support (https://codereview.chromium.org/423193002/)

Reason for revert:
Both LSAN and Valgrind complains about leaks in the tests.

Original issue's description:
> sync: Add non-blocking type encryption support
> 
> Introduces the framework for dealing with sync encryption in
> non-blocking types.  Unlike directory sync types, non-blocking type
> encryption only encrypts data before it is sent to the server.
> Encrypting the data on-disk is a separate problem.
> 
> Adds code to the ModelTypeSyncWorker so it can access the directory's
> cryptographer (through a CryptographerProvider interface) and use it to
> encrypt entities before it sends them to the server.  If the
> cryptographer is unable to encrypt with the desired key, the worker will
> not commit until the cryptographer returns to a good state.
> 
> Adds the concept of a "desired encryption key" to the data type state.
> When the cryptographer key to be used to encrypt a type changes, this
> will be reflected in the data type state.  The ModelTypeSyncProxy is
> responsible for ensuring that all items which have not yet been
> encrypted with this desired key are enqueued for commit.
> 
> Makes the ModelTypeSyncWorker, EntityTracker, and ModelTypeSyncProxy
> collaborate on the management of undecryptable (inapplicable) updates.
> The EntityTracker keeps track of their version numbers and content, and
> prevents the committing of new items to the server until the
> inapplicable update has been dealt with.  The ModelTypeSyncProxy is
> responsible for saving inapplicable updates across restarts.
> 
> This CL alone is not enough to enable encryption support for
> non-blocking types.  It requires additional code to hook up the
> ModelTypeSyncWorkers to receive cryptographer events.  This will be
> added in a future commit.  In the meantime, this CL includes plenty
> of unit tests to verify the functionality that's being added.
> 
> BUG=351005
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=287428

TBR=zea@chromium.org,stanisc@chromium.org,rlarocque@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=351005

Review URL: https://codereview.chromium.org/442623002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287433 0039d316-1c4b-4281-b951-d872f2087c98
parent f5840b7d
...@@ -85,7 +85,6 @@ class MockSyncContextProxy : public syncer::SyncContextProxy { ...@@ -85,7 +85,6 @@ class MockSyncContextProxy : public syncer::SyncContextProxy {
virtual void ConnectTypeToSync( virtual void ConnectTypeToSync(
syncer::ModelType type, syncer::ModelType type,
const syncer::DataTypeState& data_type_state, const syncer::DataTypeState& data_type_state,
const syncer::UpdateResponseDataList& saved_pending_updates,
const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_proxy) const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_proxy)
OVERRIDE { OVERRIDE {
// Normally we'd use MessageLoopProxy::current() as the TaskRunner argument // Normally we'd use MessageLoopProxy::current() as the TaskRunner argument
......
...@@ -193,14 +193,8 @@ void EntityTracker::ReceiveCommitResponse(const std::string& response_id, ...@@ -193,14 +193,8 @@ void EntityTracker::ReceiveCommitResponse(const std::string& response_id,
} }
void EntityTracker::ReceiveUpdate(int64 version) { void EntityTracker::ReceiveUpdate(int64 version) {
if (version <= highest_gu_response_version_) highest_gu_response_version_ =
return; std::max(highest_gu_response_version_, version);
highest_gu_response_version_ = version;
// Got an applicable update newer than any pending updates. It must be safe
// to discard the old pending update, if there was one.
ClearPendingUpdate();
if (IsInConflict()) { if (IsInConflict()) {
// Incoming update clobbers the pending commit on the sync thread. // Incoming update clobbers the pending commit on the sync thread.
...@@ -209,35 +203,10 @@ void EntityTracker::ReceiveUpdate(int64 version) { ...@@ -209,35 +203,10 @@ void EntityTracker::ReceiveUpdate(int64 version) {
} }
} }
bool EntityTracker::ReceivePendingUpdate(const UpdateResponseData& data) {
if (data.response_version < highest_gu_response_version_)
return false;
highest_gu_response_version_ = data.response_version;
pending_update_.reset(new UpdateResponseData(data));
ClearPendingCommit();
return true;
}
bool EntityTracker::HasPendingUpdate() const {
return !!pending_update_;
}
UpdateResponseData EntityTracker::GetPendingUpdate() const {
return *pending_update_;
}
void EntityTracker::ClearPendingUpdate() {
pending_update_.reset();
}
bool EntityTracker::IsInConflict() const { bool EntityTracker::IsInConflict() const {
if (!is_commit_pending_) if (!is_commit_pending_)
return false; return false;
if (HasPendingUpdate())
return true;
if (highest_gu_response_version_ <= highest_commit_response_version_) { if (highest_gu_response_version_ <= highest_commit_response_version_) {
// The most recent server state was created in a commit made by this // The most recent server state was created in a commit made by this
// client. We're fully up to date, and therefore not in conflict. // client. We're fully up to date, and therefore not in conflict.
......
...@@ -8,10 +8,8 @@ ...@@ -8,10 +8,8 @@
#include <string> #include <string>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "sync/base/sync_export.h" #include "sync/base/sync_export.h"
#include "sync/internal_api/public/non_blocking_sync_common.h"
#include "sync/protocol/sync.pb.h" #include "sync/protocol/sync.pb.h"
namespace syncer { namespace syncer {
...@@ -83,20 +81,6 @@ class SYNC_EXPORT EntityTracker { ...@@ -83,20 +81,6 @@ class SYNC_EXPORT EntityTracker {
// Handles receipt of an update from the server. // Handles receipt of an update from the server.
void ReceiveUpdate(int64 version); void ReceiveUpdate(int64 version);
// Handles the receipt of an pending update from the server.
//
// Returns true if the tracker decides this item is worth keeping. Returns
// false if the item is discarded, which could happen if the version number
// is out of date.
bool ReceivePendingUpdate(const UpdateResponseData& data);
// Functions to fetch the latest pending update.
bool HasPendingUpdate() const;
UpdateResponseData GetPendingUpdate() const;
// Clears the pending update. Allows us to resume regular commit behavior.
void ClearPendingUpdate();
private: private:
// Initializes received update state. Does not initialize state related to // Initializes received update state. Does not initialize state related to
// pending commits and sets |is_commit_pending_| to false. // pending commits and sets |is_commit_pending_| to false.
...@@ -162,11 +146,6 @@ class SYNC_EXPORT EntityTracker { ...@@ -162,11 +146,6 @@ class SYNC_EXPORT EntityTracker {
bool deleted_; bool deleted_;
sync_pb::EntitySpecifics specifics_; sync_pb::EntitySpecifics specifics_;
// An update for this item which can't be applied right now. The presence of
// an pending update prevents commits. As of this writing, the only source
// of pending updates is updates we can't decrypt right now.
scoped_ptr<UpdateResponseData> pending_update_;
DISALLOW_COPY_AND_ASSIGN(EntityTracker); DISALLOW_COPY_AND_ASSIGN(EntityTracker);
}; };
......
...@@ -24,8 +24,7 @@ scoped_ptr<ModelTypeEntity> ModelTypeEntity::NewLocalItem( ...@@ -24,8 +24,7 @@ scoped_ptr<ModelTypeEntity> ModelTypeEntity::NewLocalItem(
specifics, specifics,
false, false,
now, now,
now, now));
std::string()));
} }
scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate( scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate(
...@@ -36,8 +35,7 @@ scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate( ...@@ -36,8 +35,7 @@ scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate(
const sync_pb::EntitySpecifics& specifics, const sync_pb::EntitySpecifics& specifics,
bool deleted, bool deleted,
base::Time ctime, base::Time ctime,
base::Time mtime, base::Time mtime) {
const std::string& encryption_key_name) {
return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0, return scoped_ptr<ModelTypeEntity>(new ModelTypeEntity(0,
0, 0,
0, 0,
...@@ -49,8 +47,7 @@ scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate( ...@@ -49,8 +47,7 @@ scoped_ptr<ModelTypeEntity> ModelTypeEntity::FromServerUpdate(
specifics, specifics,
deleted, deleted,
ctime, ctime,
mtime, mtime));
encryption_key_name));
} }
ModelTypeEntity::ModelTypeEntity(int64 sequence_number, ModelTypeEntity::ModelTypeEntity(int64 sequence_number,
...@@ -64,8 +61,7 @@ ModelTypeEntity::ModelTypeEntity(int64 sequence_number, ...@@ -64,8 +61,7 @@ ModelTypeEntity::ModelTypeEntity(int64 sequence_number,
const sync_pb::EntitySpecifics& specifics, const sync_pb::EntitySpecifics& specifics,
bool deleted, bool deleted,
base::Time ctime, base::Time ctime,
base::Time mtime, base::Time mtime)
const std::string& encryption_key_name)
: sequence_number_(sequence_number), : sequence_number_(sequence_number),
commit_requested_sequence_number_(commit_requested_sequence_number), commit_requested_sequence_number_(commit_requested_sequence_number),
acked_sequence_number_(acked_sequence_number), acked_sequence_number_(acked_sequence_number),
...@@ -77,8 +73,7 @@ ModelTypeEntity::ModelTypeEntity(int64 sequence_number, ...@@ -77,8 +73,7 @@ ModelTypeEntity::ModelTypeEntity(int64 sequence_number,
specifics_(specifics), specifics_(specifics),
deleted_(deleted), deleted_(deleted),
ctime_(ctime), ctime_(ctime),
mtime_(mtime), mtime_(mtime) {
encryption_key_name_(encryption_key_name) {
} }
ModelTypeEntity::~ModelTypeEntity() { ModelTypeEntity::~ModelTypeEntity() {
...@@ -108,8 +103,7 @@ void ModelTypeEntity::ApplyUpdateFromServer( ...@@ -108,8 +103,7 @@ void ModelTypeEntity::ApplyUpdateFromServer(
int64 update_version, int64 update_version,
bool deleted, bool deleted,
const sync_pb::EntitySpecifics& specifics, const sync_pb::EntitySpecifics& specifics,
base::Time mtime, base::Time mtime) {
const std::string& encryption_key_name) {
// There was a conflict and the server just won it. // There was a conflict and the server just won it.
// This implicitly acks all outstanding commits because a received update // This implicitly acks all outstanding commits because a received update
// will clobber any pending commits on the sync thread. // will clobber any pending commits on the sync thread.
...@@ -127,15 +121,6 @@ void ModelTypeEntity::MakeLocalChange( ...@@ -127,15 +121,6 @@ void ModelTypeEntity::MakeLocalChange(
specifics_ = specifics; specifics_ = specifics;
} }
void ModelTypeEntity::UpdateDesiredEncryptionKey(const std::string& name) {
if (encryption_key_name_ == name)
return;
// Schedule commit with the expectation that the worker will re-encrypt with
// the latest encryption key as it does.
sequence_number_++;
}
void ModelTypeEntity::Delete() { void ModelTypeEntity::Delete() {
sequence_number_++; sequence_number_++;
specifics_.Clear(); specifics_.Clear();
...@@ -159,15 +144,12 @@ void ModelTypeEntity::SetCommitRequestInProgress() { ...@@ -159,15 +144,12 @@ void ModelTypeEntity::SetCommitRequestInProgress() {
commit_requested_sequence_number_ = sequence_number_; commit_requested_sequence_number_ = sequence_number_;
} }
void ModelTypeEntity::ReceiveCommitResponse( void ModelTypeEntity::ReceiveCommitResponse(const std::string& id,
const std::string& id, int64 sequence_number,
int64 sequence_number, int64 response_version) {
int64 response_version,
const std::string& encryption_key_name) {
id_ = id; // The server can assign us a new ID in a commit response. id_ = id; // The server can assign us a new ID in a commit response.
acked_sequence_number_ = sequence_number; acked_sequence_number_ = sequence_number;
base_version_ = response_version; base_version_ = response_version;
encryption_key_name_ = encryption_key_name;
} }
void ModelTypeEntity::ClearTransientSyncState() { void ModelTypeEntity::ClearTransientSyncState() {
......
...@@ -46,8 +46,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity { ...@@ -46,8 +46,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity {
const sync_pb::EntitySpecifics& specifics, const sync_pb::EntitySpecifics& specifics,
bool deleted, bool deleted,
base::Time ctime, base::Time ctime,
base::Time mtime, base::Time mtime);
const std::string& encryption_key_name);
// TODO(rlarocque): Implement FromDisk constructor when we implement storage. // TODO(rlarocque): Implement FromDisk constructor when we implement storage.
...@@ -80,17 +79,11 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity { ...@@ -80,17 +79,11 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity {
void ApplyUpdateFromServer(int64 update_version, void ApplyUpdateFromServer(int64 update_version,
bool deleted, bool deleted,
const sync_pb::EntitySpecifics& specifics, const sync_pb::EntitySpecifics& specifics,
base::Time mtime, base::Time mtime);
const std::string& encryption_key_name);
// Applies a local change to this item. // Applies a local change to this item.
void MakeLocalChange(const sync_pb::EntitySpecifics& specifics); void MakeLocalChange(const sync_pb::EntitySpecifics& specifics);
// Schedule a commit if the |name| does not match this item's last known
// encryption key. The worker that performs the commit is expected to
// encrypt the item using the latest available key.
void UpdateDesiredEncryptionKey(const std::string& name);
// Applies a local deletion to this item. // Applies a local deletion to this item.
void Delete(); void Delete();
...@@ -111,8 +104,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity { ...@@ -111,8 +104,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity {
// reached the server. // reached the server.
void ReceiveCommitResponse(const std::string& id, void ReceiveCommitResponse(const std::string& id,
int64 sequence_number, int64 sequence_number,
int64 response_version, int64 response_version);
const std::string& encryption_key_name);
// Clears any in-memory sync state associated with outstanding commits. // Clears any in-memory sync state associated with outstanding commits.
void ClearTransientSyncState(); void ClearTransientSyncState();
...@@ -132,8 +124,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity { ...@@ -132,8 +124,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity {
const sync_pb::EntitySpecifics& specifics, const sync_pb::EntitySpecifics& specifics,
bool deleted, bool deleted,
base::Time ctime, base::Time ctime,
base::Time mtime, base::Time mtime);
const std::string& encryption_key_name);
// A sequence number used to track in-progress commits. Each local change // A sequence number used to track in-progress commits. Each local change
// increments this number. // increments this number.
...@@ -194,10 +185,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity { ...@@ -194,10 +185,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeEntity {
// doesn't bother to inspect their values. // doesn't bother to inspect their values.
base::Time ctime_; base::Time ctime_;
base::Time mtime_; base::Time mtime_;
// The name of the encryption key used to encrypt this item on the server.
// Empty when no encryption is in use.
std::string encryption_key_name_;
}; };
} // namespace syncer } // namespace syncer
......
...@@ -64,8 +64,7 @@ TEST_F(ModelTypeEntityTest, FromServerUpdate) { ...@@ -64,8 +64,7 @@ TEST_F(ModelTypeEntityTest, FromServerUpdate) {
specifics, specifics,
false, false,
kCtime, kCtime,
kMtime, kMtime));
std::string()));
EXPECT_TRUE(entity->IsWriteRequired()); EXPECT_TRUE(entity->IsWriteRequired());
EXPECT_FALSE(entity->IsUnsynced()); EXPECT_FALSE(entity->IsUnsynced());
...@@ -88,8 +87,7 @@ TEST_F(ModelTypeEntityTest, TombstoneUpdate) { ...@@ -88,8 +87,7 @@ TEST_F(ModelTypeEntityTest, TombstoneUpdate) {
sync_pb::EntitySpecifics(), sync_pb::EntitySpecifics(),
true, true,
kCtime, kCtime,
kMtime, kMtime));
std::string()));
EXPECT_TRUE(entity->IsWriteRequired()); EXPECT_TRUE(entity->IsWriteRequired());
EXPECT_FALSE(entity->IsUnsynced()); EXPECT_FALSE(entity->IsUnsynced());
...@@ -109,15 +107,13 @@ TEST_F(ModelTypeEntityTest, ApplyUpdate) { ...@@ -109,15 +107,13 @@ TEST_F(ModelTypeEntityTest, ApplyUpdate) {
specifics, specifics,
false, false,
kCtime, kCtime,
kMtime, kMtime));
std::string()));
// A deletion update one version later. // A deletion update one version later.
entity->ApplyUpdateFromServer(11, entity->ApplyUpdateFromServer(11,
true, true,
sync_pb::EntitySpecifics(), sync_pb::EntitySpecifics(),
kMtime + base::TimeDelta::FromSeconds(10), kMtime + base::TimeDelta::FromSeconds(10));
std::string());
EXPECT_TRUE(entity->IsWriteRequired()); EXPECT_TRUE(entity->IsWriteRequired());
EXPECT_FALSE(entity->IsUnsynced()); EXPECT_FALSE(entity->IsUnsynced());
...@@ -134,8 +130,7 @@ TEST_F(ModelTypeEntityTest, LocalChange) { ...@@ -134,8 +130,7 @@ TEST_F(ModelTypeEntityTest, LocalChange) {
specifics, specifics,
false, false,
kCtime, kCtime,
kMtime, kMtime));
std::string()));
sync_pb::EntitySpecifics specifics2; sync_pb::EntitySpecifics specifics2;
specifics2.CopyFrom(specifics); specifics2.CopyFrom(specifics);
...@@ -161,8 +156,7 @@ TEST_F(ModelTypeEntityTest, LocalDeletion) { ...@@ -161,8 +156,7 @@ TEST_F(ModelTypeEntityTest, LocalDeletion) {
specifics, specifics,
false, false,
kCtime, kCtime,
kMtime, kMtime));
std::string()));
entity->Delete(); entity->Delete();
......
...@@ -21,8 +21,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxy { ...@@ -21,8 +21,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxy {
const CommitResponseDataList& response_list) = 0; const CommitResponseDataList& response_list) = 0;
virtual void OnUpdateReceived( virtual void OnUpdateReceived(
const DataTypeState& type_state, const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list) = 0;
const UpdateResponseDataList& pending_updates) = 0;
}; };
} // namespace syncer } // namespace syncer
......
...@@ -18,7 +18,6 @@ ModelTypeSyncProxyImpl::ModelTypeSyncProxyImpl(ModelType type) ...@@ -18,7 +18,6 @@ ModelTypeSyncProxyImpl::ModelTypeSyncProxyImpl(ModelType type)
is_preferred_(false), is_preferred_(false),
is_connected_(false), is_connected_(false),
entities_deleter_(&entities_), entities_deleter_(&entities_),
pending_updates_map_deleter_(&pending_updates_map_),
weak_ptr_factory_for_ui_(this), weak_ptr_factory_for_ui_(this),
weak_ptr_factory_for_sync_(this) { weak_ptr_factory_for_sync_(this) {
} }
...@@ -52,12 +51,10 @@ void ModelTypeSyncProxyImpl::Enable( ...@@ -52,12 +51,10 @@ void ModelTypeSyncProxyImpl::Enable(
data_type_state_.progress_marker.set_data_type_id( data_type_state_.progress_marker.set_data_type_id(
GetSpecificsFieldNumberFromModelType(type_)); GetSpecificsFieldNumberFromModelType(type_));
UpdateResponseDataList saved_pending_updates = GetPendingUpdates();
sync_context_proxy_ = sync_context_proxy.Pass(); sync_context_proxy_ = sync_context_proxy.Pass();
sync_context_proxy_->ConnectTypeToSync( sync_context_proxy_->ConnectTypeToSync(
GetModelType(), GetModelType(),
data_type_state_, data_type_state_,
saved_pending_updates,
weak_ptr_factory_for_sync_.GetWeakPtr()); weak_ptr_factory_for_sync_.GetWeakPtr());
} }
...@@ -183,18 +180,16 @@ void ModelTypeSyncProxyImpl::OnCommitCompleted( ...@@ -183,18 +180,16 @@ void ModelTypeSyncProxyImpl::OnCommitCompleted(
} else { } else {
it->second->ReceiveCommitResponse(response_data.id, it->second->ReceiveCommitResponse(response_data.id,
response_data.sequence_number, response_data.sequence_number,
response_data.response_version, response_data.response_version);
data_type_state_.encryption_key_name);
} }
} }
} }
void ModelTypeSyncProxyImpl::OnUpdateReceived( void ModelTypeSyncProxyImpl::OnUpdateReceived(
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list) {
const UpdateResponseDataList& pending_updates) { bool initial_sync_just_finished =
bool got_new_encryption_requirements = data_type_state_.encryption_key_name != !data_type_state_.initial_sync_done && data_type_state.initial_sync_done;
data_type_state.encryption_key_name;
data_type_state_ = data_type_state; data_type_state_ = data_type_state;
...@@ -204,14 +199,6 @@ void ModelTypeSyncProxyImpl::OnUpdateReceived( ...@@ -204,14 +199,6 @@ void ModelTypeSyncProxyImpl::OnUpdateReceived(
const UpdateResponseData& response_data = *list_it; const UpdateResponseData& response_data = *list_it;
const std::string& client_tag_hash = response_data.client_tag_hash; const std::string& client_tag_hash = response_data.client_tag_hash;
UpdateMap::iterator old_it = pending_updates_map_.find(client_tag_hash);
if (old_it != pending_updates_map_.end()) {
// If we're being asked to apply an update to this entity, this overrides
// the previous pending updates.
delete old_it->second;
pending_updates_map_.erase(old_it);
}
EntityMap::iterator it = entities_.find(client_tag_hash); EntityMap::iterator it = entities_.find(client_tag_hash);
if (it == entities_.end()) { if (it == entities_.end()) {
scoped_ptr<ModelTypeEntity> entity = scoped_ptr<ModelTypeEntity> entity =
...@@ -222,74 +209,22 @@ void ModelTypeSyncProxyImpl::OnUpdateReceived( ...@@ -222,74 +209,22 @@ void ModelTypeSyncProxyImpl::OnUpdateReceived(
response_data.specifics, response_data.specifics,
response_data.deleted, response_data.deleted,
response_data.ctime, response_data.ctime,
response_data.mtime, response_data.mtime);
response_data.encryption_key_name);
entities_.insert(std::make_pair(client_tag_hash, entity.release())); entities_.insert(std::make_pair(client_tag_hash, entity.release()));
} else { } else {
ModelTypeEntity* entity = it->second; ModelTypeEntity* entity = it->second;
entity->ApplyUpdateFromServer(response_data.response_version, entity->ApplyUpdateFromServer(response_data.response_version,
response_data.deleted, response_data.deleted,
response_data.specifics, response_data.specifics,
response_data.mtime, response_data.mtime);
response_data.encryption_key_name);
// TODO: Do something special when conflicts are detected. // TODO: Do something special when conflicts are detected.
} }
// If the received entity has out of date encryption, we schedule another
// commit to fix it.
if (data_type_state_.encryption_key_name !=
response_data.encryption_key_name) {
EntityMap::iterator it2 = entities_.find(client_tag_hash);
it2->second->UpdateDesiredEncryptionKey(
data_type_state_.encryption_key_name);
}
} }
// Save pending updates in the appropriate data structure. if (initial_sync_just_finished)
for (UpdateResponseDataList::const_iterator list_it = pending_updates.begin(); FlushPendingCommitRequests();
list_it != pending_updates.end();
++list_it) {
const UpdateResponseData& update = *list_it;
const std::string& client_tag_hash = update.client_tag_hash;
UpdateMap::iterator lookup_it = pending_updates_map_.find(client_tag_hash);
if (lookup_it == pending_updates_map_.end()) {
pending_updates_map_.insert(
std::make_pair(client_tag_hash, new UpdateResponseData(update)));
} else if (lookup_it->second->response_version <= update.response_version) {
delete lookup_it->second;
pending_updates_map_.erase(lookup_it);
pending_updates_map_.insert(
std::make_pair(client_tag_hash, new UpdateResponseData(update)));
} else {
// Received update is stale, do not overwrite existing.
}
}
if (got_new_encryption_requirements) {
for (EntityMap::iterator it = entities_.begin(); it != entities_.end();
++it) {
it->second->UpdateDesiredEncryptionKey(
data_type_state_.encryption_key_name);
}
}
// We may have new reasons to commit by the time this function is done.
FlushPendingCommitRequests();
// TODO: Inform the model of the new or updated data. // TODO: Inform the model of the new or updated data.
// TODO: Persist the new data on disk.
}
UpdateResponseDataList ModelTypeSyncProxyImpl::GetPendingUpdates() {
UpdateResponseDataList pending_updates_list;
for (UpdateMap::const_iterator it = pending_updates_map_.begin();
it != pending_updates_map_.end();
++it) {
pending_updates_list.push_back(*it->second);
}
return pending_updates_list;
} }
void ModelTypeSyncProxyImpl::ClearTransientSyncState() { void ModelTypeSyncProxyImpl::ClearTransientSyncState() {
...@@ -304,7 +239,7 @@ void ModelTypeSyncProxyImpl::ClearSyncState() { ...@@ -304,7 +239,7 @@ void ModelTypeSyncProxyImpl::ClearSyncState() {
++it) { ++it) {
it->second->ClearSyncState(); it->second->ClearSyncState();
} }
STLDeleteValues(&pending_updates_map_);
data_type_state_ = DataTypeState(); data_type_state_ = DataTypeState();
} }
......
...@@ -73,16 +73,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe { ...@@ -73,16 +73,7 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe {
// Informs this object that there are some incoming updates is should // Informs this object that there are some incoming updates is should
// handle. // handle.
void OnUpdateReceived(const DataTypeState& type_state, void OnUpdateReceived(const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list);
const UpdateResponseDataList& pending_updates);
// Returns the list of pending updates.
//
// This is used as a helper function, but it's public mainly for testing.
// The current test harness setup doesn't allow us to test the data that the
// proxy sends to the worker during initialization, so we use this to inspect
// its state instead.
UpdateResponseDataList GetPendingUpdates();
// Returns the long-lived WeakPtr that is intended to be registered with the // Returns the long-lived WeakPtr that is intended to be registered with the
// ProfileSyncService. // ProfileSyncService.
...@@ -90,7 +81,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe { ...@@ -90,7 +81,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe {
private: private:
typedef std::map<std::string, ModelTypeEntity*> EntityMap; typedef std::map<std::string, ModelTypeEntity*> EntityMap;
typedef std::map<std::string, UpdateResponseData*> UpdateMap;
// Sends all commit requests that are due to be sent to the sync thread. // Sends all commit requests that are due to be sent to the sync thread.
void FlushPendingCommitRequests(); void FlushPendingCommitRequests();
...@@ -133,12 +123,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe { ...@@ -133,12 +123,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeSyncProxyImpl : base::NonThreadSafe {
EntityMap entities_; EntityMap entities_;
STLValueDeleter<EntityMap> entities_deleter_; STLValueDeleter<EntityMap> entities_deleter_;
// A set of updates that can not be applied at this time. These are never
// used by the model. They are kept here only so we can save and restore
// them across restarts, and keep them in sync with our progress markers.
UpdateMap pending_updates_map_;
STLValueDeleter<UpdateMap> pending_updates_map_deleter_;
// We use two different WeakPtrFactories because we want the pointers they // We use two different WeakPtrFactories because we want the pointers they
// issue to have different lifetimes. When asked to disconnect from the sync // issue to have different lifetimes. When asked to disconnect from the sync
// thread, we want to make sure that no tasks generated as part of the // thread, we want to make sure that no tasks generated as part of the
......
This diff is collapsed.
...@@ -10,13 +10,11 @@ ...@@ -10,13 +10,11 @@
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "sync/base/sync_export.h" #include "sync/base/sync_export.h"
#include "sync/engine/commit_contributor.h" #include "sync/engine/commit_contributor.h"
#include "sync/engine/cryptographer_provider.h"
#include "sync/engine/model_type_sync_worker.h" #include "sync/engine/model_type_sync_worker.h"
#include "sync/engine/nudge_handler.h" #include "sync/engine/nudge_handler.h"
#include "sync/engine/update_handler.h" #include "sync/engine/update_handler.h"
#include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/non_blocking_sync_common.h" #include "sync/internal_api/public/non_blocking_sync_common.h"
#include "sync/internal_api/public/sync_encryption_handler.h"
#include "sync/protocol/sync.pb.h" #include "sync/protocol/sync.pb.h"
namespace base { namespace base {
...@@ -55,19 +53,12 @@ class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler, ...@@ -55,19 +53,12 @@ class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler,
public: public:
ModelTypeSyncWorkerImpl(ModelType type, ModelTypeSyncWorkerImpl(ModelType type,
const DataTypeState& initial_state, const DataTypeState& initial_state,
const UpdateResponseDataList& saved_pending_updates,
CryptographerProvider* cryptographer_provider,
NudgeHandler* nudge_handler, NudgeHandler* nudge_handler,
scoped_ptr<ModelTypeSyncProxy> type_sync_proxy); scoped_ptr<ModelTypeSyncProxy> type_sync_proxy);
virtual ~ModelTypeSyncWorkerImpl(); virtual ~ModelTypeSyncWorkerImpl();
ModelType GetModelType() const; ModelType GetModelType() const;
bool IsEncryptionRequired() const;
void SetEncryptionKeyName(const std::string& name);
void OnCryptographerStateChanged();
// UpdateHandler implementation. // UpdateHandler implementation.
virtual void GetDownloadProgress( virtual void GetDownloadProgress(
sync_pb::DataTypeProgressMarker* progress_marker) const OVERRIDE; sync_pb::DataTypeProgressMarker* progress_marker) const OVERRIDE;
...@@ -96,45 +87,20 @@ class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler, ...@@ -96,45 +87,20 @@ class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler,
private: private:
typedef std::map<std::string, EntityTracker*> EntityMap; typedef std::map<std::string, EntityTracker*> EntityMap;
typedef std::map<std::string, UpdateResponseData*> UpdateMap;
// Stores a single commit request in this object's internal state. // Stores a single commit request in this object's internal state.
void StorePendingCommit(const CommitRequestData& request); void StorePendingCommit(const CommitRequestData& request);
// Returns true if this type has successfully fetched all available updates // Returns true if all data type state required for commits is available. In
// from the server at least once. Our state may or may not be stale, but at // practice, this means that it returns true from the time this object first
// least we know that it was valid at some point in the past. // receives notice of a successful update fetch from the server.
bool IsTypeInitialized() const; bool CanCommitItems() const;
// Returns true if this type is prepared to commit items. Currently, this
// depends on having downloaded the initial data and having the encryption
// settings in a good state.
bool CanCommitItems(Cryptographer* cryptographer) const;
// Initializes the parts of a commit entity that are the responsibility of // Initializes the parts of a commit entity that are the responsibility of
// this class, and not the EntityTracker. Some fields, like the // this class, and not the EntityTracker. Some fields, like the
// client-assigned ID, can only be set by an entity with knowledge of the // client-assigned ID, can only be set by an entity with knowledge of the
// entire data type's state. // entire data type's state.
void HelpInitializeCommitEntity(Cryptographer* cryptographer, void HelpInitializeCommitEntity(sync_pb::SyncEntity* commit_entity);
sync_pb::SyncEntity* commit_entity);
// Attempts to decrypt pending updates stored in the EntityMap. If
// successful, will remove the update from the its EntityTracker and forward
// it to the proxy thread for application.
void TryDecryptPendingUpdates();
// Attempts to decrypt the given specifics and return them in the |out|
// parameter. Assumes cryptographer->CanDecrypt(specifics) returned true.
//
// Returns false if the decryption failed. There are no guarantees about the
// contents of |out| when that happens.
//
// In theory, this should never fail. Only corrupt or invalid entries could
// cause this to fail, and no clients are known to create such entries. The
// failure case is an attempt to be defensive against bad input.
static bool DecryptSpecifics(Cryptographer* cryptographer,
const sync_pb::EntitySpecifics& in,
sync_pb::EntitySpecifics* out);
ModelType type_; ModelType type_;
...@@ -145,10 +111,6 @@ class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler, ...@@ -145,10 +111,6 @@ class SYNC_EXPORT ModelTypeSyncWorkerImpl : public UpdateHandler,
// This is NULL when no proxy is connected.. // This is NULL when no proxy is connected..
scoped_ptr<ModelTypeSyncProxy> type_sync_proxy_; scoped_ptr<ModelTypeSyncProxy> type_sync_proxy_;
// A helper to provide access to the syncable::Directory's cryptographer.
// Not owned.
CryptographerProvider* cryptographer_provider_;
// Interface used to access and send nudges to the sync scheduler. Not owned. // Interface used to access and send nudges to the sync scheduler. Not owned.
NudgeHandler* nudge_handler_; NudgeHandler* nudge_handler_;
......
...@@ -38,11 +38,6 @@ struct SYNC_EXPORT_PRIVATE DataTypeState { ...@@ -38,11 +38,6 @@ struct SYNC_EXPORT_PRIVATE DataTypeState {
// until the first download cycle has completed. // until the first download cycle has completed.
std::string type_root_id; std::string type_root_id;
// This value is set if this type's data should be encrypted on the server.
// If this key changes, the client will need to re-commit all of its local
// data to the server using the new encryption key.
std::string encryption_key_name;
// A strictly increasing counter used to generate unique values for the // A strictly increasing counter used to generate unique values for the
// client-assigned IDs. The incrementing and ID assignment happens on the // client-assigned IDs. The incrementing and ID assignment happens on the
// sync thread, but we store the value here so we can pass it back to the // sync thread, but we store the value here so we can pass it back to the
...@@ -56,6 +51,7 @@ struct SYNC_EXPORT_PRIVATE DataTypeState { ...@@ -56,6 +51,7 @@ struct SYNC_EXPORT_PRIVATE DataTypeState {
// flag is set. // flag is set.
bool initial_sync_done; bool initial_sync_done;
}; };
struct SYNC_EXPORT_PRIVATE CommitRequestData { struct SYNC_EXPORT_PRIVATE CommitRequestData {
CommitRequestData(); CommitRequestData();
~CommitRequestData(); ~CommitRequestData();
...@@ -98,7 +94,6 @@ struct SYNC_EXPORT_PRIVATE UpdateResponseData { ...@@ -98,7 +94,6 @@ struct SYNC_EXPORT_PRIVATE UpdateResponseData {
std::string non_unique_name; std::string non_unique_name;
bool deleted; bool deleted;
sync_pb::EntitySpecifics specifics; sync_pb::EntitySpecifics specifics;
std::string encryption_key_name;
}; };
typedef std::vector<CommitRequestData> CommitRequestDataList; typedef std::vector<CommitRequestData> CommitRequestDataList;
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "sync/base/sync_export.h" #include "sync/base/sync_export.h"
#include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/non_blocking_sync_common.h"
namespace syncer { namespace syncer {
class ModelTypeSyncProxyImpl; class ModelTypeSyncProxyImpl;
struct DataTypeState;
// An interface of the core parts of sync. // An interface of the core parts of sync.
// //
...@@ -35,7 +35,6 @@ class SYNC_EXPORT_PRIVATE SyncContext { ...@@ -35,7 +35,6 @@ class SYNC_EXPORT_PRIVATE SyncContext {
virtual void ConnectSyncTypeToWorker( virtual void ConnectSyncTypeToWorker(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const syncer::UpdateResponseDataList& saved_pending_updates,
const scoped_refptr<base::SequencedTaskRunner>& datatype_task_runner, const scoped_refptr<base::SequencedTaskRunner>& datatype_task_runner,
const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) = 0; const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) = 0;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/non_blocking_sync_common.h"
namespace syncer { namespace syncer {
...@@ -28,7 +27,6 @@ class SYNC_EXPORT_PRIVATE SyncContextProxy { ...@@ -28,7 +27,6 @@ class SYNC_EXPORT_PRIVATE SyncContextProxy {
virtual void ConnectTypeToSync( virtual void ConnectTypeToSync(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& saved_pending_updates,
const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) = 0; const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) = 0;
// Tells the syncer that we're no longer interested in syncing this type. // Tells the syncer that we're no longer interested in syncing this type.
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define SYNC_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CONTEXT_PROXY_H_ #define SYNC_INTERNAL_API_PUBLIC_TEST_NULL_SYNC_CONTEXT_PROXY_H_
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "sync/internal_api/public/non_blocking_sync_common.h"
#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_context_proxy.h"
namespace syncer { namespace syncer {
...@@ -24,7 +23,6 @@ class NullSyncContextProxy : public SyncContextProxy { ...@@ -24,7 +23,6 @@ class NullSyncContextProxy : public SyncContextProxy {
virtual void ConnectTypeToSync( virtual void ConnectTypeToSync(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& saved_pending_updates,
const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) OVERRIDE; const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) OVERRIDE;
virtual void Disconnect(syncer::ModelType type) OVERRIDE; virtual void Disconnect(syncer::ModelType type) OVERRIDE;
virtual scoped_ptr<SyncContextProxy> Clone() const OVERRIDE; virtual scoped_ptr<SyncContextProxy> Clone() const OVERRIDE;
......
...@@ -25,7 +25,6 @@ SyncContextProxyImpl::~SyncContextProxyImpl() { ...@@ -25,7 +25,6 @@ SyncContextProxyImpl::~SyncContextProxyImpl() {
void SyncContextProxyImpl::ConnectTypeToSync( void SyncContextProxyImpl::ConnectTypeToSync(
ModelType type, ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& saved_pending_updates,
const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) { const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) {
VLOG(1) << "ConnectTypeToSync: " << ModelTypeToString(type); VLOG(1) << "ConnectTypeToSync: " << ModelTypeToString(type);
sync_task_runner_->PostTask(FROM_HERE, sync_task_runner_->PostTask(FROM_HERE,
...@@ -33,7 +32,6 @@ void SyncContextProxyImpl::ConnectTypeToSync( ...@@ -33,7 +32,6 @@ void SyncContextProxyImpl::ConnectTypeToSync(
sync_context_, sync_context_,
type, type,
data_type_state, data_type_state,
saved_pending_updates,
base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(),
type_sync_proxy)); type_sync_proxy));
} }
......
...@@ -40,7 +40,6 @@ class SYNC_EXPORT_PRIVATE SyncContextProxyImpl : public SyncContextProxy { ...@@ -40,7 +40,6 @@ class SYNC_EXPORT_PRIVATE SyncContextProxyImpl : public SyncContextProxy {
virtual void ConnectTypeToSync( virtual void ConnectTypeToSync(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& pending_updates,
const base::WeakPtr<ModelTypeSyncProxyImpl>& sync_proxy_impl) OVERRIDE; const base::WeakPtr<ModelTypeSyncProxyImpl>& sync_proxy_impl) OVERRIDE;
// Disables syncing for the given type on the sync thread. // Disables syncing for the given type on the sync thread.
......
...@@ -1519,7 +1519,7 @@ bool SyncEncryptionHandlerImpl::GetKeystoreDecryptor( ...@@ -1519,7 +1519,7 @@ bool SyncEncryptionHandlerImpl::GetKeystoreDecryptor(
DCHECK(!keystore_key.empty()); DCHECK(!keystore_key.empty());
DCHECK(cryptographer.is_ready()); DCHECK(cryptographer.is_ready());
std::string serialized_nigori; std::string serialized_nigori;
serialized_nigori = cryptographer.GetDefaultNigoriKeyData(); serialized_nigori = cryptographer.GetDefaultNigoriKey();
if (serialized_nigori.empty()) { if (serialized_nigori.empty()) {
LOG(ERROR) << "Failed to get cryptographer bootstrap token."; LOG(ERROR) << "Failed to get cryptographer bootstrap token.";
return false; return false;
......
...@@ -15,7 +15,6 @@ NullSyncContextProxy::~NullSyncContextProxy() { ...@@ -15,7 +15,6 @@ NullSyncContextProxy::~NullSyncContextProxy() {
void NullSyncContextProxy::ConnectTypeToSync( void NullSyncContextProxy::ConnectTypeToSync(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& saved_pending_updates,
const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) { const base::WeakPtr<ModelTypeSyncProxyImpl>& type_sync_proxy) {
NOTREACHED() << "NullSyncContextProxy is not meant to be used"; NOTREACHED() << "NullSyncContextProxy is not meant to be used";
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "sync/engine/model_type_sync_worker_impl.h" #include "sync/engine/model_type_sync_worker_impl.h"
#include "sync/internal_api/public/non_blocking_sync_common.h" #include "sync/internal_api/public/non_blocking_sync_common.h"
#include "sync/sessions/directory_type_debug_info_emitter.h" #include "sync/sessions/directory_type_debug_info_emitter.h"
#include "sync/util/cryptographer.h"
namespace syncer { namespace syncer {
...@@ -33,8 +32,7 @@ class ModelTypeSyncProxyWrapper : public ModelTypeSyncProxy { ...@@ -33,8 +32,7 @@ class ModelTypeSyncProxyWrapper : public ModelTypeSyncProxy {
const CommitResponseDataList& response_list) OVERRIDE; const CommitResponseDataList& response_list) OVERRIDE;
virtual void OnUpdateReceived( virtual void OnUpdateReceived(
const DataTypeState& type_state, const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list) OVERRIDE;
const UpdateResponseDataList& pending_updates) OVERRIDE;
private: private:
base::WeakPtr<ModelTypeSyncProxyImpl> processor_; base::WeakPtr<ModelTypeSyncProxyImpl> processor_;
...@@ -63,15 +61,13 @@ void ModelTypeSyncProxyWrapper::OnCommitCompleted( ...@@ -63,15 +61,13 @@ void ModelTypeSyncProxyWrapper::OnCommitCompleted(
void ModelTypeSyncProxyWrapper::OnUpdateReceived( void ModelTypeSyncProxyWrapper::OnUpdateReceived(
const DataTypeState& type_state, const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list) {
const UpdateResponseDataList& pending_updates) {
processor_task_runner_->PostTask( processor_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&ModelTypeSyncProxyImpl::OnUpdateReceived, base::Bind(&ModelTypeSyncProxyImpl::OnUpdateReceived,
processor_, processor_,
type_state, type_state,
response_list, response_list));
pending_updates));
} }
class ModelTypeSyncWorkerWrapper : public ModelTypeSyncWorker { class ModelTypeSyncWorkerWrapper : public ModelTypeSyncWorker {
...@@ -111,7 +107,6 @@ ModelTypeRegistry::ModelTypeRegistry( ...@@ -111,7 +107,6 @@ ModelTypeRegistry::ModelTypeRegistry(
syncable::Directory* directory, syncable::Directory* directory,
NudgeHandler* nudge_handler) NudgeHandler* nudge_handler)
: directory_(directory), : directory_(directory),
cryptographer_provider_(directory_),
nudge_handler_(nudge_handler), nudge_handler_(nudge_handler),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
for (size_t i = 0u; i < workers.size(); ++i) { for (size_t i = 0u; i < workers.size(); ++i) {
...@@ -190,7 +185,6 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes( ...@@ -190,7 +185,6 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes(
void ModelTypeRegistry::ConnectSyncTypeToWorker( void ModelTypeRegistry::ConnectSyncTypeToWorker(
ModelType type, ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& saved_pending_updates,
const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy_impl) { const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy_impl) {
DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type);
...@@ -198,13 +192,8 @@ void ModelTypeRegistry::ConnectSyncTypeToWorker( ...@@ -198,13 +192,8 @@ void ModelTypeRegistry::ConnectSyncTypeToWorker(
// Initialize Worker -> Proxy communication channel. // Initialize Worker -> Proxy communication channel.
scoped_ptr<ModelTypeSyncProxy> proxy( scoped_ptr<ModelTypeSyncProxy> proxy(
new ModelTypeSyncProxyWrapper(proxy_impl, type_task_runner)); new ModelTypeSyncProxyWrapper(proxy_impl, type_task_runner));
scoped_ptr<ModelTypeSyncWorkerImpl> worker( scoped_ptr<ModelTypeSyncWorkerImpl> worker(new ModelTypeSyncWorkerImpl(
new ModelTypeSyncWorkerImpl(type, type, data_type_state, nudge_handler_, proxy.Pass()));
data_type_state,
saved_pending_updates,
&cryptographer_provider_,
nudge_handler_,
proxy.Pass()));
// Initialize Proxy -> Worker communication channel. // Initialize Proxy -> Worker communication channel.
scoped_ptr<ModelTypeSyncWorker> wrapped_worker( scoped_ptr<ModelTypeSyncWorker> wrapped_worker(
......
...@@ -12,11 +12,9 @@ ...@@ -12,11 +12,9 @@
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "sync/base/sync_export.h" #include "sync/base/sync_export.h"
#include "sync/engine/directory_cryptographer_provider.h"
#include "sync/engine/nudge_handler.h" #include "sync/engine/nudge_handler.h"
#include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/non_blocking_sync_common.h"
#include "sync/internal_api/public/sessions/type_debug_info_observer.h" #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
#include "sync/internal_api/public/sync_context.h" #include "sync/internal_api/public/sync_context.h"
...@@ -33,6 +31,7 @@ class DirectoryTypeDebugInfoEmitter; ...@@ -33,6 +31,7 @@ class DirectoryTypeDebugInfoEmitter;
class ModelTypeSyncWorkerImpl; class ModelTypeSyncWorkerImpl;
class ModelTypeSyncProxyImpl; class ModelTypeSyncProxyImpl;
class UpdateHandler; class UpdateHandler;
struct DataTypeState;
typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
typedef std::map<ModelType, CommitContributor*> CommitContributorMap; typedef std::map<ModelType, CommitContributor*> CommitContributorMap;
...@@ -58,7 +57,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { ...@@ -58,7 +57,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext {
virtual void ConnectSyncTypeToWorker( virtual void ConnectSyncTypeToWorker(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const syncer::UpdateResponseDataList& saved_pending_updates,
const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, const scoped_refptr<base::SequencedTaskRunner>& type_task_runner,
const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE; const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy) OVERRIDE;
...@@ -114,9 +112,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext { ...@@ -114,9 +112,6 @@ class SYNC_EXPORT_PRIVATE ModelTypeRegistry : public SyncContext {
// The directory. Not owned. // The directory. Not owned.
syncable::Directory* directory_; syncable::Directory* directory_;
// Provides access to the Directory's cryptographer.
DirectoryCryptographerProvider cryptographer_provider_;
// The NudgeHandler. Not owned. // The NudgeHandler. Not owned.
NudgeHandler* nudge_handler_; NudgeHandler* nudge_handler_;
......
...@@ -154,7 +154,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { ...@@ -154,7 +154,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) {
registry()->ConnectSyncTypeToWorker(syncer::THEMES, registry()->ConnectSyncTypeToWorker(syncer::THEMES,
MakeInitialDataTypeState(THEMES), MakeInitialDataTypeState(THEMES),
UpdateResponseDataList(),
task_runner, task_runner,
themes_sync_proxy.AsWeakPtrForUI()); themes_sync_proxy.AsWeakPtrForUI());
EXPECT_TRUE(registry()->GetEnabledTypes().Equals( EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
...@@ -162,7 +161,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) { ...@@ -162,7 +161,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypes) {
registry()->ConnectSyncTypeToWorker(syncer::SESSIONS, registry()->ConnectSyncTypeToWorker(syncer::SESSIONS,
MakeInitialDataTypeState(SESSIONS), MakeInitialDataTypeState(SESSIONS),
UpdateResponseDataList(),
task_runner, task_runner,
sessions_sync_proxy.AsWeakPtrForUI()); sessions_sync_proxy.AsWeakPtrForUI());
EXPECT_TRUE(registry()->GetEnabledTypes().Equals( EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
...@@ -194,7 +192,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { ...@@ -194,7 +192,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) {
// Add the themes non-blocking type. // Add the themes non-blocking type.
registry()->ConnectSyncTypeToWorker(syncer::THEMES, registry()->ConnectSyncTypeToWorker(syncer::THEMES,
MakeInitialDataTypeState(THEMES), MakeInitialDataTypeState(THEMES),
UpdateResponseDataList(),
task_runner, task_runner,
themes_sync_proxy.AsWeakPtrForUI()); themes_sync_proxy.AsWeakPtrForUI());
current_types.Put(syncer::THEMES); current_types.Put(syncer::THEMES);
...@@ -208,7 +205,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) { ...@@ -208,7 +205,6 @@ TEST_F(ModelTypeRegistryTest, NonBlockingTypesWithDirectoryTypes) {
// Add sessions non-blocking type. // Add sessions non-blocking type.
registry()->ConnectSyncTypeToWorker(syncer::SESSIONS, registry()->ConnectSyncTypeToWorker(syncer::SESSIONS,
MakeInitialDataTypeState(SESSIONS), MakeInitialDataTypeState(SESSIONS),
UpdateResponseDataList(),
task_runner, task_runner,
sessions_sync_proxy.AsWeakPtrForUI()); sessions_sync_proxy.AsWeakPtrForUI());
current_types.Put(syncer::SESSIONS); current_types.Put(syncer::SESSIONS);
...@@ -239,12 +235,10 @@ TEST_F(ModelTypeRegistryTest, DeletionOrdering) { ...@@ -239,12 +235,10 @@ TEST_F(ModelTypeRegistryTest, DeletionOrdering) {
registry()->ConnectSyncTypeToWorker(syncer::THEMES, registry()->ConnectSyncTypeToWorker(syncer::THEMES,
MakeInitialDataTypeState(THEMES), MakeInitialDataTypeState(THEMES),
UpdateResponseDataList(),
task_runner, task_runner,
themes_sync_proxy->AsWeakPtrForUI()); themes_sync_proxy->AsWeakPtrForUI());
registry()->ConnectSyncTypeToWorker(syncer::SESSIONS, registry()->ConnectSyncTypeToWorker(syncer::SESSIONS,
MakeInitialDataTypeState(SESSIONS), MakeInitialDataTypeState(SESSIONS),
UpdateResponseDataList(),
task_runner, task_runner,
sessions_sync_proxy->AsWeakPtrForUI()); sessions_sync_proxy->AsWeakPtrForUI());
EXPECT_TRUE(registry()->GetEnabledTypes().Equals( EXPECT_TRUE(registry()->GetEnabledTypes().Equals(
......
...@@ -20,7 +20,6 @@ InjectableSyncContextProxy::~InjectableSyncContextProxy() { ...@@ -20,7 +20,6 @@ InjectableSyncContextProxy::~InjectableSyncContextProxy() {
void InjectableSyncContextProxy::ConnectTypeToSync( void InjectableSyncContextProxy::ConnectTypeToSync(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& response_list,
const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) { const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) {
// This class is allowed to participate in only one connection. // This class is allowed to participate in only one connection.
DCHECK(!is_worker_connected_); DCHECK(!is_worker_connected_);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define SYNC_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_ #define SYNC_TEST_ENGINE_INJECTABLE_SYNC_CONTEXT_PROXY_H_
#include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/non_blocking_sync_common.h"
#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_context_proxy.h"
namespace syncer { namespace syncer {
...@@ -25,7 +24,6 @@ class InjectableSyncContextProxy : public syncer::SyncContextProxy { ...@@ -25,7 +24,6 @@ class InjectableSyncContextProxy : public syncer::SyncContextProxy {
virtual void ConnectTypeToSync( virtual void ConnectTypeToSync(
syncer::ModelType type, syncer::ModelType type,
const DataTypeState& data_type_state, const DataTypeState& data_type_state,
const UpdateResponseDataList& pending_updates,
const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy) const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy)
OVERRIDE; OVERRIDE;
virtual void Disconnect(syncer::ModelType type) OVERRIDE; virtual void Disconnect(syncer::ModelType type) OVERRIDE;
......
...@@ -29,13 +29,11 @@ void MockModelTypeSyncProxy::OnCommitCompleted( ...@@ -29,13 +29,11 @@ void MockModelTypeSyncProxy::OnCommitCompleted(
void MockModelTypeSyncProxy::OnUpdateReceived( void MockModelTypeSyncProxy::OnUpdateReceived(
const DataTypeState& type_state, const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list) {
const UpdateResponseDataList& pending_updates) {
base::Closure task = base::Bind(&MockModelTypeSyncProxy::OnUpdateReceivedImpl, base::Closure task = base::Bind(&MockModelTypeSyncProxy::OnUpdateReceivedImpl,
base::Unretained(this), base::Unretained(this),
type_state, type_state,
response_list, response_list);
pending_updates);
pending_tasks_.push_back(task); pending_tasks_.push_back(task);
if (is_synchronous_) if (is_synchronous_)
RunQueuedTasks(); RunQueuedTasks();
...@@ -113,12 +111,6 @@ UpdateResponseDataList MockModelTypeSyncProxy::GetNthUpdateResponse( ...@@ -113,12 +111,6 @@ UpdateResponseDataList MockModelTypeSyncProxy::GetNthUpdateResponse(
return received_update_responses_[n]; return received_update_responses_[n];
} }
UpdateResponseDataList MockModelTypeSyncProxy::GetNthPendingUpdates(
size_t n) const {
DCHECK_LT(n, GetNumUpdateResponses());
return received_pending_updates_[n];
}
DataTypeState MockModelTypeSyncProxy::GetNthTypeStateReceivedInUpdateResponse( DataTypeState MockModelTypeSyncProxy::GetNthTypeStateReceivedInUpdateResponse(
size_t n) const { size_t n) const {
DCHECK_LT(n, GetNumUpdateResponses()); DCHECK_LT(n, GetNumUpdateResponses());
...@@ -189,10 +181,8 @@ void MockModelTypeSyncProxy::OnCommitCompletedImpl( ...@@ -189,10 +181,8 @@ void MockModelTypeSyncProxy::OnCommitCompletedImpl(
void MockModelTypeSyncProxy::OnUpdateReceivedImpl( void MockModelTypeSyncProxy::OnUpdateReceivedImpl(
const DataTypeState& type_state, const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list) {
const UpdateResponseDataList& pending_updates) {
received_update_responses_.push_back(response_list); received_update_responses_.push_back(response_list);
received_pending_updates_.push_back(pending_updates);
type_states_received_on_update_.push_back(type_state); type_states_received_on_update_.push_back(type_state);
for (UpdateResponseDataList::const_iterator it = response_list.begin(); for (UpdateResponseDataList::const_iterator it = response_list.begin();
it != response_list.end(); it != response_list.end();
......
...@@ -36,8 +36,7 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy { ...@@ -36,8 +36,7 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy {
const CommitResponseDataList& response_list) OVERRIDE; const CommitResponseDataList& response_list) OVERRIDE;
virtual void OnUpdateReceived( virtual void OnUpdateReceived(
const DataTypeState& type_state, const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list) OVERRIDE;
const UpdateResponseDataList& pending_updates) OVERRIDE;
// By default, this object behaves as if all messages are processed // By default, this object behaves as if all messages are processed
// immediately. Sometimes it is useful to defer work until later, as might // immediately. Sometimes it is useful to defer work until later, as might
...@@ -66,7 +65,6 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy { ...@@ -66,7 +65,6 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy {
// Does not includes repsonses that are in pending tasks. // Does not includes repsonses that are in pending tasks.
size_t GetNumUpdateResponses() const; size_t GetNumUpdateResponses() const;
UpdateResponseDataList GetNthUpdateResponse(size_t n) const; UpdateResponseDataList GetNthUpdateResponse(size_t n) const;
UpdateResponseDataList GetNthPendingUpdates(size_t n) const;
DataTypeState GetNthTypeStateReceivedInUpdateResponse(size_t n) const; DataTypeState GetNthTypeStateReceivedInUpdateResponse(size_t n) const;
// Getters to access the log of received commit responses. // Getters to access the log of received commit responses.
...@@ -95,8 +93,7 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy { ...@@ -95,8 +93,7 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy {
// //
// Implemented as an Impl method so we can defer its execution in some cases. // Implemented as an Impl method so we can defer its execution in some cases.
void OnUpdateReceivedImpl(const DataTypeState& type_state, void OnUpdateReceivedImpl(const DataTypeState& type_state,
const UpdateResponseDataList& response_list, const UpdateResponseDataList& response_list);
const UpdateResponseDataList& pending_updates);
// Getter and setter for per-item sequence number tracking. // Getter and setter for per-item sequence number tracking.
int64 GetCurrentSequenceNumber(const std::string& tag_hash) const; int64 GetCurrentSequenceNumber(const std::string& tag_hash) const;
...@@ -119,7 +116,6 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy { ...@@ -119,7 +116,6 @@ class MockModelTypeSyncProxy : public ModelTypeSyncProxy {
// A log of messages received by this object. // A log of messages received by this object.
std::vector<CommitResponseDataList> received_commit_responses_; std::vector<CommitResponseDataList> received_commit_responses_;
std::vector<UpdateResponseDataList> received_update_responses_; std::vector<UpdateResponseDataList> received_update_responses_;
std::vector<UpdateResponseDataList> received_pending_updates_;
std::vector<DataTypeState> type_states_received_on_update_; std::vector<DataTypeState> type_states_received_on_update_;
std::vector<DataTypeState> type_states_received_on_commit_; std::vector<DataTypeState> type_states_received_on_commit_;
......
...@@ -94,8 +94,6 @@ UpdateResponseData MockModelTypeSyncWorker::UpdateFromServer( ...@@ -94,8 +94,6 @@ UpdateResponseData MockModelTypeSyncWorker::UpdateFromServer(
data.mtime = data.ctime + base::TimeDelta::FromSeconds(version); data.mtime = data.ctime + base::TimeDelta::FromSeconds(version);
data.non_unique_name = specifics.preference().name(); data.non_unique_name = specifics.preference().name();
data.encryption_key_name = server_encryption_key_name_;
return data; return data;
} }
...@@ -120,8 +118,6 @@ UpdateResponseData MockModelTypeSyncWorker::TombstoneFromServer( ...@@ -120,8 +118,6 @@ UpdateResponseData MockModelTypeSyncWorker::TombstoneFromServer(
data.mtime = data.ctime + base::TimeDelta::FromSeconds(version); data.mtime = data.ctime + base::TimeDelta::FromSeconds(version);
data.non_unique_name = "Name Non Unique"; data.non_unique_name = "Name Non Unique";
data.encryption_key_name = server_encryption_key_name_;
return data; return data;
} }
...@@ -153,11 +149,6 @@ CommitResponseData MockModelTypeSyncWorker::SuccessfulCommitResponse( ...@@ -153,11 +149,6 @@ CommitResponseData MockModelTypeSyncWorker::SuccessfulCommitResponse(
return response_data; return response_data;
} }
void MockModelTypeSyncWorker::SetServerEncryptionKey(
const std::string& key_name) {
server_encryption_key_name_ = key_name;
}
std::string MockModelTypeSyncWorker::GenerateId(const std::string& tag_hash) { std::string MockModelTypeSyncWorker::GenerateId(const std::string& tag_hash) {
return "FakeId:" + tag_hash; return "FakeId:" + tag_hash;
} }
......
...@@ -57,11 +57,6 @@ class MockModelTypeSyncWorker : public ModelTypeSyncWorker { ...@@ -57,11 +57,6 @@ class MockModelTypeSyncWorker : public ModelTypeSyncWorker {
CommitResponseData SuccessfulCommitResponse( CommitResponseData SuccessfulCommitResponse(
const CommitRequestData& request_data); const CommitRequestData& request_data);
// Sets the encryption key name used for updates from the server.
// (ie. the key other clients are using to encrypt their commits.)
// The default value is an empty string, which indicates no encryption.
void SetServerEncryptionKey(const std::string& key_name);
private: private:
// Generate an ID string. // Generate an ID string.
static std::string GenerateId(const std::string& tag_hash); static std::string GenerateId(const std::string& tag_hash);
...@@ -77,9 +72,6 @@ class MockModelTypeSyncWorker : public ModelTypeSyncWorker { ...@@ -77,9 +72,6 @@ class MockModelTypeSyncWorker : public ModelTypeSyncWorker {
// This is an essential part of the mocked server state. // This is an essential part of the mocked server state.
std::map<const std::string, int64> server_versions_; std::map<const std::string, int64> server_versions_;
// Name of the encryption key in use on other clients.
std::string server_encryption_key_name_;
DISALLOW_COPY_AND_ASSIGN(MockModelTypeSyncWorker); DISALLOW_COPY_AND_ASSIGN(MockModelTypeSyncWorker);
}; };
......
...@@ -251,7 +251,7 @@ bool Cryptographer::DecryptPendingKeys(const KeyParams& params) { ...@@ -251,7 +251,7 @@ bool Cryptographer::DecryptPendingKeys(const KeyParams& params) {
bool Cryptographer::GetBootstrapToken(std::string* token) const { bool Cryptographer::GetBootstrapToken(std::string* token) const {
DCHECK(token); DCHECK(token);
std::string unencrypted_token = GetDefaultNigoriKeyData(); std::string unencrypted_token = GetDefaultNigoriKey();
if (unencrypted_token.empty()) if (unencrypted_token.empty())
return false; return false;
...@@ -324,11 +324,7 @@ bool Cryptographer::KeybagIsStale( ...@@ -324,11 +324,7 @@ bool Cryptographer::KeybagIsStale(
return false; return false;
} }
std::string Cryptographer::GetDefaultNigoriKeyName() const { std::string Cryptographer::GetDefaultNigoriKey() const {
return default_nigori_name_;
}
std::string Cryptographer::GetDefaultNigoriKeyData() const {
if (!is_initialized()) if (!is_initialized())
return std::string(); return std::string();
NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_); NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_);
......
...@@ -176,12 +176,9 @@ class SYNC_EXPORT Cryptographer { ...@@ -176,12 +176,9 @@ class SYNC_EXPORT Cryptographer {
// and/or has a different default key. // and/or has a different default key.
bool KeybagIsStale(const sync_pb::EncryptedData& keybag) const; bool KeybagIsStale(const sync_pb::EncryptedData& keybag) const;
// Returns the name of the Nigori key currently used for encryption.
std::string GetDefaultNigoriKeyName() const;
// Returns a serialized sync_pb::NigoriKey version of current default // Returns a serialized sync_pb::NigoriKey version of current default
// encryption key. // encryption key.
std::string GetDefaultNigoriKeyData() const; std::string GetDefaultNigoriKey() const;
// Generates a new Nigori from |serialized_nigori_key|, and if successful // Generates a new Nigori from |serialized_nigori_key|, and if successful
// installs the new nigori as the default key. // installs the new nigori as the default key.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment