| Index: components/precache/core/precache_statistics_table.h | 
| diff --git a/components/precache/core/precache_statistics_table.h b/components/precache/core/precache_statistics_table.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..ec4d19b024edb6427fd91fb4bfac40e709b438b0 | 
| --- /dev/null | 
| +++ b/components/precache/core/precache_statistics_table.h | 
| @@ -0,0 +1,79 @@ | 
| +// Copyright 2013 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ | 
| +#define COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ | 
| + | 
| +#include <map> | 
| + | 
| +#include "base/basictypes.h" | 
| +#include "base/time/time.h" | 
| + | 
| +namespace sql { | 
| +class Connection; | 
| +} | 
| + | 
| +namespace precache { | 
| + | 
| +// Keeps track of daily precache statistics in a database table. Manages one | 
| +// table { date (primary key), precached_bytes, downloaded_bytes, | 
| +// downloaded_bytes_cellular, saved_bytes, saved_bytes_cellular }. | 
| +class PrecacheStatisticsTable { | 
| + public: | 
| +  // Struct of the statistics tracked by this class. | 
| +  struct PrecacheStatistics { | 
| +    // Initializes all statistics to zero. | 
| +    PrecacheStatistics(); | 
| +    PrecacheStatistics(int64 precached_bytes, int64 downloaded_bytes, | 
| +                       int64 downloaded_bytes_cellular, int64 saved_bytes, | 
| +                       int64 saved_bytes_cellular); | 
| +    bool operator==(const PrecacheStatistics& other) const; | 
| + | 
| +    int64 precached_bytes; | 
| +    int64 downloaded_bytes; | 
| +    int64 downloaded_bytes_cellular; | 
| +    int64 saved_bytes; | 
| +    int64 saved_bytes_cellular; | 
| +  }; | 
| + | 
| +  PrecacheStatisticsTable(); | 
| +  ~PrecacheStatisticsTable(); | 
| + | 
| +  // Initialize the precache statistics table for use with the specified | 
| +  // database connection. The caller keeps ownership of |db|, and |db| must not | 
| +  // be NULL. Init must be called before any other methods. | 
| +  void Init(sql::Connection* db); | 
| + | 
| +  // Updates daily statistics for a given fetch, | 
| +  void IncreaseStatsForFetch( | 
| +      const base::Time& fetch_time, | 
| +      const PrecacheStatistics& precache_statistics_change); | 
| + | 
| +  // Returns stored daily statistics for days between the day of |start_time| | 
| +  // and the day of |end_time|, inclusive. | 
| +  void GetAllStatsBetween(const base::Time& start_time, | 
| +                          const base::Time& end_time, | 
| +                          std::map<base::Time, PrecacheStatistics>* map); | 
| + | 
| +  // Deletes stored daily statistics for days between the day of |delete_begin| | 
| +  // and the day of |delete_end|, inclusive. | 
| +  void DeleteAllStatsBetween(const base::Time& delete_begin, | 
| +                             const base::Time& delete_end); | 
| + | 
| + private: | 
| +  // Rounds |fetch_time| down to midnight of the start of the day of | 
| +  // |fetch_time|, and returns the internal value. | 
| +  static int64 GetKey(const base::Time& fetch_time); | 
| + | 
| +  void CreateTableIfNonExistent(); | 
| + | 
| +  // Non-owning pointer. | 
| +  sql::Connection* db_; | 
| + | 
| +  DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable); | 
| +}; | 
| + | 
| +}  // namespace precache | 
| + | 
| +#endif  // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_ | 
|  |