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

Side by Side Diff: sync/engine/traffic_recorder.cc

Issue 9826035: [Sync] Display the client server traffic log in about:sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For submitting. Created 8 years, 8 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
« no previous file with comments | « sync/engine/traffic_recorder.h ('k') | sync/engine/traffic_recorder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/engine/traffic_recorder.h" 5 #include "sync/engine/traffic_recorder.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 21 matching lines...) Expand all
32 32
33 TrafficRecorder::TrafficRecorder(unsigned int max_messages, 33 TrafficRecorder::TrafficRecorder(unsigned int max_messages,
34 unsigned int max_message_size) 34 unsigned int max_message_size)
35 : max_messages_(max_messages), 35 : max_messages_(max_messages),
36 max_message_size_(max_message_size) { 36 max_message_size_(max_message_size) {
37 } 37 }
38 38
39 TrafficRecorder::~TrafficRecorder() { 39 TrafficRecorder::~TrafficRecorder() {
40 } 40 }
41 41
42 namespace {
43 const char* GetMessageTypeString(TrafficRecorder::TrafficMessageType type) {
44 switch(type) {
45 case TrafficRecorder::CLIENT_TO_SERVER_MESSAGE:
46 return "Request";
47 case TrafficRecorder::CLIENT_TO_SERVER_RESPONSE:
48 return "Response";
49 default:
50 NOTREACHED();
51 return "";
52 }
53 }
54 }
55
56 DictionaryValue* TrafficRecorder::TrafficRecord::ToValue() const {
57 scoped_ptr<DictionaryValue> value;
58 if (truncated) {
59 value.reset(new DictionaryValue());
60 value->SetString("message_type",
61 GetMessageTypeString(message_type));
62 value->SetBoolean("truncated", true);
63 } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_MESSAGE) {
64 sync_pb::ClientToServerMessage message_proto;
65 if (message_proto.ParseFromString(message))
66 value.reset(
67 ClientToServerMessageToValue(message_proto,
68 false /* include_specifics */));
69 } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_RESPONSE) {
70 sync_pb::ClientToServerResponse message_proto;
71 if (message_proto.ParseFromString(message))
72 value.reset(
73 ClientToServerResponseToValue(message_proto,
74 false /* include_specifics */));
75 } else {
76 NOTREACHED();
77 }
78
79 return value.release();
80 }
81
82
83 ListValue* TrafficRecorder::ToValue() const {
84 scoped_ptr<ListValue> value(new ListValue());
85 std::deque<TrafficRecord>::const_iterator it;
86 for (it = records_.begin(); it != records_.end(); ++it) {
87 const TrafficRecord& record = *it;
88 value->Append(record.ToValue());
89 }
90
91 return value.release();
92 }
93
42 94
43 void TrafficRecorder::AddTrafficToQueue(TrafficRecord* record) { 95 void TrafficRecorder::AddTrafficToQueue(TrafficRecord* record) {
44 records_.resize(records_.size() + 1); 96 records_.resize(records_.size() + 1);
45 std::swap(records_.back(), *record); 97 std::swap(records_.back(), *record);
46 98
47 // We might have more records than our limit. 99 // We might have more records than our limit.
48 // Maintain the size invariant by deleting items. 100 // Maintain the size invariant by deleting items.
49 while (records_.size() > max_messages_) { 101 while (records_.size() > max_messages_) {
50 records_.pop_front(); 102 records_.pop_front();
51 } 103 }
(...skipping 20 matching lines...) Expand all
72 StoreProtoInQueue(msg, CLIENT_TO_SERVER_MESSAGE); 124 StoreProtoInQueue(msg, CLIENT_TO_SERVER_MESSAGE);
73 } 125 }
74 126
75 void TrafficRecorder::RecordClientToServerResponse( 127 void TrafficRecorder::RecordClientToServerResponse(
76 const sync_pb::ClientToServerResponse& response) { 128 const sync_pb::ClientToServerResponse& response) {
77 StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE); 129 StoreProtoInQueue(response, CLIENT_TO_SERVER_RESPONSE);
78 } 130 }
79 131
80 } // namespace browser_sync 132 } // namespace browser_sync
81 133
OLDNEW
« no previous file with comments | « sync/engine/traffic_recorder.h ('k') | sync/engine/traffic_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698