Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ | |
| 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/time/time.h" | |
| 12 | |
| 13 namespace sql { | |
| 14 class Connection; | |
| 15 } | |
| 16 | |
| 17 namespace precache { | |
| 18 | |
| 19 // Keeps track of daily precache statistics in a database table. Manages one | |
| 20 // table { date (primary key), precached_bytes, downloaded_bytes, | |
| 21 // downloaded_bytes_cellular, saved_bytes, saved_bytes_cellular }. | |
| 22 class PrecacheStatisticsTable { | |
| 23 public: | |
| 24 // Struct of the statistics tracked by this class. | |
| 25 struct PrecacheStatistics { | |
| 26 // Initializes all statistics to zero. | |
| 27 PrecacheStatistics(); | |
| 28 PrecacheStatistics(int64 precached_bytes, int64 downloaded_bytes, | |
| 29 int64 downloaded_bytes_cellular, int64 saved_bytes, | |
| 30 int64 saved_bytes_cellular); | |
| 31 bool operator==(const PrecacheStatistics& other) const; | |
| 32 | |
| 33 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.
| |
| 34 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.
| |
| 35 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.
| |
| 36 int64 saved_bytes; | |
| 37 int64 saved_bytes_cellular; | |
| 38 }; | |
| 39 | |
| 40 typedef std::map<base::Time, PrecacheStatistics> PrecacheStatisticsMap; | |
| 41 | |
| 42 PrecacheStatisticsTable(); | |
| 43 ~PrecacheStatisticsTable(); | |
| 44 | |
| 45 // Initialize the precache statistics table for use with the specified | |
| 46 // database connection. The caller keeps ownership of |db|, and |db| must not | |
| 47 // be NULL. Init must be called before any other methods. | |
| 48 void Init(sql::Connection* db); | |
| 49 | |
| 50 // Increase the daily statistics for the day of |time_on_day|. If a row for | |
| 51 // the day of |time_on_day| does not already exist, a new row is created. | |
| 52 void IncreaseDailyStats(const base::Time& time_on_day, | |
| 53 const PrecacheStatistics& stats_change); | |
| 54 | |
| 55 // Returns stored daily statistics for days between the day of |start_time| | |
| 56 // and the day of |end_time|, inclusive. | |
| 57 void GetAllStatsBetween(const base::Time& start_time, | |
| 58 const base::Time& end_time, | |
| 59 PrecacheStatisticsMap* map); | |
| 60 | |
| 61 // Deletes stored daily statistics for days between the day of |delete_begin| | |
| 62 // and the day of |delete_end|, inclusive. | |
| 63 void DeleteAllStatsBetween(const base::Time& delete_begin, | |
| 64 const base::Time& delete_end); | |
| 65 | |
| 66 private: | |
| 67 // Rounds |time_on_day| down to midnight of the start of the day of | |
| 68 // |time_on_day|, and returns the internal value. | |
| 69 static int64 GetKey(const base::Time& time_on_day); | |
| 70 | |
| 71 void CreateTableIfNonExistent(); | |
| 72 | |
| 73 // Non-owning pointer. | |
| 74 sql::Connection* db_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable); | |
| 77 }; | |
| 78 | |
| 79 } // namespace precache | |
| 80 | |
| 81 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ | |
| OLD | NEW |