| 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 |
| 44 // Number of bytes downloaded over any network for fetches that were not |
| 45 // motivated by precaching. |
| 46 int64 downloaded_non_precache_bytes; |
| 47 |
| 48 // Number of bytes downloaded over cellular networks for fetches that were |
| 49 // not motivated by precaching. |
| 50 int64 downloaded_non_precache_bytes_cellular; |
| 51 |
| 52 // Number of bytes that were served from the cache because of precaching, |
| 53 // but would have been downloaded over the network otherwise. |
| 54 int64 saved_bytes; |
| 55 |
| 56 // Number of bytes that were served from the cache because of precaching, |
| 57 // but would have been downloaded over a cellular network otherwise. |
| 58 int64 saved_bytes_cellular; |
| 59 }; |
| 60 |
| 61 typedef std::map<base::Time, PrecacheStatistics> PrecacheStatisticsMap; |
| 62 |
| 63 PrecacheStatisticsTable(); |
| 64 ~PrecacheStatisticsTable(); |
| 65 |
| 66 // Initialize the precache statistics table for use with the specified |
| 67 // database connection. The caller keeps ownership of |db|, and |db| must not |
| 68 // be NULL. Init must be called before any other methods. |
| 69 void Init(sql::Connection* db); |
| 70 |
| 71 // Increase the daily statistics for the day of |time_on_day|. If a row for |
| 72 // the day of |time_on_day| does not already exist, a new row is created. |
| 73 void IncreaseDailyStats(const base::Time& time_on_day, |
| 74 const PrecacheStatistics& delta); |
| 75 |
| 76 // Gets stored daily statistics for days up to but not including the day of |
| 77 // |current_time|. |
| 78 void GetOldStats(const base::Time& current_time, |
| 79 PrecacheStatisticsMap* stats_map); |
| 80 |
| 81 // Deletes stored daily statistics for days up to but not including the day of |
| 82 // |current_time|. |
| 83 void DeleteOldStats(const base::Time& current_time); |
| 84 |
| 85 private: |
| 86 void CreateTableIfNonExistent(); |
| 87 |
| 88 // Non-owning pointer. |
| 89 sql::Connection* db_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable); |
| 92 }; |
| 93 |
| 94 } // namespace precache |
| 95 |
| 96 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ |
| OLD | NEW |