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( |