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

Unified Diff: components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc

Issue 2619373003: Replace std::deque usage in drp_event_store with a circular buffer. (Closed)
Patch Set: removed unneeded includes from .cc file Created 3 years, 11 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
« no previous file with comments | « components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc
diff --git a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc
index df8c57c6b6f86dff1b44d7a3c357f1fea41ae1cc..8f7db517adb5fc1d1c4040a30ef041bcb43012d4 100644
--- a/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc
+++ b/components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.cc
@@ -5,19 +5,16 @@
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h"
#include <stddef.h>
-#include <stdint.h>
+
#include <utility>
-#include <vector>
#include "base/json/json_writer.h"
-#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/values.h"
-#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_storage_delegate.h"
namespace {
@@ -60,7 +57,7 @@ std::string JoinListValueStrings(base::ListValue* list_value) {
if (!value->GetAsString(&value_string))
return std::string();
- values.push_back(value_string);
+ values.push_back(std::move(value_string));
}
return base::JoinString(values, ";");
@@ -93,10 +90,10 @@ void DataReductionProxyEventStore::AddConstants(
}
DataReductionProxyEventStore::DataReductionProxyEventStore()
- : enabled_(false),
+ : oldest_event_index_(0),
+ enabled_(false),
secure_proxy_check_state_(CHECK_UNKNOWN),
- expiration_ticks_(0) {
-}
+ expiration_ticks_(0) {}
DataReductionProxyEventStore::~DataReductionProxyEventStore() {
}
@@ -137,17 +134,29 @@ DataReductionProxyEventStore::GetSummaryValue() const {
}
auto events_list = base::MakeUnique<base::ListValue>();
- for (const auto& event : stored_events_)
- events_list->Append(event->CreateDeepCopy());
+
+ DCHECK(oldest_event_index_ == 0 ||
+ stored_events_.size() == kMaxEventsToStore);
+ for (size_t i = oldest_event_index_; i < stored_events_.size(); ++i)
+ events_list->Append(stored_events_[i]->CreateDeepCopy());
+ for (size_t i = 0; i < oldest_event_index_; ++i)
+ events_list->Append(stored_events_[i]->CreateDeepCopy());
+
data_reduction_proxy_values->Set("events", std::move(events_list));
return data_reduction_proxy_values;
}
void DataReductionProxyEventStore::AddEvent(
std::unique_ptr<base::Value> event) {
- if (stored_events_.size() == kMaxEventsToStore)
- stored_events_.pop_front();
- stored_events_.push_back(std::move(event));
+ if (stored_events_.size() < kMaxEventsToStore) {
+ stored_events_.push_back(std::move(event));
+ return;
+ }
+ DCHECK_EQ(kMaxEventsToStore, stored_events_.size());
+
+ stored_events_[oldest_event_index_++] = std::move(event);
+ if (oldest_event_index_ >= stored_events_.size())
+ oldest_event_index_ = 0;
}
void DataReductionProxyEventStore::AddEnabledEvent(
« no previous file with comments | « components/data_reduction_proxy/core/common/data_reduction_proxy_event_store.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698