Index: components/precache/core/precache_fetcher.h |
diff --git a/components/precache/core/precache_fetcher.h b/components/precache/core/precache_fetcher.h |
index 0f136c32b1e03359201dd6b4aa532f8144dbe1f4..33c9a97adf252d1576f52fb2c2e55347babacc8c 100644 |
--- a/components/precache/core/precache_fetcher.h |
+++ b/components/precache/core/precache_fetcher.h |
@@ -8,6 +8,7 @@ |
#include <stdint.h> |
#include <deque> |
+#include <list> |
#include <memory> |
#include <string> |
#include <vector> |
@@ -40,25 +41,41 @@ class PrecacheUnfinishedWork; |
// Visible for testing. |
extern const int kNoTracking; |
+extern const int kMaxParallelFetches; |
-// Contains the information about manifest for a host. |
+// Information about the manifest for a host. |
struct ManifestHostInfo { |
ManifestHostInfo(int64_t manifest_id, |
const std::string& hostname, |
+ int64_t visits, |
const std::string& used_url_hash, |
const std::string& unused_url_hash); |
+ ~ManifestHostInfo(); |
ManifestHostInfo(ManifestHostInfo&&); |
ManifestHostInfo& operator=(ManifestHostInfo&&); |
- |
- ~ManifestHostInfo(); |
+ // Copy constructor and assignment operator are implicitly deleted. |
int64_t manifest_id; |
std::string hostname; |
GURL manifest_url; |
+ int64_t visits; |
std::string used_url_hash; |
std::string unused_url_hash; |
}; |
+// Information about a resource to be downloaded. |
+struct ResourceInfo { |
+ ResourceInfo(const GURL& url, const std::string& referrer, double weight); |
+ ~ResourceInfo(); |
+ ResourceInfo(ResourceInfo&&); |
+ ResourceInfo& operator=(ResourceInfo&&); |
+ // Copy constructor and assignment operator are implicitly deleted. |
+ |
+ GURL url; // The resource being requested. |
+ std::string referrer; // The host of the manifest requesting this resource. |
+ double weight; // Estimate of the expected utility of this resource. |
+}; |
+ |
// Public interface to code that fetches resources that the user is likely to |
// want to fetch in the future, putting them in the network stack disk cache. |
// Precaching is intended to be done when Chrome is not actively in use, likely |
@@ -110,7 +127,6 @@ class PrecacheFetcher : public base::SupportsWeakPtr<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. |
@@ -152,6 +168,8 @@ class PrecacheFetcher : public base::SupportsWeakPtr<PrecacheFetcher> { |
private: |
friend class PrecacheFetcherTest; |
+ FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, |
+ GloballyRankResourcesAfterPauseResume); |
FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, FetcherPoolMaxLimitReached); |
FRIEND_TEST_ALL_PREFIXES(PrecacheFetcherTest, |
CancelPrecachingAfterAllManifestFetch); |
@@ -168,7 +186,7 @@ class PrecacheFetcher : public base::SupportsWeakPtr<PrecacheFetcher> { |
// the |resource_urls_to_fetch_| list, reducing the memory usage. |
void StartNextFetch(); |
- void StartNextManifestFetch(); |
+ void StartNextManifestFetches(); |
void StartNextResourceFetch(); |
// Called when the precache configuration settings have been fetched. |
@@ -183,7 +201,13 @@ class PrecacheFetcher : public base::SupportsWeakPtr<PrecacheFetcher> { |
// 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. |
- void OnManifestFetchComplete(const Fetcher& source); |
+ void OnManifestFetchComplete(int64_t host_visits, const Fetcher& source); |
+ |
+ // Moves the pending resource URLs into the to-be-fetched queue, and sorts and |
+ // truncates if specified by the PrecacheConfigurationSettings. Called by |
+ // OnManifestFetchComplete after the last manifest is fetched, so that |
+ // StartNextFetch will begin fetching resource URLs. |
+ void QueueResourcesForFetch(); |
// Called when a resource has been fetched. |
void OnResourceFetchComplete(const Fetcher& source); |
@@ -215,8 +239,23 @@ class PrecacheFetcher : public base::SupportsWeakPtr<PrecacheFetcher> { |
// Non-owning pointer. Should not be NULL. |
PrecacheDelegate* precache_delegate_; |
+ // Top hosts for which manifests still need to be fetched (i.e. no Fetcher has |
+ // been created yet). |
std::deque<ManifestHostInfo> top_hosts_to_fetch_; |
- std::deque<std::pair<GURL, std::string>> resources_to_fetch_; |
+ |
+ // Top hosts for which manifests are currently being fetched. |
+ std::list<ManifestHostInfo> top_hosts_fetching_; |
+ |
+ // Resources to be fetched, in desired fetch order. Populated only after |
+ // manifest fetching is complete. |
+ std::deque<ResourceInfo> resources_to_fetch_; |
+ |
+ // Resources currently being fetched, in the order requested. |
+ std::list<ResourceInfo> resources_fetching_; |
+ |
+ // Resources to be fetched, not yet ranked. Valid until manifest fetching is |
+ // done, after which resources are sorted and places in resources_to_fetch_. |
+ std::deque<ResourceInfo> resources_to_rank_; |
FetcherPool<Fetcher> pool_; |