diff options
author | sclittle@chromium.org <sclittle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-17 07:11:50 +0000 |
---|---|---|
committer | sclittle@chromium.org <sclittle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-17 07:11:50 +0000 |
commit | 12e164f2525d4b264744004cbdf7961a31b103c0 (patch) | |
tree | 75cd723f8801b63bbd6ea4d043e0b1115688d994 /components | |
parent | 3c515077ef6eb1c293f2ed76051e73b546b7f8fa (diff) | |
download | chromium_src-12e164f2525d4b264744004cbdf7961a31b103c0.zip chromium_src-12e164f2525d4b264744004cbdf7961a31b103c0.tar.gz chromium_src-12e164f2525d4b264744004cbdf7961a31b103c0.tar.bz2 |
Added list of forced starting URLs to precache configuration settings.
BUG=306185
Review URL: https://codereview.chromium.org/103373006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r-- | components/precache/core/precache_fetcher.cc | 25 | ||||
-rw-r--r-- | components/precache/core/precache_fetcher_unittest.cc | 10 | ||||
-rw-r--r-- | components/precache/core/proto/precache.proto | 5 |
3 files changed, 39 insertions, 1 deletions
diff --git a/components/precache/core/precache_fetcher.cc b/components/precache/core/precache_fetcher.cc index d5ef31e..78ae7ac 100644 --- a/components/precache/core/precache_fetcher.cc +++ b/components/precache/core/precache_fetcher.cc @@ -10,6 +10,7 @@ #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" @@ -192,6 +193,11 @@ void PrecacheFetcher::OnConfigFetchComplete(const URLFetcher& source) { PrecacheConfigurationSettings config; if (ParseProtoFromFetchResponse(source, &config)) { + // Keep track of starting URLs that manifests are being fetched for, in + // order to remove duplicates. This is a hash set on strings, and not GURLs, + // because there is no hash function defined for GURL. + base::hash_set<std::string> unique_starting_urls; + // 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. @@ -199,7 +205,24 @@ void PrecacheFetcher::OnConfigFetchComplete(const URLFetcher& source) { for (std::list<GURL>::const_iterator it = starting_urls_.begin(); it != starting_urls_.end() && rank < config.top_sites_count(); ++it, ++rank) { - manifest_urls_to_fetch_.push_back(ConstructManifestURL(*it)); + if (unique_starting_urls.find(it->spec()) == unique_starting_urls.end()) { + // Only add a fetch for the manifest URL if this manifest isn't already + // going to be fetched. + manifest_urls_to_fetch_.push_back(ConstructManifestURL(*it)); + unique_starting_urls.insert(it->spec()); + } + } + + for (int i = 0; i < config.forced_starting_url_size(); ++i) { + // Convert the string URL into a GURL and take the spec() of it so that + // the URL string gets canonicalized. + GURL url(config.forced_starting_url(i)); + if (unique_starting_urls.find(url.spec()) == unique_starting_urls.end()) { + // Only add a fetch for the manifest URL if this manifest isn't already + // going to be fetched. + manifest_urls_to_fetch_.push_back(ConstructManifestURL(url)); + unique_starting_urls.insert(url.spec()); + } } } diff --git a/components/precache/core/precache_fetcher_unittest.cc b/components/precache/core/precache_fetcher_unittest.cc index 227fc27..acdd59d 100644 --- a/components/precache/core/precache_fetcher_unittest.cc +++ b/components/precache/core/precache_fetcher_unittest.cc @@ -99,6 +99,9 @@ const char kGoodManifestURL[] = "http://manifest-url-prefix.com/http%253A%252F%252Fgood-manifest.com%252F"; const char kResourceFetchFailureURL[] = "http://resource-fetch-failure.com"; const char kGoodResourceURL[] = "http://good-resource.com"; +const char kForcedStartingURLManifestURL[] = + "http://manifest-url-prefix.com/" + "http%253A%252F%252Fforced-starting-url.com%252F"; TEST_F(PrecacheFetcherTest, FullPrecache) { CommandLine::ForCurrentProcess()->AppendSwitchASCII( @@ -114,6 +117,9 @@ TEST_F(PrecacheFetcherTest, FullPrecache) { PrecacheConfigurationSettings config; config.set_top_sites_count(3); + config.add_forced_starting_url("http://forced-starting-url.com"); + // Duplicate starting URL, the manifest for this should only be fetched once. + config.add_forced_starting_url("http://good-manifest.com"); PrecacheManifest good_manifest; good_manifest.add_resource()->set_url(kResourceFetchFailureURL); @@ -135,6 +141,9 @@ TEST_F(PrecacheFetcherTest, FullPrecache) { net::URLRequestStatus::FAILED); factory_.SetFakeResponse(GURL(kGoodResourceURL), "good", net::HTTP_OK, net::URLRequestStatus::SUCCESS); + factory_.SetFakeResponse(GURL(kForcedStartingURLManifestURL), + PrecacheManifest().SerializeAsString(), net::HTTP_OK, + net::URLRequestStatus::SUCCESS); PrecacheFetcher precache_fetcher(starting_urls, request_context_.get(), &precache_delegate_); @@ -149,6 +158,7 @@ TEST_F(PrecacheFetcherTest, FullPrecache) { expected_requested_urls.insert(GURL(kGoodManifestURL)); expected_requested_urls.insert(GURL(kResourceFetchFailureURL)); expected_requested_urls.insert(GURL(kGoodResourceURL)); + expected_requested_urls.insert(GURL(kForcedStartingURLManifestURL)); EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); diff --git a/components/precache/core/proto/precache.proto b/components/precache/core/proto/precache.proto index ee0193f..ace5384 100644 --- a/components/precache/core/proto/precache.proto +++ b/components/precache/core/proto/precache.proto @@ -33,4 +33,9 @@ message PrecacheConfigurationSettings { // 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]; + + // List of additional starting URLs that resources will be precached for. + // These are URLs that the server predicts that the user will visit, as a + // result of server-side analytics. + repeated string forced_starting_url = 2; }; |