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

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

Issue 2586813004: Report downloaded resources at most once (Closed)
Patch Set: Fix race condition in PrecacheFetcherTest due to MaybePost Created 4 years 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_
6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "sql/statement.h"
twifkak 2016/12/20 01:42:00 If this is for sql::Statement, just fwd declare: h
jamartin 2016/12/20 21:09:34 Done.
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace sql { 18 namespace sql {
18 class Connection; 19 class Connection;
19 } 20 }
20 21
21 namespace precache { 22 namespace precache {
22 23
23 // Information about a given URL with respect to the PrecacheURLTable. 24 // Information about a given URL with respect to the PrecacheURLTable.
24 struct PrecacheURLInfo { 25 struct PrecacheURLInfo {
(...skipping 23 matching lines...) Expand all
48 PrecacheURLTable(); 49 PrecacheURLTable();
49 ~PrecacheURLTable(); 50 ~PrecacheURLTable();
50 51
51 // Initialize the precache URL table for use with the specified database 52 // Initialize the precache URL table for use with the specified database
52 // connection. The caller keeps ownership of |db|, and |db| must not be NULL. 53 // connection. The caller keeps ownership of |db|, and |db| must not be NULL.
53 // Init must be called before any other methods. 54 // Init must be called before any other methods.
54 bool Init(sql::Connection* db); 55 bool Init(sql::Connection* db);
55 56
56 // Adds an URL to the table, |referrer_host_id| is the id of the referrer host 57 // Adds an URL to the table, |referrer_host_id| is the id of the referrer host
57 // in PrecacheReferrerHostTable, |is_precached| indicates if the URL is 58 // in PrecacheReferrerHostTable, |is_precached| indicates if the URL is
58 // precached, |time| is the timestamp. Replaces the row if one already exists. 59 // precached, |time| is the timestamp. Replaces the row if one already exists.
twifkak 2016/12/20 01:42:00 Update doc.
jamartin 2016/12/20 21:09:34 Done.
59 void AddURL(const GURL& url, 60 void AddURL(const GURL& url,
60 int64_t referrer_host_id, 61 int64_t referrer_host_id,
61 bool is_precached, 62 bool is_precached,
63 bool was_cached,
62 const base::Time& precache_time); 64 const base::Time& precache_time);
63 65
64 // Returns information about the URL's status with respect to prefetching. 66 // Returns information about the URL's status with respect to prefetching.
65 PrecacheURLInfo GetURLInfo(const GURL& url); 67 PrecacheURLInfo GetURLInfo(const GURL& url);
66 68
67 // Sets the precached URL as used. 69 // Sets the precached URL as used.
68 void SetPrecachedURLAsUsed(const GURL& url); 70 void SetPrecachedURLAsUsed(const GURL& url);
69 71
70 // Set the previously precached URL as not precached, during user browsing. 72 // Set the previously precached URL as not precached, during user browsing.
71 void SetURLAsNotPrecached(const GURL& url); 73 void SetURLAsNotPrecached(const GURL& url);
72 74
73 // Populates the used and unused resource URLs for the referrer host with id 75 // Populates the used and unused resource URLs for the referrer host with id
twifkak 2016/12/20 01:42:00 s/unused/downloaded
jamartin 2016/12/20 21:09:34 Done.
74 // |referrer_host_id|. 76 // |referrer_host_id|. It will also clear the reported downloaded_urls.
75 void GetURLListForReferrerHost(int64_t referrer_host_id, 77 void GetURLListForReferrerHost(int64_t referrer_host_id,
76 std::vector<GURL>* used_urls, 78 std::vector<GURL>* used_urls,
77 std::vector<GURL>* unused_urls); 79 std::vector<GURL>* downloaded_urls);
78 80
79 // Clears all URL entries for the referrer host |referrer_host_id|. 81 // Clears all URL entries for the referrer host |referrer_host_id|.
80 void ClearAllForReferrerHost(int64_t referrer_host_id); 82 void ClearAllForReferrerHost(int64_t referrer_host_id);
81 83
82 // Deletes entries that were precached before the time of |delete_end|. 84 // Deletes entries that were precached before the time of |delete_end|.
83 void DeleteAllPrecachedBefore(const base::Time& delete_end); 85 void DeleteAllPrecachedBefore(const base::Time& delete_end);
84 86
85 // Delete all entries. 87 // Delete all entries.
86 void DeleteAll(); 88 void DeleteAll();
87 89
88 // Used by tests to get the contents of the table. 90 // Used by tests to get the contents of the table.
89 void GetAllDataForTesting(std::map<GURL, base::Time>* map); 91 void GetAllDataForTesting(std::map<GURL, base::Time>* map);
90 92
91 private: 93 private:
92 bool CreateTableIfNonExistent(); 94 bool CreateTableIfNonExistent();
93 95
96 bool SetIsDownloadReported(int64_t referrer_host_id, const GURL& url);
97
98 bool BindStatementAndRun(const GURL& url,
99 int64_t referrer_host_id,
100 bool is_precached,
101 const base::Time& precache_time,
102 sql::Statement* statement);
103
94 // Non-owned pointer. 104 // Non-owned pointer.
95 sql::Connection* db_; 105 sql::Connection* db_;
96 106
97 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable); 107 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable);
98 }; 108 };
99 109
100 } // namespace precache 110 } // namespace precache
101 111
102 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ 112 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698