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_CONTENT_PRECACHE_MANAGER_H_ | 5 #ifndef COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
6 #define COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 6 #define COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "components/history/core/browser/history_types.h" | 21 #include "components/history/core/browser/history_types.h" |
22 #include "components/keyed_service/core/keyed_service.h" | 22 #include "components/keyed_service/core/keyed_service.h" |
23 #include "components/precache/core/precache_fetcher.h" | 23 #include "components/precache/core/precache_fetcher.h" |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 class FilePath; | 27 class FilePath; |
28 class Time; | 28 class Time; |
| 29 class TimeDelta; |
29 } | 30 } |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 class BrowserContext; | 33 class BrowserContext; |
33 } | 34 } |
34 | 35 |
35 namespace history { | 36 namespace history { |
36 class HistoryService; | 37 class HistoryService; |
37 } | 38 } |
38 | 39 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // preconditions, but will not be run if precaching is canceled. | 90 // preconditions, but will not be run if precaching is canceled. |
90 void StartPrecaching( | 91 void StartPrecaching( |
91 const PrecacheCompletionCallback& precache_completion_callback); | 92 const PrecacheCompletionCallback& precache_completion_callback); |
92 | 93 |
93 // Cancels precaching if it is in progress. | 94 // Cancels precaching if it is in progress. |
94 void CancelPrecaching(); | 95 void CancelPrecaching(); |
95 | 96 |
96 // Returns true if precaching is currently in progress, or false otherwise. | 97 // Returns true if precaching is currently in progress, or false otherwise. |
97 bool IsPrecaching() const; | 98 bool IsPrecaching() const; |
98 | 99 |
99 // Update precache-related metrics in response to a URL being fetched. | |
100 void RecordStatsForFetch(const GURL& url, | |
101 const GURL& referrer, | |
102 const base::TimeDelta& latency, | |
103 const base::Time& fetch_time, | |
104 int64_t size, | |
105 bool was_cached); | |
106 | |
107 // Posts a task to the DB thread to delete all history entries from the | 100 // Posts a task to the DB thread to delete all history entries from the |
108 // database. Does not wait for completion of this task. | 101 // database. Does not wait for completion of this task. |
109 void ClearHistory(); | 102 void ClearHistory(); |
110 | 103 |
| 104 // Update precache about an URL being fetched. Metrics related to precache are |
| 105 // updated and any ongoing precache will be cancelled if this is an user |
| 106 // initiated request. Should be called on UI thread. |
| 107 void UpdatePrecacheMetricsAndState(const GURL& url, |
| 108 const GURL& referrer, |
| 109 const base::TimeDelta& latency, |
| 110 const base::Time& fetch_time, |
| 111 int64_t size, |
| 112 bool was_cached, |
| 113 bool is_user_traffic); |
| 114 |
111 private: | 115 private: |
| 116 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, DeleteExpiredPrecacheHistory); |
| 117 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| 118 RecordStatsForFetchDuringPrecaching); |
| 119 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTP); |
| 120 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTPS); |
| 121 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchInTopHosts); |
| 122 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| 123 RecordStatsForFetchWithEmptyURL); |
| 124 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP); |
| 125 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| 126 RecordStatsForFetchWithSizeZero); |
| 127 |
112 enum class AllowedType { | 128 enum class AllowedType { |
113 ALLOWED, | 129 ALLOWED, |
114 DISALLOWED, | 130 DISALLOWED, |
115 PENDING | 131 PENDING |
116 }; | 132 }; |
117 | 133 |
118 // From KeyedService. | 134 // From KeyedService. |
119 void Shutdown() override; | 135 void Shutdown() override; |
120 | 136 |
121 // From PrecacheFetcher::PrecacheDelegate. | 137 // From PrecacheFetcher::PrecacheDelegate. |
122 void OnDone() override; | 138 void OnDone() override; |
123 | 139 |
124 // Callback when fetching unfinished work from storage is done. | 140 // Callback when fetching unfinished work from storage is done. |
125 void OnGetUnfinishedWorkDone( | 141 void OnGetUnfinishedWorkDone( |
126 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); | 142 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); |
127 | 143 |
128 // From history::HistoryService::TopHosts. | 144 // From history::HistoryService::TopHosts. |
129 void OnHostsReceived(const history::TopHostsList& host_counts); | 145 void OnHostsReceived(const history::TopHostsList& host_counts); |
130 | 146 |
131 // Initializes and Starts a PrecacheFetcher with unfinished work. | 147 // Initializes and Starts a PrecacheFetcher with unfinished work. |
132 void InitializeAndStartFetcher(); | 148 void InitializeAndStartFetcher(); |
133 | 149 |
134 // From history::HistoryService::TopHosts. Used for the control group, which | 150 // From history::HistoryService::TopHosts. Used for the control group, which |
135 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. | 151 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. |
136 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); | 152 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); |
137 | 153 |
138 // Returns true if precaching is allowed for the browser context. | 154 // Returns true if precaching is allowed for the browser context. |
139 AllowedType PrecachingAllowed() const; | 155 AllowedType PrecachingAllowed() const; |
140 | 156 |
| 157 // Update precache-related metrics in response to a URL being fetched. |
| 158 void RecordStatsForFetch(const GURL& url, |
| 159 const GURL& referrer, |
| 160 const base::TimeDelta& latency, |
| 161 const base::Time& fetch_time, |
| 162 int64_t size, |
| 163 bool was_cached); |
| 164 |
141 // Update precache-related metrics in response to a URL being fetched. Called | 165 // Update precache-related metrics in response to a URL being fetched. Called |
142 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. | 166 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. |
143 void RecordStatsForFetchInternal(const GURL& url, | 167 void RecordStatsForFetchInternal(const GURL& url, |
144 const base::TimeDelta& latency, | 168 const base::TimeDelta& latency, |
145 const base::Time& fetch_time, | 169 const base::Time& fetch_time, |
146 int64_t size, | 170 int64_t size, |
147 bool was_cached, | 171 bool was_cached, |
148 int host_rank); | 172 int host_rank); |
149 | 173 |
150 // The browser context that owns this PrecacheManager. | 174 // The browser context that owns this PrecacheManager. |
(...skipping 24 matching lines...) Expand all Loading... |
175 | 199 |
176 // Work that hasn't yet finished. | 200 // Work that hasn't yet finished. |
177 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; | 201 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |
178 | 202 |
179 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 203 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
180 }; | 204 }; |
181 | 205 |
182 } // namespace precache | 206 } // namespace precache |
183 | 207 |
184 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 208 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
OLD | NEW |