Skip to content

Commit

Permalink
[Sync] Rename to (Processor|Worker)EntityTracker for clarity.
Browse files Browse the repository at this point in the history
The names ModelTypeEntity and EntityTracker did not express the purposes
and the similarities between the classes well. They are each essentially
internal to their respective components, and they each handle the logic
of tracking what's necessary for an entity in that component. I think
these names are much clearer.

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

Cr-Commit-Position: refs/heads/master@{#378348}
  • Loading branch information
maxbogue authored and Commit bot committed Mar 1, 2016
1 parent ca4f3f8 commit 4776274
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 193 deletions.
12 changes: 6 additions & 6 deletions sync/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ source_set("sync_core") {
"engine/directory_commit_contributor.h",
"engine/directory_update_handler.cc",
"engine/directory_update_handler.h",
"engine/entity_tracker.cc",
"engine/entity_tracker.h",
"engine/get_commit_ids.cc",
"engine/get_commit_ids.h",
"engine/get_updates_delegate.cc",
Expand Down Expand Up @@ -130,6 +128,8 @@ source_set("sync_core") {
"engine/update_applicator.h",
"engine/update_handler.cc",
"engine/update_handler.h",
"engine/worker_entity_tracker.cc",
"engine/worker_entity_tracker.h",
"internal_api/activation_context.cc",
"internal_api/attachments/attachment_downloader.cc",
"internal_api/attachments/attachment_downloader_impl.cc",
Expand Down Expand Up @@ -172,9 +172,9 @@ source_set("sync_core") {
"internal_api/js_sync_encryption_handler_observer.h",
"internal_api/js_sync_manager_observer.cc",
"internal_api/js_sync_manager_observer.h",
"internal_api/model_type_entity.cc",
"internal_api/model_type_store_backend.cc",
"internal_api/model_type_store_impl.cc",
"internal_api/processor_entity_tracker.cc",
"internal_api/protocol_event_buffer.cc",
"internal_api/protocol_event_buffer.h",
"internal_api/public/activation_context.h",
Expand Down Expand Up @@ -244,14 +244,14 @@ source_set("sync_core") {
"internal_api/public/http_post_provider_interface.h",
"internal_api/public/internal_components_factory.h",
"internal_api/public/internal_components_factory_impl.h",
"internal_api/public/model_type_entity.h",
"internal_api/public/model_type_processor.cc",
"internal_api/public/model_type_processor.h",
"internal_api/public/model_type_store_backend.h",
"internal_api/public/model_type_store_impl.h",
"internal_api/public/network_resources.h",
"internal_api/public/non_blocking_sync_common.cc",
"internal_api/public/non_blocking_sync_common.h",
"internal_api/public/processor_entity_tracker.h",
"internal_api/public/read_node.h",
"internal_api/public/read_transaction.h",
"internal_api/public/sessions/commit_counters.cc",
Expand Down Expand Up @@ -617,13 +617,13 @@ test("sync_unit_tests") {
"engine/backoff_delay_provider_unittest.cc",
"engine/directory_commit_contribution_unittest.cc",
"engine/directory_update_handler_unittest.cc",
"engine/entity_tracker_unittest.cc",
"engine/get_updates_processor_unittest.cc",
"engine/model_type_worker_unittest.cc",
"engine/sync_scheduler_unittest.cc",
"engine/syncer_proto_util_unittest.cc",
"engine/syncer_unittest.cc",
"engine/syncer_util_unittest.cc",
"engine/worker_entity_tracker_unittest.cc",
"internal_api/attachments/attachment_downloader_impl_unittest.cc",
"internal_api/attachments/attachment_service_impl_unittest.cc",
"internal_api/attachments/attachment_service_proxy_unittest.cc",
Expand All @@ -640,9 +640,9 @@ test("sync_unit_tests") {
"internal_api/js_mutation_event_observer_unittest.cc",
"internal_api/js_sync_encryption_handler_observer_unittest.cc",
"internal_api/js_sync_manager_observer_unittest.cc",
"internal_api/model_type_entity_unittest.cc",
"internal_api/model_type_store_backend_unittest.cc",
"internal_api/model_type_store_impl_unittest.cc",
"internal_api/processor_entity_tracker_unittest.cc",
"internal_api/protocol_event_buffer_unittest.cc",
"internal_api/public/base/attachment_id_proto_unittest.cc",
"internal_api/public/base/cancelation_signal_unittest.cc",
Expand Down
22 changes: 11 additions & 11 deletions sync/engine/model_type_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "sync/engine/commit_contribution.h"
#include "sync/engine/entity_tracker.h"
#include "sync/engine/non_blocking_type_commit_contribution.h"
#include "sync/engine/worker_entity_tracker.h"
#include "sync/internal_api/public/model_type_processor.h"
#include "sync/syncable/syncable_util.h"
#include "sync/util/cryptographer.h"
Expand Down Expand Up @@ -134,11 +134,11 @@ SyncerError ModelTypeWorker::ProcessGetUpdatesResponse(
UpdateResponseData response_data;
response_data.response_version = update_entity->version();

EntityTracker* entity_tracker = nullptr;
WorkerEntityTracker* entity_tracker = nullptr;
EntityMap::const_iterator map_it = entities_.find(client_tag_hash);
if (map_it == entities_.end()) {
scoped_ptr<EntityTracker> scoped_entity_tracker =
EntityTracker::FromUpdateResponse(response_data);
scoped_ptr<WorkerEntityTracker> scoped_entity_tracker =
WorkerEntityTracker::FromUpdateResponse(response_data);
entity_tracker = scoped_entity_tracker.get();
entities_.insert(
std::make_pair(client_tag_hash, std::move(scoped_entity_tracker)));
Expand Down Expand Up @@ -199,8 +199,8 @@ void ModelTypeWorker::ApplyUpdates(syncer::sessions::StatusController* status) {

data_type_state_.set_initial_sync_done(true);

model_type_processor_->OnUpdateReceived(
data_type_state_, UpdateResponseDataList());
model_type_processor_->OnUpdateReceived(data_type_state_,
UpdateResponseDataList());
}
}

Expand Down Expand Up @@ -242,7 +242,7 @@ scoped_ptr<CommitContribution> ModelTypeWorker::GetContribution(
// TODO(rlarocque): Avoid iterating here.
for (EntityMap::const_iterator it = entities_.begin();
it != entities_.end() && space_remaining > 0; ++it) {
EntityTracker* entity = it->second.get();
WorkerEntityTracker* entity = it->second.get();
if (entity->HasPendingCommit()) {
sync_pb::SyncEntity* commit_entity = commit_entities.Add();
int64_t sequence_number = -1;
Expand All @@ -269,11 +269,11 @@ void ModelTypeWorker::StorePendingCommit(const CommitRequestData& request) {
DCHECK_EQ(type_, syncer::GetModelTypeFromSpecifics(data.specifics));
}

EntityTracker* entity;
WorkerEntityTracker* entity;
EntityMap::const_iterator map_it = entities_.find(data.client_tag_hash);
if (map_it == entities_.end()) {
scoped_ptr<EntityTracker> scoped_entity =
EntityTracker::FromCommitRequest(request);
scoped_ptr<WorkerEntityTracker> scoped_entity =
WorkerEntityTracker::FromCommitRequest(request);
entity = scoped_entity.get();
entities_.insert(
std::make_pair(data.client_tag_hash, std::move(scoped_entity)));
Expand All @@ -299,7 +299,7 @@ void ModelTypeWorker::OnCommitResponse(
continue;
}

EntityTracker* entity = map_it->second.get();
WorkerEntityTracker* entity = map_it->second.get();
entity->ReceiveCommitResponse(response_it->id,
response_it->response_version,
response_it->sequence_number);
Expand Down
8 changes: 4 additions & 4 deletions sync/engine/model_type_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SingleThreadTaskRunner;
namespace syncer_v2 {

class ModelTypeProcessor;
class EntityTracker;
class WorkerEntityTracker;

// A smart cache for sync types that use message passing (rather than
// transactions and the syncable::Directory) to communicate with the sync
Expand Down Expand Up @@ -96,7 +96,7 @@ class SYNC_EXPORT ModelTypeWorker : public syncer::UpdateHandler,
base::WeakPtr<ModelTypeWorker> AsWeakPtr();

private:
using EntityMap = std::map<std::string, scoped_ptr<EntityTracker>>;
using EntityMap = std::map<std::string, scoped_ptr<WorkerEntityTracker>>;

// Stores a single commit request in this object's internal state.
void StorePendingCommit(const CommitRequestData& request);
Expand All @@ -112,13 +112,13 @@ class SYNC_EXPORT ModelTypeWorker : public syncer::UpdateHandler,
bool CanCommitItems() const;

// 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 WorkerEntityTracker. Some fields, like the
// client-assigned ID, can only be set by an entity with knowledge of the
// entire data type's state.
void HelpInitializeCommitEntity(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
// successful, will remove the update from the its tracker and forward
// it to the proxy thread for application. Will forward any new encryption
// keys to the proxy to trigger re-encryption if necessary.
void OnCryptographerUpdated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "sync/engine/entity_tracker.h"
#include "sync/engine/worker_entity_tracker.h"

#include <stdint.h>

Expand All @@ -14,37 +14,38 @@

namespace syncer_v2 {

scoped_ptr<EntityTracker> EntityTracker::FromUpdateResponse(
scoped_ptr<WorkerEntityTracker> WorkerEntityTracker::FromUpdateResponse(
const UpdateResponseData& data) {
return make_scoped_ptr(new EntityTracker(
return make_scoped_ptr(new WorkerEntityTracker(
data.entity->id, data.entity->client_tag_hash, 0, data.response_version));
}

scoped_ptr<EntityTracker> EntityTracker::FromCommitRequest(
scoped_ptr<WorkerEntityTracker> WorkerEntityTracker::FromCommitRequest(
const CommitRequestData& data) {
return make_scoped_ptr(
new EntityTracker(data.entity->id, data.entity->client_tag_hash, 0, 0));
return make_scoped_ptr(new WorkerEntityTracker(
data.entity->id, data.entity->client_tag_hash, 0, 0));
}

EntityTracker::EntityTracker(const std::string& id,
const std::string& client_tag_hash,
int64_t highest_commit_response_version,
int64_t highest_gu_response_version)
WorkerEntityTracker::WorkerEntityTracker(
const std::string& id,
const std::string& client_tag_hash,
int64_t highest_commit_response_version,
int64_t highest_gu_response_version)
: id_(id),
client_tag_hash_(client_tag_hash),
highest_commit_response_version_(highest_commit_response_version),
highest_gu_response_version_(highest_gu_response_version),
sequence_number_(0),
base_version_(kUncommittedVersion) {}

EntityTracker::~EntityTracker() {}
WorkerEntityTracker::~WorkerEntityTracker() {}

bool EntityTracker::HasPendingCommit() const {
bool WorkerEntityTracker::HasPendingCommit() const {
return !!pending_commit_;
}

void EntityTracker::PrepareCommitProto(sync_pb::SyncEntity* commit_entity,
int64_t* sequence_number) const {
void WorkerEntityTracker::PrepareCommitProto(sync_pb::SyncEntity* commit_entity,
int64_t* sequence_number) const {
DCHECK(HasPendingCommit());
DCHECK(!client_tag_hash_.empty());

Expand Down Expand Up @@ -73,7 +74,7 @@ void EntityTracker::PrepareCommitProto(sync_pb::SyncEntity* commit_entity,
*sequence_number = sequence_number_;
}

void EntityTracker::RequestCommit(const CommitRequestData& data) {
void WorkerEntityTracker::RequestCommit(const CommitRequestData& data) {
DCHECK_GE(data.base_version, base_version_)
<< "Base version should never decrease";

Expand Down Expand Up @@ -116,9 +117,9 @@ void EntityTracker::RequestCommit(const CommitRequestData& data) {
// so it can be committed at the next possible opportunity.
}

void EntityTracker::ReceiveCommitResponse(const std::string& response_id,
int64_t response_version,
int64_t sequence_number) {
void WorkerEntityTracker::ReceiveCommitResponse(const std::string& response_id,
int64_t response_version,
int64_t sequence_number) {
// Commit responses, especially after the first commit, can update our ID.
id_ = response_id;

Expand All @@ -141,7 +142,7 @@ void EntityTracker::ReceiveCommitResponse(const std::string& response_id,
ClearPendingCommit();
}

void EntityTracker::ReceiveUpdate(int64_t version) {
void WorkerEntityTracker::ReceiveUpdate(int64_t version) {
if (version <= highest_gu_response_version_)
return;

Expand All @@ -158,7 +159,7 @@ void EntityTracker::ReceiveUpdate(int64_t version) {
}
}

bool EntityTracker::ReceivePendingUpdate(const UpdateResponseData& data) {
bool WorkerEntityTracker::ReceivePendingUpdate(const UpdateResponseData& data) {
if (data.response_version < highest_gu_response_version_)
return false;

Expand All @@ -168,19 +169,19 @@ bool EntityTracker::ReceivePendingUpdate(const UpdateResponseData& data) {
return true;
}

bool EntityTracker::HasPendingUpdate() const {
bool WorkerEntityTracker::HasPendingUpdate() const {
return !!pending_update_;
}

UpdateResponseData EntityTracker::GetPendingUpdate() const {
UpdateResponseData WorkerEntityTracker::GetPendingUpdate() const {
return *pending_update_;
}

void EntityTracker::ClearPendingUpdate() {
void WorkerEntityTracker::ClearPendingUpdate() {
pending_update_.reset();
}

bool EntityTracker::IsInConflict() const {
bool WorkerEntityTracker::IsInConflict() const {
if (!HasPendingCommit())
return false;

Expand All @@ -203,11 +204,11 @@ bool EntityTracker::IsInConflict() const {
}
}

bool EntityTracker::IsServerKnown() const {
bool WorkerEntityTracker::IsServerKnown() const {
return base_version_ != kUncommittedVersion;
}

void EntityTracker::ClearPendingCommit() {
void WorkerEntityTracker::ClearPendingCommit() {
pending_commit_.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SYNC_ENGINE_ENTITY_TRACKER_H_
#define SYNC_ENGINE_ENTITY_TRACKER_H_
#ifndef SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_
#define SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_

#include <stdint.h>

Expand Down Expand Up @@ -31,16 +31,16 @@ struct UpdateResponseData;
//
// This object may contain state associated with a pending commit, pending
// update, or both.
class SYNC_EXPORT EntityTracker {
class SYNC_EXPORT WorkerEntityTracker {
public:
~EntityTracker();
~WorkerEntityTracker();

// Initialize a new entity based on an update response.
static scoped_ptr<EntityTracker> FromUpdateResponse(
static scoped_ptr<WorkerEntityTracker> FromUpdateResponse(
const UpdateResponseData& data);

// Initialize a new entity based on a commit request.
static scoped_ptr<EntityTracker> FromCommitRequest(
static scoped_ptr<WorkerEntityTracker> FromCommitRequest(
const CommitRequestData& data);

// Returns true if this entity should be commited to the server.
Expand Down Expand Up @@ -85,10 +85,10 @@ class SYNC_EXPORT EntityTracker {
private:
// Initializes the entity tracker's main fields. Does not initialize state
// related to a pending commit.
EntityTracker(const std::string& id,
const std::string& client_tag_hash,
int64_t highest_commit_response_version,
int64_t highest_gu_response_version);
WorkerEntityTracker(const std::string& id,
const std::string& client_tag_hash,
int64_t highest_commit_response_version,
int64_t highest_gu_response_version);

// Checks if the current state indicates a conflict.
//
Expand Down Expand Up @@ -130,9 +130,9 @@ class SYNC_EXPORT EntityTracker {
// source of pending updates is updates that can't currently be decrypted.
scoped_ptr<UpdateResponseData> pending_update_;

DISALLOW_COPY_AND_ASSIGN(EntityTracker);
DISALLOW_COPY_AND_ASSIGN(WorkerEntityTracker);
};

} // namespace syncer_v2

#endif // SYNC_ENGINE_ENTITY_TRACKER_H_
#endif // SYNC_ENGINE_WORKER_ENTITY_TRACKER_H_
Loading

0 comments on commit 4776274

Please sign in to comment.