Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: components/precache/core/precache_statistics_table.h

Issue 27047003: Precache tracking database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@precache
Patch Set: Reduced CL down to just the PrecacheDatabase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..503fc4f0e14685cb7f64fa8bc5aa0c2cbc109267
--- /dev/null
+++ b/components/precache/core/precache_statistics_table.h
@@ -0,0 +1,92 @@
+// 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;
davidben 2013/11/06 23:50:53 Nit: I'd probably put some newlines after each of
sclittle 2013/11/09 01:07:58 Done.
+ };
+
+ 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 and including the day of
+ // |end_date|.
+ void GetAllStatsUntil(const base::Time& end_date,
+ PrecacheStatisticsMap* stats_map);
+
+ // Deletes stored daily statistics for days up to and including the day of
+ // |end_date|.
+ void DeleteAllStatsUntil(const base::Time& end_date);
+
+ private:
+ void CreateTableIfNonExistent();
+
+ // Non-owning pointer.
+ sql::Connection* db_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable);
+};
+
+} // namespace precache
+
+#endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_

Powered by Google App Engine
This is Rietveld 408576698