Chromium Code Reviews| Index: components/data_reduction_proxy/core/browser/data_usage_store.h |
| diff --git a/components/data_reduction_proxy/core/browser/data_usage_store.h b/components/data_reduction_proxy/core/browser/data_usage_store.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa7f85fc4975880e24098a32e079e6795d4a7f04 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/core/browser/data_usage_store.h |
| @@ -0,0 +1,71 @@ |
| +// 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_STORE_H_ |
| +#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_USAGE_STORE_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" |
|
jeremyim
2015/07/01 21:31:01
Unused.
Not at Google. Contact bengr
2015/07/01 23:17:38
Done.
|
| +#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 DataUsageStore { |
| + public: |
| + explicit DataUsageStore(DataReductionProxyStore* db); |
| + |
| + ~DataUsageStore(); |
| + |
| + // 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|. |
| + void LoadCurrentDataUsageBucket(DataUsageBucket* bucket); |
| + |
| + // 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); |
| + |
| + private: |
| + friend class DataUsageStoreTest; |
| + |
| + // 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. |
| + 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_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DataUsageStore); |
| +}; |
| + |
| +} // namespace data_reduction_proxy |
| +#endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_USAGE_STORE_H_ |