Chromium Code Reviews| Index: components/precache/core/precache_statistics_table.h |
| diff --git a/components/precache/core/precache_statistics_table.h b/components/precache/core/precache_statistics_table.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ac12d155f09dfc9f397d442380ee3075c28737c7 |
| --- /dev/null |
| +++ b/components/precache/core/precache_statistics_table.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2013 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_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ |
| +#define COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/time/time.h" |
| + |
| +namespace sql { |
| +class Connection; |
| +} |
| + |
| +namespace precache { |
| + |
| +// Keeps track of daily precache statistics in a database table. Manages one |
| +// table { date (primary key), precached_bytes, downloaded_bytes, |
| +// downloaded_bytes_cellular, saved_bytes, saved_bytes_cellular }. |
| +class PrecacheStatisticsTable { |
| + public: |
| + // Struct of the statistics tracked by this class. |
| + struct PrecacheStatistics { |
| + // Initializes all statistics to zero. |
| + PrecacheStatistics(); |
| + PrecacheStatistics(int64 precached_bytes, int64 downloaded_bytes, |
| + int64 downloaded_bytes_cellular, int64 saved_bytes, |
| + int64 saved_bytes_cellular); |
| + bool operator==(const PrecacheStatistics& other) const; |
| + |
| + int64 precached_bytes; |
|
mmenke
2013/10/31 16:45:00
I think these names are unclear. I'm a fan of cle
sclittle
2013/11/06 01:51:42
Done.
|
| + int64 downloaded_bytes; |
|
mmenke
2013/10/31 16:45:00
I suggest calling this downloaded_non_precache_byt
sclittle
2013/11/06 01:51:42
Done.
|
| + int64 downloaded_bytes_cellular; |
|
mmenke
2013/10/31 16:45:00
And this downloaded_non_precache_bytes_cellular.
sclittle
2013/11/06 01:51:42
Done.
|
| + int64 saved_bytes; |
| + int64 saved_bytes_cellular; |
| + }; |
| + |
| + typedef std::map<base::Time, PrecacheStatistics> PrecacheStatisticsMap; |
| + |
| + PrecacheStatisticsTable(); |
| + ~PrecacheStatisticsTable(); |
| + |
| + // Initialize the precache statistics table for use with the specified |
| + // database connection. The caller keeps ownership of |db|, and |db| must not |
| + // be NULL. Init must be called before any other methods. |
| + void Init(sql::Connection* db); |
| + |
| + // Increase the daily statistics for the day of |time_on_day|. If a row for |
| + // the day of |time_on_day| does not already exist, a new row is created. |
| + void IncreaseDailyStats(const base::Time& time_on_day, |
| + const PrecacheStatistics& stats_change); |
| + |
| + // Returns stored daily statistics for days between the day of |start_time| |
| + // and the day of |end_time|, inclusive. |
| + void GetAllStatsBetween(const base::Time& start_time, |
| + const base::Time& end_time, |
| + PrecacheStatisticsMap* map); |
| + |
| + // Deletes stored daily statistics for days between the day of |delete_begin| |
| + // and the day of |delete_end|, inclusive. |
| + void DeleteAllStatsBetween(const base::Time& delete_begin, |
| + const base::Time& delete_end); |
| + |
| + private: |
| + // Rounds |time_on_day| down to midnight of the start of the day of |
| + // |time_on_day|, and returns the internal value. |
| + static int64 GetKey(const base::Time& time_on_day); |
| + |
| + void CreateTableIfNonExistent(); |
| + |
| + // Non-owning pointer. |
| + sql::Connection* db_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable); |
| +}; |
| + |
| +} // namespace precache |
| + |
| +#endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ |