summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authormgist@chromium.org <mgist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 20:12:55 +0000
committermgist@chromium.org <mgist@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 20:12:55 +0000
commitd92e0c7ca543347a391859f8ee4cd6154b547bac (patch)
tree6690d7cf11b4a70c061e111a88439b437e97ce5d /sync
parent44fd79627d23f32d817372ad60843ff5d7b2123a (diff)
downloadchromium_src-d92e0c7ca543347a391859f8ee4cd6154b547bac.zip
chromium_src-d92e0c7ca543347a391859f8ee4cd6154b547bac.tar.gz
chromium_src-d92e0c7ca543347a391859f8ee4cd6154b547bac.tar.bz2
[Sync] Add timestamp to TrafficRecorder records (reland)
Relanding after revert. Original codereview at https://chromiumcodereview.appspot.com/12088080. Fixed issue requiring GG_INT64_C wrapper for large ints in unit test cases. BUG=161922 Review URL: https://chromiumcodereview.appspot.com/12087139 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/engine/traffic_recorder.cc16
-rw-r--r--sync/engine/traffic_recorder.h12
-rw-r--r--sync/engine/traffic_recorder_unittest.cc78
3 files changed, 101 insertions, 5 deletions
diff --git a/sync/engine/traffic_recorder.cc b/sync/engine/traffic_recorder.cc
index 379c488..0e19aaa 100644
--- a/sync/engine/traffic_recorder.cc
+++ b/sync/engine/traffic_recorder.cc
@@ -11,15 +11,23 @@
#include "sync/protocol/proto_value_conversions.h"
#include "sync/protocol/sync.pb.h"
#include "sync/sessions/sync_session.h"
+#include "sync/util/time.h"
namespace syncer {
+// Return current time.
+base::Time TrafficRecorder::GetTime() {
+ return base::Time::Now();
+}
+
TrafficRecorder::TrafficRecord::TrafficRecord(const std::string& message,
TrafficMessageType message_type,
- bool truncated) :
+ bool truncated,
+ base::Time time) :
message(message),
message_type(message_type),
- truncated(truncated) {
+ truncated(truncated),
+ timestamp(time) {
}
TrafficRecorder::TrafficRecord::TrafficRecord()
@@ -76,6 +84,8 @@ DictionaryValue* TrafficRecorder::TrafficRecord::ToValue() const {
NOTREACHED();
}
+ value->SetString("timestamp", GetTimeDebugString(timestamp));
+
return value.release();
}
@@ -115,7 +125,7 @@ void TrafficRecorder::StoreProtoInQueue(
msg.SerializeToString(&message);
}
- TrafficRecord record(message, type, truncated);
+ TrafficRecord record(message, type, truncated, GetTime());
AddTrafficToQueue(&record);
}
diff --git a/sync/engine/traffic_recorder.h b/sync/engine/traffic_recorder.h
index 0e6e452..65e652e 100644
--- a/sync/engine/traffic_recorder.h
+++ b/sync/engine/traffic_recorder.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
+#include "base/time.h"
#include "base/values.h"
#include "sync/base/sync_export.h"
#include "sync/protocol/sync.pb.h"
@@ -40,14 +41,18 @@ class SYNC_EXPORT_PRIVATE TrafficRecorder {
TrafficRecord(const std::string& message,
TrafficMessageType message_type,
- bool truncated);
+ bool truncated,
+ base::Time time);
TrafficRecord();
~TrafficRecord();
DictionaryValue* ToValue() const;
+
+ // Time of record creation.
+ base::Time timestamp;
};
TrafficRecorder(unsigned int max_messages, unsigned int max_message_size);
- ~TrafficRecorder();
+ virtual ~TrafficRecorder();
void RecordClientToServerMessage(const sync_pb::ClientToServerMessage& msg);
void RecordClientToServerResponse(
@@ -63,6 +68,9 @@ class SYNC_EXPORT_PRIVATE TrafficRecorder {
void StoreProtoInQueue(const ::google::protobuf::MessageLite& msg,
TrafficMessageType type);
+ // Method to get record creation time.
+ virtual base::Time GetTime();
+
// Maximum number of messages stored in the queue.
unsigned int max_messages_;
diff --git a/sync/engine/traffic_recorder_unittest.cc b/sync/engine/traffic_recorder_unittest.cc
index cf821f5..9c10ba5 100644
--- a/sync/engine/traffic_recorder_unittest.cc
+++ b/sync/engine/traffic_recorder_unittest.cc
@@ -4,7 +4,10 @@
#include "sync/engine/traffic_recorder.h"
+#include "base/time.h"
+#include "base/values.h"
#include "sync/protocol/sync.pb.h"
+#include "sync/util/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
@@ -39,4 +42,79 @@ TEST(TrafficRecorderTest, MaxMessageSizeTest) {
EXPECT_TRUE(record.message.empty());
}
+// Test implementation of TrafficRecorder.
+class TestTrafficRecorder : public TrafficRecorder {
+ public:
+ TestTrafficRecorder(unsigned int max_messages, unsigned int max_message_size)
+ : TrafficRecorder(max_messages, max_message_size) {
+ set_time(0);
+ }
+ virtual ~TestTrafficRecorder() {}
+
+ virtual base::Time GetTime() OVERRIDE {
+ return time_;
+ }
+
+ void set_time(int64 time) {
+ time_ = ProtoTimeToTime(time);
+ }
+
+ void set_time(base::Time time) {
+ time_ = time;
+ }
+
+ private:
+ base::Time time_;
+};
+
+// Ensure that timestamp is recorded correctly in traffic record.
+TEST(TrafficRecorderTest, TimestampTest) {
+ sync_pb::ClientToServerResponse response;
+
+ TestTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
+ recorder.set_time(3);
+ recorder.RecordClientToServerResponse(response);
+
+ base::Time expect_time = ProtoTimeToTime(3);
+ TrafficRecorder::TrafficRecord record = recorder.records().front();
+ EXPECT_EQ(expect_time, record.timestamp);
+}
+
+// Ensure that timestamps are recorded correctly in traffic records.
+TEST(TrafficRecorderTest, MultipleTimestampTest) {
+ sync_pb::ClientToServerResponse response;
+ base::Time sample_time_1 = ProtoTimeToTime(GG_INT64_C(1359484676659));
+ base::Time sample_time_2 = ProtoTimeToTime(GG_INT64_C(135948467665932));
+
+ TestTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
+ recorder.set_time(sample_time_1);
+ recorder.RecordClientToServerResponse(response);
+ recorder.set_time(sample_time_2);
+ recorder.RecordClientToServerResponse(response);
+
+ TrafficRecorder::TrafficRecord record_1 = recorder.records().front();
+ TrafficRecorder::TrafficRecord record_2 = recorder.records().back();
+ EXPECT_EQ(sample_time_1, record_1.timestamp);
+ EXPECT_EQ(sample_time_2, record_2.timestamp);
+}
+
+// Ensure that timestamp is added to ListValue of DictionaryValues in ToValue().
+TEST(TrafficRecorderTest, ToValueTimestampTest) {
+ sync_pb::ClientToServerResponse response;
+ base::Time sample_time = ProtoTimeToTime(GG_INT64_C(135948467665932));
+ std::string expect_time_str = GetTimeDebugString(sample_time);
+
+ TestTrafficRecorder recorder(kMaxMessages, kMaxMessageSize);
+ recorder.set_time(sample_time);
+ recorder.RecordClientToServerResponse(response);
+
+ ListValue* value = recorder.ToValue();
+ DictionaryValue* record_value;
+ std::string time_str;
+
+ ASSERT_TRUE(value->GetDictionary(0, &record_value));
+ EXPECT_TRUE(record_value->GetString("timestamp", &time_str));
+ EXPECT_EQ(expect_time_str, time_str);
+}
+
} // namespace syncer