Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1519)

Unified Diff: chrome/browser/sync/protocol/proto_value_conversions.cc

Issue 9663023: Log the sync communication that happens between client and server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/protocol/proto_value_conversions.cc
diff --git a/chrome/browser/sync/protocol/proto_value_conversions.cc b/chrome/browser/sync/protocol/proto_value_conversions.cc
index 86b632e7dff96362ce0ade21d1419c857717a33f..7080d40d2997f68af0ffe9057680be796827a31b 100644
--- a/chrome/browser/sync/protocol/proto_value_conversions.cc
+++ b/chrome/browser/sync/protocol/proto_value_conversions.cc
@@ -8,6 +8,8 @@
#include "base/base64.h"
#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
@@ -397,6 +399,183 @@ DictionaryValue* EntitySpecificsToValue(
return value;
}
+DictionaryValue* SyncEntityToValue(const sync_pb::SyncEntity& proto,
akalin 2012/03/13 00:20:43 declarations for these functions in the header fil
lipalani1 2012/03/13 21:32:40 Put them on a namespace. They are not used elsewhe
+ bool decode_specifics) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_STR(id_string);
+ SET_STR(parent_id_string);
+ SET_STR(old_parent_id);
+ SET_INT64(version);
+ SET_INT64(mtime);
+ SET_INT64(ctime);
+ SET_STR(name);
+ SET_STR(non_unique_name);
+ SET_INT64(sync_timestamp);
+ SET_STR(server_defined_unique_tag);
+ SET_INT64(position_in_parent);
+ SET_STR(insert_after_item_id);
+ SET_BOOL(deleted);
+ SET_STR(originator_cache_guid);
+ SET_STR(originator_client_item_id);
+ // Let us not go through the specifics if we dont have to.
akalin 2012/03/13 00:20:43 Seems like premature optimization, since this code
lipalani1 2012/03/13 21:32:40 removed the comment. The optimization is needed fo
+ // So we save some CPU cycles in retail builds.
+ // This would be particularly useful in first sync scenarios.
+ // In that case it saves both memory and CPU.
+ if (decode_specifics)
+ SET(specifics, EntitySpecificsToValue);
+ SET_BOOL(folder);
+ SET_STR(client_defined_unique_tag);
+ return value;
+}
+
+void ConvertSyncEntitiesToValue(DictionaryValue* value,
+ ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities,
+ bool decode_specifics) {
+ CHECK(value);
+
+ ListValue* list = new ListValue();
+ ::google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>::const_iterator it;
+ for (it = entities.begin(); it != entities.end(); ++it) {
+ list->Append(SyncEntityToValue(*it, decode_specifics));
+ }
+
+ value->Set("entries", list);
+}
+
+DictionaryValue* ChromiumExtensionActivityToValue(
+ const sync_pb::ChromiumExtensionsActivity& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_STR(extension_id);
+ SET_INT32(bookmark_writes_since_last_commit);
+ return value;
+}
+
+DictionaryValue* CommitMessageToValue(const sync_pb::CommitMessage& proto,
+ bool decode_specifics) {
+ DictionaryValue* value = new DictionaryValue();
+ ConvertSyncEntitiesToValue(value, proto.entries(), decode_specifics);
+ SET_STR(cache_guid);
+ SET_REP(extensions_activity, ChromiumExtensionActivityToValue);
+ return value;
+}
+
+DictionaryValue* DataTypeProgressMarkerToValue(
+ const sync_pb::DataTypeProgressMarker& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_INT32(data_type_id);
+ SET_BYTES(token);
+ SET_INT64(timestamp_token_for_migration);
+ SET_STR(notification_hint);
+ return value;
+}
+
+DictionaryValue* GetUpdatesCallerInfoToValue(
+ const sync_pb::GetUpdatesCallerInfo& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_ENUM(source, GetUpdatesSourceString);
+ SET_BOOL(notifications_enabled);
+ return value;
+}
+
+DictionaryValue* GetUpdatesMessageToValue(
+ const sync_pb::GetUpdatesMessage& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET(caller_info, GetUpdatesCallerInfoToValue);
+ SET_BOOL(fetch_folders);
+ SET_INT32(batch_size);
+ SET_REP(from_progress_marker, DataTypeProgressMarkerToValue);
+ SET_BOOL(streaming);
+ SET_BOOL(create_mobile_bookmarks_folder);
+ return value;
+}
+
+DictionaryValue* EntryResponseToValue(
+ const sync_pb::CommitResponse::EntryResponse& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_ENUM(response_type, ResponseTypeString);
+ SET_STR(id_string);
+ SET_STR(parent_id_string);
+ SET_INT64(position_in_parent);
+ SET_INT64(version);
+ SET_STR(name);
+ SET_STR(error_message);
+ SET_INT64(mtime);
+ return value;
+}
+
+DictionaryValue* CommitResponseToValue(const sync_pb::CommitResponse& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_REP(entryresponse, EntryResponseToValue);
+ return value;
+}
+
+DictionaryValue* GetUpdatesResponseToValue(
+ const sync_pb::GetUpdatesResponse& proto,
+ bool decode_specifics) {
+ DictionaryValue* value = new DictionaryValue();
+ ConvertSyncEntitiesToValue(value, proto.entries(), decode_specifics);
+ SET_INT64(changes_remaining);
+ SET_REP(new_progress_marker, DataTypeProgressMarkerToValue);
+ return value;
+}
+
+DictionaryValue* ClientCommandToValue(const sync_pb::ClientCommand& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_INT32(set_sync_poll_interval);
+ SET_INT32(set_sync_long_poll_interval);
+ SET_INT32(max_commit_batch_size);
+ SET_INT32(sessions_commit_delay_seconds);
+ SET_INT32(throttle_delay_seconds);
+ return value;
+}
+
+DictionaryValue* ErrorToValue(
+ const sync_pb::ClientToServerResponse::Error& proto) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_ENUM(error_type, ErrorTypeString);
+ SET_STR(error_description);
+ SET_STR(url);
+ SET_ENUM(action, ActionString);
+ return value;
+}
+
+DictionaryValue* ClientToServerResponseToValue(
+ const sync_pb::ClientToServerResponse& proto,
+ bool decode_specifics) {
+ DictionaryValue* value = new DictionaryValue();
+ SET(commit, CommitResponseToValue);
+ if (proto.has_get_updates()) {
+ value->Set("get_updates", GetUpdatesResponseToValue(proto.get_updates(),
+ decode_specifics));
+ }
+
+ SET(error, ErrorToValue);
+ SET_ENUM(error_code, ErrorTypeString);
+ SET_STR(error_message);
+ SET_STR(store_birthday);
+ SET(client_command, ClientCommandToValue);
+ SET_INT32_REP(migrated_data_type_id);
+ return value;
+}
+
+DictionaryValue* ClientToServerMessageToValue(
+ const sync_pb::ClientToServerMessage& proto,
+ bool decode_specifics) {
+ DictionaryValue* value = new DictionaryValue();
+ SET_STR(share);
+ SET_INT32(protocol_version);
+ if (proto.has_commit()) {
+ value->Set("commit", CommitMessageToValue(proto.commit(),
+ decode_specifics));
+ }
+
+ SET(get_updates, GetUpdatesMessageToValue);
+ SET_STR(store_birthday);
+ SET_BOOL(sync_problem_detected);
+ return value;
+}
+
+
#undef SET
#undef SET_REP

Powered by Google App Engine
This is Rietveld 408576698