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 { | |
| 21 // date (primary key), | |
| 22 // downloaded_precache_motivated_bytes, | |
| 23 // downloaded_non_precache_bytes, | |
| 24 // downloaded_non_precache_bytes_cellular, | |
| 25 // saved_bytes, | |
| 26 // saved_bytes_cellular | |
| 27 // }. | |
| 28 class PrecacheStatisticsTable { | |
| 29 public: | |
| 30 // Struct of the statistics tracked by this class. | |
| 31 struct PrecacheStatistics { | |
| 32 // Initializes all statistics to zero. | |
| 33 PrecacheStatistics(); | |
| 34 PrecacheStatistics(int64 downloaded_precache_motivated_bytes, | |
| 35 int64 downloaded_non_precache_bytes, | |
| 36 int64 downloaded_non_precache_bytes_cellular, | |
| 37 int64 saved_bytes, int64 saved_bytes_cellular); | |
| 38 bool operator==(const PrecacheStatistics& other) const; | |
| 39 | |
| 40 // Number of bytes downloaded over the network for fetches that were | |
| 41 // motivated by precaching. | |
| 42 int64 downloaded_precache_motivated_bytes; | |
| 43 // Number of bytes downloaded over any network for fetches that were not | |
| 44 // motivated by precaching. | |
| 45 int64 downloaded_non_precache_bytes; | |
| 46 // Number of bytes downloaded over cellular networks for fetches that were | |
| 47 // not motivated by precaching. | |
| 48 int64 downloaded_non_precache_bytes_cellular; | |
| 49 // Number of bytes that were served from the cache because of precaching, | |
| 50 // but would have been downloaded over the network otherwise. | |
| 51 int64 saved_bytes; | |
| 52 // Number of bytes that were served from the cache because of precaching, | |
| 53 // but would have been downloaded over a cellular network otherwise. | |
| 54 int64 saved_bytes_cellular; | |
|
davidben
2013/11/06 23:50:53
Nit: I'd probably put some newlines after each of
sclittle
2013/11/09 01:07:58
Done.
| |
| 55 }; | |
| 56 | |
| 57 typedef std::map<base::Time, PrecacheStatistics> PrecacheStatisticsMap; | |
| 58 | |
| 59 PrecacheStatisticsTable(); | |
| 60 ~PrecacheStatisticsTable(); | |
| 61 | |
| 62 // Initialize the precache statistics table for use with the specified | |
| 63 // database connection. The caller keeps ownership of |db|, and |db| must not | |
| 64 // be NULL. Init must be called before any other methods. | |
| 65 void Init(sql::Connection* db); | |
| 66 | |
| 67 // Increase the daily statistics for the day of |time_on_day|. If a row for | |
| 68 // the day of |time_on_day| does not already exist, a new row is created. | |
| 69 void IncreaseDailyStats(const base::Time& time_on_day, | |
| 70 const PrecacheStatistics& delta); | |
| 71 | |
| 72 // Gets stored daily statistics for days up to and including the day of | |
| 73 // |end_date|. | |
| 74 void GetAllStatsUntil(const base::Time& end_date, | |
| 75 PrecacheStatisticsMap* stats_map); | |
| 76 | |
| 77 // Deletes stored daily statistics for days up to and including the day of | |
| 78 // |end_date|. | |
| 79 void DeleteAllStatsUntil(const base::Time& end_date); | |
| 80 | |
| 81 private: | |
| 82 void CreateTableIfNonExistent(); | |
| 83 | |
| 84 // Non-owning pointer. | |
| 85 sql::Connection* db_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable); | |
| 88 }; | |
| 89 | |
| 90 } // namespace precache | |
| 91 | |
| 92 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ | |
| OLD | NEW |