summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorlipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-01 20:22:44 +0000
committerlipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-01 20:22:44 +0000
commitb01a9b9bad2a7f403c67c0cc7d5dfe5d119a0dc8 (patch)
tree52cac4ff89e4fb2dc6666260f5035ffd84d20bb9 /sync
parent1d8634849b6155e97fb4a87fff7022d545133aad (diff)
downloadchromium_src-b01a9b9bad2a7f403c67c0cc7d5dfe5d119a0dc8.zip
chromium_src-b01a9b9bad2a7f403c67c0cc7d5dfe5d119a0dc8.tar.gz
chromium_src-b01a9b9bad2a7f403c67c0cc7d5dfe5d119a0dc8.tar.bz2
A new 'traffic' tab is introduced and clicking the button on the tab would display the traffic.
BUG=117615 TEST= Review URL: http://codereview.chromium.org/9826035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130081 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/engine/sync_scheduler_unittest.cc2
-rw-r--r--sync/engine/sync_scheduler_whitebox_unittest.cc2
-rw-r--r--sync/engine/syncer_unittest.cc11
-rw-r--r--sync/engine/traffic_recorder.cc52
-rw-r--r--sync/engine/traffic_recorder.h3
-rw-r--r--sync/engine/traffic_recorder_unittest.cc1
-rw-r--r--sync/sessions/sync_session_context.cc7
-rw-r--r--sync/sessions/sync_session_context.h8
-rw-r--r--sync/sessions/sync_session_unittest.cc2
-rw-r--r--sync/test/engine/syncer_command_test.cc5
-rw-r--r--sync/test/engine/syncer_command_test.h5
11 files changed, 84 insertions, 14 deletions
diff --git a/sync/engine/sync_scheduler_unittest.cc b/sync/engine/sync_scheduler_unittest.cc
index a48d67f..17fdeb4 100644
--- a/sync/engine/sync_scheduler_unittest.cc
+++ b/sync/engine/sync_scheduler_unittest.cc
@@ -98,7 +98,7 @@ class SyncSchedulerTest : public testing::Test {
context_ = new SyncSessionContext(
connection_.get(), directory(), registrar_.get(),
&extensions_activity_monitor_,
- std::vector<SyncEngineEventListener*>(), NULL);
+ std::vector<SyncEngineEventListener*>(), NULL, NULL);
context_->set_notifications_enabled(true);
context_->set_account_name("Test");
scheduler_.reset(
diff --git a/sync/engine/sync_scheduler_whitebox_unittest.cc b/sync/engine/sync_scheduler_whitebox_unittest.cc
index 33ddb29..1b67a18 100644
--- a/sync/engine/sync_scheduler_whitebox_unittest.cc
+++ b/sync/engine/sync_scheduler_whitebox_unittest.cc
@@ -38,7 +38,7 @@ class SyncSchedulerWhiteboxTest : public testing::Test {
new SyncSessionContext(
connection_.get(), dir_maker_.directory(),
registrar_.get(), &extensions_activity_monitor_,
- std::vector<SyncEngineEventListener*>(), NULL);
+ std::vector<SyncEngineEventListener*>(), NULL, NULL);
context_->set_notifications_enabled(true);
context_->set_account_name("Test");
scheduler_.reset(
diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc
index 56908df..1039808 100644
--- a/sync/engine/syncer_unittest.cc
+++ b/sync/engine/syncer_unittest.cc
@@ -32,6 +32,7 @@
#include "sync/engine/syncer_proto_util.h"
#include "sync/engine/syncer_util.h"
#include "sync/engine/syncproto.h"
+#include "sync/engine/traffic_recorder.h"
#include "sync/protocol/bookmark_specifics.pb.h"
#include "sync/protocol/nigori_specifics.pb.h"
#include "sync/protocol/preference_specifics.pb.h"
@@ -114,7 +115,11 @@ class SyncerTest : public testing::Test,
public ModelSafeWorkerRegistrar,
public SyncEngineEventListener {
protected:
- SyncerTest() : syncer_(NULL), saw_syncer_event_(false) {}
+ SyncerTest()
+ : syncer_(NULL),
+ saw_syncer_event_(false),
+ traffic_recorder_(0, 0) {
+}
// SyncSession::Delegate implementation.
virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) OVERRIDE {
@@ -209,7 +214,8 @@ class SyncerTest : public testing::Test,
context_.reset(
new SyncSessionContext(
mock_server_.get(), directory(), this,
- &extensions_activity_monitor_, listeners, NULL));
+ &extensions_activity_monitor_, listeners, NULL,
+ &traffic_recorder_));
ASSERT_FALSE(context_->resolver());
syncer_ = new Syncer();
session_.reset(MakeSession());
@@ -512,6 +518,7 @@ class SyncerTest : public testing::Test,
scoped_refptr<ModelSafeWorker> worker_;
syncable::ModelTypeSet enabled_datatypes_;
+ browser_sync::TrafficRecorder traffic_recorder_;
DISALLOW_COPY_AND_ASSIGN(SyncerTest);
};
diff --git a/sync/engine/traffic_recorder.cc b/sync/engine/traffic_recorder.cc
index e9ea716..ae0a059 100644
--- a/sync/engine/traffic_recorder.cc
+++ b/sync/engine/traffic_recorder.cc
@@ -39,6 +39,58 @@ TrafficRecorder::TrafficRecorder(unsigned int max_messages,
TrafficRecorder::~TrafficRecorder() {
}
+namespace {
+const char* GetMessageTypeString(TrafficRecorder::TrafficMessageType type) {
+ switch(type) {
+ case TrafficRecorder::CLIENT_TO_SERVER_MESSAGE:
+ return "Request";
+ case TrafficRecorder::CLIENT_TO_SERVER_RESPONSE:
+ return "Response";
+ default:
+ NOTREACHED();
+ return "";
+ }
+}
+}
+
+DictionaryValue* TrafficRecorder::TrafficRecord::ToValue() const {
+ scoped_ptr<DictionaryValue> value;
+ if (truncated) {
+ value.reset(new DictionaryValue());
+ value->SetString("message_type",
+ GetMessageTypeString(message_type));
+ value->SetBoolean("truncated", true);
+ } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_MESSAGE) {
+ sync_pb::ClientToServerMessage message_proto;
+ if (message_proto.ParseFromString(message))
+ value.reset(
+ ClientToServerMessageToValue(message_proto,
+ false /* include_specifics */));
+ } else if (message_type == TrafficRecorder::CLIENT_TO_SERVER_RESPONSE) {
+ sync_pb::ClientToServerResponse message_proto;
+ if (message_proto.ParseFromString(message))
+ value.reset(
+ ClientToServerResponseToValue(message_proto,
+ false /* include_specifics */));
+ } else {
+ NOTREACHED();
+ }
+
+ return value.release();
+}
+
+
+ListValue* TrafficRecorder::ToValue() const {
+ scoped_ptr<ListValue> value(new ListValue());
+ std::deque<TrafficRecord>::const_iterator it;
+ for (it = records_.begin(); it != records_.end(); ++it) {
+ const TrafficRecord& record = *it;
+ value->Append(record.ToValue());
+ }
+
+ return value.release();
+}
+
void TrafficRecorder::AddTrafficToQueue(TrafficRecord* record) {
records_.resize(records_.size() + 1);
diff --git a/sync/engine/traffic_recorder.h b/sync/engine/traffic_recorder.h
index 52bf8ce..cfcdcc0 100644
--- a/sync/engine/traffic_recorder.h
+++ b/sync/engine/traffic_recorder.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
+#include "base/values.h"
#include "sync/protocol/sync.pb.h"
namespace sync_pb {
@@ -42,6 +43,7 @@ class TrafficRecorder {
bool truncated);
TrafficRecord();
~TrafficRecord();
+ DictionaryValue* ToValue() const;
};
TrafficRecorder(unsigned int max_messages, unsigned int max_message_size);
@@ -50,6 +52,7 @@ class TrafficRecorder {
void RecordClientToServerMessage(const sync_pb::ClientToServerMessage& msg);
void RecordClientToServerResponse(
const sync_pb::ClientToServerResponse& response);
+ ListValue* ToValue() const;
const std::deque<TrafficRecord>& records() {
return records_;
diff --git a/sync/engine/traffic_recorder_unittest.cc b/sync/engine/traffic_recorder_unittest.cc
index bf3f345..89a77a6 100644
--- a/sync/engine/traffic_recorder_unittest.cc
+++ b/sync/engine/traffic_recorder_unittest.cc
@@ -40,3 +40,4 @@ TEST(TrafficRecorderTest, MaxMessageSizeTest) {
}
} //namespace browser_sync
+
diff --git a/sync/sessions/sync_session_context.cc b/sync/sessions/sync_session_context.cc
index 99b212f..2ebe655 100644
--- a/sync/sessions/sync_session_context.cc
+++ b/sync/sessions/sync_session_context.cc
@@ -20,7 +20,8 @@ SyncSessionContext::SyncSessionContext(
ModelSafeWorkerRegistrar* model_safe_worker_registrar,
ExtensionsActivityMonitor* extensions_activity_monitor,
const std::vector<SyncEngineEventListener*>& listeners,
- DebugInfoGetter* debug_info_getter)
+ DebugInfoGetter* debug_info_getter,
+ browser_sync::TrafficRecorder* traffic_recorder)
: resolver_(NULL),
connection_manager_(connection_manager),
directory_(directory),
@@ -29,7 +30,7 @@ SyncSessionContext::SyncSessionContext(
notifications_enabled_(false),
max_commit_batch_size_(kDefaultMaxCommitBatchSize),
debug_info_getter_(debug_info_getter),
- traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord) {
+ traffic_recorder_(traffic_recorder) {
std::vector<SyncEngineEventListener*>::const_iterator it;
for (it = listeners.begin(); it != listeners.end(); ++it)
listeners_.AddObserver(*it);
@@ -41,7 +42,7 @@ SyncSessionContext::SyncSessionContext()
registrar_(NULL),
extensions_activity_monitor_(NULL),
debug_info_getter_(NULL),
- traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord) {
+ traffic_recorder_(NULL) {
}
SyncSessionContext::~SyncSessionContext() {
diff --git a/sync/sessions/sync_session_context.h b/sync/sessions/sync_session_context.h
index 60e3d59..5c21726 100644
--- a/sync/sessions/sync_session_context.h
+++ b/sync/sessions/sync_session_context.h
@@ -56,7 +56,8 @@ class SyncSessionContext {
ModelSafeWorkerRegistrar* model_safe_worker_registrar,
ExtensionsActivityMonitor* extensions_activity_monitor,
const std::vector<SyncEngineEventListener*>& listeners,
- DebugInfoGetter* debug_info_getter);
+ DebugInfoGetter* debug_info_getter,
+ browser_sync::TrafficRecorder* traffic_recorder);
// Empty constructor for unit tests.
SyncSessionContext();
@@ -125,7 +126,7 @@ class SyncSessionContext {
syncable::ModelTypeSet GetThrottledTypes() const;
browser_sync::TrafficRecorder* traffic_recorder() {
- return &traffic_recorder_;
+ return traffic_recorder_;
}
private:
@@ -182,8 +183,7 @@ class SyncSessionContext {
// unthrottled.
UnthrottleTimes unthrottle_times_;
- // TODO(lipalani): Move the creation of this to |SyncManager|.
- browser_sync::TrafficRecorder traffic_recorder_;
+ browser_sync::TrafficRecorder* traffic_recorder_;
DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
};
diff --git a/sync/sessions/sync_session_unittest.cc b/sync/sessions/sync_session_unittest.cc
index 1f87018..48524a4 100644
--- a/sync/sessions/sync_session_unittest.cc
+++ b/sync/sessions/sync_session_unittest.cc
@@ -43,7 +43,7 @@ class SyncSessionTest : public testing::Test,
context_.reset(
new SyncSessionContext(
NULL, NULL, this, &extensions_activity_monitor_,
- std::vector<SyncEngineEventListener*>(), NULL));
+ std::vector<SyncEngineEventListener*>(), NULL, NULL));
routes_.clear();
routes_[syncable::BOOKMARKS] = GROUP_UI;
routes_[syncable::AUTOFILL] = GROUP_DB;
diff --git a/sync/test/engine/syncer_command_test.cc b/sync/test/engine/syncer_command_test.cc
index 53af26a..9275e17 100644
--- a/sync/test/engine/syncer_command_test.cc
+++ b/sync/test/engine/syncer_command_test.cc
@@ -6,8 +6,11 @@
namespace browser_sync {
+const unsigned int kMaxMessages = 10;
+const unsigned int kMaxMessageSize = 5 * 1024;
-SyncerCommandTestBase::SyncerCommandTestBase() {
+SyncerCommandTestBase::SyncerCommandTestBase()
+ : traffic_recorder_(kMaxMessages, kMaxMessageSize) {
}
SyncerCommandTestBase::~SyncerCommandTestBase() {
diff --git a/sync/test/engine/syncer_command_test.h b/sync/test/engine/syncer_command_test.h
index 3989def..bfa567f 100644
--- a/sync/test/engine/syncer_command_test.h
+++ b/sync/test/engine/syncer_command_test.h
@@ -15,6 +15,7 @@
#include "base/message_loop.h"
#include "sync/engine/model_changing_syncer_command.h"
#include "sync/engine/model_safe_worker.h"
+#include "sync/engine/traffic_recorder.h"
#include "sync/sessions/debug_info_getter.h"
#include "sync/sessions/sync_session.h"
#include "sync/sessions/sync_session_context.h"
@@ -126,7 +127,8 @@ class SyncerCommandTestBase : public testing::Test,
mock_server_.get(), directory(),
registrar(), &extensions_activity_monitor_,
std::vector<SyncEngineEventListener*>(),
- &mock_debug_info_getter_));
+ &mock_debug_info_getter_,
+ &traffic_recorder_));
context_->set_account_name(directory()->name());
ClearSession();
}
@@ -199,6 +201,7 @@ class SyncerCommandTestBase : public testing::Test,
ModelSafeRoutingInfo routing_info_;
NiceMock<MockDebugInfoGetter> mock_debug_info_getter_;
FakeExtensionsActivityMonitor extensions_activity_monitor_;
+ TrafficRecorder traffic_recorder_;
DISALLOW_COPY_AND_ASSIGN(SyncerCommandTestBase);
};