Chromium Code Reviews| Index: components/precache/content/precache_manager.h |
| diff --git a/components/precache/content/precache_manager.h b/components/precache/content/precache_manager.h |
| index e6bcc8094ab5e9a9bd5abed331d49c997cb20e85..621868ff9cd8381b22211a79c2295054cc1c806a 100644 |
| --- a/components/precache/content/precache_manager.h |
| +++ b/components/precache/content/precache_manager.h |
| @@ -21,6 +21,7 @@ |
| #include "components/history/core/browser/history_types.h" |
| #include "components/keyed_service/core/keyed_service.h" |
| #include "components/precache/core/precache_fetcher.h" |
| +#include "net/disk_cache/disk_cache.h" |
| #include "url/gurl.h" |
| namespace base { |
| @@ -53,6 +54,9 @@ class PrecacheUnfinishedWork; |
| // Visible for test. |
| size_t NumTopHosts(); |
| +// Minimum required cache size (inclusive). |
| +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.
|
| + |
| // Class that manages all precaching-related activities. Owned by the |
| // BrowserContext that it is constructed for. Use |
| // PrecacheManagerFactory::GetForBrowserContext to get an instance of this |
| @@ -129,6 +133,10 @@ class PrecacheManager : public KeyedService, |
| FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP); |
| FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| RecordStatsForFetchWithSizeZero); |
| + FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| + StartPrecachingStopsOnSmallCaches); |
| + FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| + StartPrecachingWithGoodSizedCache); |
| enum class AllowedType { |
| ALLOWED, |
| @@ -156,6 +164,12 @@ class PrecacheManager : public KeyedService, |
| // gets the list of TopHosts for metrics purposes, but otherwise does nothing. |
| void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); |
| + void OnCacheBackendReceived(int net_error_code); |
|
twifkak
2016/11/17 21:52:04
Add function doc.
jamartin
2016/11/18 03:55:32
Done.
|
| + |
| + // Cache size is required to figure out whether on not we can proceed with |
| + // StartPrecaching. |
| + void OnCacheSizeReceived(int cache_size_bytes); |
| + |
| // Returns true if precaching is allowed for the browser context. |
| AllowedType PrecachingAllowed() const; |
| @@ -203,6 +217,14 @@ class PrecacheManager : public KeyedService, |
| // Flag indicating whether or not precaching is currently in progress. |
| bool is_precaching_; |
| + // Pointer to the backend of the HTTP cache. Used to get the current cache |
| + // size. It is not owned and is reset on demand via callbacks. |
| + disk_cache::Backend* cache_backend_; |
| + |
| + // The minimum cache size allowed for precaching. We allow this to be modified |
| + // for testing purposes. |
| + int min_cache_size_bytes_ = kMinCacheSizeBytes; |
| + |
| // Work that hasn't yet finished. |
| std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |