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

Unified Diff: components/precache/content/precache_manager.h

Issue 2507753003: Do not precache when the cache size is small (Closed)
Patch Set: scoped_refptr 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 side-by-side diff with in-line comments
Download patch
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..5be06f3ab3af03b6422d1eb08d420b6b1c8f5a95 100644
--- a/components/precache/content/precache_manager.h
+++ b/components/precache/content/precache_manager.h
@@ -17,10 +17,13 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#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 +56,9 @@ class PrecacheUnfinishedWork;
// Visible for test.
size_t NumTopHosts();
+// Minimum required cache size (inclusive).
+constexpr int kMinCacheSizeBytes = 40e6;
gavinp 2016/12/08 17:33:47 minor nit: I find 40 * 1000 * 1000 an itsy bitsy b
jamartin 2016/12/08 22:43:58 Done.
+
// 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 +135,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 +166,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(
+ scoped_refptr<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 +221,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_;

Powered by Google App Engine
This is Rietveld 408576698