summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.cc8
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.h8
-rwxr-xr-xchrome/browser/autocomplete/autocomplete_classifier_factory.cc55
-rwxr-xr-xchrome/browser/autocomplete/autocomplete_classifier_factory.h41
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc12
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc8
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc6
-rw-r--r--chrome/browser/autocomplete/search_provider.cc4
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc7
-rw-r--r--chrome/browser/browser_process_impl.h1
-rw-r--r--chrome/browser/extensions/api/omnibox/omnibox_apitest.cc20
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc4
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h1
-rw-r--r--chrome/browser/profiles/profile.h6
-rw-r--r--chrome/browser/profiles/profile_impl.cc6
-rw-r--r--chrome/browser/profiles/profile_impl.h2
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.cc10
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.h4
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc3
-rw-r--r--chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller_unittest.mm22
-rw-r--r--chrome/browser/ui/cocoa/cocoa_profile_test.mm10
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm3
-rw-r--r--chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm3
-rw-r--r--chrome/browser/ui/gtk/gtk_util.cc5
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc3
-rw-r--r--chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc3
-rw-r--r--chrome/browser/ui/views/first_run_bubble_unittest.cc3
-rw-r--r--chrome/browser/ui/views/frame/browser_root_view.cc6
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/test/base/testing_profile.cc33
-rw-r--r--chrome/test/base/testing_profile.h17
31 files changed, 193 insertions, 123 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.cc b/chrome/browser/autocomplete/autocomplete_classifier.cc
index f3cffd4..53ef429 100644
--- a/chrome/browser/autocomplete/autocomplete_classifier.cc
+++ b/chrome/browser/autocomplete/autocomplete_classifier.cc
@@ -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.
@@ -15,6 +15,8 @@ AutocompleteClassifier::AutocompleteClassifier(Profile* profile)
}
AutocompleteClassifier::~AutocompleteClassifier() {
+ // We should only reach here after Shutdown() has been called.
+ DCHECK(!controller_.get());
}
void AutocompleteClassifier::Classify(const string16& text,
@@ -40,3 +42,7 @@ void AutocompleteClassifier::Classify(const string16& text,
if (alternate_nav_url)
*alternate_nav_url = result.alternate_nav_url();
}
+
+void AutocompleteClassifier::Shutdown() {
+ controller_.reset();
+}
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.h b/chrome/browser/autocomplete/autocomplete_classifier.h
index a089cef..d9d2e5e 100644
--- a/chrome/browser/autocomplete/autocomplete_classifier.h
+++ b/chrome/browser/autocomplete/autocomplete_classifier.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.
@@ -11,13 +11,14 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
class AutocompleteController;
struct AutocompleteMatch;
class GURL;
class Profile;
-class AutocompleteClassifier {
+class AutocompleteClassifier : public ProfileKeyedService {
public:
explicit AutocompleteClassifier(Profile* profile);
virtual ~AutocompleteClassifier();
@@ -44,6 +45,9 @@ class AutocompleteClassifier {
GURL* alternate_nav_url);
private:
+ // ProfileKeyedService:
+ virtual void Shutdown() OVERRIDE;
+
scoped_ptr<AutocompleteController> controller_;
// Are we currently in Classify? Used to verify Classify isn't invoked
diff --git a/chrome/browser/autocomplete/autocomplete_classifier_factory.cc b/chrome/browser/autocomplete/autocomplete_classifier_factory.cc
new file mode 100755
index 0000000..30557fa
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_classifier_factory.cc
@@ -0,0 +1,55 @@
+// 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.
+
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
+
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/extensions/extension_system_factory.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+
+
+// static
+AutocompleteClassifier* AutocompleteClassifierFactory::GetForProfile(
+ Profile* profile) {
+ return static_cast<AutocompleteClassifier*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+// static
+AutocompleteClassifierFactory* AutocompleteClassifierFactory::GetInstance() {
+ return Singleton<AutocompleteClassifierFactory>::get();
+}
+
+// static
+ProfileKeyedService* AutocompleteClassifierFactory::BuildInstanceFor(
+ Profile* profile) {
+ return new AutocompleteClassifier(profile);
+}
+
+AutocompleteClassifierFactory::AutocompleteClassifierFactory()
+ : ProfileKeyedServiceFactory("AutocompleteClassifier",
+ ProfileDependencyManager::GetInstance()) {
+ DependsOn(ExtensionSystemFactory::GetInstance());
+ DependsOn(TemplateURLServiceFactory::GetInstance());
+ // TODO(pkasting): Uncomment these once they exist.
+ // DependsOn(PrefServiceFactory::GetInstance());
+ // DependsOn(ShortcutsBackendFactory::GetInstance());
+}
+
+AutocompleteClassifierFactory::~AutocompleteClassifierFactory() {
+}
+
+bool AutocompleteClassifierFactory::ServiceRedirectedInIncognito() {
+ return true;
+}
+
+bool AutocompleteClassifierFactory::ServiceIsNULLWhileTesting() {
+ return true;
+}
+
+ProfileKeyedService* AutocompleteClassifierFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ return BuildInstanceFor(profile);
+}
diff --git a/chrome/browser/autocomplete/autocomplete_classifier_factory.h b/chrome/browser/autocomplete/autocomplete_classifier_factory.h
new file mode 100755
index 0000000..70cd19c
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_classifier_factory.h
@@ -0,0 +1,41 @@
+// 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.
+
+#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_FACTORY_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_FACTORY_H_
+
+#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+
+class AutocompleteClassifier;
+class Profile;
+
+// Singleton that owns all AutocompleteClassifiers and associates them with
+// Profiles.
+class AutocompleteClassifierFactory : public ProfileKeyedServiceFactory {
+ public:
+ // Returns the AutocompleteClassifier for |profile|.
+ static AutocompleteClassifier* GetForProfile(Profile* profile);
+
+ static AutocompleteClassifierFactory* GetInstance();
+
+ static ProfileKeyedService* BuildInstanceFor(Profile* profile);
+
+ private:
+ friend struct DefaultSingletonTraits<AutocompleteClassifierFactory>;
+
+ AutocompleteClassifierFactory();
+ virtual ~AutocompleteClassifierFactory();
+
+ // ProfileKeyedServiceFactory:
+ virtual bool ServiceRedirectedInIncognito() OVERRIDE;
+ virtual bool ServiceIsNULLWhileTesting() OVERRIDE;
+ virtual ProfileKeyedService* BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(AutocompleteClassifierFactory);
+};
+
+#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_FACTORY_H_
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 9067077..b313f352 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -13,6 +13,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
@@ -379,8 +380,8 @@ void AutocompleteEditModel::AdjustTextForCopy(int sel_min,
// the user is probably holding down control to cause the copy, which will
// screw up our calculation of the desired_tld.
AutocompleteMatch match;
- profile_->GetAutocompleteClassifier()->Classify(*text, string16(),
- KeywordIsSelected(), true, &match, NULL);
+ AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(*text,
+ string16(), KeywordIsSelected(), true, &match, NULL);
if (match.transition != content::PAGE_TRANSITION_TYPED)
return;
*url = match.destination_url;
@@ -459,8 +460,9 @@ bool AutocompleteEditModel::CanPasteAndGo(const string16& text) const {
if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL))
return false;
- profile_->GetAutocompleteClassifier()->Classify(text, string16(),
- false, false, &paste_and_go_match_, &paste_and_go_alternate_nav_url_);
+ AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
+ string16(), false, false, &paste_and_go_match_,
+ &paste_and_go_alternate_nav_url_);
return paste_and_go_match_.destination_url.is_valid();
}
@@ -1013,7 +1015,7 @@ void AutocompleteEditModel::GetInfoForCurrentText(
if (popup_->IsOpen() || query_in_progress()) {
InfoForCurrentSelection(match, alternate_nav_url);
} else {
- profile_->GetAutocompleteClassifier()->Classify(
+ AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(
UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(),
KeywordIsSelected(), true, match, alternate_nav_url);
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
index 37544d9..acd2b68 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
@@ -3,7 +3,9 @@
// found in the LICENSE file.
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
@@ -162,8 +164,10 @@ TEST_F(AutocompleteEditTest, AdjustTextForCopy) {
// NOTE: The TemplateURLService must be created before the
// AutocompleteClassifier so that the SearchProvider gets a non-NULL
// TemplateURLService at construction time.
- profile.CreateTemplateURLService();
- profile.CreateAutocompleteClassifier();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile, &TemplateURLServiceFactory::BuildInstanceFor);
+ AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile, &AutocompleteClassifierFactory::BuildInstanceFor);
AutocompleteEditModel model(&view, &controller, &profile);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input); ++i) {
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index c6f0820..2783f74 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -179,7 +179,8 @@ void AutocompleteProviderTest::ResetControllerWithTestProviders(
void AutocompleteProviderTest::
ResetControllerWithTestProvidersWithKeywordAndSearchProviders() {
- profile_.CreateTemplateURLService();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
// Reset the default TemplateURL.
TemplateURLData data;
@@ -218,7 +219,8 @@ void AutocompleteProviderTest::
void AutocompleteProviderTest::
ResetControllerWithKeywordProvider() {
- profile_.CreateTemplateURLService();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
TemplateURLService* turl_model =
TemplateURLServiceFactory::GetForProfile(&profile_);
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index cfa632d..419fdfe 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -18,6 +18,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_field_trial.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
@@ -846,7 +847,8 @@ SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
bool input_multiple_words,
const string16& input_text,
bool is_keyword) {
- AutocompleteClassifier* classifier = profile_->GetAutocompleteClassifier();
+ AutocompleteClassifier* classifier =
+ AutocompleteClassifierFactory::GetForProfile(profile_);
SuggestResults scored_results;
for (HistoryResults::const_iterator i(results.begin()); i != results.end();
++i) {
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index 5b702d5..3524fb3 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -9,6 +9,7 @@
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -118,7 +119,8 @@ void SearchProviderTest::SetUp() {
// We need both the history service and template url model loaded.
profile_.CreateHistoryService(true, false);
- profile_.CreateTemplateURLService();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
TemplateURLService* turl_model =
TemplateURLServiceFactory::GetForProfile(&profile_);
@@ -488,7 +490,8 @@ TEST_F(SearchProviderTest, DifferingText) {
}
TEST_F(SearchProviderTest, DontAutocompleteURLLikeTerms) {
- profile_.CreateAutocompleteClassifier();
+ AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
GURL url = AddSearchToHistory(default_t_url_,
ASCIIToUTF16("docs.google.com"), 1);
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 101fe84..869bd8f 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -126,7 +126,6 @@ class BrowserProcessImpl : public BrowserProcess,
#if defined(OS_CHROMEOS)
void InitializeWebSocketProxyThread();
#endif
- void CreateTemplateURLService();
void CreateProfileManager();
void CreateLocalState();
void CreateViewedPageTracker();
diff --git a/chrome/browser/extensions/api/omnibox/omnibox_apitest.cc b/chrome/browser/extensions/api/omnibox/omnibox_apitest.cc
index 774fdec..f136a4d 100644
--- a/chrome/browser/extensions/api/omnibox/omnibox_apitest.cc
+++ b/chrome/browser/extensions/api/omnibox/omnibox_apitest.cc
@@ -56,17 +56,6 @@ class OmniboxApiTest : public ExtensionApiTest {
autocomplete_controller();
}
- void WaitForTemplateURLServiceToLoad() {
- ui_test_utils::WindowedNotificationObserver loaded_observer(
- chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
- content::NotificationService::AllSources());
- TemplateURLService* model =
- TemplateURLServiceFactory::GetForProfile(browser()->profile());
- model->Load();
- if (!model->loaded())
- loaded_observer.Wait();
- }
-
// TODO(phajdan.jr): Get rid of this wait-in-a-loop pattern.
void WaitForAutocompleteDone(AutocompleteController* controller) {
while (!controller->done()) {
@@ -83,7 +72,8 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, DISABLED_Basic) {
// The results depend on the TemplateURLService being loaded. Make sure it is
// loaded so that the autocomplete results are consistent.
- WaitForTemplateURLServiceToLoad();
+ ui_test_utils::WaitForTemplateURLServiceToLoad(
+ TemplateURLServiceFactory::GetForProfile(browser()->profile()));
LocationBar* location_bar = GetLocationBar(browser());
AutocompleteController* autocomplete_controller =
@@ -197,7 +187,8 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, DISABLED_PopupStaysClosed) {
// The results depend on the TemplateURLService being loaded. Make sure it is
// loaded so that the autocomplete results are consistent.
- WaitForTemplateURLServiceToLoad();
+ ui_test_utils::WaitForTemplateURLServiceToLoad(
+ TemplateURLServiceFactory::GetForProfile(browser()->profile()));
LocationBar* location_bar = GetLocationBar(browser());
OmniboxView* omnibox_view = location_bar->GetLocationEntry();
@@ -251,7 +242,8 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, DISABLED_IncognitoSplitMode) {
// The results depend on the TemplateURLService being loaded. Make sure it is
// loaded so that the autocomplete results are consistent.
- WaitForTemplateURLServiceToLoad();
+ ui_test_utils::WaitForTemplateURLServiceToLoad(
+ TemplateURLServiceFactory::GetForProfile(browser()->profile()));
LocationBar* location_bar = GetLocationBar(incognito_browser);
AutocompleteController* autocomplete_controller =
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 96564a6..93d0d33 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -238,10 +238,6 @@ FaviconService* OffTheRecordProfileImpl::GetFaviconService(
return NULL;
}
-AutocompleteClassifier* OffTheRecordProfileImpl::GetAutocompleteClassifier() {
- return profile_->GetAutocompleteClassifier();
-}
-
history::ShortcutsBackend* OffTheRecordProfileImpl::GetShortcutsBackend() {
return NULL;
}
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index f7c1a66..a23b028 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -50,7 +50,6 @@ class OffTheRecordProfileImpl : public Profile,
virtual HistoryService* GetHistoryService(ServiceAccessType sat) OVERRIDE;
virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE;
virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE;
- virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE;
virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE;
virtual policy::PolicyService* GetPolicyService() OVERRIDE;
virtual PrefService* GetPrefs() OVERRIDE;
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index d84c9a0..a39d31f 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -17,7 +17,6 @@
#include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h"
#include "content/public/browser/browser_context.h"
-class AutocompleteClassifier;
class BookmarkModel;
class ChromeAppCacheService;
class ChromeURLDataManager;
@@ -255,11 +254,6 @@ class Profile : public content::BrowserContext {
// doesn't already exist.
virtual HistoryService* GetHistoryServiceWithoutCreating() = 0;
- // Retrieves a pointer to the AutocompleteClassifier associated with this
- // profile. The AutocompleteClassifier is lazily created the first time that
- // this method is called.
- virtual AutocompleteClassifier* GetAutocompleteClassifier() = 0;
-
// Returns the ShortcutsBackend for this profile. This is owned by
// the Profile and created on the first call. Callers that outlive the life of
// this profile need to be sure they refcount the returned value.
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index cd8fe00..74c2984 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -775,12 +775,6 @@ HistoryService* ProfileImpl::GetHistoryServiceWithoutCreating() {
return HistoryServiceFactory::GetForProfileIfExists(this).get();
}
-AutocompleteClassifier* ProfileImpl::GetAutocompleteClassifier() {
- if (!autocomplete_classifier_.get())
- autocomplete_classifier_.reset(new AutocompleteClassifier(this));
- return autocomplete_classifier_.get();
-}
-
history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() {
// This is called on one thread only - UI, so no magic is needed to protect
// against the multiple concurrent calls.
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index 969cf47..400c550 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -88,7 +88,6 @@ class ProfileImpl : public Profile,
virtual GAIAInfoUpdateService* GetGAIAInfoUpdateService() OVERRIDE;
virtual HistoryService* GetHistoryService(ServiceAccessType sat) OVERRIDE;
virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE;
- virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE;
virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE;
virtual policy::PolicyService* GetPolicyService() OVERRIDE;
virtual PrefService* GetPrefs() OVERRIDE;
@@ -223,7 +222,6 @@ class ProfileImpl : public Profile,
geolocation_permission_context_;
scoped_ptr<GAIAInfoUpdateService> gaia_info_update_service_;
scoped_ptr<FaviconService> favicon_service_;
- scoped_ptr<AutocompleteClassifier> autocomplete_classifier_;
scoped_refptr<history::ShortcutsBackend> shortcuts_backend_;
bool favicon_service_created_;
diff --git a/chrome/browser/search_engines/template_url_service_factory.cc b/chrome/browser/search_engines/template_url_service_factory.cc
index 90cc93a..42ad3e4 100644
--- a/chrome/browser/search_engines/template_url_service_factory.cc
+++ b/chrome/browser/search_engines/template_url_service_factory.cc
@@ -11,15 +11,23 @@
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/pref_names.h"
+// static
TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) {
return static_cast<TemplateURLService*>(
GetInstance()->GetServiceForProfile(profile, true));
}
+// static
TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() {
return Singleton<TemplateURLServiceFactory>::get();
}
+// static
+ProfileKeyedService* TemplateURLServiceFactory::BuildInstanceFor(
+ Profile* profile) {
+ return new TemplateURLService(profile);
+}
+
TemplateURLServiceFactory::TemplateURLServiceFactory()
: ProfileKeyedServiceFactory("TemplateURLServiceFactory",
ProfileDependencyManager::GetInstance()) {
@@ -33,7 +41,7 @@ TemplateURLServiceFactory::~TemplateURLServiceFactory() {}
ProfileKeyedService* TemplateURLServiceFactory::BuildServiceInstanceFor(
Profile* profile) const {
- return new TemplateURLService(profile);
+ return BuildInstanceFor(profile);
}
void TemplateURLServiceFactory::RegisterUserPrefs(PrefService* prefs) {
diff --git a/chrome/browser/search_engines/template_url_service_factory.h b/chrome/browser/search_engines/template_url_service_factory.h
index f122281..c0a248b 100644
--- a/chrome/browser/search_engines/template_url_service_factory.h
+++ b/chrome/browser/search_engines/template_url_service_factory.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.
@@ -21,6 +21,8 @@ class TemplateURLServiceFactory : public ProfileKeyedServiceFactory {
static TemplateURLServiceFactory* GetInstance();
+ static ProfileKeyedService* BuildInstanceFor(Profile* profile);
+
private:
friend struct DefaultSingletonTraits<TemplateURLServiceFactory>;
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index dc00303..73fff96 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -17,6 +17,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_process.h"
@@ -903,7 +904,7 @@ void RenderViewContextMenu::AppendSearchProvider() {
ASCIIToUTF16(" "), &params_.selection_text);
AutocompleteMatch match;
- profile_->GetAutocompleteClassifier()->Classify(
+ AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(
params_.selection_text, string16(), false, false, &match, NULL);
selection_navigation_url_ = match.destination_url;
if (!selection_navigation_url_.is_valid())
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 e05aace..f3dab55 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
@@ -7,6 +7,7 @@
#include "base/memory/scoped_nsobject.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "chrome/test/base/testing_profile.h"
#include "grit/generated_resources.h"
@@ -53,16 +54,17 @@ namespace {
class EditSearchEngineControllerTest : public CocoaProfileTest {
public:
- virtual void SetUp() {
- CocoaProfileTest::SetUp();
- ASSERT_TRUE(profile());
-
- profile()->CreateTemplateURLService();
- controller_ =
- [[FakeEditSearchEngineController alloc] initWithProfile:profile()
- delegate:nil
- templateURL:nil];
- }
+ virtual void SetUp() {
+ CocoaProfileTest::SetUp();
+ ASSERT_TRUE(profile());
+
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile(), &TemplateURLServiceFactory::BuildInstanceFor);
+ controller_ =
+ [[FakeEditSearchEngineController alloc] initWithProfile:profile()
+ delegate:nil
+ templateURL:nil];
+ }
virtual void TearDown() {
// Force the window to load so we hit |-awakeFromNib| to register as the
diff --git a/chrome/browser/ui/cocoa/cocoa_profile_test.mm b/chrome/browser/ui/cocoa/cocoa_profile_test.mm
index e0d5b2e..b1b691e 100644
--- a/chrome/browser/ui/cocoa/cocoa_profile_test.mm
+++ b/chrome/browser/ui/cocoa/cocoa_profile_test.mm
@@ -1,10 +1,12 @@
-// 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.
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/test/base/testing_browser_process.h"
#include "content/public/test/test_browser_thread.h"
@@ -62,8 +64,10 @@ void CocoaProfileTest::SetUp() {
// platforms use a stub |BrowserWindow| and thus don't need to do
// this.
// http://crbug.com/39725
- profile_->CreateAutocompleteClassifier();
- profile_->CreateTemplateURLService();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_, &TemplateURLServiceFactory::BuildInstanceFor);
+ AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_, &AutocompleteClassifierFactory::BuildInstanceFor);
browser_.reset(new Browser(Browser::TYPE_TABBED, profile_));
ASSERT_TRUE(browser_.get());
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
index 050cd21..323d655 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
@@ -17,6 +17,7 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/extensions/extension_tab_helper.h"
@@ -1950,7 +1951,7 @@ private:
// If the input is plain text, classify the input and make the URL.
AutocompleteMatch match;
- browser_->profile()->GetAutocompleteClassifier()->Classify(
+ AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify(
base::SysNSStringToUTF16(text), string16(), false, false, &match, NULL);
GURL url(match.destination_url);
diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm
index 0265fbd..9b93756 100644
--- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm
+++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm
@@ -15,6 +15,7 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -777,7 +778,7 @@ class NotificationBridge : public content::NotificationObserver {
// If the input is plain text, classify the input and make the URL.
AutocompleteMatch match;
- browser_->profile()->GetAutocompleteClassifier()->Classify(
+ AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify(
base::SysNSStringToUTF16(text), string16(), false, false, &match, NULL);
GURL url(match.destination_url);
diff --git a/chrome/browser/ui/gtk/gtk_util.cc b/chrome/browser/ui/gtk/gtk_util.cc
index 9787664..a95e5d5 100644
--- a/chrome/browser/ui/gtk/gtk_util.cc
+++ b/chrome/browser/ui/gtk/gtk_util.cc
@@ -18,6 +18,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/event_disposition.h"
@@ -1003,8 +1004,8 @@ bool URLFromPrimarySelection(Profile* profile, GURL* url) {
// Use autocomplete to clean up the text, going so far as to turn it into
// a search query if necessary.
AutocompleteMatch match;
- profile->GetAutocompleteClassifier()->Classify(UTF8ToUTF16(selection_text),
- string16(), false, false, &match, NULL);
+ AutocompleteClassifierFactory::GetForProfile(profile)->Classify(
+ UTF8ToUTF16(selection_text), string16(), false, false, &match, NULL);
g_free(selection_text);
if (!match.destination_url.is_valid())
return false;
diff --git a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
index 4205bba..ac4d846 100644
--- a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
@@ -15,6 +15,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
@@ -1770,7 +1771,7 @@ bool TabStripGtk::CompleteDrop(const guchar* data, bool is_plain_text) {
GURL url;
if (is_plain_text) {
AutocompleteMatch match;
- model_->profile()->GetAutocompleteClassifier()->Classify(
+ AutocompleteClassifierFactory::GetForProfile(model_->profile())->Classify(
UTF8ToUTF16(reinterpret_cast<const char*>(data)), string16(),
false, false, &match, NULL);
url = match.destination_url;
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 276f00d..81ac765 100644
--- a/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
+++ b/chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc
@@ -108,7 +108,8 @@ void KeywordEditorControllerTest::Init(bool simulate_load_failure) {
// the profile is.
controller_.reset();
profile_.reset(new TestingProfile());
- profile_->CreateTemplateURLService();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_.get(), &TemplateURLServiceFactory::BuildInstanceFor);
model_ = TemplateURLServiceFactory::GetForProfile(profile_.get());
if (simulate_load_failure)
diff --git a/chrome/browser/ui/views/first_run_bubble_unittest.cc b/chrome/browser/ui/views/first_run_bubble_unittest.cc
index e479bd5..7bf3cf6 100644
--- a/chrome/browser/ui/views/first_run_bubble_unittest.cc
+++ b/chrome/browser/ui/views/first_run_bubble_unittest.cc
@@ -35,7 +35,8 @@ FirstRunBubbleTest::~FirstRunBubbleTest() {}
void FirstRunBubbleTest::SetUp() {
ViewsTestBase::SetUp();
- profile_.CreateTemplateURLService();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
TemplateURLService* turl_model =
TemplateURLServiceFactory::GetForProfile(&profile_);
turl_model->Load();
diff --git a/chrome/browser/ui/views/frame/browser_root_view.cc b/chrome/browser/ui/views/frame/browser_root_view.cc
index 1c7a4f2..3450caf 100644
--- a/chrome/browser/ui/views/frame/browser_root_view.cc
+++ b/chrome/browser/ui/views/frame/browser_root_view.cc
@@ -7,6 +7,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
@@ -160,8 +161,9 @@ bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data,
text = AutocompleteMatch::SanitizeString(text);
AutocompleteMatch match;
- browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify(
- text, string16(), false, false, &match, NULL);
+ AutocompleteClassifierFactory::GetForProfile(
+ browser_view_->browser()->profile())->Classify(text, string16(), false,
+ false, &match, NULL);
if (!match.destination_url.is_valid())
return false;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 8b75d49..2d58654 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -110,6 +110,8 @@
'browser/autocomplete/autocomplete.h',
'browser/autocomplete/autocomplete_classifier.cc',
'browser/autocomplete/autocomplete_classifier.h',
+ 'browser/autocomplete/autocomplete_classifier_factory.cc',
+ 'browser/autocomplete/autocomplete_classifier_factory.h',
'browser/autocomplete/autocomplete_controller_delegate.h',
'browser/autocomplete/autocomplete_edit.cc',
'browser/autocomplete/autocomplete_edit.h',
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index cf794f6..262626d 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -38,9 +38,8 @@
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/protector/protector_service_factory.h"
#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
-#include "chrome/browser/search_engines/template_url_service.h"
-#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
+#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
@@ -357,10 +356,6 @@ void TestingProfile::CreateBookmarkModel(bool delete_file) {
}
}
-void TestingProfile::CreateAutocompleteClassifier() {
- autocomplete_classifier_.reset(new AutocompleteClassifier(this));
-}
-
void TestingProfile::CreateProtocolHandlerRegistry() {
protocol_handler_registry_ = new ProtocolHandlerRegistry(this,
new ProtocolHandlerRegistry::Delegate());
@@ -400,28 +395,6 @@ void TestingProfile::BlockUntilTopSitesLoaded() {
top_sites_loaded_observer.Wait();
}
-static ProfileKeyedService* BuildTemplateURLService(Profile* profile) {
- return new TemplateURLService(profile);
-}
-
-void TestingProfile::CreateTemplateURLService() {
- TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- this, BuildTemplateURLService);
-}
-
-void TestingProfile::BlockUntilTemplateURLServiceLoaded() {
- TemplateURLService* turl_model =
- TemplateURLServiceFactory::GetForProfile(this);
- if (turl_model->loaded())
- return;
-
- ui_test_utils::WindowedNotificationObserver turl_service_load_observer(
- chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
- content::NotificationService::AllSources());
- turl_model->Load();
- turl_service_load_observer.Wait();
-}
-
FilePath TestingProfile::GetPath() {
return profile_path_;
}
@@ -516,10 +489,6 @@ net::CookieMonster* TestingProfile::GetCookieMonster() {
GetCookieMonster();
}
-AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() {
- return autocomplete_classifier_.get();
-}
-
policy::PolicyService* TestingProfile::GetPolicyService() {
if (!policy_service_.get()) {
#if defined(ENABLE_CONFIGURATION_POLICY)
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index ff9bf7b..ceba5cd 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -31,7 +31,6 @@ namespace quota {
class SpecialStoragePolicy;
}
-class AutocompleteClassifier;
class CommandLine;
class ExtensionPrefs;
class ExtensionSpecialStoragePolicy;
@@ -95,10 +94,6 @@ class TestingProfile : public Profile {
// BlockUntilBookmarkModelLoaded.
void CreateBookmarkModel(bool delete_file);
- // Creates an AutocompleteClassifier. If not invoked the
- // AutocompleteClassifier is NULL.
- void CreateAutocompleteClassifier();
-
// Creates a ProtocolHandlerRegistry. If not invoked the protocol handler
// registry is NULL.
void CreateProtocolHandlerRegistry();
@@ -113,13 +108,6 @@ class TestingProfile : public Profile {
// Blocks until TopSites finishes loading.
void BlockUntilTopSitesLoaded();
- // Creates a TemplateURLService. If not invoked, the TemplateURLService is
- // NULL.
- void CreateTemplateURLService();
-
- // Blocks until TempalteURLService finishes loading.
- void BlockUntilTemplateURLServiceLoaded();
-
TestingPrefService* GetTestingPrefService();
// content::BrowserContext
@@ -172,7 +160,6 @@ class TestingProfile : public Profile {
// this by calling CreateRequestContext(). See the note at GetRequestContext
// for more information.
net::CookieMonster* GetCookieMonster();
- virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE;
virtual history::ShortcutsBackend* GetShortcutsBackend() OVERRIDE;
virtual policy::PolicyService* GetPolicyService() OVERRIDE;
// Sets the profile's PrefService. If a pref service hasn't been explicitly
@@ -272,10 +259,6 @@ class TestingProfile : public Profile {
// is invoked.
scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
- // The AutocompleteClassifier. Only created if CreateAutocompleteClassifier
- // is invoked.
- scoped_ptr<AutocompleteClassifier> autocomplete_classifier_;
-
// The policy service. Lazily created as a stub.
scoped_ptr<policy::PolicyService> policy_service_;