summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-23 18:40:26 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-23 18:40:26 +0000
commit16fca9b8a9e129a2bc50bc39fa3d2b33db64efdb (patch)
tree09d56d4b75a0651a3ad4f82a4111c2943af772a1
parent5284ee3d4b255ba50147550b5de9df85fc71076d (diff)
downloadchromium_src-16fca9b8a9e129a2bc50bc39fa3d2b33db64efdb.zip
chromium_src-16fca9b8a9e129a2bc50bc39fa3d2b33db64efdb.tar.gz
chromium_src-16fca9b8a9e129a2bc50bc39fa3d2b33db64efdb.tar.bz2
Add a Profile* member to TemplateURL. This makes some invocations of ReplaceSearchTerms() a bit less verbose, and will be useful later when UIThreadSearchTermsData starts taking a Profile*.
One downside is that there are a number of const_cast<>()s added when we try to access the profile() of a const TemplateURL*. These will all go away soon when TemplateURLService is switched to using "const" much less, so I didn't worry too much about them. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/10173001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133483 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc8
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc7
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc2
-rw-r--r--chrome/browser/autocomplete/search_provider.cc10
-rw-r--r--chrome/browser/autocomplete/search_provider.h6
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc4
-rw-r--r--chrome/browser/importer/firefox2_importer.cc2
-rw-r--r--chrome/browser/importer/ie_importer.cc2
-rw-r--r--chrome/browser/importer/profile_import_process_messages.h5
-rw-r--r--chrome/browser/importer/profile_writer.cc4
-rw-r--r--chrome/browser/instant/instant_browsertest.cc5
-rw-r--r--chrome/browser/instant/instant_loader.cc16
-rw-r--r--chrome/browser/instant/instant_loader.h3
-rw-r--r--chrome/browser/policy/configuration_policy_handler.cc3
-rw-r--r--chrome/browser/protector/default_search_provider_change_browsertest.cc68
-rw-r--r--chrome/browser/search_engines/search_host_to_urls_map_unittest.cc8
-rw-r--r--chrome/browser/search_engines/search_provider_install_data_unittest.cc2
-rw-r--r--chrome/browser/search_engines/template_url.cc20
-rw-r--r--chrome/browser/search_engines/template_url.h18
-rw-r--r--chrome/browser/search_engines/template_url_fetcher.cc10
-rw-r--r--chrome/browser/search_engines/template_url_fetcher_unittest.cc12
-rw-r--r--chrome/browser/search_engines/template_url_parser.cc2
-rw-r--r--chrome/browser/search_engines/template_url_prepopulate_data.cc31
-rw-r--r--chrome/browser/search_engines/template_url_prepopulate_data.h7
-rw-r--r--chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc6
-rw-r--r--chrome/browser/search_engines/template_url_service.cc52
-rw-r--r--chrome/browser/search_engines/template_url_service.h2
-rw-r--r--chrome/browser/search_engines/template_url_service_sync_unittest.cc9
-rw-r--r--chrome/browser/search_engines/template_url_service_unittest.cc92
-rw-r--r--chrome/browser/search_engines/template_url_unittest.cc61
-rw-r--r--chrome/browser/search_engines/util.cc19
-rw-r--r--chrome/browser/search_engines/util.h6
-rw-r--r--chrome/browser/sync/test/integration/search_engines_helper.cc157
-rw-r--r--chrome/browser/sync/test/integration/search_engines_helper.h52
-rw-r--r--chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc168
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc2
-rw-r--r--chrome/browser/ui/browser_init.cc5
-rw-r--r--chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller_unittest.mm2
-rw-r--r--chrome/browser/ui/omnibox/omnibox_view_browsertest.cc14
-rw-r--r--chrome/browser/ui/search_engines/edit_search_engine_controller.cc4
-rw-r--r--chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc2
-rw-r--r--chrome/browser/ui/search_engines/search_engine_tab_helper.cc2
-rw-r--r--chrome/browser/ui/search_engines/template_url_table_model.cc2
-rw-r--r--chrome/browser/webdata/keyword_table_unittest.cc36
44 files changed, 483 insertions, 465 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index 9caf94b..b008294 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -184,7 +184,7 @@ void AutocompleteProviderTest::
// Reset the default TemplateURL.
TemplateURLData data;
data.SetURL("http://defaultturl/{searchTerms}");
- TemplateURL* default_t_url = new TemplateURL(data);
+ TemplateURL* default_t_url = new TemplateURL(&profile_, data);
TemplateURLService* turl_model =
TemplateURLServiceFactory::GetForProfile(&profile_);
turl_model->Add(default_t_url);
@@ -196,7 +196,7 @@ void AutocompleteProviderTest::
data.short_name = ASCIIToUTF16("k");
data.SetKeyword(ASCIIToUTF16("k"));
data.SetURL("http://keyword/{searchTerms}");
- TemplateURL* keyword_t_url = new TemplateURL(data);
+ TemplateURL* keyword_t_url = new TemplateURL(&profile_, data);
turl_model->Add(keyword_t_url);
ASSERT_NE(0, keyword_t_url->id());
@@ -228,7 +228,7 @@ void AutocompleteProviderTest::
data.short_name = ASCIIToUTF16("foo.com");
data.SetKeyword(ASCIIToUTF16("foo.com"));
data.SetURL("http://foo.com/{searchTerms}");
- TemplateURL* keyword_t_url = new TemplateURL(data);
+ TemplateURL* keyword_t_url = new TemplateURL(&profile_, data);
turl_model->Add(keyword_t_url);
ASSERT_NE(0, keyword_t_url->id());
@@ -236,7 +236,7 @@ void AutocompleteProviderTest::
data.short_name = ASCIIToUTF16("bar.com");
data.SetKeyword(ASCIIToUTF16("bar.com"));
data.SetURL("http://bar.com/{searchTerms}");
- keyword_t_url = new TemplateURL(data);
+ keyword_t_url = new TemplateURL(&profile_, data);
turl_model->Add(keyword_t_url);
ASSERT_NE(0, keyword_t_url->id());
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index df2d00e..8c707b7 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -394,9 +394,8 @@ void KeywordProvider::FillInURLAndContents(
// input, but we rely on later canonicalization functions to do more
// fixup to make the URL valid if necessary.
DCHECK(element_ref.SupportsReplacement());
- match->destination_url = GURL(element_ref.ReplaceSearchTermsUsingProfile(
- profile, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- string16()));
+ match->destination_url = GURL(element_ref.ReplaceSearchTerms(
+ remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
std::vector<size_t> content_param_offsets;
match->contents.assign(l10n_util::GetStringFUTF16(message_id,
element->short_name(),
@@ -437,7 +436,7 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
DCHECK(model);
// Get keyword data from data store.
const TemplateURL* element = model->GetTemplateURLForKeyword(keyword);
- DCHECK(element && !element->url().empty());
+ DCHECK(element);
const bool supports_replacement = element->url_ref().SupportsReplacement();
// Create an edit entry of "[keyword] [remaining input]". This is helpful
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index dd3a2e9..685608d 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -205,7 +205,7 @@ TEST_F(KeywordProviderTest, AddKeyword) {
string16 keyword(ASCIIToUTF16("foo"));
data.SetKeyword(keyword);
data.SetURL("http://www.google.com/foo?q={searchTerms}");
- TemplateURL* template_url = new TemplateURL(data);
+ TemplateURL* template_url = new TemplateURL(NULL, data);
model_->Add(template_url);
ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword));
}
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 90a0309..35ebbfc 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -89,6 +89,7 @@ bool SearchProvider::query_suggest_immediately_ = false;
SearchProvider::SearchProvider(ACProviderListener* listener, Profile* profile)
: AutocompleteProvider(listener, profile, "Search"),
+ providers_(profile),
suggest_results_pending_(0),
have_suggest_results_(false),
instant_finalized_(false) {
@@ -461,9 +462,8 @@ content::URLFetcher* SearchProvider::CreateSuggestFetcher(
const string16& text) {
DCHECK(suggestions_url.SupportsReplacement());
content::URLFetcher* fetcher = content::URLFetcher::Create(id,
- GURL(suggestions_url.ReplaceSearchTermsUsingProfile(
- profile_, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- string16())),
+ GURL(suggestions_url.ReplaceSearchTerms(text,
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())),
content::URLFetcher::GET, this);
fetcher->SetRequestContext(profile_->GetRequestContext());
fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
@@ -906,8 +906,8 @@ void SearchProvider::AddMatchToMap(const string16& query_string,
const TemplateURLRef& search_url = provider.url_ref();
DCHECK(search_url.SupportsReplacement());
- match.destination_url = GURL(search_url.ReplaceSearchTermsUsingProfile(
- profile_, query_string, accepted_suggestion, input_text));
+ match.destination_url = GURL(search_url.ReplaceSearchTerms(query_string,
+ accepted_suggestion, input_text));
// Search results don't look like URLs.
match.transition = is_keyword ?
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 188ae3f..d4ab56e 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -90,9 +90,9 @@ class SearchProvider : public AutocompleteProvider,
// . The keyword provider. This is used if the user has typed in a keyword.
class Providers {
public:
- Providers()
- : cached_default_provider_(TemplateURLData()),
- cached_keyword_provider_(TemplateURLData()),
+ explicit Providers(Profile* profile)
+ : cached_default_provider_(profile, TemplateURLData()),
+ cached_keyword_provider_(profile, TemplateURLData()),
default_provider_(NULL),
keyword_provider_(NULL) {
}
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index e6e3a3d..976e3cd 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -125,7 +125,7 @@ void SearchProviderTest::SetUp() {
data.short_name = ASCIIToUTF16("t");
data.SetURL("http://defaultturl/{searchTerms}");
data.suggestions_url = "http://defaultturl2/{searchTerms}";
- default_t_url_ = new TemplateURL(data);
+ default_t_url_ = new TemplateURL(&profile_, data);
turl_model->Add(default_t_url_);
turl_model->SetDefaultSearchProvider(default_t_url_);
TemplateURLID default_provider_id = default_t_url_->id();
@@ -139,7 +139,7 @@ void SearchProviderTest::SetUp() {
data.SetKeyword(ASCIIToUTF16("k"));
data.SetURL("http://keyword/{searchTerms}");
data.suggestions_url = "http://suggest_keyword/{searchTerms}";
- keyword_t_url_ = new TemplateURL(data);
+ keyword_t_url_ = new TemplateURL(&profile_, data);
turl_model->Add(keyword_t_url_);
ASSERT_NE(0, keyword_t_url_->id());
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc
index 91bb725..09063ed 100644
--- a/chrome/browser/importer/firefox2_importer.cc
+++ b/chrome/browser/importer/firefox2_importer.cc
@@ -140,7 +140,7 @@ TemplateURL* Firefox2Importer::CreateTemplateURL(const string16& title,
data.short_name = title.empty() ? keyword : title;
data.SetKeyword(keyword);
data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec())));
- return new TemplateURL(data);
+ return new TemplateURL(NULL, data);
}
// static
diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc
index 0730fb8..93fde8c 100644
--- a/chrome/browser/importer/ie_importer.cc
+++ b/chrome/browser/importer/ie_importer.cc
@@ -590,7 +590,7 @@ void IEImporter::ImportSearchEngines() {
data.SetURL(url);
data.show_in_default_list = true;
t_iter = search_engines_map.insert(std::make_pair(url,
- new TemplateURL(data))).first;
+ new TemplateURL(NULL, data))).first;
}
}
}
diff --git a/chrome/browser/importer/profile_import_process_messages.h b/chrome/browser/importer/profile_import_process_messages.h
index 0c49109..93f62d0 100644
--- a/chrome/browser/importer/profile_import_process_messages.h
+++ b/chrome/browser/importer/profile_import_process_messages.h
@@ -261,7 +261,10 @@ struct ParamTraits<TemplateURL*> {
TemplateURLData data;
if (!ReadParam(m, iter, &data))
return false;
- *p = new TemplateURL(data);
+ // Since we don't have access to a Profile*, just supply NULL. The caller
+ // can create a new TemplateURL or modify this one (e.g. via
+ // TemplateURLService::AddAndSetProfile()) to correct this later.
+ *p = new TemplateURL(NULL, data);
return true;
}
static void Log(const param_type& p, std::string* l) {
diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc
index ee478a0..2450e58 100644
--- a/chrome/browser/importer/profile_writer.cc
+++ b/chrome/browser/importer/profile_writer.cc
@@ -316,8 +316,8 @@ void ProfileWriter::AddKeywords(ScopedVector<TemplateURL> template_urls,
// Only add valid TemplateURLs to the model.
if ((*i)->url_ref().IsValid()) {
- model->Add(*i); // Takes ownership.
- *i = NULL; // Prevent the vector from deleting *i later.
+ model->AddAndSetProfile(*i, profile_); // Takes ownership.
+ *i = NULL; // Prevent the vector from deleting *i later.
}
}
}
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc
index 7d856c5..34a6949 100644
--- a/chrome/browser/instant/instant_browsertest.cc
+++ b/chrome/browser/instant/instant_browsertest.cc
@@ -57,8 +57,9 @@ class InstantTest : public InProcessBrowserTest {
}
void SetupInstantProvider(const std::string& page) {
+ Profile* profile = browser()->profile();
TemplateURLService* model =
- TemplateURLServiceFactory::GetForProfile(browser()->profile());
+ TemplateURLServiceFactory::GetForProfile(profile);
ui_test_utils::WindowedNotificationObserver observer(
chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
@@ -76,7 +77,7 @@ class InstantTest : public InProcessBrowserTest {
test_server()->host_port_pair().port(), page.c_str()));
data.instant_url = data.url();
// TemplateURLService takes ownership of this.
- TemplateURL* template_url = new TemplateURL(data);
+ TemplateURL* template_url = new TemplateURL(profile, data);
model->Add(template_url);
model->SetDefaultSearchProvider(template_url);
}
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index d280bcb0..928d2ec 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -727,8 +727,7 @@ bool InstantLoader::Update(TabContentsWrapper* tab_contents,
complete_suggested_text_.substr(user_text_.size());
}
} else {
- LoadInstantURL(tab_contents, template_url, transition_type, user_text_,
- verbatim);
+ LoadInstantURL(template_url, transition_type, user_text_, verbatim);
}
} else {
DCHECK(template_url_id_ == 0);
@@ -856,8 +855,8 @@ void InstantLoader::MaybeLoadInstantURL(TabContentsWrapper* tab_contents,
return;
CreatePreviewContents(tab_contents);
- LoadInstantURL(tab_contents, template_url, content::PAGE_TRANSITION_GENERATED,
- string16(), true);
+ LoadInstantURL(template_url, content::PAGE_TRANSITION_GENERATED, string16(),
+ true);
}
bool InstantLoader::IsNavigationPending() const {
@@ -1112,8 +1111,7 @@ void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) {
preview_contents_->web_contents()->ShowContents();
}
-void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents,
- const TemplateURL* template_url,
+void InstantLoader::LoadInstantURL(const TemplateURL* template_url,
content::PageTransition transition_type,
const string16& user_text,
bool verbatim) {
@@ -1127,10 +1125,8 @@ void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents,
// functionality so that embeded tags (like {google:baseURL}) are escaped
// correctly.
// TODO(sky): having to use a replaceable url is a bit of a hack here.
- GURL instant_url(
- template_url->instant_url_ref().ReplaceSearchTermsUsingProfile(
- tab_contents->profile(), string16(),
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
+ GURL instant_url(template_url->instant_url_ref().ReplaceSearchTerms(
+ string16(), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
CommandLine* cl = CommandLine::ForCurrentProcess();
if (cl->HasSwitch(switches::kInstantURL))
instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL));
diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h
index 2df45ffe..5ac326c 100644
--- a/chrome/browser/instant/instant_loader.h
+++ b/chrome/browser/instant/instant_loader.h
@@ -193,8 +193,7 @@ class InstantLoader : public content::NotificationObserver {
void CreatePreviewContents(TabContentsWrapper* tab_contents);
// Creates and loads the |template_url|'s instant URL.
- void LoadInstantURL(TabContentsWrapper* tab_contents,
- const TemplateURL* template_url,
+ void LoadInstantURL(const TemplateURL* template_url,
content::PageTransition transition_type,
const string16& user_text,
bool verbatim);
diff --git a/chrome/browser/policy/configuration_policy_handler.cc b/chrome/browser/policy/configuration_policy_handler.cc
index 0bae4da..769e991 100644
--- a/chrome/browser/policy/configuration_policy_handler.cc
+++ b/chrome/browser/policy/configuration_policy_handler.cc
@@ -606,7 +606,8 @@ bool DefaultSearchPolicyHandler::DefaultSearchURLIsValid(
TemplateURLData data;
data.SetURL(*url_string);
SearchTermsData search_terms_data;
- return TemplateURL(data).SupportsReplacementUsingTermsData(search_terms_data);
+ return TemplateURL(NULL, data).SupportsReplacementUsingTermsData(
+ search_terms_data);
}
void DefaultSearchPolicyHandler::EnsureStringPrefExists(
diff --git a/chrome/browser/protector/default_search_provider_change_browsertest.cc b/chrome/browser/protector/default_search_provider_change_browsertest.cc
index 5d8aca8..f95ac0b 100644
--- a/chrome/browser/protector/default_search_provider_change_browsertest.cc
+++ b/chrome/browser/protector/default_search_provider_change_browsertest.cc
@@ -50,31 +50,16 @@ const std::string example_domain = "example.net";
const BaseSettingChange::DisplayName kNoDisplayName(
BaseSettingChange::kDefaultNamePriority, string16());
-// Convenience function.
-TemplateURL* MakeTemplateURL(const string16& short_name,
- const string16& keyword,
- const std::string& url) {
- TemplateURLData data;
- data.short_name = short_name;
- if (keyword.empty())
- data.SetAutogenerateKeyword(true);
- else
- data.SetKeyword(keyword);
- data.SetURL(url);
- return new TemplateURL(data);
-}
-
} // namespace
class DefaultSearchProviderChangeTest : public InProcessBrowserTest {
public:
virtual void SetUpOnMainThread() OVERRIDE {
- mock_protector_service_ =
- MockProtectorService::BuildForProfile(browser()->profile());
+ Profile* profile = browser()->profile();
+ mock_protector_service_ = MockProtectorService::BuildForProfile(profile);
// Ensure that TemplateURLService is loaded.
- turl_service_ =
- TemplateURLServiceFactory::GetForProfile(browser()->profile());
+ turl_service_ = TemplateURLServiceFactory::GetForProfile(profile);
ui_test_utils::WaitForTemplateURLServiceToLoad(turl_service_);
prepopulated_url_.reset(
@@ -85,6 +70,19 @@ class DefaultSearchProviderChangeTest : public InProcessBrowserTest {
EXPECT_CALL(*mock_protector_service_, Shutdown());
}
+ TemplateURL* MakeTemplateURL(const string16& short_name,
+ const string16& keyword,
+ const std::string& url) {
+ TemplateURLData data;
+ data.short_name = short_name;
+ if (keyword.empty())
+ data.SetAutogenerateKeyword(true);
+ else
+ data.SetKeyword(keyword);
+ data.SetURL(url);
+ return new TemplateURL(browser()->profile(), data);
+ }
+
const TemplateURL* FindTemplateURL(const std::string& search_url) {
TemplateURLService::TemplateURLVector urls =
turl_service_->GetTemplateURLs();
@@ -163,13 +161,14 @@ IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupValid) {
int current_histogram_id =
protector::GetSearchProviderHistogramID(current_url);
- turl_service_->Add(new TemplateURL(backup_url->data()));
+ Profile* profile = browser()->profile();
+ turl_service_->Add(new TemplateURL(profile, backup_url->data()));
AddAndSetDefault(current_url);
scoped_ptr<BaseSettingChange> change(
CreateDefaultSearchProviderChange(current_url, backup_url));
ASSERT_TRUE(change.get());
- ASSERT_TRUE(change->Init(browser()->profile()));
+ ASSERT_TRUE(change->Init(profile));
// Verify that backup is active.
EXPECT_EQ(FindTemplateURL(http_example_info),
@@ -216,15 +215,16 @@ IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupValidLongNames) {
TemplateURL* current_url_long =
MakeTemplateURL(example_com_long, ASCIIToUTF16("b"), http_example_com);
+ Profile* profile = browser()->profile();
{
// Backup name too long.
- turl_service_->Add(new TemplateURL(backup_url_long->data()));
+ turl_service_->Add(new TemplateURL(profile, backup_url_long->data()));
AddAndSetDefault(current_url);
scoped_ptr<BaseSettingChange> change(
CreateDefaultSearchProviderChange(current_url, backup_url_long));
ASSERT_TRUE(change.get());
- ASSERT_TRUE(change->Init(browser()->profile()));
+ ASSERT_TRUE(change->Init(profile));
// Verify text messages.
EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage());
@@ -237,13 +237,13 @@ IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupValidLongNames) {
{
// Current name too long.
- turl_service_->Add(new TemplateURL(backup_url->data()));
+ turl_service_->Add(new TemplateURL(profile, backup_url->data()));
AddAndSetDefault(current_url_long);
scoped_ptr<BaseSettingChange> change(
CreateDefaultSearchProviderChange(current_url_long, backup_url));
ASSERT_TRUE(change.get());
- ASSERT_TRUE(change->Init(browser()->profile()));
+ ASSERT_TRUE(change->Init(profile));
// Verify text messages.
EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage());
@@ -430,13 +430,14 @@ IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest,
MakeTemplateURL(example_info, ASCIIToUTF16("a"), http_example_info);
int backup_histogram_id = protector::GetSearchProviderHistogramID(backup_url);
- turl_service_->Add(new TemplateURL(backup_url->data()));
+ Profile* profile = browser()->profile();
+ turl_service_->Add(new TemplateURL(profile, backup_url->data()));
turl_service_->SetDefaultSearchProvider(NULL);
scoped_ptr<BaseSettingChange> change(
CreateDefaultSearchProviderChange(NULL, backup_url));
ASSERT_TRUE(change.get());
- ASSERT_TRUE(change->Init(browser()->profile()));
+ ASSERT_TRUE(change->Init(profile));
// Verify that backup is active.
EXPECT_EQ(FindTemplateURL(http_example_info),
@@ -480,14 +481,15 @@ IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest,
int current_histogram_id =
protector::GetSearchProviderHistogramID(current_url);
- turl_service_->Add(new TemplateURL(backup_url->data()));
+ Profile* profile = browser()->profile();
+ turl_service_->Add(new TemplateURL(profile, backup_url->data()));
// TODO(ivankr): this may become unsupported soon.
AddAndSetDefault(current_url);
scoped_ptr<BaseSettingChange> change(
CreateDefaultSearchProviderChange(current_url, backup_url));
ASSERT_TRUE(change.get());
- ASSERT_TRUE(change->Init(browser()->profile()));
+ ASSERT_TRUE(change->Init(profile));
// Verify that backup is active.
EXPECT_EQ(FindTemplateURL(http_example_info),
@@ -613,13 +615,14 @@ IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest,
TemplateURL* new_url =
MakeTemplateURL(example_net, ASCIIToUTF16("c"), http_example_net);
- turl_service_->Add(new TemplateURL(backup_url->data()));
+ Profile* profile = browser()->profile();
+ turl_service_->Add(new TemplateURL(profile, backup_url->data()));
AddAndSetDefault(current_url);
scoped_ptr<BaseSettingChange> change(
CreateDefaultSearchProviderChange(current_url, backup_url));
ASSERT_TRUE(change.get());
- ASSERT_TRUE(change->Init(browser()->profile()));
+ ASSERT_TRUE(change->Init(profile));
// Verify that backup is active.
EXPECT_EQ(FindTemplateURL(http_example_info),
@@ -639,13 +642,14 @@ IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest,
TemplateURL* current_url =
MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com);
- turl_service_->Add(new TemplateURL(backup_url->data()));
+ Profile* profile = browser()->profile();
+ turl_service_->Add(new TemplateURL(profile, backup_url->data()));
AddAndSetDefault(current_url);
scoped_ptr<BaseSettingChange> change(
CreateDefaultSearchProviderChange(current_url, backup_url));
ASSERT_TRUE(change.get());
- ASSERT_TRUE(change->Init(browser()->profile()));
+ ASSERT_TRUE(change->Init(profile));
// Verify that backup is active.
EXPECT_EQ(FindTemplateURL(http_example_info),
diff --git a/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc b/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc
index 6a7d75c..edbec3d 100644
--- a/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc
+++ b/chrome/browser/search_engines/search_host_to_urls_map_unittest.cc
@@ -31,9 +31,9 @@ void SearchHostToURLsMapTest::SetUp() {
host_ = "www.unittest.com";
TemplateURLData data;
data.SetURL("http://" + host_ + "/path1");
- t_urls_[0].reset(new TemplateURL(data));
+ t_urls_[0].reset(new TemplateURL(NULL, data));
data.SetURL("http://" + host_ + "/path2");
- t_urls_[1].reset(new TemplateURL(data));
+ t_urls_[1].reset(new TemplateURL(NULL, data));
std::vector<const TemplateURL*> template_urls;
template_urls.push_back(t_urls_[0].get());
template_urls.push_back(t_urls_[1].get());
@@ -47,7 +47,7 @@ TEST_F(SearchHostToURLsMapTest, Add) {
std::string new_host = "example.com";
TemplateURLData data;
data.SetURL("http://" + new_host + "/");
- TemplateURL new_t_url(data);
+ TemplateURL new_t_url(NULL, data);
UIThreadSearchTermsData search_terms_data;
provider_map_->Add(&new_t_url, search_terms_data);
@@ -79,7 +79,7 @@ TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) {
// Add in a url with the templated Google base url.
TemplateURLData data;
data.SetURL("{google:baseURL}?q={searchTerms}");
- TemplateURL new_t_url(data);
+ TemplateURL new_t_url(NULL, data);
provider_map_->Add(&new_t_url, search_terms_data);
ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(google_base_url));
diff --git a/chrome/browser/search_engines/search_provider_install_data_unittest.cc b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
index 2f69d2e..e7ae29b 100644
--- a/chrome/browser/search_engines/search_provider_install_data_unittest.cc
+++ b/chrome/browser/search_engines/search_provider_install_data_unittest.cc
@@ -236,7 +236,7 @@ TemplateURL* SearchProviderInstallDataTest::AddNewTemplateURL(
data.short_name = keyword;
data.SetKeyword(keyword);
data.SetURL(url);
- TemplateURL* t_url = new TemplateURL(data);
+ TemplateURL* t_url = new TemplateURL(util_.profile(), data);
util_.model()->Add(t_url);
return t_url;
}
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 39343ea..b47696a 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -121,17 +121,8 @@ std::string TemplateURLRef::ReplaceSearchTerms(
const string16& terms,
int accepted_suggestion,
const string16& original_query_for_suggestion) const {
- return ReplaceSearchTermsUsingProfile(NULL, terms, accepted_suggestion,
- original_query_for_suggestion);
-}
-
-std::string TemplateURLRef::ReplaceSearchTermsUsingProfile(
- Profile* profile,
- const string16& terms,
- int accepted_suggestion,
- const string16& original_query_for_suggestion) const {
UIThreadSearchTermsData search_terms_data;
- search_terms_data.set_profile(profile);
+ search_terms_data.set_profile(owner_->profile());
return ReplaceSearchTermsUsingTermsData(terms, accepted_suggestion,
original_query_for_suggestion, search_terms_data);
}
@@ -623,8 +614,9 @@ void TemplateURLData::SetURL(const std::string& url) {
// TemplateURL ----------------------------------------------------------------
-TemplateURL::TemplateURL(const TemplateURLData& data)
- : data_(data),
+TemplateURL::TemplateURL(Profile* profile, const TemplateURLData& data)
+ : profile_(profile),
+ data_(data),
url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH),
suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
TemplateURLRef::SUGGEST),
@@ -634,7 +626,8 @@ TemplateURL::TemplateURL(const TemplateURLData& data)
}
TemplateURL::TemplateURL(const TemplateURL& other)
- : data_(other.data_),
+ : profile_(other.profile_),
+ data_(other.data_),
url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH),
suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
TemplateURLRef::SUGGEST),
@@ -647,6 +640,7 @@ TemplateURL& TemplateURL::operator=(const TemplateURL& other) {
if (this == &other)
return *this;
+ profile_ = other.profile_;
data_ = other.data_;
url_ref_.InvalidateCachedValues();
suggestions_url_ref_.InvalidateCachedValues();
diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h
index 1a10256..a0d703a 100644
--- a/chrome/browser/search_engines/template_url.h
+++ b/chrome/browser/search_engines/template_url.h
@@ -27,7 +27,8 @@ class TemplateURL;
// callers can substitute values to get a "real" URL using ReplaceSearchTerms().
//
// TemplateURLRefs always have a non-NULL |owner_| TemplateURL, which they
-// access in order to get at important data like the underlying URL string.
+// access in order to get at important data like the underlying URL string or
+// the associated Profile.
class TemplateURLRef {
public:
// Magic numbers to pass to ReplaceSearchTerms() for the |accepted_suggestion|
@@ -70,15 +71,6 @@ class TemplateURLRef {
int accepted_suggestion,
const string16& original_query_for_suggestion) const;
- // Just like ReplaceSearchTerms except that it takes a Profile that's used to
- // retrieve Instant field trial params. Most callers don't care about those
- // params, and so can use ReplaceSearchTerms instead.
- std::string ReplaceSearchTermsUsingProfile(
- Profile* profile,
- const string16& terms,
- int accepted_suggestion,
- const string16& original_query_for_suggestion) const;
-
// Just like ReplaceSearchTerms except that it takes SearchTermsData to supply
// the data for some search terms. Most of the time ReplaceSearchTerms should
// be called.
@@ -364,7 +356,9 @@ struct TemplateURLData {
// is made a friend so that it can be the exception to this pattern.
class TemplateURL {
public:
- explicit TemplateURL(const TemplateURLData& data);
+ // |profile| may be NULL. This will affect the results of e.g. calling
+ // ReplaceSearchTerms() on the member TemplateURLRefs.
+ TemplateURL(Profile* profile, const TemplateURLData& data);
TemplateURL(const TemplateURL& other);
TemplateURL& operator=(const TemplateURL& other);
@@ -374,6 +368,7 @@ class TemplateURL {
// Generates a favicon URL from the specified url.
static GURL GenerateFaviconURL(const GURL& url);
+ Profile* profile() { return profile_; }
const TemplateURLData& data() const { return data_; }
const string16& short_name() const { return data_.short_name; }
@@ -443,6 +438,7 @@ class TemplateURL {
// Invalidates cached values on this object and its child TemplateURLRefs.
void InvalidateCachedValues();
+ Profile* profile_;
TemplateURLData data_;
TemplateURLRef url_ref_;
TemplateURLRef suggestions_url_ref_;
diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc
index fc855c3..575fef3 100644
--- a/chrome/browser/search_engines/template_url_fetcher.cc
+++ b/chrome/browser/search_engines/template_url_fetcher.cc
@@ -177,8 +177,8 @@ void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete(
void TemplateURLFetcher::RequestDelegate::AddSearchProvider() {
DCHECK(template_url_.get());
DCHECK(!keyword_.empty());
- TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(
- fetcher_->profile());
+ Profile* profile = fetcher_->profile();
+ TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(profile);
DCHECK(model);
DCHECK(model->loaded());
@@ -206,7 +206,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() {
case AUTODETECTED_PROVIDER:
// Mark the keyword as replaceable so it can be removed if necessary.
data.safe_for_autoreplace = true;
- model->Add(new TemplateURL(data));
+ model->Add(new TemplateURL(profile, data));
break;
case EXPLICIT_PROVIDER:
@@ -216,8 +216,8 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() {
// The source WebContents' delegate takes care of adding the URL to the
// model, which takes ownership, or of deleting it if the add is
// cancelled.
- callbacks_->ConfirmAddSearchProvider(new TemplateURL(data),
- fetcher_->profile());
+ callbacks_->ConfirmAddSearchProvider(new TemplateURL(profile, data),
+ profile);
break;
default:
diff --git a/chrome/browser/search_engines/template_url_fetcher_unittest.cc b/chrome/browser/search_engines/template_url_fetcher_unittest.cc
index 448ccd2..6592e30 100644
--- a/chrome/browser/search_engines/template_url_fetcher_unittest.cc
+++ b/chrome/browser/search_engines/template_url_fetcher_unittest.cc
@@ -47,12 +47,12 @@ class TemplateURLFetcherTest : public testing::Test {
virtual void SetUp() OVERRIDE {
test_util_.SetUp();
test_util_.StartIOThread();
- ASSERT_TRUE(test_util_.profile());
- ASSERT_TRUE(
- TemplateURLFetcherFactory::GetForProfile(test_util_.profile()));
+ TestingProfile* profile = test_util_.profile();
+ ASSERT_TRUE(profile);
+ ASSERT_TRUE(TemplateURLFetcherFactory::GetForProfile(profile));
- test_util_.profile()->CreateRequestContext();
- ASSERT_TRUE(test_util_.profile()->GetRequestContext());
+ profile->CreateRequestContext();
+ ASSERT_TRUE(profile->GetRequestContext());
ASSERT_TRUE(test_server_.Start());
}
@@ -291,7 +291,7 @@ TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) {
data.short_name = keyword;
data.SetKeyword(keyword);
data.SetURL("http://example.com/");
- test_util_.model()->Add(new TemplateURL(data));
+ test_util_.model()->Add(new TemplateURL(test_util_.profile(), data));
test_util_.ChangeModelToLoadState();
ASSERT_TRUE(test_util_.model()->GetTemplateURLForKeyword(keyword));
diff --git a/chrome/browser/search_engines/template_url_parser.cc b/chrome/browser/search_engines/template_url_parser.cc
index f83efd7..a9f6939 100644
--- a/chrome/browser/search_engines/template_url_parser.cc
+++ b/chrome/browser/search_engines/template_url_parser.cc
@@ -313,7 +313,7 @@ TemplateURL* TemplateURLParsingContext::GetTemplateURL(
DCHECK(!keyword.empty());
data_.SetKeyword(keyword);
data_.show_in_default_list = show_in_default_list;
- return new TemplateURL(data_);
+ return new TemplateURL(profile, data_);
}
// static
diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.cc b/chrome/browser/search_engines/template_url_prepopulate_data.cc
index 5f785ce..7cd25c3 100644
--- a/chrome/browser/search_engines/template_url_prepopulate_data.cc
+++ b/chrome/browser/search_engines/template_url_prepopulate_data.cc
@@ -3150,7 +3150,8 @@ int GetDataVersion(PrefService* prefs) {
return (version >= 0) ? version : kCurrentDataVersion;
}
-TemplateURL* MakePrepopulatedTemplateURL(const string16& name,
+TemplateURL* MakePrepopulatedTemplateURL(Profile* profile,
+ const string16& name,
const string16& keyword,
const base::StringPiece& search_url,
const base::StringPiece& suggest_url,
@@ -3174,16 +3175,16 @@ TemplateURL* MakePrepopulatedTemplateURL(const string16& name,
data.date_created = base::Time();
data.last_modified = base::Time();
data.prepopulate_id = id;
- return new TemplateURL(data);
+ return new TemplateURL(profile, data);
}
-void GetPrepopulatedTemplateFromPrefs(PrefService* prefs,
+void GetPrepopulatedTemplateFromPrefs(Profile* profile,
std::vector<TemplateURL*>* t_urls) {
- if (!prefs)
+ if (!profile)
return;
const ListValue* list =
- prefs->GetList(prefs::kSearchProviderOverrides);
+ profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides);
if (!list)
return;
@@ -3217,45 +3218,47 @@ void GetPrepopulatedTemplateFromPrefs(PrefService* prefs,
// Got a parsing error. No big deal.
continue;
}
- t_urls->push_back(MakePrepopulatedTemplateURL(name, keyword, search_url,
- suggest_url, instant_url, favicon_url, encoding, id));
+ t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword,
+ search_url, suggest_url, instant_url, favicon_url, encoding, id));
}
}
// The caller owns the returned TemplateURL.
TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine(
+ Profile* profile,
const PrepopulatedEngine& engine) {
- return MakePrepopulatedTemplateURL(WideToUTF16(engine.name),
+ return MakePrepopulatedTemplateURL(profile, WideToUTF16(engine.name),
WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url,
engine.instant_url, engine.favicon_url, engine.encoding, engine.id);
}
-void GetPrepopulatedEngines(PrefService* prefs,
+void GetPrepopulatedEngines(Profile* profile,
std::vector<TemplateURL*>* t_urls,
size_t* default_search_provider_index) {
// If there is a set of search engines in the preferences file, it overrides
// the built-in set.
*default_search_provider_index = 0;
- GetPrepopulatedTemplateFromPrefs(prefs, t_urls);
+ GetPrepopulatedTemplateFromPrefs(profile, t_urls);
if (!t_urls->empty())
return;
const PrepopulatedEngine** engines;
size_t num_engines;
- GetPrepopulationSetFromCountryID(prefs, &engines, &num_engines);
+ GetPrepopulationSetFromCountryID(profile ? profile->GetPrefs() : NULL,
+ &engines, &num_engines);
for (size_t i = 0; i != num_engines; ++i) {
t_urls->push_back(
- MakePrepopulatedTemplateURLFromPrepopulateEngine(*engines[i]));
+ MakePrepopulatedTemplateURLFromPrepopulateEngine(profile, *engines[i]));
}
}
-TemplateURL* GetPrepopulatedDefaultSearch(PrefService* prefs) {
+TemplateURL* GetPrepopulatedDefaultSearch(Profile* profile) {
TemplateURL* default_search_provider = NULL;
ScopedVector<TemplateURL> loaded_urls;
size_t default_search_index;
// This could be more efficient. We are loading all the URLs to only keep
// the first one.
- GetPrepopulatedEngines(prefs, &loaded_urls.get(), &default_search_index);
+ GetPrepopulatedEngines(profile, &loaded_urls.get(), &default_search_index);
if (default_search_index < loaded_urls.size()) {
default_search_provider = loaded_urls[default_search_index];
loaded_urls.weak_erase(loaded_urls.begin() + default_search_index);
diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.h b/chrome/browser/search_engines/template_url_prepopulate_data.h
index b30eff8..dc989f9 100644
--- a/chrome/browser/search_engines/template_url_prepopulate_data.h
+++ b/chrome/browser/search_engines/template_url_prepopulate_data.h
@@ -15,6 +15,7 @@
class GURL;
class PrefService;
+class Profile;
class TemplateURL;
namespace TemplateURLPrepopulateData {
@@ -32,15 +33,15 @@ int GetDataVersion(PrefService* prefs);
// TemplateURLs is passed to the caller. On return,
// |default_search_provider_index| is set to the index of the default search
// provider.
-void GetPrepopulatedEngines(PrefService* prefs,
+void GetPrepopulatedEngines(Profile* profile,
std::vector<TemplateURL*>* t_urls,
size_t* default_search_provider_index);
// Returns the default search provider specified by the prepopulate data.
// The caller owns the returned value, which may be NULL.
-// If |prefs| is NULL, any search provider overrides from the preferences are
+// If |profile| is NULL, any search provider overrides from the preferences are
// not used.
-TemplateURL* GetPrepopulatedDefaultSearch(PrefService* prefs);
+TemplateURL* GetPrepopulatedDefaultSearch(Profile* profile);
// Both the next two functions use same-origin checks unless the |url| is a
// Google seach URL, in which case we'll identify any valid Google hostname, or
diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
index ee91e85..14b89a9 100644
--- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
+++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc
@@ -78,8 +78,8 @@ TEST(TemplateURLPrepopulateDataTest, UniqueIDs) {
profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]);
ScopedVector<TemplateURL> urls;
size_t default_index;
- TemplateURLPrepopulateData::GetPrepopulatedEngines(profile.GetPrefs(),
- &urls.get(), &default_index);
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &urls.get(),
+ &default_index);
std::set<int> unique_ids;
for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) ==
@@ -114,7 +114,7 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
ScopedVector<TemplateURL> t_urls;
size_t default_index;
- TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &t_urls.get(),
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(&profile, &t_urls.get(),
&default_index);
ASSERT_EQ(1u, t_urls.size());
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index a2f99ae4..70c3d1f 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -326,6 +326,12 @@ void TemplateURLService::Add(TemplateURL* template_url) {
NotifyObservers();
}
+void TemplateURLService::AddAndSetProfile(TemplateURL* template_url,
+ Profile* profile) {
+ template_url->profile_ = profile;
+ Add(template_url);
+}
+
void TemplateURLService::AddWithOverrides(const TemplateURL* template_url,
const string16& short_name,
const string16& keyword,
@@ -395,7 +401,7 @@ void TemplateURLService::RegisterExtensionKeyword(const Extension* extension) {
// ID, as well as forcing the TemplateURL to be treated as a search keyword.
data.SetURL(std::string(chrome::kExtensionScheme) + "://" +
extension->id() + "/?q={searchTerms}");
- Add(new TemplateURL(data));
+ Add(new TemplateURL(profile_, data));
}
}
@@ -456,7 +462,7 @@ void TemplateURLService::ResetTemplateURL(const TemplateURL* url,
}
data.safe_for_autoreplace = false;
data.last_modified = time_provider_();
- TemplateURL new_url(data);
+ TemplateURL new_url(const_cast<TemplateURL*>(url)->profile(), data);
UpdateNoNotify(url, new_url);
NotifyObservers();
}
@@ -488,7 +494,7 @@ const TemplateURL* TemplateURLService::GetDefaultSearchProvider() {
const TemplateURL* TemplateURLService::FindNewDefaultSearchProvider() {
// See if the prepopulated default still exists.
scoped_ptr<TemplateURL> prepopulated_default(
- TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(GetPrefs()));
+ TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(profile_));
for (TemplateURLVector::iterator i = template_urls_.begin();
i != template_urls_.end(); ++i) {
if ((*i)->prepopulate_id() == prepopulated_default->prepopulate_id())
@@ -551,7 +557,7 @@ void TemplateURLService::OnWebDataServiceRequestDone(
std::vector<TemplateURL*> template_urls;
const TemplateURL* default_search_provider = NULL;
int new_resource_keyword_version = 0;
- GetSearchProvidersUsingKeywordResult(*result, service_.get(), GetPrefs(),
+ GetSearchProvidersUsingKeywordResult(*result, service_.get(), profile_,
&template_urls, &default_search_provider, &new_resource_keyword_version);
bool database_specified_a_default = (default_search_provider != NULL);
@@ -570,7 +576,7 @@ void TemplateURLService::OnWebDataServiceRequestDone(
// No check is required if the default search is managed.
// |DidDefaultSearchProviderChange| must always be called because it will
// take care of the unowned backup default search provider instance.
- if (DidDefaultSearchProviderChange(*result,
+ if (DidDefaultSearchProviderChange(*result, profile_,
&backup_default_search_provider) &&
!is_default_search_managed_) {
hijacked_default_search_provider = default_search_provider;
@@ -599,7 +605,7 @@ void TemplateURLService::OnWebDataServiceRequestDone(
TemplateURLData data(default_from_prefs->data());
data.created_by_policy = true;
data.id = kInvalidTemplateURLID;
- TemplateURL* managed_default = new TemplateURL(data);
+ TemplateURL* managed_default = new TemplateURL(profile_, data);
AddNoNotify(managed_default, true);
default_search_provider = managed_default;
}
@@ -619,7 +625,7 @@ void TemplateURLService::OnWebDataServiceRequestDone(
default_search_provider == NULL) {
for (std::vector<TemplateURL*>::const_iterator i = template_urls.begin();
i != template_urls.end(); ++i) {
- if (!(*i)->IsExtensionKeyword()) {
+ if (!(*i)->IsExtensionKeyword() && (*i)->SupportsReplacement()) {
default_search_provider = *i;
break;
}
@@ -800,7 +806,7 @@ SyncError TemplateURLService::ProcessSyncChanges(
iter->sync_data().GetSpecifics().search_engine().sync_guid();
const TemplateURL* existing_turl = GetTemplateURLForGUID(guid);
scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData(
- existing_turl, iter->sync_data(), &new_changes));
+ profile_, existing_turl, iter->sync_data(), &new_changes));
if (!turl.get())
continue;
@@ -829,7 +835,7 @@ SyncError TemplateURLService::ProcessSyncChanges(
// Force the local ID to kInvalidTemplateURLID so we can add it.
TemplateURLData data(turl->data());
data.id = kInvalidTemplateURLID;
- Add(new TemplateURL(data));
+ Add(new TemplateURL(profile_, data));
// Possibly set the newly added |turl| as the default search provider.
SetDefaultSearchProviderIfNewlySynced(guid);
@@ -904,8 +910,8 @@ SyncError TemplateURLService::MergeDataAndStartSyncing(
iter != sync_data_map.end(); ++iter) {
const TemplateURL* local_turl = GetTemplateURLForGUID(iter->first);
scoped_ptr<TemplateURL> sync_turl(
- CreateTemplateURLFromTemplateURLAndSyncData(local_turl, iter->second,
- &new_changes));
+ CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl,
+ iter->second, &new_changes));
if (!sync_turl.get())
continue;
@@ -950,7 +956,7 @@ SyncError TemplateURLService::MergeDataAndStartSyncing(
// Force the local ID to kInvalidTemplateURLID so we can add it.
TemplateURLData data(sync_turl->data());
data.id = kInvalidTemplateURLID;
- Add(new TemplateURL(data));
+ Add(new TemplateURL(profile_, data));
// Possibly set the newly added |turl| as the default search provider.
SetDefaultSearchProviderIfNewlySynced(guid);
@@ -1038,9 +1044,12 @@ SyncData TemplateURLService::CreateSyncDataFromTemplateURL(
// static
TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
+ Profile* profile,
const TemplateURL* existing_turl,
const SyncData& sync_data,
SyncChangeList* change_list) {
+ DCHECK(change_list);
+
sync_pb::SearchEngineSpecifics specifics =
sync_data.GetSpecifics().search_engine();
@@ -1073,7 +1082,7 @@ TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
data.usage_count = existing_turl->usage_count();
}
- TemplateURL* turl = new TemplateURL(data);
+ TemplateURL* turl = new TemplateURL(profile, data);
DCHECK(!turl->IsExtensionKeyword());
return turl;
}
@@ -1141,7 +1150,7 @@ void TemplateURLService::Init(const Initializer* initializers,
data.short_name = UTF8ToUTF16(initializers[i].content);
data.SetKeyword(UTF8ToUTF16(initializers[i].keyword));
data.SetURL(osd_url);
- AddNoNotify(new TemplateURL(data), true);
+ AddNoNotify(new TemplateURL(profile_, data), true);
}
}
@@ -1358,7 +1367,7 @@ bool TemplateURLService::LoadDefaultSearchProviderFromPrefs(
base::StringToInt(prepopulate_id, &value);
data.prepopulate_id = value;
}
- default_provider->reset(new TemplateURL(data));
+ default_provider->reset(new TemplateURL(profile_, data));
DCHECK(!(*default_provider)->IsExtensionKeyword());
return true;
}
@@ -1581,7 +1590,7 @@ void TemplateURLService::UpdateDefaultSearch() {
// Prefs does not specify, so rely on the prepopulated engines. This
// should happen only the first time Chrome is started.
initial_default_search_provider_.reset(
- TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(GetPrefs()));
+ TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(profile_));
is_default_search_managed_ = false;
}
return;
@@ -1618,14 +1627,14 @@ void TemplateURLService::UpdateDefaultSearch() {
} else if (default_search_provider_) {
TemplateURLData data(new_default_from_prefs->data());
data.created_by_policy = true;
- TemplateURL new_values(data);
+ TemplateURL new_values(profile_, data);
UpdateNoNotify(default_search_provider_, new_values);
} else {
TemplateURL* new_template = NULL;
if (new_default_from_prefs.get()) {
TemplateURLData data(new_default_from_prefs->data());
data.created_by_policy = true;
- new_template = new TemplateURL(data);
+ new_template = new TemplateURL(profile_, data);
AddNoNotify(new_template, true);
}
SetDefaultSearchProviderNoNotify(new_template);
@@ -1638,7 +1647,7 @@ void TemplateURLService::UpdateDefaultSearch() {
if (new_default_from_prefs.get()) {
TemplateURLData data(new_default_from_prefs->data());
data.created_by_policy = true;
- new_template = new TemplateURL(data);
+ new_template = new TemplateURL(profile_, data);
AddNoNotify(new_template, true);
}
SetDefaultSearchProviderNoNotify(new_template);
@@ -1848,7 +1857,7 @@ void TemplateURLService::ResetTemplateURLGUID(const TemplateURL* url,
TemplateURLData data(url->data());
data.sync_guid = guid;
- TemplateURL new_url(data);
+ TemplateURL new_url(const_cast<TemplateURL*>(url)->profile(), data);
UpdateNoNotify(url, new_url);
}
@@ -1902,7 +1911,8 @@ bool TemplateURLService::ResolveSyncKeywordConflict(
string16 new_keyword = UniquifyKeyword(*existing_turl);
TemplateURLData data(existing_turl->data());
data.SetKeyword(new_keyword);
- TemplateURL new_turl(data);
+ TemplateURL new_turl(const_cast<TemplateURL*>(existing_turl)->profile(),
+ data);
UpdateNoNotify(existing_turl, new_turl);
NotifyObservers();
}
diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h
index 476797e..764df40 100644
--- a/chrome/browser/search_engines/template_url_service.h
+++ b/chrome/browser/search_engines/template_url_service.h
@@ -144,6 +144,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Like Add(), but overwrites the |template_url|'s values with the provided
// ones.
+ void AddAndSetProfile(TemplateURL* template_url, Profile* profile);
void AddWithOverrides(const TemplateURL* template_url,
const string16& short_name,
const string16& keyword,
@@ -308,6 +309,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// data is bad for some reason, an ACTION_DELETE change is added and the
// function returns NULL.
static TemplateURL* CreateTemplateURLFromTemplateURLAndSyncData(
+ Profile* profile,
const TemplateURL* existing_turl,
const SyncData& sync_data,
SyncChangeList* change_list);
diff --git a/chrome/browser/search_engines/template_url_service_sync_unittest.cc b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
index a7ba778..7cec55b 100644
--- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
@@ -277,7 +277,7 @@ TemplateURL* TemplateURLServiceSyncTest::CreateTestTemplateURL(
data.prepopulate_id = 999999;
if (!guid.empty())
data.sync_guid = guid;
- return new TemplateURL(data);
+ return new TemplateURL(NULL, data);
}
void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected,
@@ -341,7 +341,7 @@ TemplateURL* TemplateURLServiceSyncTest::Deserialize(
const SyncData& sync_data) {
SyncChangeList dummy;
return TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(NULL,
- sync_data, &dummy);
+ NULL, sync_data, &dummy);
}
@@ -1135,7 +1135,8 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) {
// Keep a copy of it so we can compare it after we re-merge.
const TemplateURL* key1_url = model()->GetTemplateURLForGUID("key1");
ASSERT_TRUE(key1_url);
- scoped_ptr<TemplateURL> updated_turl(new TemplateURL(key1_url->data()));
+ scoped_ptr<TemplateURL> updated_turl(new TemplateURL(
+ const_cast<TemplateURL*>(key1_url)->profile(), key1_url->data()));
EXPECT_EQ(Time::FromTimeT(90), updated_turl->last_modified());
// Modify a single field of the initial data. This should not be updated in
@@ -1143,7 +1144,7 @@ TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) {
scoped_ptr<TemplateURL> temp_turl(Deserialize(initial_data[0]));
TemplateURLData data(temp_turl->data());
data.short_name = ASCIIToUTF16("SomethingDifferent");
- temp_turl.reset(new TemplateURL(data));
+ temp_turl.reset(new TemplateURL(temp_turl->profile(), data));
initial_data.clear();
initial_data.push_back(
TemplateURLService::CreateSyncDataFromTemplateURL(*temp_turl));
diff --git a/chrome/browser/search_engines/template_url_service_unittest.cc b/chrome/browser/search_engines/template_url_service_unittest.cc
index b44b31d..4bf0e23 100644
--- a/chrome/browser/search_engines/template_url_service_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_unittest.cc
@@ -33,25 +33,6 @@ using ::testing::StrictMock;
namespace {
-// Create an URL that appears to have been prepopulated, but won't be in the
-// current data. The caller owns the returned TemplateURL*.
-TemplateURL* CreatePreloadedTemplateURL(bool safe_for_autoreplace,
- int prepopulate_id) {
- TemplateURLData data;
- data.short_name = ASCIIToUTF16("unittest");
- data.SetKeyword(ASCIIToUTF16("unittest"));
- data.SetURL("http://www.unittest.com/{searchTerms}");
- data.favicon_url = GURL("http://favicon.url");
- data.show_in_default_list = true;
- data.safe_for_autoreplace = safe_for_autoreplace;
- data.input_encodings.push_back("UTF-8");
- data.date_created = Time::FromTimeT(100);
- data.last_modified = Time::FromTimeT(100);
- data.prepopulate_id = prepopulate_id;
- return new TemplateURL(data);
-}
-
-
// TestGenerateSearchURL ------------------------------------------------------
// Test the GenerateSearchURL on a thread or the main thread.
@@ -100,7 +81,7 @@ void TestGenerateSearchURL::RunTest() {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
TemplateURLData data;
data.SetURL(generate_url_cases[i].url);
- TemplateURL t_url(data);
+ TemplateURL t_url(NULL, data);
std::string result = (search_terms_data_ ?
TemplateURLService::GenerateSearchURLUsingTermsData(&t_url,
*search_terms_data_) :
@@ -172,6 +153,11 @@ class TemplateURLServiceTest : public testing::Test {
// date_created or the last_modified time. Neither pointer should be NULL.
void ExpectSimilar(const TemplateURL* expected, const TemplateURL* actual);
+ // Create an URL that appears to have been prepopulated, but won't be in the
+ // current data. The caller owns the returned TemplateURL*.
+ TemplateURL* CreatePreloadedTemplateURL(bool safe_for_autoreplace,
+ int prepopulate_id);
+
// Creates a TemplateURL with the same prepopulated id as a real prepopulated
// item. The input number determines which prepopulated item. The caller is
// responsible for owning the returned TemplateURL*.
@@ -231,7 +217,7 @@ TemplateURL* TemplateURLServiceTest::AddKeywordWithDate(
base::SplitString(encodings, ';', &data.input_encodings);
data.date_created = date_created;
data.last_modified = last_modified;
- TemplateURL* t_url = new TemplateURL(data);
+ TemplateURL* t_url = new TemplateURL(test_util_.profile(), data);
model()->Add(t_url);
EXPECT_NE(0, t_url->id());
return t_url;
@@ -267,15 +253,31 @@ void TemplateURLServiceTest::ExpectSimilar(const TemplateURL* expected,
EXPECT_EQ(expected->input_encodings(), actual->input_encodings());
}
+TemplateURL* TemplateURLServiceTest::CreatePreloadedTemplateURL(
+ bool safe_for_autoreplace,
+ int prepopulate_id) {
+ TemplateURLData data;
+ data.short_name = ASCIIToUTF16("unittest");
+ data.SetKeyword(ASCIIToUTF16("unittest"));
+ data.SetURL("http://www.unittest.com/{searchTerms}");
+ data.favicon_url = GURL("http://favicon.url");
+ data.show_in_default_list = true;
+ data.safe_for_autoreplace = safe_for_autoreplace;
+ data.input_encodings.push_back("UTF-8");
+ data.date_created = Time::FromTimeT(100);
+ data.last_modified = Time::FromTimeT(100);
+ data.prepopulate_id = prepopulate_id;
+ return new TemplateURL(test_util_.profile(), data);
+}
+
TemplateURL* TemplateURLServiceTest::CreateReplaceablePreloadedTemplateURL(
bool safe_for_autoreplace,
size_t index_offset_from_default,
string16* prepopulated_display_url) {
ScopedVector<TemplateURL> prepopulated_urls;
size_t default_search_provider_index = 0;
- TemplateURLPrepopulateData::GetPrepopulatedEngines(
- test_util_.profile()->GetPrefs(), &prepopulated_urls.get(),
- &default_search_provider_index);
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(test_util_.profile(),
+ &prepopulated_urls.get(), &default_search_provider_index);
EXPECT_LT(index_offset_from_default, prepopulated_urls.size());
size_t prepopulated_index = (default_search_provider_index +
index_offset_from_default) % prepopulated_urls.size();
@@ -351,7 +353,7 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
data.date_created = Time::FromTimeT(100);
data.last_modified = Time::FromTimeT(100);
data.sync_guid = "00000000-0000-0000-0000-000000000001";
- TemplateURL* t_url = new TemplateURL(data);
+ TemplateURL* t_url = new TemplateURL(test_util_.profile(), data);
model()->Add(t_url);
ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(),
NULL));
@@ -362,7 +364,8 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
// We need to make a second copy as the model takes ownership of |t_url| and
// will delete it. We have to do this after calling Add() since that gives
// |t_url| its ID.
- scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
+ scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
+ t_url->data()));
// Reload the model to verify it was actually saved to the database.
test_util_.ResetModel(true);
@@ -391,7 +394,8 @@ TEST_F(TemplateURLServiceTest, AddUpdateRemove) {
ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), GURL(),
NULL));
ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL));
- cloned_url.reset(new TemplateURL(loaded_url->data()));
+ cloned_url.reset(new TemplateURL(
+ const_cast<TemplateURL*>(loaded_url)->profile(), loaded_url->data()));
test_util_.BlockTillServiceProcessesRequests();
test_util_.ResetModel(true);
ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size());
@@ -575,7 +579,7 @@ TEST_F(TemplateURLServiceTest, Reset) {
data.favicon_url = GURL("http://favicon.url");
data.date_created = Time::FromTimeT(100);
data.last_modified = Time::FromTimeT(100);
- TemplateURL* t_url = new TemplateURL(data);
+ TemplateURL* t_url = new TemplateURL(test_util_.profile(), data);
model()->Add(t_url);
VerifyObserverCount(1);
@@ -599,7 +603,8 @@ TEST_F(TemplateURLServiceTest, Reset) {
ASSERT_TRUE(
model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL);
- scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
+ scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
+ t_url->data()));
// Reload the model from the database and make sure the change took.
test_util_.ResetModel(true);
@@ -628,7 +633,8 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProvider) {
VerifyObserverCount(1);
test_util_.BlockTillServiceProcessesRequests();
- scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
+ scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
+ t_url->data()));
// Make sure when we reload we get a default search provider.
test_util_.ResetModel(true);
@@ -724,13 +730,14 @@ TEST_F(TemplateURLServiceTest, DefaultSearchProviderLoadedFromPrefs) {
data.instant_url = "http://instant";
data.date_created = Time::FromTimeT(100);
data.last_modified = Time::FromTimeT(100);
- TemplateURL* t_url = new TemplateURL(data);
+ TemplateURL* t_url = new TemplateURL(test_util_.profile(), data);
model()->Add(t_url);
const TemplateURLID id = t_url->id();
model()->SetDefaultSearchProvider(t_url);
test_util_.BlockTillServiceProcessesRequests();
- scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
+ scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
+ t_url->data()));
// Reset the model and don't load it. The template url we set as the default
// should be pulled from prefs now.
@@ -971,7 +978,8 @@ TEST_F(TemplateURLServiceTest, LoadRetainsModifiedProvider) {
model()->Add(t_url);
// Do the copy after t_url is added so that the id is set.
- scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
+ scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
+ t_url->data()));
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
// Wait for any saves to finish.
@@ -1001,7 +1009,9 @@ TEST_F(TemplateURLServiceTest, LoadSavesPrepopulatedDefaultSearchProvider) {
// Verify that the default search provider is set to something.
const TemplateURL* default_search = model()->GetDefaultSearchProvider();
ASSERT_TRUE(default_search != NULL);
- scoped_ptr<TemplateURL> cloned_url(new TemplateURL(default_search->data()));
+ scoped_ptr<TemplateURL> cloned_url(new TemplateURL(
+ const_cast<TemplateURL*>(default_search)->profile(),
+ default_search->data()));
// Wait for any saves to finish.
test_util_.BlockTillServiceProcessesRequests();
@@ -1027,7 +1037,8 @@ TEST_F(TemplateURLServiceTest, LoadRetainsDefaultProvider) {
model()->SetDefaultSearchProvider(t_url);
// Do the copy after t_url is added and set as default so that its
// internal state is correct.
- scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->data()));
+ scoped_ptr<TemplateURL> cloned_url(new TemplateURL(t_url->profile(),
+ t_url->data()));
ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")));
ASSERT_EQ(t_url, model()->GetDefaultSearchProvider());
@@ -1118,7 +1129,7 @@ TEST_F(TemplateURLServiceTest, LoadDoesAutoKeywordUpdate) {
// Then add it to the model and save it all.
test_util_.ChangeModelToLoadState();
- model()->Add(new TemplateURL(data));
+ model()->Add(new TemplateURL(test_util_.profile(), data));
test_util_.BlockTillServiceProcessesRequests();
// Now reload the model and verify that the merge updates the url.
@@ -1186,7 +1197,9 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
data.favicon_url = GURL(kIconURL);
data.show_in_default_list = true;
base::SplitString(kEncodings, ';', &data.input_encodings);
- scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL(data));
+ Profile* profile = test_util_.profile();
+ scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL(profile,
+ data));
const TemplateURL* actual_managed_default =
model()->GetDefaultSearchProvider();
ExpectSimilar(expected_managed_default1.get(), actual_managed_default);
@@ -1210,7 +1223,8 @@ TEST_F(TemplateURLServiceTest, TestManagedDefaultSearch) {
data2.SetURL(kNewSearchURL);
data2.suggestions_url = kNewSuggestURL;
data2.show_in_default_list = true;
- scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL(data2));
+ scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL(profile,
+ data2));
actual_managed_default = model()->GetDefaultSearchProvider();
ExpectSimilar(expected_managed_default2.get(), actual_managed_default);
EXPECT_EQ(actual_managed_default->show_in_default_list(), true);
@@ -1283,7 +1297,7 @@ TEST_F(TemplateURLServiceTest, PatchEmptySyncGUID) {
data.SetKeyword(ASCIIToUTF16("keyword"));
data.SetURL("http://www.google.com/foo/bar");
data.sync_guid.clear();
- TemplateURL* t_url = new TemplateURL(data);
+ TemplateURL* t_url = new TemplateURL(test_util_.profile(), data);
model()->Add(t_url);
VerifyObserverCount(1);
diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc
index e9a9769..dbc5c39 100644
--- a/chrome/browser/search_engines/template_url_unittest.cc
+++ b/chrome/browser/search_engines/template_url_unittest.cc
@@ -67,7 +67,7 @@ TEST_F(TemplateURLTest, Defaults) {
TEST_F(TemplateURLTest, TestValidWithComplete) {
TemplateURLData data;
data.SetURL("{searchTerms}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
}
@@ -91,7 +91,7 @@ TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
const SearchTermsCase& value = search_term_cases[i];
TemplateURLData data;
data.SetURL(value.url);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
std::string result = url.url_ref().ReplaceSearchTerms(value.terms,
@@ -105,7 +105,7 @@ TEST_F(TemplateURLTest, URLRefTestSearchTerms) {
TEST_F(TemplateURLTest, URLRefTestCount) {
TemplateURLData data;
data.SetURL("http://foo{searchTerms}{count?}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
@@ -117,7 +117,7 @@ TEST_F(TemplateURLTest, URLRefTestCount) {
TEST_F(TemplateURLTest, URLRefTestCount2) {
TemplateURLData data;
data.SetURL("http://foo{searchTerms}{count}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
@@ -129,7 +129,7 @@ TEST_F(TemplateURLTest, URLRefTestCount2) {
TEST_F(TemplateURLTest, URLRefTestIndices) {
TemplateURLData data;
data.SetURL("http://foo{searchTerms}x{startIndex?}y{startPage?}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
@@ -141,7 +141,7 @@ TEST_F(TemplateURLTest, URLRefTestIndices) {
TEST_F(TemplateURLTest, URLRefTestIndices2) {
TemplateURLData data;
data.SetURL("http://foo{searchTerms}x{startIndex}y{startPage}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
@@ -153,7 +153,7 @@ TEST_F(TemplateURLTest, URLRefTestIndices2) {
TEST_F(TemplateURLTest, URLRefTestEncoding) {
TemplateURLData data;
data.SetURL("http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
@@ -167,7 +167,7 @@ TEST_F(TemplateURLTest, URLRefTestEncoding) {
TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
TemplateURLData data;
data.SetURL("http://foo{fhqwhgads}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
TemplateURLRef::Replacements replacements;
bool valid = false;
EXPECT_EQ("http://foo{fhqwhgads}",
@@ -176,7 +176,7 @@ TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
EXPECT_TRUE(valid);
data.prepopulate_id = 123;
- TemplateURL url2(data);
+ TemplateURL url2(NULL, data);
EXPECT_EQ("http://foo", url2.url_ref().ParseURL("http://foo{fhqwhgads}",
&replacements, &valid));
EXPECT_TRUE(replacements.empty());
@@ -186,7 +186,7 @@ TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {
TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
TemplateURLData data;
data.SetURL("http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
@@ -198,7 +198,7 @@ TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {
TEST_F(TemplateURLTest, URLRefTestEncoding2) {
TemplateURLData data;
data.SetURL("http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("X"),
@@ -224,7 +224,7 @@ TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) {
const SearchTermsCase& value = search_term_cases[i];
data.SetURL(value.url);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTermsUsingTermsData(value.terms,
@@ -259,7 +259,7 @@ TEST_F(TemplateURLTest, URLRefTermToWide) {
TemplateURLData data;
data.SetURL("http://foo?q={searchTerms}");
data.input_encodings.push_back("big-5");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) {
@@ -286,7 +286,7 @@ TEST_F(TemplateURLTest, DisplayURLToURLRef) {
TemplateURLData data;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
data.SetURL(test_data[i].url);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_EQ(test_data[i].expected_result, url.url_ref().DisplayURL());
EXPECT_EQ(test_data[i].url,
TemplateURLRef::DisplayURLToURLRef(url.url_ref().DisplayURL()));
@@ -327,7 +327,7 @@ TEST_F(TemplateURLTest, ReplaceSearchTerms) {
data.input_encodings.push_back("UTF-8");
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
data.SetURL(test_data[i].url);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
std::string expected_result = test_data[i].expected_result;
@@ -368,7 +368,7 @@ TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {
data.SetURL(test_data[i].url);
data.input_encodings.clear();
data.input_encodings.push_back(test_data[i].encoding);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(test_data[i].search_term,
@@ -399,7 +399,7 @@ TEST_F(TemplateURLTest, Suggestions) {
data.SetURL("http://bar/foo?{google:acceptedSuggestion}"
"{google:originalQueryForSuggestion}q={searchTerms}");
data.input_encodings.push_back("UTF-8");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
@@ -424,7 +424,7 @@ TEST_F(TemplateURLTest, RLZ) {
TemplateURLData data;
data.SetURL("http://bar/?{google:RLZ}{searchTerms}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_TRUE(url.url_ref().IsValid());
ASSERT_TRUE(url.url_ref().SupportsReplacement());
GURL result(url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"),
@@ -468,7 +468,7 @@ TEST_F(TemplateURLTest, HostAndSearchTermKey) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
TemplateURLData data;
data.SetURL(test_data[i].url);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
EXPECT_EQ(test_data[i].host, url.url_ref().GetHost());
EXPECT_EQ(test_data[i].path, url.url_ref().GetPath());
EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey());
@@ -496,20 +496,20 @@ TEST_F(TemplateURLTest, Keyword) {
data.SetURL("http://www.google.com/search");
EXPECT_FALSE(data.autogenerate_keyword());
data.SetKeyword(ASCIIToUTF16("foo"));
- EXPECT_EQ(ASCIIToUTF16("foo"), TemplateURL(data).keyword());
+ EXPECT_EQ(ASCIIToUTF16("foo"), TemplateURL(NULL, data).keyword());
data.SetAutogenerateKeyword(true);
EXPECT_TRUE(data.autogenerate_keyword());
- EXPECT_EQ(ASCIIToUTF16("google.com"), TemplateURL(data).keyword());
+ EXPECT_EQ(ASCIIToUTF16("google.com"), TemplateURL(NULL, data).keyword());
data.SetKeyword(ASCIIToUTF16("foo"));
EXPECT_FALSE(data.autogenerate_keyword());
- EXPECT_EQ(ASCIIToUTF16("foo"), TemplateURL(data).keyword());
+ EXPECT_EQ(ASCIIToUTF16("foo"), TemplateURL(NULL, data).keyword());
}
TEST_F(TemplateURLTest, ParseParameterKnown) {
std::string parsed_url("{searchTerms}");
TemplateURLData data;
data.SetURL(parsed_url);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
TemplateURLRef::Replacements replacements;
EXPECT_TRUE(url.url_ref().ParseParameter(0, 12, &parsed_url, &replacements));
EXPECT_EQ(std::string(), parsed_url);
@@ -522,7 +522,7 @@ TEST_F(TemplateURLTest, ParseParameterUnknown) {
std::string parsed_url("{fhqwhgads}");
TemplateURLData data;
data.SetURL(parsed_url);
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
TemplateURLRef::Replacements replacements;
// By default, TemplateURLRef should not consider itself prepopulated.
@@ -534,7 +534,7 @@ TEST_F(TemplateURLTest, ParseParameterUnknown) {
// If the TemplateURLRef is prepopulated, we should remove unknown parameters.
parsed_url = "{fhqwhgads}";
data.prepopulate_id = 1;
- TemplateURL url2(data);
+ TemplateURL url2(NULL, data);
EXPECT_FALSE(url2.url_ref().ParseParameter(0, 10, &parsed_url,
&replacements));
EXPECT_EQ(std::string(), parsed_url);
@@ -542,8 +542,7 @@ TEST_F(TemplateURLTest, ParseParameterUnknown) {
}
TEST_F(TemplateURLTest, ParseURLEmpty) {
- TemplateURLData data;
- TemplateURL url(data);
+ TemplateURL url(NULL, TemplateURLData());
TemplateURLRef::Replacements replacements;
bool valid = false;
EXPECT_EQ(std::string(),
@@ -555,7 +554,7 @@ TEST_F(TemplateURLTest, ParseURLEmpty) {
TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
TemplateURLData data;
data.SetURL("{");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
TemplateURLRef::Replacements replacements;
bool valid = false;
EXPECT_EQ(std::string(), url.url_ref().ParseURL("{", &replacements, &valid));
@@ -566,7 +565,7 @@ TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {
TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
TemplateURLData data;
data.SetURL("{}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
TemplateURLRef::Replacements replacements;
bool valid = false;
EXPECT_EQ("{}", url.url_ref().ParseURL("{}", &replacements, &valid));
@@ -577,7 +576,7 @@ TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {
TEST_F(TemplateURLTest, ParseURLTwoParameters) {
TemplateURLData data;
data.SetURL("{}{{%s}}");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
TemplateURLRef::Replacements replacements;
bool valid = false;
EXPECT_EQ("{}{}",
@@ -591,7 +590,7 @@ TEST_F(TemplateURLTest, ParseURLTwoParameters) {
TEST_F(TemplateURLTest, ParseURLNestedParameter) {
TemplateURLData data;
data.SetURL("{%s");
- TemplateURL url(data);
+ TemplateURL url(NULL, data);
TemplateURLRef::Replacements replacements;
bool valid = false;
EXPECT_EQ("{",
diff --git a/chrome/browser/search_engines/util.cc b/chrome/browser/search_engines/util.cc
index b284aec..63d71a5 100644
--- a/chrome/browser/search_engines/util.cc
+++ b/chrome/browser/search_engines/util.cc
@@ -8,7 +8,6 @@
#include <vector>
#include "base/logging.h"
-#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
@@ -83,7 +82,7 @@ TemplateURL* GetTemplateURLByID(
// Loads engines from prepopulate data and merges them in with the existing
// engines. This is invoked when the version of the prepopulate data changes.
void MergeEnginesFromPrepopulateData(
- PrefService* prefs,
+ Profile* profile,
WebDataService* service,
std::vector<TemplateURL*>* template_urls,
const TemplateURL** default_search_provider) {
@@ -105,7 +104,7 @@ void MergeEnginesFromPrepopulateData(
// Get the current set of prepopulatd URLs.
std::vector<TemplateURL*> prepopulated_urls;
size_t default_search_index;
- TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs,
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(profile,
&prepopulated_urls, &default_search_index);
// For each current prepopulated URL, check whether |template_urls| contained
@@ -135,7 +134,7 @@ void MergeEnginesFromPrepopulateData(
data.short_name = existing_url->short_name();
}
data.id = existing_url->id();
- url_in_vector = new TemplateURL(data);
+ url_in_vector = new TemplateURL(profile, data);
if (service)
service->UpdateKeyword(*url_in_vector);
@@ -175,7 +174,7 @@ void MergeEnginesFromPrepopulateData(
void GetSearchProvidersUsingKeywordResult(
const WDTypedResult& result,
WebDataService* service,
- PrefService* prefs,
+ Profile* profile,
std::vector<TemplateURL*>* template_urls,
const TemplateURL** default_search_provider,
int* new_resource_keyword_version) {
@@ -194,10 +193,11 @@ void GetSearchProvidersUsingKeywordResult(
for (KeywordTable::Keywords::const_iterator i(
keyword_result.keywords.begin()); i != keyword_result.keywords.end();
++i)
- template_urls->push_back(new TemplateURL(*i));
+ template_urls->push_back(new TemplateURL(profile, *i));
const int resource_keyword_version =
- TemplateURLPrepopulateData::GetDataVersion(prefs);
+ TemplateURLPrepopulateData::GetDataVersion(
+ profile ? profile->GetPrefs() : NULL);
if (keyword_result.builtin_keyword_version != resource_keyword_version) {
// There should never be duplicate TemplateURLs. We had a bug such that
// duplicate TemplateURLs existed for one locale. As such we invoke
@@ -212,7 +212,7 @@ void GetSearchProvidersUsingKeywordResult(
}
if (keyword_result.builtin_keyword_version != resource_keyword_version) {
- MergeEnginesFromPrepopulateData(prefs, service, template_urls,
+ MergeEnginesFromPrepopulateData(profile, service, template_urls,
default_search_provider);
*new_resource_keyword_version = resource_keyword_version;
}
@@ -220,6 +220,7 @@ void GetSearchProvidersUsingKeywordResult(
bool DidDefaultSearchProviderChange(
const WDTypedResult& result,
+ Profile* profile,
scoped_ptr<TemplateURL>* backup_default_search_provider) {
DCHECK(backup_default_search_provider);
DCHECK(!backup_default_search_provider->get());
@@ -232,7 +233,7 @@ bool DidDefaultSearchProviderChange(
return false;
if (keyword_result.backup_valid) {
- backup_default_search_provider->reset(new TemplateURL(
+ backup_default_search_provider->reset(new TemplateURL(profile,
keyword_result.default_search_provider_backup));
}
return true;
diff --git a/chrome/browser/search_engines/util.h b/chrome/browser/search_engines/util.h
index c2ba446..bba6a9a 100644
--- a/chrome/browser/search_engines/util.h
+++ b/chrome/browser/search_engines/util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,7 +12,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
-class PrefService;
class Profile;
class TemplateURL;
class WDTypedResult;
@@ -36,7 +35,7 @@ string16 GetDefaultSearchEngineName(Profile* profile);
void GetSearchProvidersUsingKeywordResult(
const WDTypedResult& result,
WebDataService* service,
- PrefService* prefs,
+ Profile* profile,
std::vector<TemplateURL*>* template_urls,
const TemplateURL** default_search_provider,
int* new_resource_keyword_version);
@@ -47,6 +46,7 @@ void GetSearchProvidersUsingKeywordResult(
// lost.
bool DidDefaultSearchProviderChange(
const WDTypedResult& result,
+ Profile* profile,
scoped_ptr<TemplateURL>* backup_default_search_provider);
#endif // CHROME_BROWSER_SEARCH_ENGINES_UTIL_H_
diff --git a/chrome/browser/sync/test/integration/search_engines_helper.cc b/chrome/browser/sync/test/integration/search_engines_helper.cc
index 97f0667..1a9f4e0 100644
--- a/chrome/browser/sync/test/integration/search_engines_helper.cc
+++ b/chrome/browser/sync/test/integration/search_engines_helper.cc
@@ -20,15 +20,7 @@
using sync_datatype_helper::test;
-namespace search_engines_helper {
-
-TemplateURLService* GetServiceForProfile(int index) {
- return TemplateURLServiceFactory::GetForProfile(test()->GetProfile(index));
-}
-
-TemplateURLService* GetVerifierService() {
- return TemplateURLServiceFactory::GetForProfile(test()->verifier());
-}
+namespace {
GUIDToTURLMap CreateGUIDToTURLMap(TemplateURLService* service) {
CHECK(service);
@@ -67,43 +59,11 @@ bool TURLsMatch(const TemplateURL* turl1, const TemplateURL* turl2) {
return result;
}
-bool ServiceMatchesVerifier(int profile) {
- TemplateURLService* verifier = GetVerifierService();
- TemplateURLService* other = GetServiceForProfile(profile);
-
- CHECK(verifier);
- CHECK(other);
-
- TemplateURLService::TemplateURLVector verifier_turls =
- verifier->GetTemplateURLs();
- if (verifier_turls.size() != other->GetTemplateURLs().size()) {
- LOG(ERROR) << "Verifier and other service have a different count of TURLs: "
- << verifier_turls.size() << " vs "
- << other->GetTemplateURLs().size() << " respectively.";
- return false;
- }
-
- for (size_t i = 0; i < verifier_turls.size(); ++i) {
- const TemplateURL* verifier_turl = verifier_turls.at(i);
- CHECK(verifier_turl);
- const TemplateURL* other_turl = other->GetTemplateURLForKeyword(
- verifier_turl->keyword());
-
- if (!other_turl) {
- LOG(ERROR) << "The other service did not contain a TURL with keyword: "
- << verifier_turl->keyword();
- return false;
- }
- if (!TURLsMatch(verifier_turl, other_turl))
- return false;
- }
-
- return true;
-}
-
bool ServicesMatch(int profile_a, int profile_b) {
- TemplateURLService* service_a = GetServiceForProfile(profile_a);
- TemplateURLService* service_b = GetServiceForProfile(profile_b);
+ TemplateURLService* service_a =
+ search_engines_helper::GetServiceForProfile(profile_a);
+ TemplateURLService* service_b =
+ search_engines_helper::GetServiceForProfile(profile_b);
CHECK(service_a);
CHECK(service_b);
@@ -145,6 +105,59 @@ bool ServicesMatch(int profile_a, int profile_b) {
return true;
}
+// Convenience helper for consistently generating the same keyword for a given
+// seed.
+string16 CreateKeyword(int seed) {
+ return ASCIIToUTF16(base::StringPrintf("test%d", seed));
+}
+
+} // namespace
+
+namespace search_engines_helper {
+
+TemplateURLService* GetServiceForProfile(int profile_index) {
+ return TemplateURLServiceFactory::GetForProfile(
+ test()->GetProfile(profile_index));
+}
+
+TemplateURLService* GetVerifierService() {
+ return TemplateURLServiceFactory::GetForProfile(test()->verifier());
+}
+
+bool ServiceMatchesVerifier(int profile_index) {
+ TemplateURLService* verifier = GetVerifierService();
+ TemplateURLService* other = GetServiceForProfile(profile_index);
+
+ CHECK(verifier);
+ CHECK(other);
+
+ TemplateURLService::TemplateURLVector verifier_turls =
+ verifier->GetTemplateURLs();
+ if (verifier_turls.size() != other->GetTemplateURLs().size()) {
+ LOG(ERROR) << "Verifier and other service have a different count of TURLs: "
+ << verifier_turls.size() << " vs "
+ << other->GetTemplateURLs().size() << " respectively.";
+ return false;
+ }
+
+ for (size_t i = 0; i < verifier_turls.size(); ++i) {
+ const TemplateURL* verifier_turl = verifier_turls.at(i);
+ CHECK(verifier_turl);
+ const TemplateURL* other_turl = other->GetTemplateURLForKeyword(
+ verifier_turl->keyword());
+
+ if (!other_turl) {
+ LOG(ERROR) << "The other service did not contain a TURL with keyword: "
+ << verifier_turl->keyword();
+ return false;
+ }
+ if (!TURLsMatch(verifier_turl, other_turl))
+ return false;
+ }
+
+ return true;
+}
+
bool AllServicesMatch() {
// Use 0 as the baseline.
if (test()->use_verifier() && !ServiceMatchesVerifier(0)) {
@@ -162,25 +175,21 @@ bool AllServicesMatch() {
return true;
}
-// Convenience helper for consistently generating the same keyword for a given
-// seed.
-string16 CreateKeyword(int seed) {
- return ASCIIToUTF16(base::StringPrintf("test%d", seed));
-}
-
-TemplateURL* CreateTestTemplateURL(int seed) {
- return CreateTestTemplateURL(seed, CreateKeyword(seed),
+TemplateURL* CreateTestTemplateURL(Profile* profile, int seed) {
+ return CreateTestTemplateURL(profile, seed, CreateKeyword(seed),
base::StringPrintf("0000-0000-0000-%04d", seed));
}
-TemplateURL* CreateTestTemplateURL(int seed,
+TemplateURL* CreateTestTemplateURL(Profile* profile,
+ int seed,
const string16& keyword,
const std::string& sync_guid) {
- return CreateTestTemplateURL(seed, keyword,
+ return CreateTestTemplateURL(profile, seed, keyword,
base::StringPrintf("http://www.test%d.com/", seed), sync_guid);
}
-TemplateURL* CreateTestTemplateURL(int seed,
+TemplateURL* CreateTestTemplateURL(Profile* profile,
+ int seed,
const string16& keyword,
const std::string& url,
const std::string& sync_guid) {
@@ -194,27 +203,28 @@ TemplateURL* CreateTestTemplateURL(int seed,
data.last_modified = base::Time::FromTimeT(100);
data.prepopulate_id = 999999;
data.sync_guid = sync_guid;
- return new TemplateURL(data);
+ return new TemplateURL(profile, data);
}
-void AddSearchEngine(int profile, int seed) {
- GetServiceForProfile(profile)->Add(CreateTestTemplateURL(seed));
+void AddSearchEngine(int profile_index, int seed) {
+ Profile* profile = test()->GetProfile(profile_index);
+ TemplateURLServiceFactory::GetForProfile(profile)->Add(
+ CreateTestTemplateURL(profile, seed));
if (test()->use_verifier())
- GetVerifierService()->Add(CreateTestTemplateURL(seed));
+ GetVerifierService()->Add(CreateTestTemplateURL(profile, seed));
}
-void EditSearchEngine(int profile,
+void EditSearchEngine(int profile_index,
const string16& keyword,
const string16& short_name,
const string16& new_keyword,
const std::string& url) {
DCHECK(!url.empty());
- const TemplateURL* turl =
- GetServiceForProfile(profile)->GetTemplateURLForKeyword(keyword);
+ TemplateURLService* service = GetServiceForProfile(profile_index);
+ const TemplateURL* turl = service->GetTemplateURLForKeyword(keyword);
EXPECT_TRUE(turl);
ASSERT_FALSE(new_keyword.empty());
- GetServiceForProfile(profile)->ResetTemplateURL(turl, short_name, new_keyword,
- url);
+ service->ResetTemplateURL(turl, short_name, new_keyword, url);
// Make sure we do the same on the verifier.
if (test()->use_verifier()) {
const TemplateURL* verifier_turl =
@@ -225,11 +235,12 @@ void EditSearchEngine(int profile,
}
}
-void DeleteSearchEngineByKeyword(int profile, const string16& keyword) {
- const TemplateURL* turl =
- GetServiceForProfile(profile)->GetTemplateURLForKeyword(keyword);
+void DeleteSearchEngineBySeed(int profile_index, int seed) {
+ TemplateURLService* service = GetServiceForProfile(profile_index);
+ string16 keyword(CreateKeyword(seed));
+ const TemplateURL* turl = service->GetTemplateURLForKeyword(keyword);
EXPECT_TRUE(turl);
- GetServiceForProfile(profile)->Remove(turl);
+ service->Remove(turl);
// Make sure we do the same on the verifier.
if (test()->use_verifier()) {
const TemplateURL* verifier_turl =
@@ -239,12 +250,8 @@ void DeleteSearchEngineByKeyword(int profile, const string16& keyword) {
}
}
-void DeleteSearchEngineBySeed(int profile, int seed) {
- DeleteSearchEngineByKeyword(profile, CreateKeyword(seed));
-}
-
-void ChangeDefaultSearchProvider(int profile, int seed) {
- TemplateURLService* service = GetServiceForProfile(profile);
+void ChangeDefaultSearchProvider(int profile_index, int seed) {
+ TemplateURLService* service = GetServiceForProfile(profile_index);
ASSERT_TRUE(service);
const TemplateURL* turl =
service->GetTemplateURLForKeyword(CreateKeyword(seed));
diff --git a/chrome/browser/sync/test/integration/search_engines_helper.h b/chrome/browser/sync/test/integration/search_engines_helper.h
index f404864..8924853 100644
--- a/chrome/browser/sync/test/integration/search_engines_helper.h
+++ b/chrome/browser/sync/test/integration/search_engines_helper.h
@@ -11,6 +11,7 @@
#include "base/string16.h"
+class Profile;
class TemplateURL;
class TemplateURLService;
@@ -19,64 +20,51 @@ typedef std::map<std::string, const TemplateURL*> GUIDToTURLMap;
namespace search_engines_helper {
// Used to access the search engines within a particular sync profile.
-TemplateURLService* GetServiceForProfile(int index);
+TemplateURLService* GetServiceForProfile(int profile_index);
// Used to access the search engines within the verifier sync profile.
TemplateURLService* GetVerifierService();
-// Returns a mapping of |service|'s TemplateURL collection with their sync
-// GUIDs as keys.
-GUIDToTURLMap CreateGUIDToTURLMap(TemplateURLService* service);
-
-// Returns true iff the major user-visible fields of |turl1| and |turl2| match.
-bool TURLsMatch(const TemplateURL* turl1, const TemplateURL* turl2);
-
// Compared a single TemplateURLService for a given profile to the verifier.
// Retrns true iff their user-visible fields match.
-bool ServiceMatchesVerifier(int profile);
-
-// Returns true iff |other|'s TemplateURLs matches the verifier's TemplateURLs
-// by sync GUIDs and user-visible fields.
-bool ServicesMatch(TemplateURLService* other);
+bool ServiceMatchesVerifier(int profile_index);
// Returns true iff all TemplateURLServices match with the verifier.
bool AllServicesMatch();
// Create a TemplateURL with some test values based on |seed|. The caller owns
// the returned TemplateURL*.
-TemplateURL* CreateTestTemplateURL(int seed);
-TemplateURL* CreateTestTemplateURL(int seed,
+TemplateURL* CreateTestTemplateURL(Profile* profile,
+ int seed,
const string16& keyword,
const std::string& sync_guid);
-TemplateURL* CreateTestTemplateURL(int seed,
+TemplateURL* CreateTestTemplateURL(Profile* profile,
+ int seed,
const string16& keyword,
const std::string& url,
const std::string& sync_guid);
-// Add a search engine based on a seed to the service at index |profile| and the
-// verifier if it is used.
-void AddSearchEngine(int profile, int seed);
+// Add a search engine based on a seed to the service at index |profile_index|
+// and the verifier if it is used.
+void AddSearchEngine(int profile_index, int seed);
-// Retrieves a search engine from the service at index |profile| with original
-// keyword |keyword| and changes its user-visible fields. Does the same to the
-// verifier, if it is used.
-void EditSearchEngine(int profile,
+// Retrieves a search engine from the service at index |profile_index| with
+// original keyword |keyword| and changes its user-visible fields. Does the same
+// to the verifier, if it is used.
+void EditSearchEngine(int profile_index,
const string16& keyword,
const string16& short_name,
const string16& new_keyword,
const std::string& url);
-// Deletes a search engine from the service at index |profile| with original
-// keyword |keyword|. Does the same to the verifier, if it is used.
-void DeleteSearchEngineByKeyword(int profile, const string16& keyword);
-
-// Deletes a search engine from the service at index |profile| which was
+// Deletes a search engine from the service at index |profile_index| which was
// generated by seed |seed|.
-void DeleteSearchEngineBySeed(int profile, int seed);
+void DeleteSearchEngineBySeed(int profile_index, int seed);
-// Change the search engine generated with |seed| in service at index |profile|
-// to be the new default. Does the same to the verifier, if it is used.
-void ChangeDefaultSearchProvider(int profile, int seed);
+// Change the search engine generated with |seed| in service at index
+// |profile_index| to be the new default. Does the same to the verifier, if it
+// is used.
+void ChangeDefaultSearchProvider(int profile_index, int seed);
} // namespace search_engines_helper
diff --git a/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc b/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc
index 67c0106..83ec779 100644
--- a/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc
+++ b/chrome/browser/sync/test/integration/two_client_search_engines_sync_test.cc
@@ -5,20 +5,12 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/search_engines_helper.h"
+#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
-using search_engines_helper::AddSearchEngine;
-using search_engines_helper::AllServicesMatch;
-using search_engines_helper::ChangeDefaultSearchProvider;
-using search_engines_helper::CreateTestTemplateURL;
-using search_engines_helper::DeleteSearchEngineBySeed;
-using search_engines_helper::EditSearchEngine;
-using search_engines_helper::GetServiceForProfile;
-using search_engines_helper::GetVerifierService;
-using search_engines_helper::ServiceMatchesVerifier;
-
class TwoClientSearchEnginesSyncTest : public SyncTest {
public:
TwoClientSearchEnginesSyncTest() : SyncTest(TWO_CLIENT) {}
@@ -31,211 +23,217 @@ class TwoClientSearchEnginesSyncTest : public SyncTest {
// TCM ID - 8898628.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, Add) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 8912240.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, AddMultiple) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
// Add a few entries.
- for (int i = 0; i < 3; ++i) {
- AddSearchEngine(0, i);
- }
+ for (int i = 0; i < 3; ++i)
+ search_engines_helper::AddSearchEngine(0, i);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 9011135.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, Duplicates) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
// Add two entries with the same Name and URL (but different keywords).
// Note that we have to change the GUID of the duplicate.
- AddSearchEngine(0, 0);
- GetServiceForProfile(0)->Add(CreateTestTemplateURL(0,
- ASCIIToUTF16("somethingelse"), "newguid"));
- GetVerifierService()->Add(CreateTestTemplateURL(0,
- ASCIIToUTF16("somethingelse"), "newguid"));
- ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ search_engines_helper::AddSearchEngine(0, 0);
+ Profile* profile = sync_datatype_helper::test()->GetProfile(0);
+ TemplateURLServiceFactory::GetForProfile(profile)->Add(
+ search_engines_helper::CreateTestTemplateURL(profile, 0,
+ ASCIIToUTF16("somethingelse"), "newguid"));
+ search_engines_helper::GetVerifierService()->Add(
+ search_engines_helper::CreateTestTemplateURL(profile, 0,
+ ASCIIToUTF16("somethingelse"), "newguid"));
+ ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 9004201.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateKeyword) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 0);
// Change the keyword.
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- EditSearchEngine(0, ASCIIToUTF16("test0"), ASCIIToUTF16("test0"),
- ASCIIToUTF16("newkeyword"), "http://www.test0.com/");
+ search_engines_helper::EditSearchEngine(0, ASCIIToUTF16("test0"),
+ ASCIIToUTF16("test0"), ASCIIToUTF16("newkeyword"),
+ "http://www.test0.com/");
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 8894859.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateUrl) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
// Change the URL.
- EditSearchEngine(0, ASCIIToUTF16("test0"), ASCIIToUTF16("test0"),
- ASCIIToUTF16("test0"), "http://www.wikipedia.org/q=%s");
+ search_engines_helper::EditSearchEngine(0, ASCIIToUTF16("test0"),
+ ASCIIToUTF16("test0"), ASCIIToUTF16("test0"),
+ "http://www.wikipedia.org/q=%s");
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 8910490.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, UpdateName) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
// Change the short name.
- EditSearchEngine(0, ASCIIToUTF16("test0"), ASCIIToUTF16("New Name"),
- ASCIIToUTF16("test0"), "http://www.test0.com/");
+ search_engines_helper::EditSearchEngine(0, ASCIIToUTF16("test0"),
+ ASCIIToUTF16("New Name"), ASCIIToUTF16("test0"), "http://www.test0.com/");
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 8898660.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, Delete) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- DeleteSearchEngineBySeed(0, 0);
+ search_engines_helper::DeleteSearchEngineBySeed(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 9004196.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, ConflictKeyword) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
DisableVerifier();
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
// Add a different search engine to each client, but make their keywords
// conflict.
- AddSearchEngine(0, 0);
- AddSearchEngine(1, 1);
- const TemplateURL* turl = GetServiceForProfile(1)->GetTemplateURLForKeyword(
- ASCIIToUTF16("test1"));
+ search_engines_helper::AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(1, 1);
+ TemplateURLService* service = search_engines_helper::GetServiceForProfile(1);
+ const TemplateURL* turl =
+ service->GetTemplateURLForKeyword(ASCIIToUTF16("test1"));
EXPECT_TRUE(turl);
- GetServiceForProfile(1)->ResetTemplateURL(turl, turl->short_name(),
- ASCIIToUTF16("test0"), turl->url());
+ service->ResetTemplateURL(turl, turl->short_name(), ASCIIToUTF16("test0"),
+ turl->url());
ASSERT_TRUE(AwaitQuiescence());
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 9004187.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, MergeMultiple) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
DisableVerifier();
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
// Set up some different search engines on each client, with some interesting
// conflicts.
// client0: { SE0, SE1, SE2 }
- for (int i = 0; i < 3; ++i) {
- AddSearchEngine(0, i);
- }
+ for (int i = 0; i < 3; ++i)
+ search_engines_helper::AddSearchEngine(0, i);
// client1: { SE0, SE2, SE3, SE0 + different URL }
- AddSearchEngine(1, 0);
- AddSearchEngine(1, 2);
- AddSearchEngine(1, 3);
- GetServiceForProfile(1)->Add(CreateTestTemplateURL(0,
- ASCIIToUTF16("somethingelse.com"), "http://www.somethingelse.com/",
- "somethingelse"));
+ search_engines_helper::AddSearchEngine(1, 0);
+ search_engines_helper::AddSearchEngine(1, 2);
+ search_engines_helper::AddSearchEngine(1, 3);
+ Profile* profile = sync_datatype_helper::test()->GetProfile(1);
+ TemplateURLServiceFactory::GetForProfile(profile)->Add(
+ search_engines_helper::CreateTestTemplateURL(profile, 0,
+ ASCIIToUTF16("somethingelse.com"), "http://www.somethingelse.com/",
+ "somethingelse"));
ASSERT_TRUE(AwaitQuiescence());
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 8906436.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, DisableSync) {
ASSERT_TRUE(SetupSync());
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
ASSERT_TRUE(GetClient(1)->DisableSyncForAllDatatypes());
- AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 0);
ASSERT_TRUE(
GetClient(0)->AwaitFullSyncCompletion("Added a search engine."));
- ASSERT_TRUE(ServiceMatchesVerifier(0));
- ASSERT_FALSE(ServiceMatchesVerifier(1));
+ ASSERT_TRUE(search_engines_helper::ServiceMatchesVerifier(0));
+ ASSERT_FALSE(search_engines_helper::ServiceMatchesVerifier(1));
ASSERT_TRUE(GetClient(1)->EnableSyncForAllDatatypes());
ASSERT_TRUE(AwaitQuiescence());
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// TCM ID - 8891809.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, SyncDefault) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
// Change the default to the new search engine, sync, and ensure that it
// changed in the second client. AllServicesMatch does a default search
// provider check.
- ChangeDefaultSearchProvider(0, 0);
+ search_engines_helper::ChangeDefaultSearchProvider(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
// Ensure that we can change the search engine and immediately delete it
// without putting the clients out of sync.
IN_PROC_BROWSER_TEST_F(TwoClientSearchEnginesSyncTest, DeleteSyncedDefault) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
- AddSearchEngine(0, 0);
- AddSearchEngine(0, 1);
+ search_engines_helper::AddSearchEngine(0, 0);
+ search_engines_helper::AddSearchEngine(0, 1);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ChangeDefaultSearchProvider(0, 0);
+ search_engines_helper::ChangeDefaultSearchProvider(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
// Change the default on the first client and delete the old default.
- ChangeDefaultSearchProvider(0, 1);
- DeleteSearchEngineBySeed(0, 0);
+ search_engines_helper::ChangeDefaultSearchProvider(0, 1);
+ search_engines_helper::DeleteSearchEngineBySeed(0, 0);
ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
- ASSERT_TRUE(AllServicesMatch());
+ ASSERT_TRUE(search_engines_helper::AllServicesMatch());
}
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 71cc273..4251989 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -1843,7 +1843,7 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin());
// Takes ownership of the TemplateURL.
tab_contents_wrapper->search_engine_tab_helper()->delegate()->
- ConfirmAddSearchProvider(new TemplateURL(data), profile_);
+ ConfirmAddSearchProvider(new TemplateURL(profile_, data), profile_);
}
break;
}
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index 7573efa..f021a8d 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -1655,9 +1655,8 @@ std::vector<GURL> BrowserInit::GetURLsFromCommandLine(
const TemplateURLRef& search_url = default_provider->url_ref();
DCHECK(search_url.SupportsReplacement());
string16 search_term = param.LossyDisplayName().substr(2);
- urls.push_back(GURL(search_url.ReplaceSearchTermsUsingProfile(
- profile, search_term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- string16())));
+ urls.push_back(GURL(search_url.ReplaceSearchTerms(search_term,
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())));
continue;
}
}
diff --git a/chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller_unittest.mm b/chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller_unittest.mm
index 987679d..e05aace 100644
--- a/chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller_unittest.mm
@@ -212,7 +212,7 @@ TEST_F(EditSearchEngineControllerTest, EditTemplateURL) {
std::string urlString = TemplateURLRef::DisplayURLToURLRef(
ASCIIToUTF16("http://foo-bar.com"));
data.SetURL(urlString);
- TemplateURL url(data);
+ TemplateURL url(profile(), data);
FakeEditSearchEngineController *controller =
[[FakeEditSearchEngineController alloc] initWithProfile:profile()
delegate:nil
diff --git a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
index a96634a..d184acd 100644
--- a/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view_browsertest.cc
@@ -264,8 +264,9 @@ class OmniboxViewTest : public InProcessBrowserTest,
}
void SetupSearchEngine() {
+ Profile* profile = browser()->profile();
TemplateURLService* model =
- TemplateURLServiceFactory::GetForProfile(browser()->profile());
+ TemplateURLServiceFactory::GetForProfile(profile);
ASSERT_TRUE(model);
if (!model->loaded()) {
@@ -289,12 +290,12 @@ class OmniboxViewTest : public InProcessBrowserTest,
data.short_name = ASCIIToUTF16(kSearchShortName);
data.SetKeyword(ASCIIToUTF16(kSearchKeyword));
data.SetURL(kSearchURL);
- TemplateURL* template_url = new TemplateURL(data);
+ TemplateURL* template_url = new TemplateURL(profile, data);
model->Add(template_url);
model->SetDefaultSearchProvider(template_url);
data.SetKeyword(ASCIIToUTF16(kSearchKeyword2));
- model->Add(new TemplateURL(data));
+ model->Add(new TemplateURL(profile, data));
}
void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
@@ -939,15 +940,16 @@ class OmniboxViewTest : public InProcessBrowserTest,
AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
ASSERT_TRUE(popup_model);
+ Profile* profile = browser()->profile();
TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(browser()->profile());
+ TemplateURLServiceFactory::GetForProfile(profile);
// Add a non-default substituting keyword.
TemplateURLData data;
data.short_name = ASCIIToUTF16("Search abc");
data.SetKeyword(ASCIIToUTF16(kSearchText));
data.SetURL("http://abc.com/{searchTerms}");
- TemplateURL* template_url = new TemplateURL(data);
+ TemplateURL* template_url = new TemplateURL(profile, data);
template_url_service->Add(template_url);
omnibox_view->SetUserText(string16());
@@ -971,7 +973,7 @@ class OmniboxViewTest : public InProcessBrowserTest,
template_url_service->Remove(template_url);
data.short_name = ASCIIToUTF16("abc");
data.SetURL("http://abc.com/");
- template_url_service->Add(new TemplateURL(data));
+ template_url_service->Add(new TemplateURL(profile, data));
// We always allow exact matches for non-substituting keywords.
ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
diff --git a/chrome/browser/ui/search_engines/edit_search_engine_controller.cc b/chrome/browser/ui/search_engines/edit_search_engine_controller.cc
index 1a82510..ad9ec91 100644
--- a/chrome/browser/ui/search_engines/edit_search_engine_controller.cc
+++ b/chrome/browser/ui/search_engines/edit_search_engine_controller.cc
@@ -43,7 +43,7 @@ bool EditSearchEngineController::IsURLValid(
// TemplateURLRef::IsValid() when its owner is NULL.
TemplateURLData data;
data.SetURL(url);
- TemplateURL t_url(data);
+ TemplateURL t_url(profile_, data);
const TemplateURLRef& template_ref = t_url.url_ref();
if (!template_ref.IsValid())
return false;
@@ -132,7 +132,7 @@ std::string EditSearchEngineController::GetFixedUpURL(
// we need to replace the search terms before testing for the scheme.
TemplateURLData data;
data.SetURL(url);
- TemplateURL t_url(data);
+ TemplateURL t_url(profile_, data);
std::string expanded_url(t_url.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"),
TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
url_parse::Parsed parts;
diff --git a/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc b/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
index 68ef24f..7373089 100644
--- a/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
+++ b/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
@@ -243,7 +243,7 @@ TEST_F(KeywordEditorControllerTest, MutateTemplateURLService) {
TemplateURLData data;
data.short_name = ASCIIToUTF16("b");
data.SetKeyword(ASCIIToUTF16("a"));
- TemplateURL* turl = new TemplateURL(data);
+ TemplateURL* turl = new TemplateURL(profile_.get(), data);
model_->Add(turl);
// Table model should have updated.
diff --git a/chrome/browser/ui/search_engines/search_engine_tab_helper.cc b/chrome/browser/ui/search_engines/search_engine_tab_helper.cc
index 3065749..b10bfac 100644
--- a/chrome/browser/ui/search_engines/search_engine_tab_helper.cc
+++ b/chrome/browser/ui/search_engines/search_engine_tab_helper.cc
@@ -187,5 +187,5 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary(
current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url);
data.safe_for_autoreplace = true;
data.input_encodings.push_back(params.searchable_form_encoding);
- url_service->Add(new TemplateURL(data));
+ url_service->Add(new TemplateURL(profile, data));
}
diff --git a/chrome/browser/ui/search_engines/template_url_table_model.cc b/chrome/browser/ui/search_engines/template_url_table_model.cc
index 3c7a0e7..256a9c1 100644
--- a/chrome/browser/ui/search_engines/template_url_table_model.cc
+++ b/chrome/browser/ui/search_engines/template_url_table_model.cc
@@ -259,7 +259,7 @@ void TemplateURLTableModel::Add(int index,
data.short_name = short_name;
data.SetKeyword(keyword);
data.SetURL(url);
- TemplateURL* turl = new TemplateURL(data);
+ TemplateURL* turl = new TemplateURL(template_url_service_->profile(), data);
template_url_service_->Add(turl);
ModelEntry* entry = new ModelEntry(this, turl);
template_url_service_->AddObserver(this);
diff --git a/chrome/browser/webdata/keyword_table_unittest.cc b/chrome/browser/webdata/keyword_table_unittest.cc
index 6d49701..5af4343 100644
--- a/chrome/browser/webdata/keyword_table_unittest.cc
+++ b/chrome/browser/webdata/keyword_table_unittest.cc
@@ -69,7 +69,7 @@ TEST_F(KeywordTableTest, Keywords) {
keyword.created_by_policy = true;
keyword.usage_count = 32;
keyword.prepopulate_id = 10;
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
KeywordTable::Keywords keywords;
@@ -78,7 +78,7 @@ TEST_F(KeywordTableTest, Keywords) {
const TemplateURLData& restored_keyword = keywords.front();
EXPECT_EQ(keyword.short_name, restored_keyword.short_name);
- EXPECT_EQ(url.keyword(), TemplateURL(restored_keyword).keyword());
+ EXPECT_EQ(url.keyword(), TemplateURL(NULL, restored_keyword).keyword());
EXPECT_EQ(keyword.autogenerate_keyword(),
restored_keyword.autogenerate_keyword());
EXPECT_EQ(keyword.url(), restored_keyword.url());
@@ -133,7 +133,7 @@ TEST_F(KeywordTableTest, KeywordMisc) {
keyword.created_by_policy = true;
keyword.usage_count = 32;
keyword.prepopulate_id = 10;
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
EXPECT_TRUE(keyword_table->SetDefaultSearchProviderID(10));
@@ -160,7 +160,7 @@ TEST_F(KeywordTableTest, DefaultSearchProviderBackup) {
keyword.show_in_default_list = true;
keyword.safe_for_autoreplace = true;
keyword.id = 1;
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
EXPECT_TRUE(keyword_table->SetDefaultSearchProviderID(1));
@@ -172,7 +172,7 @@ TEST_F(KeywordTableTest, DefaultSearchProviderBackup) {
// Backup URL should have an invalid ID.
EXPECT_EQ(kInvalidTemplateURLID, backup.id);
EXPECT_EQ(keyword.short_name, backup.short_name);
- EXPECT_EQ(url.keyword(), TemplateURL(backup).keyword());
+ EXPECT_EQ(url.keyword(), TemplateURL(NULL, backup).keyword());
EXPECT_EQ(keyword.url(), backup.url());
EXPECT_EQ(keyword.favicon_url, backup.favicon_url);
EXPECT_EQ(keyword.suggestions_url, backup.suggestions_url);
@@ -189,7 +189,7 @@ TEST_F(KeywordTableTest, DefaultSearchProviderBackup) {
EXPECT_TRUE(keyword_table->GetDefaultSearchProviderBackup(&backup));
EXPECT_EQ(kInvalidTemplateURLID, backup.id);
EXPECT_EQ(keyword.short_name, backup.short_name);
- EXPECT_EQ(url.keyword(), TemplateURL(backup).keyword());
+ EXPECT_EQ(url.keyword(), TemplateURL(NULL, backup).keyword());
EXPECT_EQ(keyword.url(), backup.url());
EXPECT_EQ(keyword.favicon_url, backup.favicon_url);
EXPECT_EQ(keyword.suggestions_url, backup.suggestions_url);
@@ -228,7 +228,7 @@ TEST_F(KeywordTableTest, DefaultSearchProviderBackup) {
EXPECT_TRUE(keyword_table->GetDefaultSearchProviderBackup(&backup));
EXPECT_EQ(kInvalidTemplateURLID, backup.id);
EXPECT_EQ(keyword.short_name, backup.short_name);
- EXPECT_EQ(url.keyword(), TemplateURL(backup).keyword());
+ EXPECT_EQ(url.keyword(), TemplateURL(NULL, backup).keyword());
EXPECT_EQ(keyword.url(), backup.url());
EXPECT_EQ(keyword.suggestions_url, backup.suggestions_url);
EXPECT_EQ(keyword.favicon_url, backup.favicon_url);
@@ -263,7 +263,7 @@ TEST_F(KeywordTableTest, GetTableContents) {
keyword.date_created = base::Time::UnixEpoch();
keyword.last_modified = base::Time::UnixEpoch();
keyword.sync_guid = "1234-5678-90AB-CDEF";
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
keyword.SetAutogenerateKeyword(true);
@@ -273,7 +273,7 @@ TEST_F(KeywordTableTest, GetTableContents) {
keyword.id = 2;
keyword.prepopulate_id = 5;
keyword.sync_guid = "FEDC-BA09-8765-4321";
- TemplateURL url2(keyword);
+ TemplateURL url2(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url2));
const char kTestContents[] = "1short_namekeywordhttp://favicon.url/"
@@ -306,7 +306,7 @@ TEST_F(KeywordTableTest, GetTableContentsOrdering) {
keyword.date_created = base::Time::UnixEpoch();
keyword.last_modified = base::Time::UnixEpoch();
keyword.sync_guid = "1234-5678-90AB-CDEF";
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
keyword.SetAutogenerateKeyword(true);
@@ -316,7 +316,7 @@ TEST_F(KeywordTableTest, GetTableContentsOrdering) {
keyword.id = 1;
keyword.prepopulate_id = 5;
keyword.sync_guid = "FEDC-BA09-8765-4321";
- TemplateURL url2(keyword);
+ TemplateURL url2(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url2));
const char kTestContents[] = "1short_nameurlhttp://favicon.url/http://url/1"
@@ -346,7 +346,7 @@ TEST_F(KeywordTableTest, UpdateKeyword) {
keyword.show_in_default_list = true;
keyword.safe_for_autoreplace = true;
keyword.id = 1;
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
keyword.originating_url = GURL("http://originating.url/");
@@ -354,7 +354,7 @@ TEST_F(KeywordTableTest, UpdateKeyword) {
keyword.instant_url = "http://instant2/";
keyword.input_encodings.push_back("Shift_JIS");
keyword.prepopulate_id = 5;
- TemplateURL url2(keyword);
+ TemplateURL url2(NULL, keyword);
EXPECT_TRUE(keyword_table->UpdateKeyword(url2));
KeywordTable::Keywords keywords;
@@ -363,7 +363,7 @@ TEST_F(KeywordTableTest, UpdateKeyword) {
const TemplateURLData& restored_keyword = keywords.front();
EXPECT_EQ(keyword.short_name, restored_keyword.short_name);
- EXPECT_EQ(url2.keyword(), TemplateURL(restored_keyword).keyword());
+ EXPECT_EQ(url2.keyword(), TemplateURL(NULL, restored_keyword).keyword());
EXPECT_EQ(keyword.autogenerate_keyword(),
restored_keyword.autogenerate_keyword());
EXPECT_EQ(keyword.suggestions_url, restored_keyword.suggestions_url);
@@ -390,7 +390,7 @@ TEST_F(KeywordTableTest, KeywordWithNoFavicon) {
keyword.SetURL("http://url/");
keyword.safe_for_autoreplace = true;
keyword.id = -100;
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
KeywordTable::Keywords keywords;
@@ -399,7 +399,7 @@ TEST_F(KeywordTableTest, KeywordWithNoFavicon) {
const TemplateURLData& restored_keyword = keywords.front();
EXPECT_EQ(keyword.short_name, restored_keyword.short_name);
- EXPECT_EQ(url.keyword(), TemplateURL(restored_keyword).keyword());
+ EXPECT_EQ(url.keyword(), TemplateURL(NULL, restored_keyword).keyword());
EXPECT_EQ(keyword.favicon_url, restored_keyword.favicon_url);
EXPECT_EQ(keyword.safe_for_autoreplace,
restored_keyword.safe_for_autoreplace);
@@ -416,13 +416,13 @@ TEST_F(KeywordTableTest, SanitizeURLs) {
keyword.SetKeyword(ASCIIToUTF16("legit"));
keyword.SetURL("http://url/");
keyword.id = 1000;
- TemplateURL url(keyword);
+ TemplateURL url(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url));
keyword.short_name = ASCIIToUTF16("bogus");
keyword.SetKeyword(ASCIIToUTF16("bogus"));
keyword.id = 2000;
- TemplateURL url2(keyword);
+ TemplateURL url2(NULL, keyword);
EXPECT_TRUE(keyword_table->AddKeyword(url2));
KeywordTable::Keywords keywords;