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

Side by Side Diff: components/precache/core/precache_referrer_host_table.h

Issue 2229983002: Send the list of used and unused resources for precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added-test Created 4 years, 4 months 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 2016 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_REFERRER_HOST_TABLE_H_
6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_REFERRER_HOST_TABLE_H_
7
8 #include <stdint.h>
9
10 #include <map>
11 #include <string>
12
13 #include "base/macros.h"
14 #include "base/time/time.h"
15
16 namespace sql {
17 class Connection;
18 }
19
20 namespace precache {
21
22 struct PrecacheReferrerHostEntry {
23 static const int64_t kInvalidId;
24
25 PrecacheReferrerHostEntry(int64_t id,
26 const std::string& referrer_host,
27 int64_t manifest_id,
28 const base::Time& time)
29 : id(id),
30 referrer_host(referrer_host),
31 manifest_id(manifest_id),
32 time(time) {}
33
34 // Comparison for testing.
35 bool operator==(const PrecacheReferrerHostEntry entry) const {
36 return id == entry.id && referrer_host == entry.referrer_host &&
37 manifest_id == entry.manifest_id && time == entry.time;
38 ;
39 }
40
41 int64_t id;
42 std::string referrer_host;
43 int64_t manifest_id;
44 base::Time time;
45 };
46
47 class PrecacheReferrerHostTable {
48 public:
49 PrecacheReferrerHostTable();
50 ~PrecacheReferrerHostTable();
51
52 // Initialize the precache referrer host table for use with the specified
53 // database connection. The caller keeps ownership of |db|, and |db| must not
54 // be NULL. Init must be called before any other methods.
55 bool Init(sql::Connection* db);
56
57 // Returns the referrer host information about |referrer_host|.
58 PrecacheReferrerHostEntry GetReferrerHost(const std::string& referrer_host);
59
60 // Updates the referrer host information about |referrer_host|.
61 int64_t UpdateReferrerHost(const std::string& referrer_host,
62 int64_t manifest_id,
63 const base::Time& time);
64
65 // Deletes entries that were created before the time of |delete_end|.
66 void DeleteAllEntriesBefore(const base::Time& delete_end);
67
68 // Delete all entries.
69 void DeleteAll();
70
71 // Used by tests to get the contents of the table.
72 std::map<std::string, PrecacheReferrerHostEntry> GetAllDataForTesting();
73
74 private:
75 bool CreateTableIfNonExistent();
76
77 // Not owned by |this|.
78 sql::Connection* db_;
79
80 DISALLOW_COPY_AND_ASSIGN(PrecacheReferrerHostTable);
81 };
82
83 } // namespace precache
84
85 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_REFERRER_HOST_TABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698