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

Unified Diff: sync/engine/traffic_recorder.cc

Issue 9732008: [Sync] Store the past 10 traffic records in memory. (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: sync/engine/traffic_recorder.cc
diff --git a/sync/engine/traffic_recorder.cc b/sync/engine/traffic_recorder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea085bc14677ccf5266693812744cdc7043d44e7
--- /dev/null
+++ b/sync/engine/traffic_recorder.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2012 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/engine/traffic_recorder.h"
+
+#include <queue>
akalin 2012/03/27 20:21:04 omit <queue> (not needed anymore) omit <string> (i
lipalani1 2012/03/27 21:08:57 Done.
+#include <string>
+
+#include "base/json/json_writer.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "sync/protocol/proto_value_conversions.h"
+#include "sync/protocol/sync.pb.h"
+#include "sync/sessions/sync_session.h"
+
+namespace browser_sync {
+
+using sessions::SyncSession;
akalin 2012/03/27 20:21:04 not needed naymore
lipalani1 2012/03/27 21:08:57 Done.
+
+TrafficRecorder::TrafficRecord::TrafficRecord(const std::string& message,
+ TrafficMessageType message_type,
+ bool truncated) :
+ message(message),
+ message_type(message_type),
+ truncated(truncated) {
+}
+
+TrafficRecorder::TrafficRecord::TrafficRecord()
+ : message_type(UNKNOWN_MESSAGE_TYPE),
+ truncated(false) {
+}
+
+TrafficRecorder::TrafficRecord::~TrafficRecord() {
+}
+
+static const unsigned int kMaxMessages = 10;
+static const unsigned int kMaxMessageSize = 5 * 1024;
+
+TrafficRecorder::TrafficRecorder() {
+}
+
+TrafficRecorder::~TrafficRecorder() {
+}
+
+
+void TrafficRecorder::AddTrafficToQueue(const TrafficRecord& record) {
+ records_.push_back(record);
+
+ // We might have more records than our limit.
+ // Maintain the size invariant by deleting items.
+ while (records_.size() >= browser_sync::kMaxMessages) {
akalin 2012/03/27 20:21:04 this is wrong -- please see my previous comment ag
akalin 2012/03/27 20:24:43 quoting mangled my 2nd line -- should be: "The >=
lipalani1 2012/03/27 21:08:57 Done.
lipalani1 2012/03/27 21:08:57 Done.
+ records_.pop_front();
+ }
+}
+
+void TrafficRecorder::StoreProtoInQueue(
+ const ::google::protobuf::MessageLite& msg,
+ TrafficMessageType type) {
+ bool truncated = false;
+ std::string message;
+ if (msg.ByteSize() >= browser_sync::kMaxMessageSize) {
+ // TODO(lipalani): Trim the specifics to fit in size.
+ truncated = true;
+ } else {
+ msg.SerializeToString(&message);
+ }
+
+ TrafficRecord record(message, type, truncated);
+ AddTrafficToQueue(record);
+}
+
+void TrafficRecorder::RecordClientToServerMessage(
+ const sync_pb::ClientToServerMessage& msg) {
+ StoreProtoInQueue(msg, CLIENT_TO_SERVER_MESSAGE);
+}
+
+void TrafficRecorder::RecordClientToServerResponse(
+ const sync_pb::ClientToServerResponse& response) {
+ StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE);
+}
+
+} // namespace browser_sync
+

Powered by Google App Engine
This is Rietveld 408576698