diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-18 18:44:49 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-18 18:44:49 +0000 |
commit | e480e169e72bceecef04fe63c3bfea1f201af3bd (patch) | |
tree | 98a47302e51322f715095a49712bf8bc3a856fae | |
parent | 392767f9bea403dc9274b2ce3146ad027d6adb4d (diff) | |
download | chromium_src-e480e169e72bceecef04fe63c3bfea1f201af3bd.zip chromium_src-e480e169e72bceecef04fe63c3bfea1f201af3bd.tar.gz chromium_src-e480e169e72bceecef04fe63c3bfea1f201af3bd.tar.bz2 |
sync: Add definitions for ProtocolEvents
This is a part of a much larger change list. The eventual goal is to
have these ProtocolEvents emitted all the way to the UI thread, where
they can be displayed on about:sync.
This CL just defines the objects without using them.
BUG=349301
R=tim@chromium.org
Review URL: https://codereview.chromium.org/187083003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257700 0039d316-1c4b-4281-b951-d872f2087c98
17 files changed, 783 insertions, 2 deletions
diff --git a/sync/internal_api/events/commit_request_event.cc b/sync/internal_api/events/commit_request_event.cc new file mode 100644 index 0000000..bed23d3 --- /dev/null +++ b/sync/internal_api/events/commit_request_event.cc @@ -0,0 +1,54 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/internal_api/events/commit_request_event.h" + +#include "base/format_macros.h" +#include "base/strings/stringprintf.h" +#include "sync/protocol/proto_value_conversions.h" + +namespace syncer { + +CommitRequestEvent::CommitRequestEvent( + base::Time timestamp, + size_t num_items, + ModelTypeSet contributing_types_, + const sync_pb::ClientToServerMessage& request) + : timestamp_(timestamp), + num_items_(num_items), + contributing_types_(contributing_types_), + request_(request) {} + +CommitRequestEvent::~CommitRequestEvent() {} + +base::Time CommitRequestEvent::GetTimestamp() const { + return timestamp_; +} + +std::string CommitRequestEvent::GetType() const { + return "Commit Request"; +} + +std::string CommitRequestEvent::GetDetails() const { + return base::StringPrintf( + "Item count: %" PRIuS "\n" + "Contributing types: %s", + num_items_, + ModelTypeSetToString(contributing_types_).c_str()); +} + +scoped_ptr<base::DictionaryValue> CommitRequestEvent::GetProtoMessage() const { + return scoped_ptr<base::DictionaryValue>( + ClientToServerMessageToValue(request_, false)); +} + +scoped_ptr<ProtocolEvent> CommitRequestEvent::Clone() const { + return scoped_ptr<ProtocolEvent>( + new CommitRequestEvent(timestamp_, + num_items_, + contributing_types_, + request_)); +} + +} // namespace syncer diff --git a/sync/internal_api/events/commit_request_event.h b/sync/internal_api/events/commit_request_event.h new file mode 100644 index 0000000..cf379a9 --- /dev/null +++ b/sync/internal_api/events/commit_request_event.h @@ -0,0 +1,49 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_INTERNAL_API_EVENTS_COMMIT_REQUEST_EVENT_H +#define SYNC_INTERNAL_API_EVENTS_COMMIT_REQUEST_EVENT_H + +#include <cstddef> + +#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" +#include "base/values.h" +#include "sync/internal_api/public/base/model_type.h" +#include "sync/internal_api/public/events/protocol_event.h" +#include "sync/protocol/sync.pb.h" + +namespace syncer { + +// An event representing a commit request message sent to the server. +class CommitRequestEvent : public ProtocolEvent { + public: + CommitRequestEvent( + base::Time timestamp, + size_t num_items, + ModelTypeSet contributing_types, + const sync_pb::ClientToServerMessage& request); + virtual ~CommitRequestEvent(); + + virtual base::Time GetTimestamp() const OVERRIDE; + virtual std::string GetType() const OVERRIDE; + virtual std::string GetDetails() const OVERRIDE; + virtual scoped_ptr<base::DictionaryValue> GetProtoMessage() const OVERRIDE; + virtual scoped_ptr<ProtocolEvent> Clone() const OVERRIDE; + + static scoped_ptr<base::DictionaryValue> ToValue( + const ProtocolEvent& event); + + private: + const base::Time timestamp_; + const size_t num_items_; + const ModelTypeSet contributing_types_; + const sync_pb::ClientToServerMessage request_; + + DISALLOW_COPY_AND_ASSIGN(CommitRequestEvent); +}; + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_EVENTS_COMMIT_REQUEST_EVENT_H diff --git a/sync/internal_api/events/commit_response_event.cc b/sync/internal_api/events/commit_response_event.cc new file mode 100644 index 0000000..ec51f5e --- /dev/null +++ b/sync/internal_api/events/commit_response_event.cc @@ -0,0 +1,47 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/internal_api/events/commit_response_event.h" + +#include "base/strings/stringprintf.h" +#include "sync/protocol/proto_value_conversions.h" + +namespace syncer { + +CommitResponseEvent::CommitResponseEvent( + base::Time timestamp, + SyncerError result, + const sync_pb::ClientToServerResponse& response) + : timestamp_(timestamp), + result_(result), + response_(response) {} + +CommitResponseEvent::~CommitResponseEvent() {} + +base::Time CommitResponseEvent::GetTimestamp() const { + return timestamp_; +} + +std::string CommitResponseEvent::GetType() const { + return "Commit Response"; +} + +std::string CommitResponseEvent::GetDetails() const { + return base::StringPrintf("Result: %s", GetSyncerErrorString(result_)); +} + +scoped_ptr<base::DictionaryValue> CommitResponseEvent::GetProtoMessage() const { + return scoped_ptr<base::DictionaryValue>( + ClientToServerResponseToValue(response_, false)); +} + +scoped_ptr<ProtocolEvent> CommitResponseEvent::Clone() const { + return scoped_ptr<ProtocolEvent>( + new CommitResponseEvent( + timestamp_, + result_, + response_)); +} + +} // namespace syncer diff --git a/sync/internal_api/events/commit_response_event.h b/sync/internal_api/events/commit_response_event.h new file mode 100644 index 0000000..e1f1797 --- /dev/null +++ b/sync/internal_api/events/commit_response_event.h @@ -0,0 +1,47 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_INTERNAL_API_EVENTS_COMMIT_RESPONSE_EVENT_H_ +#define SYNC_INTERNAL_API_EVENTS_COMMIT_RESPONSE_EVENT_H_ + +#include <cstddef> + +#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" +#include "base/values.h" +#include "sync/internal_api/public/events/protocol_event.h" +#include "sync/internal_api/public/util/syncer_error.h" +#include "sync/protocol/sync.pb.h" + +namespace syncer { + +// An event representing a commit response event from the server. +class CommitResponseEvent : public ProtocolEvent { + public: + CommitResponseEvent( + base::Time timestamp, + SyncerError result, + const sync_pb::ClientToServerResponse& response); + virtual ~CommitResponseEvent(); + + virtual base::Time GetTimestamp() const OVERRIDE; + virtual std::string GetType() const OVERRIDE; + virtual std::string GetDetails() const OVERRIDE; + virtual scoped_ptr<base::DictionaryValue> GetProtoMessage() const OVERRIDE; + virtual scoped_ptr<ProtocolEvent> Clone() const OVERRIDE; + + static scoped_ptr<base::DictionaryValue> ToValue( + const ProtocolEvent& event); + + private: + const base::Time timestamp_; + const SyncerError result_; + const sync_pb::ClientToServerResponse response_; + + DISALLOW_COPY_AND_ASSIGN(CommitResponseEvent); +}; + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_EVENTS_COMMIT_RESPONSE_EVENT_H_ diff --git a/sync/internal_api/events/configure_get_updates_request_event.cc b/sync/internal_api/events/configure_get_updates_request_event.cc new file mode 100644 index 0000000..252ae0a --- /dev/null +++ b/sync/internal_api/events/configure_get_updates_request_event.cc @@ -0,0 +1,49 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/internal_api/events/configure_get_updates_request_event.h" + +#include "base/strings/stringprintf.h" +#include "sync/protocol/proto_enum_conversions.h" +#include "sync/protocol/proto_value_conversions.h" + +namespace syncer { + +ConfigureGetUpdatesRequestEvent::ConfigureGetUpdatesRequestEvent( + base::Time timestamp, + sync_pb::SyncEnums::GetUpdatesOrigin origin, + const sync_pb::ClientToServerMessage& request) + : timestamp_(timestamp), + origin_(origin), + request_(request) { } + +ConfigureGetUpdatesRequestEvent::~ConfigureGetUpdatesRequestEvent() {} + +base::Time ConfigureGetUpdatesRequestEvent::GetTimestamp() const { + return timestamp_; +} + +std::string ConfigureGetUpdatesRequestEvent::GetType() const { + return "Initial GetUpdates"; +} + +std::string ConfigureGetUpdatesRequestEvent::GetDetails() const { + return base::StringPrintf("Reason: %s", GetUpdatesOriginString(origin_)); +} + +scoped_ptr<base::DictionaryValue> +ConfigureGetUpdatesRequestEvent::GetProtoMessage() const { + return scoped_ptr<base::DictionaryValue>( + ClientToServerMessageToValue(request_, false)); +} + +scoped_ptr<ProtocolEvent> ConfigureGetUpdatesRequestEvent::Clone() const { + return scoped_ptr<ProtocolEvent>( + new ConfigureGetUpdatesRequestEvent( + timestamp_, + origin_, + request_)); +} + +} // namespace syncer diff --git a/sync/internal_api/events/configure_get_updates_request_event.h b/sync/internal_api/events/configure_get_updates_request_event.h new file mode 100644 index 0000000..eb783ab --- /dev/null +++ b/sync/internal_api/events/configure_get_updates_request_event.h @@ -0,0 +1,41 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_INTERNAL_API_EVENTS_CONFIGURE_GET_UPDATES_REQUEST_H +#define SYNC_INTERNAL_API_EVENTS_CONFIGURE_GET_UPDATES_REQUEST_H + +#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" +#include "base/values.h" +#include "sync/internal_api/public/events/protocol_event.h" +#include "sync/protocol/sync.pb.h" + +namespace syncer { + +// An event representing a configure GetUpdates request to the server. +class ConfigureGetUpdatesRequestEvent : public ProtocolEvent { + public: + ConfigureGetUpdatesRequestEvent( + base::Time timestamp, + sync_pb::SyncEnums::GetUpdatesOrigin origin, + const sync_pb::ClientToServerMessage& request); + virtual ~ConfigureGetUpdatesRequestEvent(); + + virtual base::Time GetTimestamp() const OVERRIDE; + virtual std::string GetType() const OVERRIDE; + virtual std::string GetDetails() const OVERRIDE; + virtual scoped_ptr<base::DictionaryValue> GetProtoMessage() const OVERRIDE; + virtual scoped_ptr<ProtocolEvent> Clone() const OVERRIDE; + + private: + const base::Time timestamp_; + const sync_pb::SyncEnums::GetUpdatesOrigin origin_; + const sync_pb::ClientToServerMessage request_; + + DISALLOW_COPY_AND_ASSIGN(ConfigureGetUpdatesRequestEvent); +}; + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_EVENTS_CONFIGURE_GET_UPDATES_REQUEST_H diff --git a/sync/internal_api/events/get_updates_response_event.cc b/sync/internal_api/events/get_updates_response_event.cc new file mode 100644 index 0000000..17c0e8e --- /dev/null +++ b/sync/internal_api/events/get_updates_response_event.cc @@ -0,0 +1,59 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/internal_api/events/get_updates_response_event.h" + +#include "base/strings/stringprintf.h" +#include "sync/protocol/proto_value_conversions.h" + +namespace syncer { + +GetUpdatesResponseEvent::GetUpdatesResponseEvent( + base::Time timestamp, + const sync_pb::ClientToServerResponse& response, + SyncerError error) + : timestamp_(timestamp), + response_(response), + error_(error) { +} + +GetUpdatesResponseEvent::~GetUpdatesResponseEvent() {} + +base::Time GetUpdatesResponseEvent::GetTimestamp() const { + return timestamp_; +} + +std::string GetUpdatesResponseEvent::GetType() const { + return "GetUpdates Response"; +} + +std::string GetUpdatesResponseEvent::GetDetails() const { + switch (error_) { + case SYNCER_OK: + return base::StringPrintf("Received %d update(s).", + response_.get_updates().entries_size()); + case SERVER_MORE_TO_DOWNLOAD: + return base::StringPrintf("Received %d update(s). Some updates remain.", + response_.get_updates().entries_size()); + default: + return base::StringPrintf("Received error: %s", + GetSyncerErrorString(error_)); + } +} + +scoped_ptr<base::DictionaryValue> +GetUpdatesResponseEvent::GetProtoMessage() const { + return scoped_ptr<base::DictionaryValue>( + ClientToServerResponseToValue(response_, false)); +} + +scoped_ptr<ProtocolEvent> GetUpdatesResponseEvent::Clone() const { + return scoped_ptr<ProtocolEvent>( + new GetUpdatesResponseEvent( + timestamp_, + response_, + error_)); +} + +} // namespace syncer diff --git a/sync/internal_api/events/get_updates_response_event.h b/sync/internal_api/events/get_updates_response_event.h new file mode 100644 index 0000000..1d31ccc --- /dev/null +++ b/sync/internal_api/events/get_updates_response_event.h @@ -0,0 +1,46 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_INTERNAL_API_EVENTS_GET_UPDATES_RESPONSE_EVENT_H +#define SYNC_INTERNAL_API_EVENTS_GET_UPDATES_RESPONSE_EVENT_H + +#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" +#include "base/values.h" +#include "sync/internal_api/public/events/protocol_event.h" +#include "sync/internal_api/public/util/syncer_error.h" +#include "sync/protocol/sync.pb.h" + +namespace syncer { + +// An event representing a GetUpdates response event from the server. +// +// Unlike the events for the request message, the response events are generic +// and do not vary for each type of GetUpdate cycle. +class GetUpdatesResponseEvent : public ProtocolEvent { + public: + GetUpdatesResponseEvent( + base::Time timestamp, + const sync_pb::ClientToServerResponse& response, + SyncerError error); + + virtual ~GetUpdatesResponseEvent(); + + virtual base::Time GetTimestamp() const OVERRIDE; + virtual std::string GetType() const OVERRIDE; + virtual std::string GetDetails() const OVERRIDE; + virtual scoped_ptr<base::DictionaryValue> GetProtoMessage() const OVERRIDE; + virtual scoped_ptr<ProtocolEvent> Clone() const OVERRIDE; + + private: + const base::Time timestamp_; + const sync_pb::ClientToServerResponse response_; + const SyncerError error_; + + DISALLOW_COPY_AND_ASSIGN(GetUpdatesResponseEvent); +}; + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_EVENTS_GET_UPDATES_RESPONSE_EVENT_H diff --git a/sync/internal_api/events/normal_get_updates_request_event.cc b/sync/internal_api/events/normal_get_updates_request_event.cc new file mode 100644 index 0000000..d6a2f884 --- /dev/null +++ b/sync/internal_api/events/normal_get_updates_request_event.cc @@ -0,0 +1,101 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/internal_api/events/normal_get_updates_request_event.h" + +#include "base/strings/stringprintf.h" +#include "sync/protocol/proto_value_conversions.h" +#include "sync/sessions/nudge_tracker.h" + +namespace syncer { + +NormalGetUpdatesRequestEvent::NormalGetUpdatesRequestEvent( + base::Time timestamp, + const sessions::NudgeTracker& nudge_tracker, + const sync_pb::ClientToServerMessage& request) + : timestamp_(timestamp), + nudged_types_(nudge_tracker.GetNudgedTypes()), + notified_types_(nudge_tracker.GetNotifiedTypes()), + refresh_requested_types_(nudge_tracker.GetRefreshRequestedTypes()), + is_retry_(nudge_tracker.IsRetryRequired()), + request_(request) { } + +NormalGetUpdatesRequestEvent::~NormalGetUpdatesRequestEvent() {} + +base::Time NormalGetUpdatesRequestEvent::GetTimestamp() const { + return timestamp_; +} + +std::string NormalGetUpdatesRequestEvent::GetType() const { + return "Normal GetUpdate request"; +} + +std::string NormalGetUpdatesRequestEvent::GetDetails() const { + std::string details; + + if (!nudged_types_.Empty()) { + if (!details.empty()) + details.append("\n"); + details.append(base::StringPrintf( + "Nudged types: %s", + ModelTypeSetToString(nudged_types_).c_str())); + } + + if (!notified_types_.Empty()) { + if (!details.empty()) + details.append("\n"); + details.append(base::StringPrintf( + "Notified types: %s", + ModelTypeSetToString(notified_types_).c_str())); + } + + if (!refresh_requested_types_.Empty()) { + if (!details.empty()) + details.append("\n"); + details.append(base::StringPrintf( + "Refresh requested types: %s", + ModelTypeSetToString(refresh_requested_types_).c_str())); + } + + if (is_retry_) { + if (!details.empty()) + details.append("\n"); + details.append(base::StringPrintf("Is retry: True")); + } + + return details; +} + +scoped_ptr<base::DictionaryValue> +NormalGetUpdatesRequestEvent::GetProtoMessage() const { + return scoped_ptr<base::DictionaryValue>( + ClientToServerMessageToValue(request_, false)); +} + +scoped_ptr<ProtocolEvent> NormalGetUpdatesRequestEvent::Clone() const { + return scoped_ptr<ProtocolEvent>( + new NormalGetUpdatesRequestEvent( + timestamp_, + nudged_types_, + notified_types_, + refresh_requested_types_, + is_retry_, + request_)); +} + +NormalGetUpdatesRequestEvent::NormalGetUpdatesRequestEvent( + base::Time timestamp, + ModelTypeSet nudged_types, + ModelTypeSet notified_types, + ModelTypeSet refresh_requested_types, + bool is_retry, + sync_pb::ClientToServerMessage request) + : timestamp_(timestamp), + nudged_types_(nudged_types), + notified_types_(notified_types), + refresh_requested_types_(refresh_requested_types), + is_retry_(is_retry), + request_(request) {} + +} // namespace diff --git a/sync/internal_api/events/normal_get_updates_request_event.h b/sync/internal_api/events/normal_get_updates_request_event.h new file mode 100644 index 0000000..7d0b874 --- /dev/null +++ b/sync/internal_api/events/normal_get_updates_request_event.h @@ -0,0 +1,60 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_INTERNAL_API_EVENTS_NORMAL_GET_UPDATES_REQUEST_H +#define SYNC_INTERNAL_API_EVENTS_NORMAL_GET_UPDATES_REQUEST_H + +#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" +#include "base/values.h" +#include "sync/internal_api/public/base/model_type.h" +#include "sync/internal_api/public/events/protocol_event.h" +#include "sync/protocol/sync.pb.h" + +namespace syncer { + +namespace sessions { +class NudgeTracker; +} // namespace sessions + +// An event representing a 'normal mode' GetUpdate request to the server. +class NormalGetUpdatesRequestEvent : public ProtocolEvent { + public: + NormalGetUpdatesRequestEvent( + base::Time timestamp, + const sessions::NudgeTracker& nudge_tracker, + const sync_pb::ClientToServerMessage& request); + + virtual ~NormalGetUpdatesRequestEvent(); + + virtual base::Time GetTimestamp() const OVERRIDE; + virtual std::string GetType() const OVERRIDE; + virtual std::string GetDetails() const OVERRIDE; + virtual scoped_ptr<base::DictionaryValue> GetProtoMessage() const OVERRIDE; + virtual scoped_ptr<ProtocolEvent> Clone() const OVERRIDE; + + private: + NormalGetUpdatesRequestEvent( + base::Time timestamp, + ModelTypeSet nudged_types, + ModelTypeSet notified_types, + ModelTypeSet refresh_requested_types, + bool is_retry, + sync_pb::ClientToServerMessage request); + + const base::Time timestamp_; + + const ModelTypeSet nudged_types_; + const ModelTypeSet notified_types_; + const ModelTypeSet refresh_requested_types_; + const bool is_retry_; + + const sync_pb::ClientToServerMessage request_; + + DISALLOW_COPY_AND_ASSIGN(NormalGetUpdatesRequestEvent); +}; + +} + +#endif // SYNC_INTERNAL_API_EVENTS_NORMAL_GET_UPDATES_REQUEST_H diff --git a/sync/internal_api/events/poll_get_updates_request_event.cc b/sync/internal_api/events/poll_get_updates_request_event.cc new file mode 100644 index 0000000..802d4cb --- /dev/null +++ b/sync/internal_api/events/poll_get_updates_request_event.cc @@ -0,0 +1,44 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/internal_api/events/poll_get_updates_request_event.h" + +#include "sync/protocol/proto_value_conversions.h" + +namespace syncer { + +PollGetUpdatesRequestEvent::PollGetUpdatesRequestEvent( + base::Time timestamp, + const sync_pb::ClientToServerMessage& request) + : timestamp_(timestamp), + request_(request) { } + +PollGetUpdatesRequestEvent::~PollGetUpdatesRequestEvent() {} + +base::Time PollGetUpdatesRequestEvent::GetTimestamp() const { + return timestamp_; +} + +std::string PollGetUpdatesRequestEvent::GetType() const { + return "Poll GetUpdate request"; +} + +std::string PollGetUpdatesRequestEvent::GetDetails() const { + return std::string(); +} + +scoped_ptr<base::DictionaryValue> +PollGetUpdatesRequestEvent::GetProtoMessage() const { + return scoped_ptr<base::DictionaryValue>( + ClientToServerMessageToValue(request_, false)); +} + +scoped_ptr<ProtocolEvent> PollGetUpdatesRequestEvent::Clone() const { + return scoped_ptr<ProtocolEvent>( + new PollGetUpdatesRequestEvent( + timestamp_, + request_)); +} + +} // namespace diff --git a/sync/internal_api/events/poll_get_updates_request_event.h b/sync/internal_api/events/poll_get_updates_request_event.h new file mode 100644 index 0000000..d4a679c --- /dev/null +++ b/sync/internal_api/events/poll_get_updates_request_event.h @@ -0,0 +1,44 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_INTERNAL_API_EVENTS_POLL_GET_UPDATES_REQUEST_H +#define SYNC_INTERNAL_API_EVENTS_POLL_GET_UPDATES_REQUEST_H + +#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" +#include "base/values.h" +#include "sync/internal_api/public/base/model_type.h" +#include "sync/internal_api/public/events/protocol_event.h" +#include "sync/protocol/sync.pb.h" + +namespace syncer { + +namespace sessions { +class NudgeTracker; +} // namespace sessions + +// An event representing a poll request sent to the server. +class PollGetUpdatesRequestEvent : public ProtocolEvent { + public: + PollGetUpdatesRequestEvent( + base::Time timestamp, + const sync_pb::ClientToServerMessage& request); + virtual ~PollGetUpdatesRequestEvent(); + + virtual base::Time GetTimestamp() const OVERRIDE; + virtual std::string GetType() const OVERRIDE; + virtual std::string GetDetails() const OVERRIDE; + virtual scoped_ptr<base::DictionaryValue> GetProtoMessage() const OVERRIDE; + virtual scoped_ptr<ProtocolEvent> Clone() const OVERRIDE; + + private: + const base::Time timestamp_; + const sync_pb::ClientToServerMessage request_; + + DISALLOW_COPY_AND_ASSIGN(PollGetUpdatesRequestEvent); +}; + +} + +#endif // SYNC_INTERNAL_API_EVENTS_POLL_GET_UPDATES_REQUEST_H diff --git a/sync/internal_api/events/protocol_event.cc b/sync/internal_api/events/protocol_event.cc new file mode 100644 index 0000000..78682b4 --- /dev/null +++ b/sync/internal_api/events/protocol_event.cc @@ -0,0 +1,25 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/internal_api/public/events/protocol_event.h" + +namespace syncer { + +ProtocolEvent::ProtocolEvent() {} + +ProtocolEvent::~ProtocolEvent() {} + +scoped_ptr<base::DictionaryValue> ProtocolEvent::ToValue( + const ProtocolEvent& event) { + scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); + + dict->SetDouble("time", event.GetTimestamp().ToJsTime()); + dict->SetString("type", event.GetType()); + dict->SetString("details", event.GetDetails()); + dict->Set("proto", event.GetProtoMessage().release()); + + return dict.Pass(); +} + +} // namespace syncer diff --git a/sync/internal_api/public/events/protocol_event.h b/sync/internal_api/public/events/protocol_event.h new file mode 100644 index 0000000..fc69e00 --- /dev/null +++ b/sync/internal_api/public/events/protocol_event.h @@ -0,0 +1,59 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_INTERNAL_API_PUBLIC_EVENTS_PROTOCOL_EVENT_H +#define SYNC_INTERNAL_API_PUBLIC_EVENTS_PROTOCOL_EVENT_H + +#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" +#include "base/values.h" +#include "sync/base/sync_export.h" + +namespace syncer { + +// SyncNetworkEvents represent a single client <-> server sync protocol event +// that recently took place. Sync protocol events occur when the client decides +// to send a sync protocol request (such as GetUpdates or Commit) to the server, +// and when the server responds. Note that the requests and responses themselves +// are modelled by {GetUpdates, Commit}x{Request,Response} objects. +// +// These objects are intended to be used for displaying information on +// about:sync. They should be considered to be immutable and opaque. No +// program behavior should depend on their contents. +// +// Each type of request can maintain its own set of additional metadata and have +// its own custom serialization routines. For example, the "configure" +// GetUpdates request will include information about its "origin" in its debug +// info. +class SYNC_EXPORT ProtocolEvent { + public: + ProtocolEvent(); + virtual ~ProtocolEvent(); + + // Returns the time when the request was sent or received. + virtual base::Time GetTimestamp() const = 0; + + // Returns a string representing they type of the request. Should be short. + virtual std::string GetType() const = 0; + + // Returns a string representing details of the request. May be verbose. The + // implementer is allowed to return lots of data separated by newlines. + virtual std::string GetDetails() const = 0; + + // Returns a DictionaryValue representing the protobuf message associated with + // this event. + virtual scoped_ptr<base::DictionaryValue> GetProtoMessage() const = 0; + + // Need a virtual copy contructor to copy this object across threads. + virtual scoped_ptr<ProtocolEvent> Clone() const = 0; + + // A static function that assembles the data exposed through the + // ProtocolEvent's interface into a single DictionaryValue. + static scoped_ptr<base::DictionaryValue> ToValue( + const ProtocolEvent& event); +}; + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_PUBLIC_EVENTS_PROTOCOL_EVENT_H diff --git a/sync/sessions/nudge_tracker.cc b/sync/sessions/nudge_tracker.cc index 5b599b8..e9e731d 100644 --- a/sync/sessions/nudge_tracker.cc +++ b/sync/sessions/nudge_tracker.cc @@ -201,6 +201,39 @@ ModelTypeSet NudgeTracker::GetThrottledTypes() const { return result; } +ModelTypeSet NudgeTracker::GetNudgedTypes() const { + ModelTypeSet result; + for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); + it != type_trackers_.end(); ++it) { + if (it->second.HasLocalChangePending()) { + result.Put(it->first); + } + } + return result; +} + +ModelTypeSet NudgeTracker::GetNotifiedTypes() const { + ModelTypeSet result; + for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); + it != type_trackers_.end(); ++it) { + if (it->second.HasPendingInvalidation()) { + result.Put(it->first); + } + } + return result; +} + +ModelTypeSet NudgeTracker::GetRefreshRequestedTypes() const { + ModelTypeSet result; + for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); + it != type_trackers_.end(); ++it) { + if (it->second.HasRefreshRequestPending()) { + result.Put(it->first); + } + } + return result; +} + void NudgeTracker::SetLegacyNotificationHint( ModelType type, sync_pb::DataTypeProgressMarker* progress) const { diff --git a/sync/sessions/nudge_tracker.h b/sync/sessions/nudge_tracker.h index 4a167bb8..e14f31f 100644 --- a/sync/sessions/nudge_tracker.h +++ b/sync/sessions/nudge_tracker.h @@ -86,6 +86,15 @@ class SYNC_EXPORT_PRIVATE NudgeTracker { // Returns the set of currently throttled types. ModelTypeSet GetThrottledTypes() const; + // Returns the set of types with local changes pending. + ModelTypeSet GetNudgedTypes() const; + + // Returns the set of types that have pending invalidations. + ModelTypeSet GetNotifiedTypes() const; + + // Returns the set of types that have pending refresh requests. + ModelTypeSet GetRefreshRequestedTypes() const; + // Returns the 'source' of the GetUpdate request. // // This flag is deprecated, but still used by the server. There can be more diff --git a/sync/sync_internal_api.gypi b/sync/sync_internal_api.gypi index abcfa4f..77416eb 100644 --- a/sync/sync_internal_api.gypi +++ b/sync/sync_internal_api.gypi @@ -21,9 +21,22 @@ 'internal_api/change_record.cc', 'internal_api/change_reorder_buffer.cc', 'internal_api/change_reorder_buffer.h', - 'internal_api/delete_journal.cc', 'internal_api/debug_info_event_listener.cc', 'internal_api/debug_info_event_listener.h', + 'internal_api/delete_journal.cc', + 'internal_api/events/commit_request_event.cc', + 'internal_api/events/commit_request_event.h', + 'internal_api/events/commit_response_event.cc', + 'internal_api/events/commit_response_event.h', + 'internal_api/events/configure_get_updates_request_event.cc', + 'internal_api/events/configure_get_updates_request_event.h', + 'internal_api/events/get_updates_response_event.cc', + 'internal_api/events/get_updates_response_event.h', + 'internal_api/events/normal_get_updates_request_event.cc', + 'internal_api/events/normal_get_updates_request_event.h', + 'internal_api/events/poll_get_updates_request_event.cc', + 'internal_api/events/poll_get_updates_request_event.h', + 'internal_api/events/protocol_event.cc', 'internal_api/http_bridge.cc', 'internal_api/http_bridge_network_resources.cc', 'internal_api/internal_components_factory_impl.cc', @@ -33,7 +46,6 @@ 'internal_api/js_sync_encryption_handler_observer.h', 'internal_api/js_sync_manager_observer.cc', 'internal_api/js_sync_manager_observer.h', - 'internal_api/public/base/enum_set.h', 'internal_api/public/base/ack_handle.cc', 'internal_api/public/base/ack_handle.h', 'internal_api/public/base/cancelation_observer.cc', @@ -41,6 +53,7 @@ 'internal_api/public/base/cancelation_signal.cc', 'internal_api/public/base/cancelation_signal.h', 'internal_api/public/base/enum_set.h', + 'internal_api/public/base/enum_set.h', 'internal_api/public/base/invalidation.cc', 'internal_api/public/base/invalidation.h', 'internal_api/public/base/model_type.h', @@ -68,6 +81,7 @@ 'internal_api/public/engine/polling_constants.h', 'internal_api/public/engine/sync_status.cc', 'internal_api/public/engine/sync_status.h', + 'internal_api/public/events/protocol_event.h', 'internal_api/public/http_bridge.h', 'internal_api/public/http_bridge_network_resources.h', 'internal_api/public/http_post_provider_factory.h', |