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