summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-07 18:13:33 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-07 18:13:33 +0000
commit8e5c89a5218b2cea6c19a0bbec74a6c51bdf1142 (patch)
tree969478be1a6f6bf4905f7a95c5bdef91a897b1eb /chrome/browser/autocomplete
parentce829a60f9df9ca9655f467cdb87dd4b1604fcc1 (diff)
downloadchromium_src-8e5c89a5218b2cea6c19a0bbec74a6c51bdf1142.zip
chromium_src-8e5c89a5218b2cea6c19a0bbec74a6c51bdf1142.tar.gz
chromium_src-8e5c89a5218b2cea6c19a0bbec74a6c51bdf1142.tar.bz2
Changes TemplateURLModel into TemplateURLService. Changes all access points to go through the newly made ProfileKeyedServiceFactory subclass.
In addition, makes further modifications to the unit testing stuff because the TemplateURL tests change the active TemplateURLService on a profile during the test. BUG=77155 TEST=unit tests R=mirandac Review URL: http://codereview.chromium.org/7056056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc15
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc13
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc10
-rw-r--r--chrome/browser/autocomplete/extension_app_provider.h2
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc19
-rw-r--r--chrome/browser/autocomplete/keyword_provider.h14
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc8
-rw-r--r--chrome/browser/autocomplete/search_provider.cc6
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc12
10 files changed, 58 insertions, 43 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 0ac3f3d..eb6c6a7 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -25,7 +25,8 @@
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
@@ -460,7 +461,8 @@ void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition,
match.type == AutocompleteMatch::SEARCH_HISTORY ||
match.type == AutocompleteMatch::SEARCH_SUGGEST) {
const TemplateURL* default_provider =
- profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
+ TemplateURLServiceFactory::GetForProfile(profile_)->
+ GetDefaultSearchProvider();
if (default_provider && default_provider->url() &&
default_provider->url()->HasGoogleBaseURLs()) {
GoogleURLTracker::GoogleURLSearchCommitted();
@@ -497,10 +499,11 @@ void AutocompleteEditModel::OpenMatch(const AutocompleteMatch& match,
Details<AutocompleteLog>(&log));
}
- TemplateURLModel* template_url_model = profile_->GetTemplateURLModel();
- if (template_url_model && !keyword.empty()) {
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ if (template_url_service && !keyword.empty()) {
const TemplateURL* const template_url =
- template_url_model->GetTemplateURLForKeyword(keyword);
+ template_url_service->GetTemplateURLForKeyword(keyword);
// Special case for extension keywords. Don't increment usage count for
// these.
@@ -523,7 +526,7 @@ void AutocompleteEditModel::OpenMatch(const AutocompleteMatch& match,
if (template_url) {
UserMetrics::RecordAction(UserMetricsAction("AcceptedKeyword"));
- template_url_model->IncrementUsageCount(template_url);
+ template_url_service->IncrementUsageCount(template_url);
}
// NOTE: We purposefully don't increment the usage count of the default
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index 11794f6..ea8492f 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -16,7 +16,8 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "ui/gfx/rect.h"
///////////////////////////////////////////////////////////////////////////////
@@ -143,20 +144,22 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
bool AutocompletePopupModel::GetKeywordForText(const string16& text,
string16* keyword) const {
// Creates keyword_hint first in case |keyword| is a pointer to |text|.
- const string16 keyword_hint(TemplateURLModel::CleanUserInputKeyword(text));
+ const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text));
// Assume we have no keyword until we find otherwise.
keyword->clear();
if (keyword_hint.empty())
return false;
- if (!profile_->GetTemplateURLModel())
+ TemplateURLService* url_service =
+ TemplateURLServiceFactory::GetForProfile(profile_);
+ if (!url_service)
return false;
- profile_->GetTemplateURLModel()->Load();
+ url_service->Load();
// Don't provide a hint if this keyword doesn't support replacement.
const TemplateURL* const template_url =
- profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint);
+ url_service->GetTemplateURLForKeyword(keyword_hint);
if (!TemplateURL::SupportsReplacement(template_url))
return false;
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 7602046..55f335f 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -21,7 +21,7 @@
#include "chrome/browser/defaults.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/ui/gtk/gtk_theme_service.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index 9d0f7c1..5b76bf1 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -12,7 +12,8 @@
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/autocomplete/search_provider.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_browser_process_test.h"
#include "chrome/test/testing_profile.h"
@@ -164,12 +165,13 @@ void AutocompleteProviderTest::ResetControllerWithTestProviders(
void AutocompleteProviderTest::
ResetControllerWithTestProvidersWithKeywordAndSearchProviders() {
- profile_.CreateTemplateURLModel();
+ profile_.CreateTemplateURLService();
// Reset the default TemplateURL.
TemplateURL* default_t_url = new TemplateURL();
default_t_url->SetURL("http://defaultturl/{searchTerms}", 0, 0);
- TemplateURLModel* turl_model = profile_.GetTemplateURLModel();
+ TemplateURLService* turl_model =
+ TemplateURLServiceFactory::GetForProfile(&profile_);
turl_model->Add(default_t_url);
turl_model->SetDefaultSearchProvider(default_t_url);
TemplateURLID default_provider_id = default_t_url->id();
@@ -180,7 +182,7 @@ void AutocompleteProviderTest::
keyword_t_url->set_short_name(ASCIIToUTF16("k"));
keyword_t_url->set_keyword(ASCIIToUTF16("k"));
keyword_t_url->SetURL("http://keyword/{searchTerms}", 0, 0);
- profile_.GetTemplateURLModel()->Add(keyword_t_url);
+ turl_model->Add(keyword_t_url);
ASSERT_NE(0, keyword_t_url->id());
// Forget about any existing providers. The controller owns them and will
diff --git a/chrome/browser/autocomplete/extension_app_provider.h b/chrome/browser/autocomplete/extension_app_provider.h
index ade0123..54480d7 100644
--- a/chrome/browser/autocomplete/extension_app_provider.h
+++ b/chrome/browser/autocomplete/extension_app_provider.h
@@ -25,8 +25,6 @@
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
-class TemplateURLModel;
-
class ExtensionAppProvider : public AutocompleteProvider,
public NotificationObserver {
public:
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index 69a64d8..693d824 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -14,7 +14,8 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "content/common/notification_details.h"
#include "content/common/notification_source.h"
#include "grit/generated_resources.h"
@@ -72,7 +73,7 @@ KeywordProvider::KeywordProvider(ACProviderListener* listener, Profile* profile)
}
KeywordProvider::KeywordProvider(ACProviderListener* listener,
- TemplateURLModel* model)
+ TemplateURLService* model)
: AutocompleteProvider(listener, NULL, "Keyword"),
model_(model),
current_input_id_(0) {
@@ -117,7 +118,7 @@ const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput(
// Make sure the model is loaded. This is cheap and quickly bails out if
// the model is already loaded.
- TemplateURLModel* model = profile->GetTemplateURLModel();
+ TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(profile);
DCHECK(model);
model->Load();
@@ -160,7 +161,10 @@ void KeywordProvider::Start(const AutocompleteInput& input,
// Make sure the model is loaded. This is cheap and quickly bails out if
// the model is already loaded.
- TemplateURLModel* model = profile_ ? profile_->GetTemplateURLModel() : model_;
+ TemplateURLService* model =
+ profile_ ?
+ TemplateURLServiceFactory::GetForProfile(profile_) :
+ model_;
DCHECK(model);
model->Load();
@@ -282,7 +286,7 @@ bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input,
string16 trimmed_input;
TrimWhitespace(input.text(), TRIM_TRAILING, &trimmed_input);
- *keyword = TemplateURLModel::CleanUserInputKeyword(
+ *keyword = TemplateURLService::CleanUserInputKeyword(
SplitKeywordFromInput(trimmed_input, true, remaining_input));
return !keyword->empty();
}
@@ -382,7 +386,7 @@ int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type,
}
AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
- TemplateURLModel* model,
+ TemplateURLService* model,
const string16& keyword,
const AutocompleteInput& input,
size_t prefix_length,
@@ -450,7 +454,8 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
void KeywordProvider::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- TemplateURLModel* model = profile_ ? profile_->GetTemplateURLModel() : model_;
+ TemplateURLService* model =
+ profile_ ? TemplateURLServiceFactory::GetForProfile(profile_) : model_;
const AutocompleteInput& input = extension_suggest_last_input_;
switch (type.value) {
diff --git a/chrome/browser/autocomplete/keyword_provider.h b/chrome/browser/autocomplete/keyword_provider.h
index abfc029..7e4518c 100644
--- a/chrome/browser/autocomplete/keyword_provider.h
+++ b/chrome/browser/autocomplete/keyword_provider.h
@@ -6,7 +6,7 @@
// is responsible for remembering/suggesting user "search keyword queries"
// (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An
// instance of it gets created and managed by the autocomplete controller.
-// KeywordProvider uses a TemplateURLModel to find the set of keywords.
+// KeywordProvider uses a TemplateURLService to find the set of keywords.
//
// For more information on the autocomplete system in general, including how
// the autocomplete controller and autocomplete providers work, see
@@ -24,7 +24,7 @@
class Profile;
class TemplateURL;
-class TemplateURLModel;
+class TemplateURLService;
// Autocomplete provider for keyword input.
//
@@ -53,7 +53,7 @@ class KeywordProvider : public AutocompleteProvider,
public:
KeywordProvider(ACProviderListener* listener, Profile* profile);
// For testing.
- KeywordProvider(ACProviderListener* listener, TemplateURLModel* model);
+ KeywordProvider(ACProviderListener* listener, TemplateURLService* model);
// Returns the replacement string from the user input. The replacement
// string is the portion of the input that does not contain the keyword.
@@ -85,7 +85,7 @@ class KeywordProvider : public AutocompleteProvider,
// after the keyword are placed in |remaining_input|. Returns true if |input|
// is valid and has a keyword. This makes use of SplitKeywordFromInput to
// extract the keyword and remaining string, and uses
- // TemplateURLModel::CleanUserInputKeyword to remove unnecessary characters.
+ // TemplateURLService::CleanUserInputKeyword to remove unnecessary characters.
// In general use this instead of SplitKeywordFromInput.
// Leading whitespace in |*remaining_input| will be trimmed.
static bool ExtractKeywordFromInput(const AutocompleteInput& input,
@@ -122,7 +122,7 @@ class KeywordProvider : public AutocompleteProvider,
// Creates a fully marked-up AutocompleteMatch from the user's input.
// If |relevance| is negative, calculate a relevance based on heuristics.
AutocompleteMatch CreateAutocompleteMatch(
- TemplateURLModel* model,
+ TemplateURLService* model,
const string16& keyword,
const AutocompleteInput& input,
size_t prefix_length,
@@ -138,8 +138,8 @@ class KeywordProvider : public AutocompleteProvider,
const NotificationDetails& details);
// Model for the keywords. This is only non-null when testing, otherwise the
- // TemplateURLModel from the Profile is used.
- TemplateURLModel* model_;
+ // TemplateURLService from the Profile is used.
+ TemplateURLService* model_;
// Identifies the current input state. This is incremented each time the
// autocomplete edit's input changes in any way. It is used to tell whether
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index 511fbe7..f87af2c5 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -7,7 +7,7 @@
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_browser_process_test.h"
#include "googleurl/src/gurl.h"
@@ -35,11 +35,11 @@ class KeywordProviderTest : public TestingBrowserProcessTest {
protected:
scoped_refptr<KeywordProvider> kw_provider_;
- scoped_ptr<TemplateURLModel> model_;
+ scoped_ptr<TemplateURLService> model_;
};
void KeywordProviderTest::SetUp() {
- static const TemplateURLModel::Initializer kTestKeywordData[] = {
+ static const TemplateURLService::Initializer kTestKeywordData[] = {
{ "aa", "aa.com?foo=%s", "aa" },
{ "aaaa", "http://aaaa/?aaaa=1&b=%s&c", "aaaa" },
{ "aaaaa", "%s", "aaaaa" },
@@ -49,7 +49,7 @@ void KeywordProviderTest::SetUp() {
{ "z", "%s=z", "z" },
};
- model_.reset(new TemplateURLModel(kTestKeywordData,
+ model_.reset(new TemplateURLService(kTestKeywordData,
arraysize(kTestKeywordData)));
kw_provider_ = new KeywordProvider(NULL, model_.get());
}
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 79f1b84..546a4a2 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -23,7 +23,8 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/history/in_memory_database.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/common/json_value_serializer.h"
@@ -152,7 +153,8 @@ void SearchProvider::Start(const AutocompleteInput& input,
keyword_provider = NULL;
const TemplateURL* default_provider =
- profile_->GetTemplateURLModel()->GetDefaultSearchProvider();
+ TemplateURLServiceFactory::GetForProfile(profile_)->
+ GetDefaultSearchProvider();
if (!TemplateURL::SupportsReplacement(default_provider))
default_provider = NULL;
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index 681ffb2..4a1263e 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -11,7 +11,8 @@
#include "chrome/browser/history/history.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_browser_process_test.h"
@@ -23,7 +24,7 @@
// The following environment is configured for these tests:
// . The TemplateURL default_t_url_ is set as the default provider.
-// . The TemplateURL keyword_t_url_ is added to the TemplateURLModel. This
+// . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This
// TemplateURL has a valid suggest and search URL.
// . The URL created by using the search term term1_ with default_t_url_ is
// added to history.
@@ -102,9 +103,10 @@ void SearchProviderTest::SetUp() {
// We need both the history service and template url model loaded.
profile_.CreateHistoryService(true, false);
- profile_.CreateTemplateURLModel();
+ profile_.CreateTemplateURLService();
- TemplateURLModel* turl_model = profile_.GetTemplateURLModel();
+ TemplateURLService* turl_model =
+ TemplateURLServiceFactory::GetForProfile(&profile_);
// Reset the default TemplateURL.
default_t_url_ = new TemplateURL();
@@ -132,7 +134,7 @@ void SearchProviderTest::SetUp() {
keyword_t_url_->SetURL("http://keyword/{searchTerms}", 0, 0);
keyword_t_url_->SetSuggestionsURL("http://suggest_keyword/{searchTerms}", 0,
0);
- profile_.GetTemplateURLModel()->Add(keyword_t_url_);
+ turl_model->Add(keyword_t_url_);
ASSERT_NE(0, keyword_t_url_->id());
// Add a page and search term for keyword_t_url_.