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..904e74f1b916abc5eb6151e59068418032ce8463 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. |
@@ -86,12 +99,13 @@ class PrecacheFetcher { |
// Constructs a new PrecacheFetcher. The |starting_hosts| parameter is a |
// 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); |
+ // the user is likely to fetch. Takes ownership of |unfinished_work|. |
+ PrecacheFetcher( |
+ net::URLRequestContextGetter* request_context, |
+ const GURL& config_url, |
+ const std::string& manifest_url_prefix, |
+ std::unique_ptr<PrecacheUnfinishedWork> unfinished_work, |
+ PrecacheDelegate* precache_delegate); |
virtual ~PrecacheFetcher(); |
@@ -100,6 +114,16 @@ class PrecacheFetcher { |
// PrecacheFetcher instance. |
void Start(); |
+ std::unique_ptr<PrecacheUnfinishedWork> CancelPrecaching(); |
sclittle
2016/05/20 21:57:07
nit: add a comment saying that nothing should be d
bengr
2016/05/21 00:16:32
Done.
|
+ |
+ // Used for testing to put the fetcher into a state where it has work to do. |
+ void AssignWorkForTest(const std::list<GURL>& manifests, |
sclittle
2016/05/20 21:57:07
Is this method really necessary? Couldn't you just
bengr
2016/05/21 00:16:32
Done.
|
+ 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 +140,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. |
@@ -158,14 +185,16 @@ 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_; |
FetcherPool<Fetcher> pool_; |
+ std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |
+ |
DISALLOW_COPY_AND_ASSIGN(PrecacheFetcher); |
}; |