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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sync/engine/traffic_recorder.h"
6
7 #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.
8 #include <string>
9
10 #include "base/json/json_writer.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/values.h"
14 #include "sync/protocol/proto_value_conversions.h"
15 #include "sync/protocol/sync.pb.h"
16 #include "sync/sessions/sync_session.h"
17
18 namespace browser_sync {
19
20 using sessions::SyncSession;
akalin 2012/03/27 20:21:04 not needed naymore
lipalani1 2012/03/27 21:08:57 Done.
21
22 TrafficRecorder::TrafficRecord::TrafficRecord(const std::string& message,
23 TrafficMessageType message_type,
24 bool truncated) :
25 message(message),
26 message_type(message_type),
27 truncated(truncated) {
28 }
29
30 TrafficRecorder::TrafficRecord::TrafficRecord()
31 : message_type(UNKNOWN_MESSAGE_TYPE),
32 truncated(false) {
33 }
34
35 TrafficRecorder::TrafficRecord::~TrafficRecord() {
36 }
37
38 static const unsigned int kMaxMessages = 10;
39 static const unsigned int kMaxMessageSize = 5 * 1024;
40
41 TrafficRecorder::TrafficRecorder() {
42 }
43
44 TrafficRecorder::~TrafficRecorder() {
45 }
46
47
48 void TrafficRecorder::AddTrafficToQueue(const TrafficRecord& record) {
49 records_.push_back(record);
50
51 // We might have more records than our limit.
52 // Maintain the size invariant by deleting items.
53 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.
54 records_.pop_front();
55 }
56 }
57
58 void TrafficRecorder::StoreProtoInQueue(
59 const ::google::protobuf::MessageLite& msg,
60 TrafficMessageType type) {
61 bool truncated = false;
62 std::string message;
63 if (msg.ByteSize() >= browser_sync::kMaxMessageSize) {
64 // TODO(lipalani): Trim the specifics to fit in size.
65 truncated = true;
66 } else {
67 msg.SerializeToString(&message);
68 }
69
70 TrafficRecord record(message, type, truncated);
71 AddTrafficToQueue(record);
72 }
73
74 void TrafficRecorder::RecordClientToServerMessage(
75 const sync_pb::ClientToServerMessage& msg) {
76 StoreProtoInQueue(msg, CLIENT_TO_SERVER_MESSAGE);
77 }
78
79 void TrafficRecorder::RecordClientToServerResponse(
80 const sync_pb::ClientToServerResponse& response) {
81 StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE);
82 }
83
84 } // namespace browser_sync
85
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698