| 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; |
| 34 int64 downloaded_bytes; |
| 35 int64 downloaded_bytes_cellular; |
| 36 int64 saved_bytes; |
| 37 int64 saved_bytes_cellular; |
| 38 }; |
| 39 |
| 40 PrecacheStatisticsTable(); |
| 41 ~PrecacheStatisticsTable(); |
| 42 |
| 43 // Initialize the precache statistics table for use with the specified |
| 44 // database connection. The caller keeps ownership of |db|, and |db| must not |
| 45 // be NULL. Init must be called before any other methods. |
| 46 void Init(sql::Connection* db); |
| 47 |
| 48 // Updates daily statistics for a given fetch, |
| 49 void IncreaseStatsForFetch( |
| 50 const base::Time& fetch_time, |
| 51 const PrecacheStatistics& precache_statistics_change); |
| 52 |
| 53 // Returns stored daily statistics for days between the day of |start_time| |
| 54 // and the day of |end_time|, inclusive. |
| 55 void GetAllStatsBetween(const base::Time& start_time, |
| 56 const base::Time& end_time, |
| 57 std::map<base::Time, PrecacheStatistics>* map); |
| 58 |
| 59 // Deletes stored daily statistics for days between the day of |delete_begin| |
| 60 // and the day of |delete_end|, inclusive. |
| 61 void DeleteAllStatsBetween(const base::Time& delete_begin, |
| 62 const base::Time& delete_end); |
| 63 |
| 64 private: |
| 65 // Rounds |fetch_time| down to midnight of the start of the day of |
| 66 // |fetch_time|, and returns the internal value. |
| 67 static int64 GetKey(const base::Time& fetch_time); |
| 68 |
| 69 void CreateTableIfNonExistent(); |
| 70 |
| 71 // Non-owning pointer. |
| 72 sql::Connection* db_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable); |
| 75 }; |
| 76 |
| 77 } // namespace precache |
| 78 |
| 79 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ |
| OLD | NEW |