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

Side by Side Diff: components/precache/core/precache_database.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: 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
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_DATABASE_H_ 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <deque>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/threading/thread_checker.h" 20 #include "base/threading/thread_checker.h"
21 #include "components/precache/core/precache_fetcher.h" 21 #include "components/precache/core/precache_fetcher.h"
22 #include "components/precache/core/precache_referrer_host_table.h"
22 #include "components/precache/core/precache_session_table.h" 23 #include "components/precache/core/precache_session_table.h"
23 #include "components/precache/core/precache_url_table.h" 24 #include "components/precache/core/precache_url_table.h"
24 25
25 class GURL; 26 class GURL;
26 27
27 namespace base { 28 namespace base {
28 class FilePath; 29 class FilePath;
29 class Time; 30 class Time;
30 } 31 }
31 32
(...skipping 29 matching lines...) Expand all
61 62
62 // Delete all history entries from the database. 63 // Delete all history entries from the database.
63 void ClearHistory(); 64 void ClearHistory();
64 65
65 // Setter and getter for the last precache timestamp. 66 // Setter and getter for the last precache timestamp.
66 void SetLastPrecacheTimestamp(const base::Time& time); 67 void SetLastPrecacheTimestamp(const base::Time& time);
67 base::Time GetLastPrecacheTimestamp(); 68 base::Time GetLastPrecacheTimestamp();
68 69
69 // Report precache-related metrics in response to a URL being fetched, where 70 // Report precache-related metrics in response to a URL being fetched, where
70 // the fetch was motivated by precaching. 71 // the fetch was motivated by precaching.
72 void RecordURLPrefetchMetrics(const net::HttpResponseInfo& info,
73 const base::TimeDelta& latency);
74
75 // Records the precache of an url |url| for top host |referrer_host|.
71 void RecordURLPrefetch(const GURL& url, 76 void RecordURLPrefetch(const GURL& url,
72 const base::TimeDelta& latency, 77 const std::string& referrer_host,
73 const base::Time& fetch_time, 78 const base::Time& fetch_time,
74 const net::HttpResponseInfo& info, 79 bool was_cached,
75 int64_t size); 80 int64_t size);
76 81
77 // Report precache-related metrics in response to a URL being fetched, where 82 // Report precache-related metrics in response to a URL being fetched, where
78 // the fetch was not motivated by precaching. |is_connection_cellular| 83 // the fetch was not motivated by precaching. |is_connection_cellular|
79 // indicates whether the current network connection is a cellular network. 84 // indicates whether the current network connection is a cellular network.
80 void RecordURLNonPrefetch(const GURL& url, 85 void RecordURLNonPrefetch(const GURL& url,
81 const base::TimeDelta& latency, 86 const base::TimeDelta& latency,
82 const base::Time& fetch_time, 87 const base::Time& fetch_time,
83 const net::HttpResponseInfo& info, 88 const net::HttpResponseInfo& info,
84 int64_t size, 89 int64_t size,
85 int host_rank, 90 int host_rank,
86 bool is_connection_cellular); 91 bool is_connection_cellular);
87 92
93 // Returns the referrer host entry for the |referrer_host|.
94 PrecacheReferrerHostEntry GetReferrerHost(const std::string& referrer_host);
95
96 // Populates the list of used and unused resources for referrer host with id
97 // |referrer_host_id|.
98 void GetURLListForReferrerHost(int64_t referrer_host_id,
99 std::deque<GURL>& used_urls,
sclittle 2016/08/11 22:52:35 Don't pass stuff in Chromium by non-const referenc
Raj 2016/08/12 19:04:20 Done.
100 std::deque<GURL>& unused_urls);
101
102 // Updates the |manifest_id| and |fetch_time| for the referrer host
103 // |hostname|.
104 void UpdatePrecacheReferrerHost(const std::string& hostname,
105 int64_t manifest_id,
106 const base::Time& fetch_time);
107
88 // Gets the state required to continue a precache session. 108 // Gets the state required to continue a precache session.
89 std::unique_ptr<PrecacheUnfinishedWork> GetUnfinishedWork(); 109 std::unique_ptr<PrecacheUnfinishedWork> GetUnfinishedWork();
90 110
91 // Stores the state required to continue a precache session so that the 111 // Stores the state required to continue a precache session so that the
92 // session can be resumed later. 112 // session can be resumed later.
93 void SaveUnfinishedWork( 113 void SaveUnfinishedWork(
94 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); 114 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work);
95 115
96 // Deletes unfinished work from the database. 116 // Deletes unfinished work from the database.
97 void DeleteUnfinishedWork(); 117 void DeleteUnfinishedWork();
(...skipping 15 matching lines...) Expand all
113 void PostedFlush(); 133 void PostedFlush();
114 134
115 // Post a call to PostedFlush() on the current thread's MessageLoop, if 135 // Post a call to PostedFlush() on the current thread's MessageLoop, if
116 // |buffered_writes_| is non-empty and there isn't already a flush call 136 // |buffered_writes_| is non-empty and there isn't already a flush call
117 // posted. 137 // posted.
118 void MaybePostFlush(); 138 void MaybePostFlush();
119 139
120 // Records the time since the last precache. 140 // Records the time since the last precache.
121 void RecordTimeSinceLastPrecache(const base::Time& fetch_time); 141 void RecordTimeSinceLastPrecache(const base::Time& fetch_time);
122 142
143 void RecordURLPrefetchInternal(const GURL& url,
144 const std::string& referrer_host,
145 bool is_precached,
146 const base::Time& fetch_time);
147
148 void UpdatePrecacheReferrerHostInternal(const std::string& hostname,
149 int64_t manifest_id,
150 const base::Time& fetch_time);
151
123 std::unique_ptr<sql::Connection> db_; 152 std::unique_ptr<sql::Connection> db_;
124 153
125 // Table that keeps track of URLs that are in the cache because of precaching, 154 // Table that keeps track of URLs that are in the cache because of precaching,
126 // and wouldn't be in the cache otherwise. If |buffered_writes_| is non-empty, 155 // and wouldn't be in the cache otherwise. If |buffered_writes_| is non-empty,
127 // then this table will not be up to date until the next call to Flush(). 156 // then this table will not be up to date until the next call to Flush().
128 PrecacheURLTable precache_url_table_; 157 PrecacheURLTable precache_url_table_;
129 158
159 // If |buffered_writes_| is non-empty,
160 // then this table will not be up to date until the next call to Flush().
161 PrecacheReferrerHostTable precache_referrer_host_table_;
162
130 // Table that persists state related to a precache session, including 163 // Table that persists state related to a precache session, including
131 // unfinished work to be done. 164 // unfinished work to be done.
132 PrecacheSessionTable precache_session_table_; 165 PrecacheSessionTable precache_session_table_;
133 166
134 // A vector of write operations to be run on the database. 167 // A vector of write operations to be run on the database.
135 std::vector<base::Closure> buffered_writes_; 168 std::vector<base::Closure> buffered_writes_;
136 169
137 // Set of URLs that have been modified in |buffered_writes_|. It's a hash set 170 // Set of URLs that have been modified in |buffered_writes_|. It's a hash set
138 // of strings, and not GURLs, because there is no hash function on GURL. 171 // of strings, and not GURLs, because there is no hash function on GURL.
139 base::hash_set<std::string> buffered_urls_; 172 base::hash_set<std::string> buffered_urls_;
140 173
141 // Flag indicating whether or not a call to Flush() has been posted to run in 174 // Flag indicating whether or not a call to Flush() has been posted to run in
142 // the future. 175 // the future.
143 bool is_flush_posted_; 176 bool is_flush_posted_;
144 177
145 // ThreadChecker used to ensure that all methods other than the constructor 178 // ThreadChecker used to ensure that all methods other than the constructor
146 // or destructor are called on the same thread. 179 // or destructor are called on the same thread.
147 base::ThreadChecker thread_checker_; 180 base::ThreadChecker thread_checker_;
148 181
149 // Time of the last precache. This is a cached copy of 182 // Time of the last precache. This is a cached copy of
150 // precache_session_table_.GetLastPrecacheTimestamp. 183 // precache_session_table_.GetLastPrecacheTimestamp.
151 base::Time last_precache_timestamp_; 184 base::Time last_precache_timestamp_;
sclittle 2016/08/11 22:52:35 nit: Could you add #include "base/time/time.h", si
Raj 2016/08/12 19:04:20 Done.
152 185
153 // This must be the last member of this class. 186 // This must be the last member of this class.
154 base::WeakPtrFactory<PrecacheDatabase> weak_factory_; 187 base::WeakPtrFactory<PrecacheDatabase> weak_factory_;
155 188
156 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); 189 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase);
157 }; 190 };
158 191
159 } // namespace precache 192 } // namespace precache
160 193
161 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ 194 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698