summaryrefslogtreecommitdiffstats
path: root/chrome/browser/predictors
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-09 08:46:45 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-09 08:46:45 +0000
commit007b3f812fc9c989fb99d4a668d8bd9c7807ad81 (patch)
tree43e69dd0f4e4dbbe68afb6319fa18cee07a4be64 /chrome/browser/predictors
parent2bde7e94eb8f402839145e48924391a5c645a554 (diff)
downloadchromium_src-007b3f812fc9c989fb99d4a668d8bd9c7807ad81.zip
chromium_src-007b3f812fc9c989fb99d4a668d8bd9c7807ad81.tar.gz
chromium_src-007b3f812fc9c989fb99d4a668d8bd9c7807ad81.tar.bz2
Rewrite std::string("") to std::string(), Linux edition.
This patch was generated by running the empty_string clang tool across the Chromium Linux compilation database. Implicitly or explicitly constructing std::string() with a "" argument is inefficient as the caller needs to emit extra instructions to pass an argument, and the constructor needlessly copies a byte into internal storage. Rewriting these instances to simply call the default constructor appears to save ~14-18 kilobytes on an optimized release build. BUG=none Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=193020 Review URL: https://codereview.chromium.org/13145003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/predictors')
-rw-r--r--chrome/browser/predictors/autocomplete_action_predictor.cc2
-rw-r--r--chrome/browser/predictors/resource_prefetch_predictor.cc3
-rw-r--r--chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc240
-rw-r--r--chrome/browser/predictors/resource_prefetch_predictor_unittest.cc494
-rw-r--r--chrome/browser/predictors/resource_prefetcher_unittest.cc3
5 files changed, 476 insertions, 266 deletions
diff --git a/chrome/browser/predictors/autocomplete_action_predictor.cc b/chrome/browser/predictors/autocomplete_action_predictor.cc
index cc183c36..184e7a7 100644
--- a/chrome/browser/predictors/autocomplete_action_predictor.cc
+++ b/chrome/browser/predictors/autocomplete_action_predictor.cc
@@ -148,7 +148,7 @@ void AutocompleteActionPredictor::StartPrerendering(
prerender::PrerenderManagerFactory::GetForProfile(profile_)) {
content::SessionStorageNamespace* session_storage_namespace = NULL;
content::SessionStorageNamespaceMap::const_iterator it =
- session_storage_namespace_map.find("");
+ session_storage_namespace_map.find(std::string());
if (it != session_storage_namespace_map.end())
session_storage_namespace = it->second;
prerender_handle_.reset(
diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc
index a6d7cbd..b37f3a1 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
@@ -1012,7 +1012,8 @@ void ResourcePrefetchPredictor::LearnNavigation(
} else {
bool is_host = key_type == PREFETCH_KEY_TYPE_HOST;
PrefetchData empty_data(
- !is_host ? PREFETCH_KEY_TYPE_HOST : PREFETCH_KEY_TYPE_URL , "");
+ !is_host ? PREFETCH_KEY_TYPE_HOST : PREFETCH_KEY_TYPE_URL,
+ std::string());
const PrefetchData& host_data = is_host ? cache_entry->second : empty_data;
const PrefetchData& url_data = is_host ? empty_data : cache_entry->second;
BrowserThread::PostTask(
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc b/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
index d39e892..fa5be14 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc
@@ -167,34 +167,45 @@ void ResourcePrefetchPredictorTablesTest::TestDeleteSingleDataPoint() {
void ResourcePrefetchPredictorTablesTest::TestUpdateData() {
PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com");
google.last_visit = base::Time::FromInternalValue(10);
- google.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/style.css",
- ResourceType::STYLESHEET,
- 6, 2, 0, 1.0));
- google.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/image.png",
- ResourceType::IMAGE,
- 6, 4, 1, 4.2));
- google.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/a.xml",
- ResourceType::LAST_TYPE,
- 1, 0, 0, 6.1));
- google.resources.push_back(ResourceRow(
- "",
- "http://www.resources.google.com/script.js",
- ResourceType::SCRIPT,
- 12, 0, 0, 8.5));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/style.css",
+ ResourceType::STYLESHEET,
+ 6,
+ 2,
+ 0,
+ 1.0));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/image.png",
+ ResourceType::IMAGE,
+ 6,
+ 4,
+ 1,
+ 4.2));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/a.xml",
+ ResourceType::LAST_TYPE,
+ 1,
+ 0,
+ 0,
+ 6.1));
+ google.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.resources.google.com/script.js",
+ ResourceType::SCRIPT,
+ 12,
+ 0,
+ 0,
+ 8.5));
PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com");
yahoo.last_visit = base::Time::FromInternalValue(7);
- yahoo.resources.push_back(ResourceRow(
- "",
- "http://www.yahoo.com/image.png",
- ResourceType::IMAGE,
- 120, 1, 1, 10.0));
+ yahoo.resources.push_back(ResourceRow(std::string(),
+ "http://www.yahoo.com/image.png",
+ ResourceType::IMAGE,
+ 120,
+ 1,
+ 1,
+ 10.0));
tables_->UpdateData(google, yahoo);
@@ -276,59 +287,78 @@ void ResourcePrefetchPredictorTablesTest::InitializeSampleData() {
{ // Url data.
PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com");
google.last_visit = base::Time::FromInternalValue(1);
- google.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/style.css",
- ResourceType::STYLESHEET,
- 5, 2, 1, 1.1));
- google.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/script.js",
- ResourceType::SCRIPT,
- 4, 0, 1, 2.1));
- google.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/image.png",
- ResourceType::IMAGE,
- 6, 3, 0, 2.2));
- google.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/a.font",
- ResourceType::LAST_TYPE,
- 2, 0, 0, 5.1));
- google.resources.push_back(ResourceRow(
- "",
- "http://www.resources.google.com/script.js",
- ResourceType::SCRIPT,
- 11, 0, 0, 8.5));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/style.css",
+ ResourceType::STYLESHEET,
+ 5,
+ 2,
+ 1,
+ 1.1));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/script.js",
+ ResourceType::SCRIPT,
+ 4,
+ 0,
+ 1,
+ 2.1));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/image.png",
+ ResourceType::IMAGE,
+ 6,
+ 3,
+ 0,
+ 2.2));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/a.font",
+ ResourceType::LAST_TYPE,
+ 2,
+ 0,
+ 0,
+ 5.1));
+ google.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.resources.google.com/script.js",
+ ResourceType::SCRIPT,
+ 11,
+ 0,
+ 0,
+ 8.5));
PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com");
reddit.last_visit = base::Time::FromInternalValue(2);
- reddit.resources.push_back(ResourceRow(
- "",
- "http://reddit-resource.com/script1.js",
- ResourceType::SCRIPT,
- 4, 0, 1, 1.0));
- reddit.resources.push_back(ResourceRow(
- "",
- "http://reddit-resource.com/script2.js",
- ResourceType::SCRIPT,
- 2, 0, 0, 2.1));
+ reddit.resources
+ .push_back(ResourceRow(std::string(),
+ "http://reddit-resource.com/script1.js",
+ ResourceType::SCRIPT,
+ 4,
+ 0,
+ 1,
+ 1.0));
+ reddit.resources
+ .push_back(ResourceRow(std::string(),
+ "http://reddit-resource.com/script2.js",
+ ResourceType::SCRIPT,
+ 2,
+ 0,
+ 0,
+ 2.1));
PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com");
yahoo.last_visit = base::Time::FromInternalValue(3);
- yahoo.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/image.png",
- ResourceType::IMAGE,
- 20, 1, 0, 10.0));
+ yahoo.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/image.png",
+ ResourceType::IMAGE,
+ 20,
+ 1,
+ 0,
+ 10.0));
test_url_data_.clear();
test_url_data_.insert(std::make_pair("http://www.google.com", google));
test_url_data_.insert(std::make_pair("http://www.reddit.com", reddit));
test_url_data_.insert(std::make_pair("http://www.yahoo.com", yahoo));
- PrefetchData empty_host_data(PREFETCH_KEY_TYPE_HOST, "");
+ PrefetchData empty_host_data(PREFETCH_KEY_TYPE_HOST, std::string());
tables_->UpdateData(google, empty_host_data);
tables_->UpdateData(reddit, empty_host_data);
tables_->UpdateData(yahoo, empty_host_data);
@@ -337,45 +367,61 @@ void ResourcePrefetchPredictorTablesTest::InitializeSampleData() {
{ // Host data.
PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com");
facebook.last_visit = base::Time::FromInternalValue(4);
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/style.css",
- ResourceType::STYLESHEET,
- 5, 2, 1, 1.1));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/script.js",
- ResourceType::SCRIPT,
- 4, 0, 1, 2.1));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/image.png",
- ResourceType::IMAGE,
- 6, 3, 0, 2.2));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/a.font",
- ResourceType::LAST_TYPE,
- 2, 0, 0, 5.1));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.resources.facebook.com/script.js",
- ResourceType::SCRIPT,
- 11, 0, 0, 8.5));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/style.css",
+ ResourceType::STYLESHEET,
+ 5,
+ 2,
+ 1,
+ 1.1));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/script.js",
+ ResourceType::SCRIPT,
+ 4,
+ 0,
+ 1,
+ 2.1));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/image.png",
+ ResourceType::IMAGE,
+ 6,
+ 3,
+ 0,
+ 2.2));
+ facebook.resources.push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/a.font",
+ ResourceType::LAST_TYPE,
+ 2,
+ 0,
+ 0,
+ 5.1));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.resources.facebook.com/script.js",
+ ResourceType::SCRIPT,
+ 11,
+ 0,
+ 0,
+ 8.5));
PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com");
yahoo.last_visit = base::Time::FromInternalValue(5);
- yahoo.resources.push_back(ResourceRow(
- "",
- "http://www.google.com/image.png",
- ResourceType::IMAGE,
- 20, 1, 0, 10.0));
+ yahoo.resources.push_back(ResourceRow(std::string(),
+ "http://www.google.com/image.png",
+ ResourceType::IMAGE,
+ 20,
+ 1,
+ 0,
+ 10.0));
test_host_data_.clear();
test_host_data_.insert(std::make_pair("www.facebook.com", facebook));
test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo));
- PrefetchData empty_url_data(PREFETCH_KEY_TYPE_URL, "");
+ PrefetchData empty_url_data(PREFETCH_KEY_TYPE_URL, std::string());
tables_->UpdateData(empty_url_data, facebook);
tables_->UpdateData(empty_url_data, yahoo);
}
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc b/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
index 891b70c..b6203da 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
@@ -176,9 +176,8 @@ ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest()
profile_(new TestingProfile()),
predictor_(NULL),
mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>()),
- empty_url_data_(PREFETCH_KEY_TYPE_URL, ""),
- empty_host_data_(PREFETCH_KEY_TYPE_HOST, "") {
-}
+ empty_url_data_(PREFETCH_KEY_TYPE_URL, std::string()),
+ empty_host_data_(PREFETCH_KEY_TYPE_HOST, std::string()) {}
ResourcePrefetchPredictorTest::~ResourcePrefetchPredictorTest() {
profile_.reset(NULL);
@@ -214,52 +213,70 @@ void ResourcePrefetchPredictorTest::InitializeSampleData() {
{ // Url data.
PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/");
google.last_visit = base::Time::FromInternalValue(1);
- google.resources.push_back(ResourceRow(
- "",
- "http://google.com/style1.css",
- ResourceType::STYLESHEET,
- 3, 2, 1, 1.0));
- google.resources.push_back(ResourceRow(
- "",
- "http://google.com/script3.js",
- ResourceType::SCRIPT,
- 4, 0, 1, 2.1));
- google.resources.push_back(ResourceRow(
- "",
- "http://google.com/script4.js",
- ResourceType::SCRIPT,
- 11, 0, 0, 2.1));
- google.resources.push_back(ResourceRow(
- "",
- "http://google.com/image1.png",
- ResourceType::IMAGE,
- 6, 3, 0, 2.2));
- google.resources.push_back(ResourceRow(
- "",
- "http://google.com/a.font",
- ResourceType::LAST_TYPE,
- 2, 0, 0, 5.1));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/style1.css",
+ ResourceType::STYLESHEET,
+ 3,
+ 2,
+ 1,
+ 1.0));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script3.js",
+ ResourceType::SCRIPT,
+ 4,
+ 0,
+ 1,
+ 2.1));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script4.js",
+ ResourceType::SCRIPT,
+ 11,
+ 0,
+ 0,
+ 2.1));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/image1.png",
+ ResourceType::IMAGE,
+ 6,
+ 3,
+ 0,
+ 2.2));
+ google.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/a.font",
+ ResourceType::LAST_TYPE,
+ 2,
+ 0,
+ 0,
+ 5.1));
PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/");
reddit.last_visit = base::Time::FromInternalValue(2);
- reddit.resources.push_back(ResourceRow(
- "",
- "http://reddit-resource.com/script1.js",
- ResourceType::SCRIPT,
- 4, 0, 1, 1.0));
- reddit.resources.push_back(ResourceRow(
- "",
- "http://reddit-resource.com/script2.js",
- ResourceType::SCRIPT,
- 2, 0, 0, 2.1));
+ reddit.resources
+ .push_back(ResourceRow(std::string(),
+ "http://reddit-resource.com/script1.js",
+ ResourceType::SCRIPT,
+ 4,
+ 0,
+ 1,
+ 1.0));
+ reddit.resources
+ .push_back(ResourceRow(std::string(),
+ "http://reddit-resource.com/script2.js",
+ ResourceType::SCRIPT,
+ 2,
+ 0,
+ 0,
+ 2.1));
PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/");
yahoo.last_visit = base::Time::FromInternalValue(3);
- yahoo.resources.push_back(ResourceRow(
- "",
- "http://google.com/image.png",
- ResourceType::IMAGE,
- 20, 1, 0, 10.0));
+ yahoo.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/image.png",
+ ResourceType::IMAGE,
+ 20,
+ 1,
+ 0,
+ 10.0));
test_url_data_.clear();
test_url_data_.insert(std::make_pair("http://www.google.com/", google));
@@ -270,39 +287,55 @@ void ResourcePrefetchPredictorTest::InitializeSampleData() {
{ // Host data.
PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com");
facebook.last_visit = base::Time::FromInternalValue(4);
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/style.css",
- ResourceType::STYLESHEET,
- 5, 2, 1, 1.1));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/script.js",
- ResourceType::SCRIPT,
- 4, 0, 1, 2.1));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/image.png",
- ResourceType::IMAGE,
- 6, 3, 0, 2.2));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.facebook.com/a.font",
- ResourceType::LAST_TYPE,
- 2, 0, 0, 5.1));
- facebook.resources.push_back(ResourceRow(
- "",
- "http://www.resources.facebook.com/script.js",
- ResourceType::SCRIPT,
- 11, 0, 0, 8.5));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/style.css",
+ ResourceType::STYLESHEET,
+ 5,
+ 2,
+ 1,
+ 1.1));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/script.js",
+ ResourceType::SCRIPT,
+ 4,
+ 0,
+ 1,
+ 2.1));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/image.png",
+ ResourceType::IMAGE,
+ 6,
+ 3,
+ 0,
+ 2.2));
+ facebook.resources.push_back(ResourceRow(std::string(),
+ "http://www.facebook.com/a.font",
+ ResourceType::LAST_TYPE,
+ 2,
+ 0,
+ 0,
+ 5.1));
+ facebook.resources
+ .push_back(ResourceRow(std::string(),
+ "http://www.resources.facebook.com/script.js",
+ ResourceType::SCRIPT,
+ 11,
+ 0,
+ 0,
+ 8.5));
PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com");
yahoo.last_visit = base::Time::FromInternalValue(5);
- yahoo.resources.push_back(ResourceRow(
- "",
- "http://google.com/image.png",
- ResourceType::IMAGE,
- 20, 1, 0, 10.0));
+ yahoo.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/image.png",
+ ResourceType::IMAGE,
+ 20,
+ 1,
+ 0,
+ 10.0));
test_host_data_.clear();
test_host_data_.insert(std::make_pair("www.facebook.com", facebook));
@@ -343,9 +376,14 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) {
// Single navigation but history count is low, so should not record.
AddUrlToHistory("http://www.google.com", 1);
- URLRequestSummary main_frame = CreateURLRequestSummary(
- 1, 1, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary main_frame =
+ CreateURLRequestSummary(1,
+ 1,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->RecordURLRequest(main_frame);
EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size()));
@@ -364,15 +402,27 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) {
predictor_->RecordUrlResponse(resource3);
PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
- host_data.resources.push_back(ResourceRow(
- "", "http://google.com/style1.css",
- ResourceType::STYLESHEET, 1, 0, 0, 1.0));
- host_data.resources.push_back(ResourceRow(
- "", "http://google.com/script1.js",
- ResourceType::SCRIPT, 1, 0, 0, 2.0));
- host_data.resources.push_back(ResourceRow(
- "", "http://google.com/script2.js",
- ResourceType::SCRIPT, 1, 0, 0, 3.0));
+ host_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/style1.css",
+ ResourceType::STYLESHEET,
+ 1,
+ 0,
+ 0,
+ 1.0));
+ host_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script1.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 2.0));
+ host_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script2.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 3.0));
EXPECT_CALL(*mock_tables_, UpdateData(empty_url_data_, host_data));
predictor_->OnNavigationComplete(main_frame.navigation_id);
@@ -384,9 +434,14 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) {
// resources and also for number of resources saved.
AddUrlToHistory("http://www.google.com", 4);
- URLRequestSummary main_frame = CreateURLRequestSummary(
- 1, 1, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary main_frame =
+ CreateURLRequestSummary(1,
+ 1,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->RecordURLRequest(main_frame);
EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size()));
@@ -424,18 +479,34 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) {
resource7.resource_type);
PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/");
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/style1.css",
- ResourceType::STYLESHEET, 1, 0, 0, 1.0));
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/script1.js",
- ResourceType::SCRIPT, 1, 0, 0, 2.0));
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/script2.js",
- ResourceType::SCRIPT, 1, 0, 0, 3.0));
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/style2.css",
- ResourceType::STYLESHEET, 1, 0, 0, 7.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/style1.css",
+ ResourceType::STYLESHEET,
+ 1,
+ 0,
+ 0,
+ 1.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script1.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 2.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script2.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 3.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/style2.css",
+ ResourceType::STYLESHEET,
+ 1,
+ 0,
+ 0,
+ 7.0));
EXPECT_CALL(*mock_tables_, UpdateData(url_data, empty_host_data_));
PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
@@ -461,9 +532,14 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
EXPECT_EQ(3, static_cast<int>(predictor_->url_table_cache_->size()));
EXPECT_EQ(2, static_cast<int>(predictor_->host_table_cache_->size()));
- URLRequestSummary main_frame = CreateURLRequestSummary(
- 1, 1, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary main_frame =
+ CreateURLRequestSummary(1,
+ 1,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->RecordURLRequest(main_frame);
EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size()));
@@ -501,18 +577,34 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
resource7.resource_type);
PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/");
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/style1.css",
- ResourceType::STYLESHEET, 4, 2, 0, 1.0));
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/script1.js",
- ResourceType::SCRIPT, 1, 0, 0, 2.0));
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/script4.js",
- ResourceType::SCRIPT, 11, 1, 1, 2.1));
- url_data.resources.push_back(ResourceRow(
- "", "http://google.com/script2.js",
- ResourceType::SCRIPT, 1, 0, 0, 3.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/style1.css",
+ ResourceType::STYLESHEET,
+ 4,
+ 2,
+ 0,
+ 1.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script1.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 2.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script4.js",
+ ResourceType::SCRIPT,
+ 11,
+ 1,
+ 1,
+ 2.1));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script2.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 3.0));
EXPECT_CALL(*mock_tables_, UpdateData(url_data, empty_host_data_));
EXPECT_CALL(*mock_tables_,
@@ -520,18 +612,34 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
PREFETCH_KEY_TYPE_HOST));
PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
- host_data.resources.push_back(ResourceRow(
- "", "http://google.com/style1.css",
- ResourceType::STYLESHEET, 1, 0, 0, 1.0));
- host_data.resources.push_back(ResourceRow(
- "", "http://google.com/script1.js",
- ResourceType::SCRIPT, 1, 0, 0, 2.0));
- host_data.resources.push_back(ResourceRow(
- "", "http://google.com/script2.js",
- ResourceType::SCRIPT, 1, 0, 0, 3.0));
- host_data.resources.push_back(ResourceRow(
- "", "http://google.com/style2.css",
- ResourceType::STYLESHEET, 1, 0, 0, 7.0));
+ host_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/style1.css",
+ ResourceType::STYLESHEET,
+ 1,
+ 0,
+ 0,
+ 1.0));
+ host_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script1.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 2.0));
+ host_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/script2.js",
+ ResourceType::SCRIPT,
+ 1,
+ 0,
+ 0,
+ 3.0));
+ host_data.resources.push_back(ResourceRow(std::string(),
+ "http://google.com/style2.css",
+ ResourceType::STYLESHEET,
+ 1,
+ 0,
+ 0,
+ 7.0));
EXPECT_CALL(*mock_tables_, UpdateData(empty_url_data_, host_data));
predictor_->OnNavigationComplete(main_frame.navigation_id);
@@ -552,9 +660,14 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
EXPECT_EQ(3, static_cast<int>(predictor_->url_table_cache_->size()));
EXPECT_EQ(2, static_cast<int>(predictor_->host_table_cache_->size()));
- URLRequestSummary main_frame = CreateURLRequestSummary(
- 1, 1, "http://www.nike.com", "http://www.nike.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary main_frame =
+ CreateURLRequestSummary(1,
+ 1,
+ "http://www.nike.com",
+ "http://www.nike.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->RecordURLRequest(main_frame);
EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size()));
@@ -575,12 +688,20 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
PREFETCH_KEY_TYPE_HOST));
PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/");
- url_data.resources.push_back(ResourceRow(
- "", "http://nike.com/style1.css",
- ResourceType::STYLESHEET, 1, 0, 0, 1.0));
- url_data.resources.push_back(ResourceRow(
- "", "http://nike.com/image2.png",
- ResourceType::IMAGE, 1, 0, 0, 2.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://nike.com/style1.css",
+ ResourceType::STYLESHEET,
+ 1,
+ 0,
+ 0,
+ 1.0));
+ url_data.resources.push_back(ResourceRow(std::string(),
+ "http://nike.com/image2.png",
+ ResourceType::IMAGE,
+ 1,
+ 0,
+ 0,
+ 2.0));
EXPECT_CALL(*mock_tables_, UpdateData(url_data, empty_host_data_));
PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com");
@@ -647,15 +768,27 @@ TEST_F(ResourcePrefetchPredictorTest, DeleteUrls) {
}
TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) {
- URLRequestSummary summary1 = CreateURLRequestSummary(
- 1, 1, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
- URLRequestSummary summary2 = CreateURLRequestSummary(
- 1, 2, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
- URLRequestSummary summary3 = CreateURLRequestSummary(
- 2, 1, "http://www.yahoo.com", "http://www.yahoo.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary summary1 = CreateURLRequestSummary(1,
+ 1,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
+ URLRequestSummary summary2 = CreateURLRequestSummary(1,
+ 2,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
+ URLRequestSummary summary3 = CreateURLRequestSummary(2,
+ 1,
+ "http://www.yahoo.com",
+ "http://www.yahoo.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->OnMainFrameRequest(summary1);
EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size()));
@@ -665,12 +798,20 @@ TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) {
EXPECT_EQ(3, static_cast<int>(predictor_->inflight_navigations_.size()));
// Insert anther with same navigation id. It should replace.
- URLRequestSummary summary4 = CreateURLRequestSummary(
- 1, 1, "http://www.nike.com", "http://www.nike.com",
- ResourceType::MAIN_FRAME, "", false);
- URLRequestSummary summary5 = CreateURLRequestSummary(
- 1, 2, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary summary4 = CreateURLRequestSummary(1,
+ 1,
+ "http://www.nike.com",
+ "http://www.nike.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
+ URLRequestSummary summary5 = CreateURLRequestSummary(1,
+ 2,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->OnMainFrameRequest(summary4);
EXPECT_EQ(3, static_cast<int>(predictor_->inflight_navigations_.size()));
@@ -681,9 +822,13 @@ TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) {
predictor_->OnMainFrameRequest(summary5);
EXPECT_EQ(3, static_cast<int>(predictor_->inflight_navigations_.size()));
- URLRequestSummary summary6 = CreateURLRequestSummary(
- 3, 1, "http://www.shoes.com", "http://www.shoes.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary summary6 = CreateURLRequestSummary(3,
+ 1,
+ "http://www.shoes.com",
+ "http://www.shoes.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->OnMainFrameRequest(summary6);
EXPECT_EQ(3, static_cast<int>(predictor_->inflight_navigations_.size()));
@@ -696,15 +841,27 @@ TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) {
}
TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRedirect) {
- URLRequestSummary summary1 = CreateURLRequestSummary(
- 1, 1, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
- URLRequestSummary summary2 = CreateURLRequestSummary(
- 1, 2, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
- URLRequestSummary summary3 = CreateURLRequestSummary(
- 2, 1, "http://www.yahoo.com", "http://www.yahoo.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary summary1 = CreateURLRequestSummary(1,
+ 1,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
+ URLRequestSummary summary2 = CreateURLRequestSummary(1,
+ 2,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
+ URLRequestSummary summary3 = CreateURLRequestSummary(2,
+ 1,
+ "http://www.yahoo.com",
+ "http://www.yahoo.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->OnMainFrameRedirect(summary1);
EXPECT_TRUE(predictor_->inflight_navigations_.empty());
@@ -731,9 +888,14 @@ TEST_F(ResourcePrefetchPredictorTest, OnSubresourceResponse) {
EXPECT_TRUE(predictor_->inflight_navigations_.empty());
// Add an inflight navigation.
- URLRequestSummary main_frame1 = CreateURLRequestSummary(
- 1, 1, "http://www.google.com", "http://www.google.com",
- ResourceType::MAIN_FRAME, "", false);
+ URLRequestSummary main_frame1 =
+ CreateURLRequestSummary(1,
+ 1,
+ "http://www.google.com",
+ "http://www.google.com",
+ ResourceType::MAIN_FRAME,
+ std::string(),
+ false);
predictor_->OnMainFrameRequest(main_frame1);
EXPECT_EQ(1, static_cast<int>(predictor_->inflight_navigations_.size()));
diff --git a/chrome/browser/predictors/resource_prefetcher_unittest.cc b/chrome/browser/predictors/resource_prefetcher_unittest.cc
index 9d5ef5a..865c8af 100644
--- a/chrome/browser/predictors/resource_prefetcher_unittest.cc
+++ b/chrome/browser/predictors/resource_prefetcher_unittest.cc
@@ -111,7 +111,8 @@ class ResourcePrefetcherTest : public testing::Test {
void OnReceivedRedirect(const std::string& url) {
- prefetcher_->OnReceivedRedirect(GetInFlightRequest(url), GURL(""), NULL);
+ prefetcher_->OnReceivedRedirect(
+ GetInFlightRequest(url), GURL(std::string()), NULL);
}
void OnAuthRequired(const std::string& url) {
prefetcher_->OnAuthRequired(GetInFlightRequest(url), NULL);