summaryrefslogtreecommitdiffstats
path: root/sync/engine
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 22:14:35 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 22:14:35 +0000
commiteb370fc0fba62ea44db5c35514fb3223523928cc (patch)
tree314febd8e19760c68cd7a20c1fd95bc5a26c1f97 /sync/engine
parent560b54e7a49100618417e59a0f1589c864816b6a (diff)
downloadchromium_src-eb370fc0fba62ea44db5c35514fb3223523928cc.zip
chromium_src-eb370fc0fba62ea44db5c35514fb3223523928cc.tar.gz
chromium_src-eb370fc0fba62ea44db5c35514fb3223523928cc.tar.bz2
sync: Expose ProtocolEvents on ProfileSyncService
Adds code to the sync engine to have it generate protocol events when it contacts the server. These events are then sent through the SyncSession, SyncManager, SyncBackendHostCore, SyncBackendHost, and finally to the ProfileSyncService. Objects on the UI thread can register with the ProfileSyncService as observers of these events, though this CL does not introduce any of these listeners. BUG=349301 Review URL: https://codereview.chromium.org/203463005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine')
-rw-r--r--sync/engine/DEPS1
-rw-r--r--sync/engine/all_status.cc2
-rw-r--r--sync/engine/all_status.h1
-rw-r--r--sync/engine/commit.cc17
-rw-r--r--sync/engine/get_updates_delegate.cc27
-rw-r--r--sync/engine/get_updates_delegate.h14
-rw-r--r--sync/engine/get_updates_processor.cc20
-rw-r--r--sync/engine/sync_engine_event_listener.h4
-rw-r--r--sync/engine/sync_scheduler_impl.cc2
-rw-r--r--sync/engine/syncer_proto_util_unittest.cc2
-rw-r--r--sync/engine/syncer_unittest.cc1
11 files changed, 86 insertions, 5 deletions
diff --git a/sync/engine/DEPS b/sync/engine/DEPS
index b43d31c..0978697 100644
--- a/sync/engine/DEPS
+++ b/sync/engine/DEPS
@@ -2,6 +2,7 @@ include_rules = [
"+sync/base",
"+sync/internal_api/public/base",
"+sync/internal_api/public/engine",
+ "+sync/internal_api/public/events",
"+sync/internal_api/public/sessions",
"+sync/internal_api/public/test",
"+sync/internal_api/public/util",
diff --git a/sync/engine/all_status.cc b/sync/engine/all_status.cc
index 6fa98d3..d73f206 100644
--- a/sync/engine/all_status.cc
+++ b/sync/engine/all_status.cc
@@ -124,6 +124,8 @@ void AllStatus::OnThrottledTypesChanged(ModelTypeSet throttled_types) {
void AllStatus::OnMigrationRequested(ModelTypeSet) {}
+void AllStatus::OnProtocolEvent(const ProtocolEvent&) {}
+
SyncStatus AllStatus::status() const {
base::AutoLock lock(mutex_);
return status_;
diff --git a/sync/engine/all_status.h b/sync/engine/all_status.h
index add42e5..999f2f3 100644
--- a/sync/engine/all_status.h
+++ b/sync/engine/all_status.h
@@ -46,6 +46,7 @@ class AllStatus : public SyncEngineEventListener {
virtual void OnRetryTimeChanged(base::Time retry_time) OVERRIDE;
virtual void OnThrottledTypesChanged(ModelTypeSet throttled_types) OVERRIDE;
virtual void OnMigrationRequested(ModelTypeSet types) OVERRIDE;
+ virtual void OnProtocolEvent(const ProtocolEvent& event) OVERRIDE;
SyncStatus status() const;
diff --git a/sync/engine/commit.cc b/sync/engine/commit.cc
index 90b9742..92cf4d2 100644
--- a/sync/engine/commit.cc
+++ b/sync/engine/commit.cc
@@ -10,6 +10,8 @@
#include "sync/engine/commit_util.h"
#include "sync/engine/syncer.h"
#include "sync/engine/syncer_proto_util.h"
+#include "sync/internal_api/public/events/commit_request_event.h"
+#include "sync/internal_api/public/events/commit_response_event.h"
#include "sync/sessions/sync_session.h"
namespace syncer {
@@ -97,11 +99,26 @@ SyncerError Commit::PostAndProcessResponse(
}
DVLOG(1) << "Sending commit message.";
+
+ CommitRequestEvent request_event(
+ base::Time::Now(),
+ message_.commit().entries_size(),
+ request_types,
+ message_);
+ session->SendProtocolEvent(request_event);
+
TRACE_EVENT_BEGIN0("sync", "PostCommit");
const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage(
&message_, &response_, session);
TRACE_EVENT_END0("sync", "PostCommit");
+ // TODO(rlarocque): Use result that includes errors captured later?
+ CommitResponseEvent response_event(
+ base::Time::Now(),
+ post_result,
+ response_);
+ session->SendProtocolEvent(response_event);
+
if (post_result != SYNCER_OK) {
LOG(WARNING) << "Post commit failed";
return post_result;
diff --git a/sync/engine/get_updates_delegate.cc b/sync/engine/get_updates_delegate.cc
index 4697485..fe53841 100644
--- a/sync/engine/get_updates_delegate.cc
+++ b/sync/engine/get_updates_delegate.cc
@@ -6,6 +6,9 @@
#include "sync/engine/directory_update_handler.h"
#include "sync/engine/get_updates_processor.h"
+#include "sync/internal_api/public/events/configure_get_updates_request_event.h"
+#include "sync/internal_api/public/events/normal_get_updates_request_event.h"
+#include "sync/internal_api/public/events/poll_get_updates_request_event.h"
namespace syncer {
@@ -80,6 +83,13 @@ void NormalGetUpdatesDelegate::ApplyUpdates(
NonPassiveApplyUpdates(status_controller, update_handler_map);
}
+scoped_ptr<ProtocolEvent> NormalGetUpdatesDelegate::GetNetworkRequestEvent(
+ base::Time timestamp,
+ const sync_pb::ClientToServerMessage& request) const {
+ return scoped_ptr<ProtocolEvent>(
+ new NormalGetUpdatesRequestEvent(timestamp, nudge_tracker_, request));
+}
+
ConfigureGetUpdatesDelegate::ConfigureGetUpdatesDelegate(
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) : source_(source) {}
@@ -97,6 +107,16 @@ void ConfigureGetUpdatesDelegate::ApplyUpdates(
PassiveApplyUpdates(status_controller, update_handler_map);
}
+scoped_ptr<ProtocolEvent> ConfigureGetUpdatesDelegate::GetNetworkRequestEvent(
+ base::Time timestamp,
+ const sync_pb::ClientToServerMessage& request) const {
+ return scoped_ptr<ProtocolEvent>(
+ new ConfigureGetUpdatesRequestEvent(
+ timestamp,
+ ConvertConfigureSourceToOrigin(source_),
+ request));
+}
+
sync_pb::SyncEnums::GetUpdatesOrigin
ConfigureGetUpdatesDelegate::ConvertConfigureSourceToOrigin(
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) {
@@ -136,4 +156,11 @@ void PollGetUpdatesDelegate::ApplyUpdates(
NonPassiveApplyUpdates(status_controller, update_handler_map);
}
+scoped_ptr<ProtocolEvent> PollGetUpdatesDelegate::GetNetworkRequestEvent(
+ base::Time timestamp,
+ const sync_pb::ClientToServerMessage& request) const {
+ return scoped_ptr<ProtocolEvent>(
+ new PollGetUpdatesRequestEvent(timestamp, request));
+}
+
} // namespace syncer
diff --git a/sync/engine/get_updates_delegate.h b/sync/engine/get_updates_delegate.h
index 9ebc6d8..d897edf 100644
--- a/sync/engine/get_updates_delegate.h
+++ b/sync/engine/get_updates_delegate.h
@@ -5,6 +5,7 @@
#ifndef SYNC_ENGINE_GET_UPDATES_DELEGATE_H_
#define SYNC_ENGINE_GET_UPDATES_DELEGATE_H_
+#include "sync/internal_api/public/events/protocol_event.h"
#include "sync/protocol/sync.pb.h"
#include "sync/sessions/model_type_registry.h"
#include "sync/sessions/nudge_tracker.h"
@@ -31,6 +32,10 @@ class SYNC_EXPORT_PRIVATE GetUpdatesDelegate {
virtual void ApplyUpdates(
sessions::StatusController* session,
UpdateHandlerMap* update_handler_map) const = 0;
+
+ virtual scoped_ptr<ProtocolEvent> GetNetworkRequestEvent(
+ base::Time timestamp,
+ const sync_pb::ClientToServerMessage& request) const = 0;
};
// Functionality specific to the normal GetUpdate request.
@@ -48,6 +53,9 @@ class SYNC_EXPORT_PRIVATE NormalGetUpdatesDelegate : public GetUpdatesDelegate {
sessions::StatusController* status,
UpdateHandlerMap* update_handler_map) const OVERRIDE;
+ virtual scoped_ptr<ProtocolEvent> GetNetworkRequestEvent(
+ base::Time timestamp,
+ const sync_pb::ClientToServerMessage& request) const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(NormalGetUpdatesDelegate);
@@ -74,6 +82,9 @@ class SYNC_EXPORT_PRIVATE ConfigureGetUpdatesDelegate
sessions::StatusController* status,
UpdateHandlerMap* update_handler_map) const OVERRIDE;
+ virtual scoped_ptr<ProtocolEvent> GetNetworkRequestEvent(
+ base::Time timestamp,
+ const sync_pb::ClientToServerMessage& request) const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(ConfigureGetUpdatesDelegate);
@@ -98,6 +109,9 @@ class SYNC_EXPORT_PRIVATE PollGetUpdatesDelegate : public GetUpdatesDelegate {
sessions::StatusController* status,
UpdateHandlerMap* update_handler_map) const OVERRIDE;
+ virtual scoped_ptr<ProtocolEvent> GetNetworkRequestEvent(
+ base::Time timestamp,
+ const sync_pb::ClientToServerMessage& request) const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(PollGetUpdatesDelegate);
};
diff --git a/sync/engine/get_updates_processor.cc b/sync/engine/get_updates_processor.cc
index 399c78c..a5ab59b 100644
--- a/sync/engine/get_updates_processor.cc
+++ b/sync/engine/get_updates_processor.cc
@@ -10,6 +10,7 @@
#include "sync/engine/get_updates_delegate.h"
#include "sync/engine/syncer_proto_util.h"
#include "sync/engine/update_handler.h"
+#include "sync/internal_api/public/events/get_updates_response_event.h"
#include "sync/protocol/sync.pb.h"
#include "sync/sessions/status_controller.h"
#include "sync/sessions/sync_session.h"
@@ -193,6 +194,9 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates(
CopyClientDebugInfo(session->context()->debug_info_getter(), debug_info);
}
+ session->SendProtocolEvent(
+ *(delegate_.GetNetworkRequestEvent(base::Time::Now(), *msg)));
+
SyncerError result = SyncerProtoUtil::PostClientToServerMessage(
msg,
&update_response,
@@ -202,6 +206,10 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates(
update_response);
if (result != SYNCER_OK) {
+ GetUpdatesResponseEvent response_event(
+ base::Time::Now(), update_response, result);
+ session->SendProtocolEvent(response_event);
+
LOG(ERROR) << "PostClientToServerMessage() failed during GetUpdates";
return result;
}
@@ -225,9 +233,15 @@ SyncerError GetUpdatesProcessor::ExecuteDownloadUpdates(
HandleGetEncryptionKeyResponse(update_response, dir));
}
- return ProcessResponse(update_response.get_updates(),
- request_types,
- status);
+ SyncerError process_result = ProcessResponse(update_response.get_updates(),
+ request_types,
+ status);
+
+ GetUpdatesResponseEvent response_event(
+ base::Time::Now(), update_response, process_result);
+ session->SendProtocolEvent(response_event);
+
+ return process_result;
}
SyncerError GetUpdatesProcessor::ProcessResponse(
diff --git a/sync/engine/sync_engine_event_listener.h b/sync/engine/sync_engine_event_listener.h
index 35fc05e..d5678a9 100644
--- a/sync/engine/sync_engine_event_listener.h
+++ b/sync/engine/sync_engine_event_listener.h
@@ -13,6 +13,7 @@ namespace syncer {
struct SyncProtocolError;
struct SyncCycleEvent;
+class ProtocolEvent;
class SYNC_EXPORT_PRIVATE SyncEngineEventListener {
public:
@@ -36,6 +37,9 @@ class SYNC_EXPORT_PRIVATE SyncEngineEventListener {
// This event is sent when the server requests a migration.
virtual void OnMigrationRequested(ModelTypeSet migration_types) = 0;
+ // Emits events when sync communicates with the server.
+ virtual void OnProtocolEvent(const ProtocolEvent& event) = 0;
+
protected:
virtual ~SyncEngineEventListener();
};
diff --git a/sync/engine/sync_scheduler_impl.cc b/sync/engine/sync_scheduler_impl.cc
index a9c6359..2240cd6 100644
--- a/sync/engine/sync_scheduler_impl.cc
+++ b/sync/engine/sync_scheduler_impl.cc
@@ -744,6 +744,7 @@ void SyncSchedulerImpl::Unthrottle() {
// We're no longer throttled, so clear the wait interval.
wait_interval_.reset();
NotifyRetryTime(base::Time());
+ NotifyThrottledTypesChanged(nudge_tracker_.GetThrottledTypes());
// We treat this as a 'canary' in the sense that it was originally scheduled
// to run some time ago, failed, and we now want to retry, versus a job that
@@ -815,6 +816,7 @@ void SyncSchedulerImpl::OnThrottled(const base::TimeDelta& throttle_duration) {
wait_interval_.reset(new WaitInterval(WaitInterval::THROTTLED,
throttle_duration));
NotifyRetryTime(base::Time::Now() + wait_interval_->length);
+ NotifyThrottledTypesChanged(ModelTypeSet::All());
}
void SyncSchedulerImpl::OnTypesThrottled(
diff --git a/sync/engine/syncer_proto_util_unittest.cc b/sync/engine/syncer_proto_util_unittest.cc
index d43b350..93f9088 100644
--- a/sync/engine/syncer_proto_util_unittest.cc
+++ b/sync/engine/syncer_proto_util_unittest.cc
@@ -39,13 +39,11 @@ class MockDelegate : public sessions::SyncSession::Delegate {
MockDelegate() {}
~MockDelegate() {}
- MOCK_METHOD0(IsSyncingCurrentlySilenced, bool());
MOCK_METHOD1(OnReceivedShortPollIntervalUpdate, void(const base::TimeDelta&));
MOCK_METHOD1(OnReceivedLongPollIntervalUpdate ,void(const base::TimeDelta&));
MOCK_METHOD1(OnReceivedSessionsCommitDelay, void(const base::TimeDelta&));
MOCK_METHOD1(OnReceivedClientInvalidationHintBufferSize, void(int));
MOCK_METHOD1(OnSyncProtocolError, void(const SyncProtocolError&));
- MOCK_METHOD1(OnSilencedUntil, void(const base::TimeTicks&));
};
// Builds a ClientToServerResponse with some data type ids, including
diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc
index d0a2ab4..7a3afe3 100644
--- a/sync/engine/syncer_unittest.cc
+++ b/sync/engine/syncer_unittest.cc
@@ -152,6 +152,7 @@ class SyncerTest : public testing::Test,
}
virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) OVERRIDE {}
virtual void OnReceivedMigrationRequest(ModelTypeSet types) OVERRIDE {}
+ virtual void OnProtocolEvent(const ProtocolEvent& event) OVERRIDE {}
virtual void OnSyncProtocolError(const SyncProtocolError& error) OVERRIDE {}
void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {