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