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

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

Issue 2507753003: Do not precache when the cache size is small (Closed)
Patch Set: Use IO thread and report UMA on the cache size 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..7919eabf00b32a848bcb11f0d6846d5315011c90 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,12 @@ 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();
+ void OnCacheBackendReceived(int net_error_code);
+ void OnCacheSizeReceived(int cache_size_bytes);
+
// Returns true if precaching is allowed for the browser context.
AllowedType PrecachingAllowed() const;
@@ -203,6 +218,15 @@ class PrecacheManager : public KeyedService,
// Flag indicating whether or not precaching is currently in progress.
bool is_precaching_;
+ // Pointers required to get the size of the cache.
+ // They are not owned and are reset on demand via callbacks.
twifkak 2016/11/18 23:50:01 Add a note that they should only be accessed on th
jamartin 2016/11/19 02:00:13 Done.
+ disk_cache::Backend* cache_backend_;
+ net::URLRequestContextGetter* url_request_context_getter_;
+
+ // 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