diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-02 01:48:06 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-02 01:48:06 +0000 |
commit | 8dafed5b8aede5253f8adbbab44585076e9c4f60 (patch) | |
tree | 1c939afd67561c24662ac6be57896cf1507e9011 /sync/engine | |
parent | 624c0f9617ee61b875e6b9bf3628b2a97756ba43 (diff) | |
download | chromium_src-8dafed5b8aede5253f8adbbab44585076e9c4f60.zip chromium_src-8dafed5b8aede5253f8adbbab44585076e9c4f60.tar.gz chromium_src-8dafed5b8aede5253f8adbbab44585076e9c4f60.tar.bz2 |
sync: Remove TrafficRecorder
The new protocol events framework handles all the use cases of the
TrafficRecorder, and more. The traffic recorder implementation and about:sync
tab are now redundant.
BUG=357821
Review URL: https://codereview.chromium.org/217633003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine')
-rw-r--r-- | sync/engine/sync_scheduler_unittest.cc | 2 | ||||
-rw-r--r-- | sync/engine/syncer_proto_util.cc | 4 | ||||
-rw-r--r-- | sync/engine/syncer_unittest.cc | 7 | ||||
-rw-r--r-- | sync/engine/traffic_recorder.cc | 143 | ||||
-rw-r--r-- | sync/engine/traffic_recorder.h | 86 | ||||
-rw-r--r-- | sync/engine/traffic_recorder_unittest.cc | 123 |
6 files changed, 3 insertions, 362 deletions
diff --git a/sync/engine/sync_scheduler_unittest.cc b/sync/engine/sync_scheduler_unittest.cc index 45ebf19..c231087 100644 --- a/sync/engine/sync_scheduler_unittest.cc +++ b/sync/engine/sync_scheduler_unittest.cc @@ -135,7 +135,7 @@ class SyncSchedulerTest : public testing::Test { context_.reset(new SyncSessionContext( connection_.get(), directory(), extensions_activity_.get(), - std::vector<SyncEngineEventListener*>(), NULL, NULL, + std::vector<SyncEngineEventListener*>(), NULL, model_type_registry_.get(), true, // enable keystore encryption false, // force enable pre-commit GU avoidance diff --git a/sync/engine/syncer_proto_util.cc b/sync/engine/syncer_proto_util.cc index d6fb8d5..dab228f 100644 --- a/sync/engine/syncer_proto_util.cc +++ b/sync/engine/syncer_proto_util.cc @@ -358,7 +358,6 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage( syncable::Directory* dir = session->context()->directory(); LogClientToServerMessage(*msg); - session->context()->traffic_recorder()->RecordClientToServerMessage(*msg); if (!PostAndProcessHeaders(session->context()->connection_manager(), session, *msg, response)) { // There was an error establishing communication with the server. @@ -371,10 +370,7 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage( return ServerConnectionErrorAsSyncerError(server_status); } - LogClientToServerResponse(*response); - session->context()->traffic_recorder()->RecordClientToServerResponse( - *response); // Persist a bag of chips if it has been sent by the server. PersistBagOfChips(dir, *response); diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index 7a3afe3..72972a4 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -28,7 +28,6 @@ #include "sync/engine/sync_scheduler_impl.h" #include "sync/engine/syncer.h" #include "sync/engine/syncer_proto_util.h" -#include "sync/engine/traffic_recorder.h" #include "sync/internal_api/public/base/cancelation_signal.h" #include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/engine/model_safe_worker.h" @@ -118,8 +117,7 @@ class SyncerTest : public testing::Test, : extensions_activity_(new ExtensionsActivity), syncer_(NULL), saw_syncer_event_(false), - last_client_invalidation_hint_buffer_size_(10), - traffic_recorder_(0, 0) { + last_client_invalidation_hint_buffer_size_(10) { } // SyncSession::Delegate implementation. @@ -231,7 +229,7 @@ class SyncerTest : public testing::Test, new SyncSessionContext( mock_server_.get(), directory(), extensions_activity_, - listeners, debug_info_getter_.get(), &traffic_recorder_, + listeners, debug_info_getter_.get(), model_type_registry_.get(), true, // enable keystore encryption false, // force enable pre-commit GU avoidance experiment @@ -511,7 +509,6 @@ class SyncerTest : public testing::Test, std::vector<scoped_refptr<ModelSafeWorker> > workers_; ModelTypeSet enabled_datatypes_; - TrafficRecorder traffic_recorder_; sessions::NudgeTracker nudge_tracker_; scoped_ptr<MockDebugInfoGetter> debug_info_getter_; diff --git a/sync/engine/traffic_recorder.cc b/sync/engine/traffic_recorder.cc deleted file mode 100644 index d3f2347..0000000 --- a/sync/engine/traffic_recorder.cc +++ /dev/null @@ -1,143 +0,0 @@ -// 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 "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" -#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, - base::Time time) : - message(message), - message_type(message_type), - truncated(truncated), - timestamp(time) { -} - -TrafficRecorder::TrafficRecord::TrafficRecord() - : message_type(UNKNOWN_MESSAGE_TYPE), - truncated(false) { -} - -TrafficRecorder::TrafficRecord::~TrafficRecord() { -} - -TrafficRecorder::TrafficRecorder(unsigned int max_messages, - unsigned int max_message_size) - : max_messages_(max_messages), - max_message_size_(max_message_size) { -} - -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 ""; - } -} -} - -base::DictionaryValue* TrafficRecorder::TrafficRecord::ToValue() const { - scoped_ptr<base::DictionaryValue> value; - if (truncated) { - value.reset(new base::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(); - } - - value->SetString("timestamp", GetTimeDebugString(timestamp)); - - return value.release(); -} - - -base::ListValue* TrafficRecorder::ToValue() const { - scoped_ptr<base::ListValue> value(new base::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); - std::swap(records_.back(), *record); - - // We might have more records than our limit. - // Maintain the size invariant by deleting items. - while (records_.size() > max_messages_) { - records_.pop_front(); - } -} - -void TrafficRecorder::StoreProtoInQueue( - const ::google::protobuf::MessageLite& msg, - TrafficMessageType type) { - bool truncated = false; - std::string message; - if (static_cast<unsigned int>(msg.ByteSize()) >= max_message_size_) { - // TODO(lipalani): Trim the specifics to fit in size. - truncated = true; - } else { - msg.SerializeToString(&message); - } - - TrafficRecord record(message, type, truncated, GetTime()); - 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 syncer - diff --git a/sync/engine/traffic_recorder.h b/sync/engine/traffic_recorder.h deleted file mode 100644 index 55ee0b3..0000000 --- a/sync/engine/traffic_recorder.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 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. - -#ifndef CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ -#define CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ - -#include <deque> -#include <string> - -#include "base/basictypes.h" -#include "base/gtest_prod_util.h" -#include "base/time/time.h" -#include "base/values.h" -#include "sync/base/sync_export.h" -#include "sync/protocol/sync.pb.h" - -namespace sync_pb { -class ClientToServerResponse; -class ClientToServerMessage; -} - -namespace syncer { - -class SYNC_EXPORT_PRIVATE TrafficRecorder { - public: - enum TrafficMessageType { - CLIENT_TO_SERVER_MESSAGE, - CLIENT_TO_SERVER_RESPONSE, - UNKNOWN_MESSAGE_TYPE - }; - - struct SYNC_EXPORT_PRIVATE TrafficRecord { - // The serialized message. - std::string message; - TrafficMessageType message_type; - // If the message is too big to be kept in memory then it should be - // truncated. For now the entire message is omitted if it is too big. - // TODO(lipalani): Truncate the specifics to fit within size. - bool truncated; - - TrafficRecord(const std::string& message, - TrafficMessageType message_type, - bool truncated, - base::Time time); - TrafficRecord(); - ~TrafficRecord(); - base::DictionaryValue* ToValue() const; - - // Time of record creation. - base::Time timestamp; - }; - - TrafficRecorder(unsigned int max_messages, unsigned int max_message_size); - virtual ~TrafficRecorder(); - - void RecordClientToServerMessage(const sync_pb::ClientToServerMessage& msg); - void RecordClientToServerResponse( - const sync_pb::ClientToServerResponse& response); - base::ListValue* ToValue() const; - - const std::deque<TrafficRecord>& records() { - return records_; - } - - private: - void AddTrafficToQueue(TrafficRecord* record); - 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_; - - // Maximum size of each message. - unsigned int max_message_size_; - std::deque<TrafficRecord> records_; - DISALLOW_COPY_AND_ASSIGN(TrafficRecorder); -}; - -} // namespace syncer - -#endif // CHROME_BROWSER_SYNC_ENGINE_TRAFFIC_RECORDER_H_ - diff --git a/sync/engine/traffic_recorder_unittest.cc b/sync/engine/traffic_recorder_unittest.cc deleted file mode 100644 index 363a3c8..0000000 --- a/sync/engine/traffic_recorder_unittest.cc +++ /dev/null @@ -1,123 +0,0 @@ -// 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 "base/memory/scoped_ptr.h" -#include "base/time/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 { - -const unsigned int kMaxMessages = 10; -const unsigned int kMaxMessageSize = 5 * 1024; - -// Ensure the number of records don't exceed |kMaxMessages|. -TEST(TrafficRecorderTest, MaxRecordsTest) { - TrafficRecorder recorder(kMaxMessages, kMaxMessageSize); - sync_pb::ClientToServerResponse response; - - for (unsigned int i = 0; i < 2*kMaxMessages; ++i) - recorder.RecordClientToServerResponse(response); - - EXPECT_EQ(recorder.records().size(), kMaxMessages); -} - -// Ensure records with size greater than |kMaxMessageSize| are truncated. -TEST(TrafficRecorderTest, MaxMessageSizeTest) { - sync_pb::ClientToServerResponse response; - - sync_pb::ClientToServerResponse::Error* error = response.mutable_error(); - std::string error_description(kMaxMessageSize * 2, 'a'); - error->set_error_description(error_description); - - TrafficRecorder recorder(kMaxMessages, kMaxMessageSize); - recorder.RecordClientToServerResponse(response); - - TrafficRecorder::TrafficRecord record = recorder.records().front(); - EXPECT_TRUE(record.truncated); - 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); - - scoped_ptr<base::ListValue> value; - value.reset(recorder.ToValue()); - - base::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 |