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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc

Issue 1173343009: LevelDB storage for data reduction proxy to store data usage stats. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 5 years, 6 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
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
index f272fd999af26c7f841be8920a2fd3135d417fb7..856e746d0b49815adf24b30359b0b872809ab1f9 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.cc
@@ -20,7 +20,10 @@
#include "base/time/time.h"
#include "base/values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metrics.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_store.h"
+#include "components/data_reduction_proxy/core/browser/data_usage_storage_helper.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
+#include "components/data_reduction_proxy/proto/store.pb.h"
namespace data_reduction_proxy {
@@ -302,10 +305,14 @@ class DailyDataSavingUpdate {
DataReductionProxyCompressionStats::DataReductionProxyCompressionStats(
PrefService* prefs,
- scoped_refptr<base::SequencedTaskRunner> task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> db_task_runner,
+ scoped_refptr<DataReductionProxyStore> store,
const base::TimeDelta& delay)
: pref_service_(prefs),
- task_runner_(task_runner),
+ ui_task_runner_(ui_task_runner),
+ db_task_runner_(db_task_runner),
+ store_(store),
delay_(delay),
delayed_task_posted_(false),
pref_change_registrar_(new PrefChangeRegistrar()),
@@ -313,6 +320,9 @@ DataReductionProxyCompressionStats::DataReductionProxyCompressionStats(
DCHECK(prefs);
DCHECK_GE(delay.InMilliseconds(), 0);
Init();
+ db_task_runner->PostTask(
+ FROM_HERE, base::Bind(&DataReductionProxyCompressionStats::InitOnDBThread,
+ weak_factory_.GetWeakPtr()));
}
DataReductionProxyCompressionStats::~DataReductionProxyCompressionStats() {
@@ -322,6 +332,11 @@ DataReductionProxyCompressionStats::~DataReductionProxyCompressionStats() {
weak_factory_.InvalidateWeakPtrs();
}
+void DataReductionProxyCompressionStats::InitOnDBThread() {
+ DCHECK(db_task_runner_->BelongsToCurrentThread());
+ data_usage_store_.reset(new DataUsageStorageHelper(store_));
+}
+
void DataReductionProxyCompressionStats::Init() {
DCHECK(thread_checker_.CalledOnValidThread());
if (delay_ == base::TimeDelta())
@@ -383,6 +398,8 @@ void DataReductionProxyCompressionStats::UpdateContentLengths(
SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength,
total_original);
+ // TODO(kundaji): Collect data usage metrics broken down by site and store
+ // in |data_usage_store_|.
RecordContentLengthPrefs(
received_content_length,
original_content_length,
@@ -559,10 +576,9 @@ void DataReductionProxyCompressionStats::DelayedWritePrefs() {
if (delayed_task_posted_)
return;
- task_runner_->PostDelayedTask(
- FROM_HERE,
- base::Bind(&DataReductionProxyCompressionStats::WritePrefs,
- weak_factory_.GetWeakPtr()),
+ ui_task_runner_->PostDelayedTask(
+ FROM_HERE, base::Bind(&DataReductionProxyCompressionStats::WritePrefs,
+ weak_factory_.GetWeakPtr()),
delay_);
delayed_task_posted_ = true;

Powered by Google App Engine
This is Rietveld 408576698