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

Side by Side Diff: components/precache/content/precache_manager.h

Issue 2507753003: Do not precache when the cache size is small (Closed)
Patch Set: Created 4 years, 1 month 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_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 "net/disk_cache/disk_cache.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 namespace base { 27 namespace base {
27 class FilePath; 28 class FilePath;
28 class Time; 29 class Time;
29 class TimeDelta; 30 class TimeDelta;
30 } 31 }
31 32
32 namespace content { 33 namespace content {
33 class BrowserContext; 34 class BrowserContext;
(...skipping 12 matching lines...) Expand all
46 } 47 }
47 48
48 namespace precache { 49 namespace precache {
49 50
50 class PrecacheDatabase; 51 class PrecacheDatabase;
51 class PrecacheUnfinishedWork; 52 class PrecacheUnfinishedWork;
52 53
53 // Visible for test. 54 // Visible for test.
54 size_t NumTopHosts(); 55 size_t NumTopHosts();
55 56
57 // Minimum required cache size (inclusive).
58 constexpr int kMinCacheSizeBytes = 40e6;
twifkak 2016/11/17 21:52:04 FYI 40e6 is a float literal, which (by way of the
jamartin 2016/11/18 03:55:32 Acknowledged.
59
56 // Class that manages all precaching-related activities. Owned by the 60 // Class that manages all precaching-related activities. Owned by the
57 // BrowserContext that it is constructed for. Use 61 // BrowserContext that it is constructed for. Use
58 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this 62 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this
59 // class. All methods must be called on the UI thread unless indicated 63 // class. All methods must be called on the UI thread unless indicated
60 // otherwise. 64 // otherwise.
61 // TODO(sclittle): Delete precache history when browsing history is deleted. 65 // TODO(sclittle): Delete precache history when browsing history is deleted.
62 // http://crbug.com/326549 66 // http://crbug.com/326549
63 class PrecacheManager : public KeyedService, 67 class PrecacheManager : public KeyedService,
64 public PrecacheFetcher::PrecacheDelegate, 68 public PrecacheFetcher::PrecacheDelegate,
65 public base::SupportsWeakPtr<PrecacheManager> { 69 public base::SupportsWeakPtr<PrecacheManager> {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, 126 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest,
123 RecordStatsForFetchDuringPrecaching); 127 RecordStatsForFetchDuringPrecaching);
124 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTP); 128 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTP);
125 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTPS); 129 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTPS);
126 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchInTopHosts); 130 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchInTopHosts);
127 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, 131 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest,
128 RecordStatsForFetchWithEmptyURL); 132 RecordStatsForFetchWithEmptyURL);
129 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP); 133 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP);
130 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, 134 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest,
131 RecordStatsForFetchWithSizeZero); 135 RecordStatsForFetchWithSizeZero);
136 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest,
137 StartPrecachingStopsOnSmallCaches);
138 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest,
139 StartPrecachingWithGoodSizedCache);
132 140
133 enum class AllowedType { 141 enum class AllowedType {
134 ALLOWED, 142 ALLOWED,
135 DISALLOWED, 143 DISALLOWED,
136 PENDING 144 PENDING
137 }; 145 };
138 146
139 // From KeyedService. 147 // From KeyedService.
140 void Shutdown() override; 148 void Shutdown() override;
141 149
142 // From PrecacheFetcher::PrecacheDelegate. 150 // From PrecacheFetcher::PrecacheDelegate.
143 void OnDone() override; 151 void OnDone() override;
144 152
145 // Callback when fetching unfinished work from storage is done. 153 // Callback when fetching unfinished work from storage is done.
146 void OnGetUnfinishedWorkDone( 154 void OnGetUnfinishedWorkDone(
147 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); 155 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work);
148 156
149 // From history::HistoryService::TopHosts. 157 // From history::HistoryService::TopHosts.
150 void OnHostsReceived(const history::TopHostsList& host_counts); 158 void OnHostsReceived(const history::TopHostsList& host_counts);
151 159
152 // Initializes and Starts a PrecacheFetcher with unfinished work. 160 // Initializes and Starts a PrecacheFetcher with unfinished work.
153 void InitializeAndStartFetcher(); 161 void InitializeAndStartFetcher();
154 162
155 // From history::HistoryService::TopHosts. Used for the control group, which 163 // From history::HistoryService::TopHosts. Used for the control group, which
156 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. 164 // gets the list of TopHosts for metrics purposes, but otherwise does nothing.
157 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); 165 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts);
158 166
167 void OnCacheBackendReceived(int net_error_code);
twifkak 2016/11/17 21:52:04 Add function doc.
jamartin 2016/11/18 03:55:32 Done.
168
169 // Cache size is required to figure out whether on not we can proceed with
170 // StartPrecaching.
171 void OnCacheSizeReceived(int cache_size_bytes);
172
159 // Returns true if precaching is allowed for the browser context. 173 // Returns true if precaching is allowed for the browser context.
160 AllowedType PrecachingAllowed() const; 174 AllowedType PrecachingAllowed() const;
161 175
162 // Update precache-related metrics in response to a URL being fetched. 176 // Update precache-related metrics in response to a URL being fetched.
163 void RecordStatsForFetch(const GURL& url, 177 void RecordStatsForFetch(const GURL& url,
164 const GURL& referrer, 178 const GURL& referrer,
165 const base::TimeDelta& latency, 179 const base::TimeDelta& latency,
166 const base::Time& fetch_time, 180 const base::Time& fetch_time,
167 const net::HttpResponseInfo& info, 181 const net::HttpResponseInfo& info,
168 int64_t size); 182 int64_t size);
(...skipping 27 matching lines...) Expand all
196 // canceled. 210 // canceled.
197 PrecacheCompletionCallback precache_completion_callback_; 211 PrecacheCompletionCallback precache_completion_callback_;
198 212
199 // The PrecacheDatabase for tracking precache metrics. Should only be used on 213 // The PrecacheDatabase for tracking precache metrics. Should only be used on
200 // the DB thread. 214 // the DB thread.
201 std::unique_ptr<PrecacheDatabase> precache_database_; 215 std::unique_ptr<PrecacheDatabase> precache_database_;
202 216
203 // Flag indicating whether or not precaching is currently in progress. 217 // Flag indicating whether or not precaching is currently in progress.
204 bool is_precaching_; 218 bool is_precaching_;
205 219
220 // Pointer to the backend of the HTTP cache. Used to get the current cache
221 // size. It is not owned and is reset on demand via callbacks.
222 disk_cache::Backend* cache_backend_;
223
224 // The minimum cache size allowed for precaching. We allow this to be modified
225 // for testing purposes.
226 int min_cache_size_bytes_ = kMinCacheSizeBytes;
227
206 // Work that hasn't yet finished. 228 // Work that hasn't yet finished.
207 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; 229 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_;
208 230
209 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); 231 DISALLOW_COPY_AND_ASSIGN(PrecacheManager);
210 }; 232 };
211 233
212 } // namespace precache 234 } // namespace precache
213 235
214 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ 236 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698