Index: components/previews/previews_data_savings.cc |
diff --git a/components/previews/previews_data_savings.cc b/components/previews/previews_data_savings.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a3ddd6ccb55c00eda646b033b8cc46401b955f60 |
--- /dev/null |
+++ b/components/previews/previews_data_savings.cc |
@@ -0,0 +1,40 @@ |
+// Copyright 2016 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 "components/previews/previews_data_savings.h" |
+ |
+#include "base/logging.h" |
+#include "base/metrics/histogram_macros.h" |
+#include "components/data_reduction_proxy/core/common/data_saver_status.h" |
+#include "components/data_reduction_proxy/core/common/data_savings_recorder.h" |
+ |
+namespace previews { |
+ |
+PreviewsDataSavings::PreviewsDataSavings( |
+ data_reduction_proxy::DataSavingsRecorder* data_savings_recorder, |
+ data_reduction_proxy::DataSaverStatus* data_saver_status) |
+ : data_savings_recorder_(data_savings_recorder), |
+ data_saver_status_(data_saver_status) { |
+ DCHECK(data_savings_recorder); |
+ DCHECK(data_saver_status); |
+} |
+ |
+PreviewsDataSavings::~PreviewsDataSavings() { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+} |
+ |
+void PreviewsDataSavings::RecordDataSavings(const std::string& host, |
+ int64_t data_used, |
+ int64_t original_size) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ // Only record savings when data saver is enabled. |
bengr
2016/08/25 23:04:19
Again, this class shouldn't know about Data Saver.
RyanSturm
2016/08/26 17:47:39
I think it's fundamental to previews/ to understan
|
+ if (!data_savings_recorder_ || !data_saver_status_ || |
bengr
2016/08/25 23:04:19
You don't need to check these if they're expected
RyanSturm
2016/08/26 17:47:39
Good point, these were left over from when this wa
|
+ !data_saver_status_->IsDataSaverEnabled()) { |
bengr
2016/08/25 23:04:19
Use a callback called should_record_data_savings_
RyanSturm
2016/08/26 17:47:39
See other comment.
|
+ return; |
+ } |
+ data_savings_recorder_->UpdateDataSavings(host, data_used, original_size); |
+} |
+ |
+} // namespace previews |