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

Unified Diff: components/data_reduction_proxy/core/browser/data_usage_storage_helper.h

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: Remove friend from impl 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_usage_storage_helper.h
diff --git a/components/data_reduction_proxy/core/browser/data_usage_storage_helper.h b/components/data_reduction_proxy/core/browser/data_usage_storage_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..d4e23896103f63b34ff4b79093a591e071be6d41
--- /dev/null
+++ b/components/data_reduction_proxy/core/browser/data_usage_storage_helper.h
@@ -0,0 +1,73 @@
+// Copyright 2015 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 COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_USAGE_STORAGE_HELPER_H_
+#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_USAGE_STORAGE_HELPER_H_
+
+#include <map>
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "base/time/time.h"
+
+namespace data_reduction_proxy {
+class DataReductionProxyStore;
+class DataUsageBucket;
+
+// Store for detailed data usage stats. Data usage from every
+// |kDataUsageBucketLengthMins| interval is stored in a DataUsageBucket.
+class DataUsageStorageHelper {
jeremyim 2015/06/30 01:59:19 rename to DataReductionProxyUsageStore or DataUsag
Not at Google. Contact bengr 2015/07/01 17:13:49 Done.
+ public:
+ explicit DataUsageStorageHelper(scoped_refptr<DataReductionProxyStore> db);
jeremyim 2015/06/30 01:59:19 const scoped_refptr&
Not at Google. Contact bengr 2015/07/01 17:13:49 No longer using ref ptr.
+
+ ~DataUsageStorageHelper();
+
+ // Loads the data usage bucket for the current interval into |current_bucket|.
+ // This method must be called at least once before any calls to
+ // |StoreCurrentDataUsageBucket|.
+ scoped_ptr<DataUsageBucket> LoadCurrentDataUsageBucket();
+
+ // Stores the data usage bucket for the current interval. This will overwrite
+ // the current data usage bucket in the DB if they are for the same interval.
+ // It will also backfill any missed intervals with empty data. Intervals might
+ // be missed because Chrome was not running, or there was no network activity
+ // during an interval.
+ void StoreCurrentDataUsageBucket(const DataUsageBucket* current_bucket);
jeremyim 2015/06/30 01:59:19 const DataUsageBucket& ?
Not at Google. Contact bengr 2015/07/01 17:13:49 Done.
+
+ private:
+ friend class DataUsageStorageHelperTest;
+
+ // Converts the given |bucket| into a string format for persistance to
+ // |DataReductionProxyStore| and add to the map.
+ void AddBucketToMap(const DataUsageBucket* bucket,
+ std::map<std::string, std::string>* map);
+
+ // Returns the number of buckets between the current interval bucket and the
+ // last bucket that was persisted to the store.
+ int NumBucketsSinceLastSaved(base::Time current) const;
+
+ // The store to persist data usage information.
+ scoped_refptr<DataReductionProxyStore> db_;
+
+ // The index of the last bucket persisted in the DB. |DataUsageBucket| is
+ // stored in the DB as a circular array. This index points to the array
+ // position corresponding to the current bucket.
+ int current_bucket_index_;
+
+ // The time when the current bucket was last written to DB. This field is
+ // used to determine if a DataUsageBucket to be saved belongs to the same
+ // interval, or a more recent interval.
+ base::Time current_bucket_last_updated_;
+
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(DataUsageStorageHelper);
+};
+
+} // namespace data_reduction_proxy
+#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_USAGE_STORAGE_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698