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

Unified Diff: components/precache/core/precache_fetcher.h

Issue 1961153003: Add pause/resume functionality to precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a proto Created 4 years, 7 months 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/core/precache_fetcher.h
diff --git a/components/precache/core/precache_fetcher.h b/components/precache/core/precache_fetcher.h
index 324ab08fa474c727cafd5a9c55bd2ebe3a5955ce..899c50db210618f8413e3b7656665a5deaeb1ce4 100644
--- a/components/precache/core/precache_fetcher.h
+++ b/components/precache/core/precache_fetcher.h
@@ -15,13 +15,18 @@
#include "base/callback.h"
#include "base/macros.h"
-#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/single_thread_task_runner.h"
#include "base/time/time.h"
#include "components/precache/core/fetcher_pool.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"
+namespace base {
+class SingleThreadTaskRunner;
+}
+
namespace net {
class URLRequestContextGetter;
}
@@ -29,6 +34,7 @@ class URLRequestContextGetter;
namespace precache {
class PrecacheConfigurationSettings;
+class PrecacheUnfinishedWork;
// Visible for testing.
extern const int kNoTracking;
@@ -59,10 +65,16 @@ extern const int kNoTracking;
// void PrecacheResourcesForTopURLs(
// net::URLRequestContextGetter* request_context,
// const std::list<GURL>& top_urls) {
-// fetcher_.reset(new PrecacheFetcher(request_context, top_urls, this));
+// fetcher_.reset(new PrecacheFetcher(...));
// fetcher_->Start();
// }
//
+// void Cancel() {
+// std::unique_ptr<PrecacheUnfinishedWork> unfinished_work =
+// fetcher_->GetUnfinishedWork();
+// fetcher_.reset();
+// }
+//
// virtual void OnDone() {
// // Do something when precaching is done.
// }
@@ -70,7 +82,7 @@ extern const int kNoTracking;
// private:
// std::unique_ptr<PrecacheFetcher> fetcher_;
// };
-class PrecacheFetcher {
+class PrecacheFetcher : public base::SupportsWeakPtr<PrecacheFetcher> {
public:
class PrecacheDelegate {
public:
@@ -78,6 +90,7 @@ class PrecacheFetcher {
// were fetched or not. If the PrecacheFetcher is destroyed before OnDone is
// called, then precaching will be canceled and OnDone will not be called.
virtual void OnDone() = 0;
+
};
// Visible for testing.
@@ -87,11 +100,13 @@ class PrecacheFetcher {
// prioritized list of hosts that the user commonly visits. These hosts are
// used by a server side component to construct a list of resource URLs that
// the user is likely to fetch.
- PrecacheFetcher(const std::vector<std::string>& starting_hosts,
- net::URLRequestContextGetter* request_context,
- const GURL& config_url,
- const std::string& manifest_url_prefix,
- PrecacheDelegate* precache_delegate);
+ PrecacheFetcher(
sclittle 2016/05/19 01:59:46 Could this be separated into two constructors, wit
bengr 2016/05/19 23:19:31 Done.
+ const std::vector<std::string>& starting_hosts,
+ net::URLRequestContextGetter* request_context,
+ const GURL& config_url,
+ const std::string& manifest_url_prefix,
+ const PrecacheUnfinishedWork* unfinished_work,
sclittle 2016/05/19 01:59:45 Could you just pass in an unfinished_work with the
bengr 2016/05/19 23:19:31 Yes.
+ PrecacheDelegate* precache_delegate);
virtual ~PrecacheFetcher();
@@ -100,6 +115,16 @@ class PrecacheFetcher {
// PrecacheFetcher instance.
void Start();
+ std::unique_ptr<PrecacheUnfinishedWork> GetUnfinishedWork();
+
+ // Used for testing to put the fetcher into a state where it has work to do.
+ void AssignWorkForTest(const std::list<GURL>& manifests,
+ const std::list<GURL>& resources,
+ size_t total_response_bytes,
+ size_t network_response_bytes,
+ size_t num_manifest_urls_to_fetch,
+ const base::Time& start_time);
+
private:
// Fetches the next resource or manifest URL, if any remain. Fetching is done
// sequentially and depth-first: all resources are fetched for a manifest
@@ -116,6 +141,9 @@ class PrecacheFetcher {
// If the fetch of the configuration settings fails, then precaching ends.
void OnConfigFetchComplete(const Fetcher& source);
+ // Constructs manifest URLs using a manifest URL prefix, and lists of hosts.
+ void DetermineManifests();
+
// Called when a precache manifest has been fetched. Builds the list of
// resource URLs to fetch according to the URLs in the manifest. If the fetch
// of a manifest fails, then it skips to the next manifest.
@@ -134,6 +162,10 @@ class PrecacheFetcher {
// The request context used when fetching URLs.
const scoped_refptr<net::URLRequestContextGetter> request_context_;
+ // True if configuration settings have been retrieved, either from the network
+ // or from unfinished work.
+ bool has_config_;
sclittle 2016/05/19 01:59:45 Could you just check if |config_| is non-null?
bengr 2016/05/19 23:19:31 Done.
+
// The custom URL to use when fetching the config. If not provided, the
// default flag-specified URL will be used.
const GURL config_url_;
@@ -158,9 +190,9 @@ class PrecacheFetcher {
size_t network_response_bytes_;
// Time when the prefetch was started.
- base::TimeTicks start_time_;
+ base::Time start_time_;
- int num_manifest_urls_to_fetch_;
+ size_t num_manifest_urls_to_fetch_;
std::list<GURL> manifest_urls_to_fetch_;
std::list<GURL> resource_urls_to_fetch_;

Powered by Google App Engine
This is Rietveld 408576698