diff options
author | sclittle@chromium.org <sclittle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-06 00:03:10 +0000 |
---|---|---|
committer | sclittle@chromium.org <sclittle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-06 00:03:10 +0000 |
commit | af925574f249270557749e1fbb877157f9ef9aff (patch) | |
tree | e5280c40184f2cec02350653943467e19d6c410e /components/precache | |
parent | e96226874f903bb0a3143eaefa5704eb92109a27 (diff) | |
download | chromium_src-af925574f249270557749e1fbb877157f9ef9aff.zip chromium_src-af925574f249270557749e1fbb877157f9ef9aff.tar.gz chromium_src-af925574f249270557749e1fbb877157f9ef9aff.tar.bz2 |
Changed the precache config settings proto to not include the whitelist of starting URLs.
The precache fetcher will now attempt to fetch manifests for the first |top_sites_count| starting URLs. Fetches of manifests for non-whitelisted URLs will fail and be skipped.
The reason for this change is so that the server side component can have a large whitelist of starting URLs, without forcing the client to download the entire list every time precaching is done.
BUG=306185
Review URL: https://codereview.chromium.org/83283004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/precache')
-rw-r--r-- | components/precache/core/precache_fetcher.cc | 22 | ||||
-rw-r--r-- | components/precache/core/precache_fetcher.h | 7 | ||||
-rw-r--r-- | components/precache/core/precache_fetcher_unittest.cc | 23 | ||||
-rw-r--r-- | components/precache/core/proto/precache.proto | 16 |
4 files changed, 24 insertions, 44 deletions
diff --git a/components/precache/core/precache_fetcher.cc b/components/precache/core/precache_fetcher.cc index 42b281f..d5ef31e 100644 --- a/components/precache/core/precache_fetcher.cc +++ b/components/precache/core/precache_fetcher.cc @@ -10,7 +10,6 @@ #include "base/callback.h" #include "base/command_line.h" #include "base/compiler_specific.h" -#include "base/containers/hash_tables.h" #include "components/precache/core/precache_switches.h" #include "components/precache/core/proto/precache.pb.h" #include "net/base/escape.h" @@ -193,25 +192,14 @@ void PrecacheFetcher::OnConfigFetchComplete(const URLFetcher& source) { PrecacheConfigurationSettings config; if (ParseProtoFromFetchResponse(source, &config)) { - // A hash set of strings is used instead of GURLs because there is no - // standard hash function defined for GURLs. - base::hash_set<std::string> whitelisted_urls; - for (int i = 0; i < config.whitelisted_starting_url_size(); ++i) { - // Instead of using the raw URL string, construct a GURL and take the spec - // of it so that the URL string is canonicalized. - whitelisted_urls.insert(GURL(config.whitelisted_starting_url(i)).spec()); - } - - // Only fetch manifests for starting URLs up to the maximum rank that are in - // the whitelist. + // Attempt to fetch manifests for starting URLs up to the maximum top sites + // count. If a manifest does not exist for a particular starting URL, then + // the fetch will fail, and that starting URL will be ignored. int64 rank = 0; for (std::list<GURL>::const_iterator it = starting_urls_.begin(); - it != starting_urls_.end() && - rank < config.maximum_rank_starting_url(); + it != starting_urls_.end() && rank < config.top_sites_count(); ++it, ++rank) { - if (whitelisted_urls.find(it->spec()) != whitelisted_urls.end()) { - manifest_urls_to_fetch_.push_back(ConstructManifestURL(*it)); - } + manifest_urls_to_fetch_.push_back(ConstructManifestURL(*it)); } } diff --git a/components/precache/core/precache_fetcher.h b/components/precache/core/precache_fetcher.h index a3dde62..1fc56d7 100644 --- a/components/precache/core/precache_fetcher.h +++ b/components/precache/core/precache_fetcher.h @@ -91,10 +91,9 @@ class PrecacheFetcher { void StartNextFetch(); // Called when the precache configuration settings have been fetched. - // Determines the list of manifest URLs to fetch according to the URLs that - // are present in both the list of |starting_urls_| and the whitelist - // contained in the precache configuration settings. If the fetch of the - // configuration settings fails, then precaching ends. + // Determines the list of manifest URLs to fetch according to the list of + // |starting_urls_| and information from the precache configuration settings. + // If the fetch of the configuration settings fails, then precaching ends. void OnConfigFetchComplete(const net::URLFetcher& source); // Called when a precache manifest has been fetched. Builds the list of diff --git a/components/precache/core/precache_fetcher_unittest.cc b/components/precache/core/precache_fetcher_unittest.cc index 2552586..227fc27 100644 --- a/components/precache/core/precache_fetcher_unittest.cc +++ b/components/precache/core/precache_fetcher_unittest.cc @@ -107,19 +107,13 @@ TEST_F(PrecacheFetcherTest, FullPrecache) { switches::kPrecacheManifestURLPrefix, kManfiestURLPrefix); std::list<GURL> starting_urls; - starting_urls.push_back(GURL("http://not-whitelisted.com")); starting_urls.push_back(GURL("http://manifest-fetch-failure.com")); starting_urls.push_back(GURL("http://bad-manifest.com")); starting_urls.push_back(GURL("http://good-manifest.com")); - starting_urls.push_back(GURL("http://not-in-top-4.com")); + starting_urls.push_back(GURL("http://not-in-top-3.com")); PrecacheConfigurationSettings config; - config.add_whitelisted_starting_url("http://whitelisted-unused.com"); - config.add_whitelisted_starting_url("http://manifest-fetch-failure.com"); - config.add_whitelisted_starting_url("http://bad-manifest.com"); - config.add_whitelisted_starting_url("http://good-manifest.com"); - config.add_whitelisted_starting_url("http://not-in-top-4.com"); - config.set_maximum_rank_starting_url(4); + config.set_top_sites_count(3); PrecacheManifest good_manifest; good_manifest.add_resource()->set_url(kResourceFetchFailureURL); @@ -213,8 +207,7 @@ TEST_F(PrecacheFetcherTest, Cancel) { std::list<GURL> starting_urls(1, GURL("http://starting-url.com")); PrecacheConfigurationSettings config; - config.add_whitelisted_starting_url("http://starting-url.com"); - config.set_maximum_rank_starting_url(1); + config.set_top_sites_count(1); factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(), net::HTTP_OK, net::URLRequestStatus::SUCCESS); @@ -243,9 +236,12 @@ TEST_F(PrecacheFetcherTest, Cancel) { TEST_F(PrecacheFetcherTest, PrecacheUsingDefaultConfigSettingsURL) { std::list<GURL> starting_urls(1, GURL("http://starting-url.com")); + PrecacheConfigurationSettings config; + config.set_top_sites_count(0); + factory_.SetFakeResponse(GURL(PRECACHE_CONFIG_SETTINGS_URL), - PrecacheConfigurationSettings().SerializeAsString(), - net::HTTP_OK, net::URLRequestStatus::SUCCESS); + config.SerializeAsString(), net::HTTP_OK, + net::URLRequestStatus::SUCCESS); PrecacheFetcher precache_fetcher(starting_urls, request_context_.get(), &precache_delegate_); @@ -273,8 +269,7 @@ TEST_F(PrecacheFetcherTest, PrecacheUsingDefaultManifestURLPrefix) { std::list<GURL> starting_urls(1, GURL("http://starting-url.com")); PrecacheConfigurationSettings config; - config.add_whitelisted_starting_url("http://starting-url.com"); - config.set_maximum_rank_starting_url(1); + config.set_top_sites_count(1); GURL manifest_url(PRECACHE_MANIFEST_URL_PREFIX "http%253A%252F%252Fstarting-url.com%252F"); diff --git a/components/precache/core/proto/precache.proto b/components/precache/core/proto/precache.proto index 0429d58..ee0193f 100644 --- a/components/precache/core/proto/precache.proto +++ b/components/precache/core/proto/precache.proto @@ -24,15 +24,13 @@ message PrecacheManifest { }; message PrecacheConfigurationSettings { - // The whitelist of starting URLs that are currently supported. Precaching - // should only be attempted for starting URLs that are in this list. - repeated string whitelisted_starting_url = 1; - // The maximum rank of the user's most visited URLs to consider precaching // resources for, starting from 1. For example, a value of 10 means that only - // URLs that are both in the user's top 10 most visited URLs and in the - // whitelist will be considered as starting URLs for resource precaching. - // This is specified by the server for testing purposes, so that we can - // easily adjust how aggressively we precache resources. - optional int64 maximum_rank_starting_url = 2 [default = 10]; + // URLs that are in the user's top 10 most visited URLs will be considered as + // starting URLs for resource precaching. This is specified by the server for + // testing purposes, so that it's easy to adjust how aggressively resources + // are precached. + // Values that are zero or lower indicate that none of the user's top sites + // will be used for precaching. + optional int64 top_sites_count = 1 [default = 10]; }; |