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

Side by Side 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: Moved MostVisitedURLsProvider into chrome/browser/precache 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 unified diff | Download patch
OLDNEW
(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 after a fetch. If a row for the day of
mmenke 2013/10/29 18:23:34 "Fetch" is ambiguous. Particularly given that thi
sclittle 2013/10/29 23:40:45 Removed the concept of "fetch" from this method.
49 // |fetch_time| does not already exist, a new row is created.
50 void IncreaseStatsForFetch(
51 const base::Time& fetch_time,
52 const PrecacheStatistics& precache_statistics_change);
53
54 // Returns stored daily statistics for days between the day of |start_time|
55 // and the day of |end_time|, inclusive.
56 void GetAllStatsBetween(const base::Time& start_time,
57 const base::Time& end_time,
58 std::map<base::Time, PrecacheStatistics>* map);
59
60 // Deletes stored daily statistics for days between the day of |delete_begin|
61 // and the day of |delete_end|, inclusive.
62 void DeleteAllStatsBetween(const base::Time& delete_begin,
63 const base::Time& delete_end);
64
65 private:
66 // Rounds |fetch_time| down to midnight of the start of the day of
67 // |fetch_time|, and returns the internal value.
68 static int64 GetKey(const base::Time& fetch_time);
69
70 void CreateTableIfNonExistent();
71
72 // Non-owning pointer.
73 sql::Connection* db_;
74
75 DISALLOW_COPY_AND_ASSIGN(PrecacheStatisticsTable);
76 };
77
78 } // namespace precache
79
80 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_STATISTICS_TABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698