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

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

Issue 2586813004: Report downloaded resources at most once (Closed)
Patch Set: Improved tests 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>
(...skipping 16 matching lines...) Expand all
27 bool was_precached; 27 bool was_precached;
28 28
29 // True if the cache entry is the one fetched by PrecacheFetcher. False if a 29 // True if the cache entry is the one fetched by PrecacheFetcher. False if a
30 // new network fetch overwrote the cache entry since the prefetch. 30 // new network fetch overwrote the cache entry since the prefetch.
31 bool is_precached; 31 bool is_precached;
32 32
33 // The prefetched copy of the URL was used in browsing (i.e. while 33 // The prefetched copy of the URL was used in browsing (i.e. while
34 // is_precached was true). 34 // is_precached was true).
35 bool was_used; 35 bool was_used;
36 36
37 // It was already reported that this resources was downloaded.
38 bool is_download_reported;
39
37 bool operator==(const PrecacheURLInfo& other) const; 40 bool operator==(const PrecacheURLInfo& other) const;
38 }; 41 };
39 42
40 // Interface for database table that keeps track of the URLs that have been 43 // Interface for database table that keeps track of the URLs that have been
41 // precached but not used. This table is used to count how many bytes were saved 44 // precached but not used. This table is used to count how many bytes were saved
42 // by precached resources. 45 // by precached resources.
43 // Each row in this table represents a URL that was precached over the network, 46 // Each row in this table represents a URL that was precached over the network,
44 // and has not been fetched through user browsing since then. 47 // and has not been fetched through user browsing since then.
45 // Manages one table { URL (primary key), precache timestamp }. 48 // Manages one table { URL (primary key), precache timestamp }.
46 class PrecacheURLTable { 49 class PrecacheURLTable {
47 public: 50 public:
48 PrecacheURLTable(); 51 PrecacheURLTable();
49 ~PrecacheURLTable(); 52 ~PrecacheURLTable();
50 53
51 // Initialize the precache URL table for use with the specified database 54 // 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. 55 // connection. The caller keeps ownership of |db|, and |db| must not be NULL.
53 // Init must be called before any other methods. 56 // Init must be called before any other methods.
54 bool Init(sql::Connection* db); 57 bool Init(sql::Connection* db);
55 58
56 // Adds an URL to the table, |referrer_host_id| is the id of the referrer host 59 // 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 60 // in PrecacheReferrerHostTable, |is_precached| indicates if the URL is
58 // precached, |time| is the timestamp. Replaces the row if one already exists. 61 // precached, |time| is the timestamp, |is_download_reported| indicates if
62 // this the download of this URL was already reported. Replaces the row if one
63 // already exists.
59 void AddURL(const GURL& url, 64 void AddURL(const GURL& url,
60 int64_t referrer_host_id, 65 int64_t referrer_host_id,
61 bool is_precached, 66 bool is_precached,
62 const base::Time& precache_time); 67 const base::Time& precache_time,
68 bool is_download_reported);
63 69
64 // Returns information about the URL's status with respect to prefetching. 70 // Returns information about the URL's status with respect to prefetching.
65 PrecacheURLInfo GetURLInfo(const GURL& url); 71 PrecacheURLInfo GetURLInfo(const GURL& url);
66 72
67 // Sets the precached URL as used. 73 // Sets the precached URL as used.
68 void SetPrecachedURLAsUsed(const GURL& url); 74 void SetPrecachedURLAsUsed(const GURL& url);
69 75
70 // Set the previously precached URL as not precached, during user browsing. 76 // Set the previously precached URL as not precached, during user browsing.
71 void SetURLAsNotPrecached(const GURL& url); 77 void SetURLAsNotPrecached(const GURL& url);
72 78
73 // Populates the used and unused resource URLs for the referrer host with id 79 // Populates the used and downloaded resource URLs for the referrer host with
74 // |referrer_host_id|. 80 // id |referrer_host_id|.
75 void GetURLListForReferrerHost(int64_t referrer_host_id, 81 void GetURLListForReferrerHost(int64_t referrer_host_id,
76 std::vector<GURL>* used_urls, 82 std::vector<GURL>* used_urls,
77 std::vector<GURL>* unused_urls); 83 std::vector<GURL>* downloaded_urls);
84
85 // Sets all the URLs of the given referrer_host_id as is_download_reported.
86 void SetDownloadReported(int64_t referrer_host_id);
78 87
79 // Clears all URL entries for the referrer host |referrer_host_id|. 88 // Clears all URL entries for the referrer host |referrer_host_id|.
80 void ClearAllForReferrerHost(int64_t referrer_host_id); 89 void ClearAllForReferrerHost(int64_t referrer_host_id);
81 90
82 // Deletes entries that were precached before the time of |delete_end|. 91 // Deletes entries that were precached before the time of |delete_end|.
83 void DeleteAllPrecachedBefore(const base::Time& delete_end); 92 void DeleteAllPrecachedBefore(const base::Time& delete_end);
84 93
85 // Delete all entries. 94 // Delete all entries.
86 void DeleteAll(); 95 void DeleteAll();
87 96
88 // Used by tests to get the contents of the table. 97 // Used by tests to get the contents of the table.
89 void GetAllDataForTesting(std::map<GURL, base::Time>* map); 98 void GetAllDataForTesting(std::map<GURL, base::Time>* map);
90 99
91 private: 100 private:
92 bool CreateTableIfNonExistent(); 101 bool CreateTableIfNonExistent();
93 102
94 // Non-owned pointer. 103 // Non-owned pointer.
95 sql::Connection* db_; 104 sql::Connection* db_;
96 105
97 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable); 106 DISALLOW_COPY_AND_ASSIGN(PrecacheURLTable);
98 }; 107 };
99 108
100 } // namespace precache 109 } // namespace precache
101 110
102 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_ 111 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_URL_TABLE_H_
OLDNEW
« no previous file with comments | « components/precache/core/precache_fetcher_unittest.cc ('k') | components/precache/core/precache_url_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698