| 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..04978dfae6797f5df1aa84733879a61b37e1dfad 100644
|
| --- a/components/precache/content/precache_manager.h
|
| +++ b/components/precache/content/precache_manager.h
|
| @@ -21,6 +21,8 @@
|
| #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 "net/http/http_cache.h"
|
| #include "url/gurl.h"
|
|
|
| namespace base {
|
| @@ -53,6 +55,9 @@ class PrecacheUnfinishedWork;
|
| // Visible for test.
|
| size_t NumTopHosts();
|
|
|
| +// Minimum required cache size (inclusive).
|
| +constexpr int kMinCacheSizeBytes = 40e6;
|
| +
|
| // 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 +134,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 +165,14 @@ class PrecacheManager : public KeyedService,
|
| // gets the list of TopHosts for metrics purposes, but otherwise does nothing.
|
| void OnHostsReceivedThenDone(const history::TopHostsList& host_counts);
|
|
|
| + // Chain of callbacks for StartPrecaching that make sure that we only precache
|
| + // if there is a cache big enough.
|
| + void PrecacheIfCacheIsBigEnough(
|
| + net::URLRequestContextGetter* url_request_context_getter);
|
| + void OnCacheBackendReceived(int net_error_code);
|
| + void OnCacheSizeReceived(int cache_size_bytes);
|
| + void OnCacheSizeReceivedInUIThread(int cache_size_bytes);
|
| +
|
| // Returns true if precaching is allowed for the browser context.
|
| AllowedType PrecachingAllowed() const;
|
|
|
| @@ -203,6 +220,15 @@ class PrecacheManager : public KeyedService,
|
| // Flag indicating whether or not precaching is currently in progress.
|
| bool is_precaching_;
|
|
|
| + // Pointer to the backend of the cache. Required to get the size of the cache.
|
| + // It is not owned and it is reset on demand via callbacks.
|
| + // It should only be accessed from the IO thread.
|
| + 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_;
|
|
|
|
|