| 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..9244fc989a782f1e09e82abece1e9843bf72b9a5
|
| --- /dev/null
|
| +++ b/components/precache/core/precache_statistics_table.h
|
| @@ -0,0 +1,96 @@
|
| +// 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),
|
| +// downloaded_precache_motivated_bytes,
|
| +// downloaded_non_precache_bytes,
|
| +// downloaded_non_precache_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 downloaded_precache_motivated_bytes,
|
| + int64 downloaded_non_precache_bytes,
|
| + int64 downloaded_non_precache_bytes_cellular,
|
| + int64 saved_bytes, int64 saved_bytes_cellular);
|
| + bool operator==(const PrecacheStatistics& other) const;
|
| +
|
| + // Number of bytes downloaded over the network for fetches that were
|
| + // motivated by precaching.
|
| + int64 downloaded_precache_motivated_bytes;
|
| +
|
| + // Number of bytes downloaded over any network for fetches that were not
|
| + // motivated by precaching.
|
| + int64 downloaded_non_precache_bytes;
|
| +
|
| + // Number of bytes downloaded over cellular networks for fetches that were
|
| + // not motivated by precaching.
|
| + int64 downloaded_non_precache_bytes_cellular;
|
| +
|
| + // Number of bytes that were served from the cache because of precaching,
|
| + // but would have been downloaded over the network otherwise.
|
| + int64 saved_bytes;
|
| +
|
| + // Number of bytes that were served from the cache because of precaching,
|
| + // but would have been downloaded over a cellular network otherwise.
|
| + int64 saved_bytes_cellular;
|
| + };
|
| +
|
| + typedef std::map<base::Time, PrecacheStatistics> PrecacheStatisticsMap;
|
| +
|
| + 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);
|
| +
|
| + // Increase the daily statistics for the day of |time_on_day|. If a row for
|
| + // the day of |time_on_day| does not already exist, a new row is created.
|
| + void IncreaseDailyStats(const base::Time& time_on_day,
|
| + const PrecacheStatistics& delta);
|
| +
|
| + // Gets stored daily statistics for days up to but not including the day of
|
| + // |current_time|.
|
| + void GetOldStats(const base::Time& current_time,
|
| + PrecacheStatisticsMap* stats_map);
|
| +
|
| + // Deletes stored daily statistics for days up to but not including the day of
|
| + // |current_time|.
|
| + void DeleteOldStats(const base::Time& current_time);
|
| +
|
| + private:
|
| + void CreateTableIfNonExistent();
|
| +
|
| + // Non-owning pointer.
|
| + sql::Connection* db_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable);
|
| +};
|
| +
|
| +} // namespace precache
|
| +
|
| +#endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_
|
|
|