summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc2
-rw-r--r--chrome/browser/browser_process.h2
-rw-r--r--chrome/browser/browser_process_impl.cc28
-rw-r--r--chrome/browser/browser_process_impl.h3
-rw-r--r--chrome/browser/chrome_browser_main.cc17
-rw-r--r--chrome/browser/google/google_url_tracker.cc53
-rw-r--r--chrome/browser/google/google_url_tracker.h40
-rw-r--r--chrome/browser/google/google_url_tracker_factory.cc54
-rw-r--r--chrome/browser/google/google_url_tracker_factory.h41
-rw-r--r--chrome/browser/google/google_url_tracker_unittest.cc25
-rw-r--r--chrome/browser/google/google_util.cc4
-rw-r--r--chrome/browser/google/google_util.h7
-rw-r--r--chrome/browser/prefs/browser_prefs.cc28
-rw-r--r--chrome/browser/prefs/browser_prefs.h6
-rw-r--r--chrome/browser/profiles/profile_dependency_manager.cc36
-rw-r--r--chrome/browser/profiles/profile_impl.cc6
-rw-r--r--chrome/browser/search_engines/search_host_to_urls_map_unittest.cc6
-rw-r--r--chrome/browser/search_engines/search_provider_install_data.cc18
-rw-r--r--chrome/browser/search_engines/search_terms_data.cc10
-rw-r--r--chrome/browser/search_engines/search_terms_data.h12
-rw-r--r--chrome/browser/search_engines/template_url.cc11
-rw-r--r--chrome/browser/search_engines/template_url_service.cc23
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.cc2
-rw-r--r--chrome/browser/search_engines/template_url_service_sync_unittest.cc6
-rw-r--r--chrome/browser/search_engines/template_url_service_test_util.cc4
-rw-r--r--chrome/browser/ui/alternate_error_tab_observer.cc4
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/common/chrome_notification_types.h12
-rw-r--r--chrome/test/base/testing_browser_process.cc10
-rw-r--r--chrome/test/base/testing_browser_process.h4
30 files changed, 289 insertions, 187 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 9882fb7..7190cdb 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -498,7 +498,7 @@ void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition,
const TemplateURL* template_url = match.GetTemplateURL(profile_);
if (template_url && template_url->url_ref().HasGoogleBaseURLs())
- GoogleURLTracker::GoogleURLSearchCommitted();
+ GoogleURLTracker::GoogleURLSearchCommitted(profile_);
view_->OpenMatch(match, disposition, alternate_nav_url,
AutocompletePopupModel::kNoMatch);
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index b60bc33..1fc817b0 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -23,7 +23,6 @@ class ComponentUpdateService;
class DownloadRequestLimiter;
class DownloadStatusUpdater;
class ExtensionEventRouterForwarder;
-class GoogleURLTracker;
class IconManager;
class IntranetRedirectDetector;
class IOThread;
@@ -148,7 +147,6 @@ class BrowserProcess {
virtual printing::BackgroundPrintingManager*
background_printing_manager() = 0;
- virtual GoogleURLTracker* google_url_tracker() = 0;
virtual IntranetRedirectDetector* intranet_redirect_detector() = 0;
// Returns the locale used by the application.
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 6fa799f..84e2662 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -30,7 +30,6 @@
#include "chrome/browser/extensions/extension_event_router_forwarder.h"
#include "chrome/browser/extensions/extension_tab_id_map.h"
#include "chrome/browser/first_run/upgrade_util.h"
-#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/browser/intranet_redirect_detector.h"
#include "chrome/browser/io_thread.h"
@@ -185,14 +184,13 @@ void BrowserProcessImpl::StartTearDown() {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&SdchDictionaryFetcher::Shutdown));
- // We need to destroy the MetricsService, GoogleURLTracker,
- // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
- // (owned by the SafeBrowsingService) before the io_thread_ gets destroyed,
- // since their destructors can call the URLFetcher destructor, which does a
- // PostDelayedTask operation on the IO thread.
- // (The IO thread will handle that URLFetcher operation before going away.)
+ // We need to destroy the MetricsService, IntranetRedirectDetector, and
+ // SafeBrowsing ClientSideDetectionService (owned by the SafeBrowsingService)
+ // before the io_thread_ gets destroyed, since their destructors can call the
+ // URLFetcher destructor, which does a PostDelayedTask operation on the IO
+ // thread. (The IO thread will handle that URLFetcher operation before going
+ // away.)
metrics_service_.reset();
- google_url_tracker_.reset();
intranet_redirect_detector_.reset();
#if defined(ENABLE_SAFE_BROWSING)
if (safe_browsing_service_.get()) {
@@ -513,13 +511,6 @@ printing::BackgroundPrintingManager*
#endif
}
-GoogleURLTracker* BrowserProcessImpl::google_url_tracker() {
- DCHECK(CalledOnValidThread());
- if (!google_url_tracker_.get())
- CreateGoogleURLTracker();
- return google_url_tracker_.get();
-}
-
IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
DCHECK(CalledOnValidThread());
if (!intranet_redirect_detector_.get())
@@ -794,13 +785,6 @@ void BrowserProcessImpl::CreateIconManager() {
icon_manager_.reset(new IconManager);
}
-void BrowserProcessImpl::CreateGoogleURLTracker() {
- DCHECK(google_url_tracker_.get() == NULL);
- scoped_ptr<GoogleURLTracker> google_url_tracker(
- new GoogleURLTracker(GoogleURLTracker::NORMAL_MODE));
- google_url_tracker_.swap(google_url_tracker);
-}
-
void BrowserProcessImpl::CreateIntranetRedirectDetector() {
DCHECK(intranet_redirect_detector_.get() == NULL);
scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector(
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 65cc7f3..592f119 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -92,7 +92,6 @@ class BrowserProcessImpl : public BrowserProcess,
print_preview_tab_controller() OVERRIDE;
virtual printing::BackgroundPrintingManager*
background_printing_manager() OVERRIDE;
- virtual GoogleURLTracker* google_url_tracker() OVERRIDE;
virtual IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE;
virtual const std::string& GetApplicationLocale() OVERRIDE;
virtual void SetApplicationLocale(const std::string& locale) OVERRIDE;
@@ -132,7 +131,6 @@ class BrowserProcessImpl : public BrowserProcess,
void CreateLocalState();
void CreateViewedPageTracker();
void CreateIconManager();
- void CreateGoogleURLTracker();
void CreateIntranetRedirectDetector();
void CreateNotificationUIManager();
void CreateStatusTrayManager();
@@ -191,7 +189,6 @@ class BrowserProcessImpl : public BrowserProcess,
scoped_ptr<AutomationProviderList> automation_provider_list_;
#endif
- scoped_ptr<GoogleURLTracker> google_url_tracker_;
scoped_ptr<IntranetRedirectDetector> intranet_redirect_detector_;
scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_;
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index a92d1cd..e063377 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -43,7 +43,6 @@
#include "chrome/browser/extensions/extensions_startup.h"
#include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/google/google_search_counter.h"
-#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/gpu_blacklist.h"
#include "chrome/browser/gpu_util.h"
@@ -1701,18 +1700,16 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
// In unittest mode, this will do nothing. In normal mode, this will create
- // the global GoogleURLTracker and IntranetRedirectDetector instances, which
- // will promptly go to sleep for five and seven seconds, respectively (to
- // avoid slowing startup), and wake up afterwards to see if they should do
- // anything else.
+ // the global IntranetRedirectDetector instance, which will promptly go to
+ // sleep for seven seconds (to avoid slowing startup), and wake up afterwards
+ // to see if it should do anything else.
//
// A simpler way of doing all this would be to have some function which could
- // give the time elapsed since startup, and simply have these objects check
- // that when asked to initialize themselves, but this doesn't seem to exist.
+ // give the time elapsed since startup, and simply have this object check that
+ // when asked to initialize itself, but this doesn't seem to exist.
//
- // These can't be created in the BrowserProcessImpl constructor because they
- // need to read prefs that get set after that runs.
- browser_process_->google_url_tracker();
+ // This can't be created in the BrowserProcessImpl constructor because it
+ // needs to read prefs that get set after that runs.
browser_process_->intranet_redirect_detector();
GoogleSearchCounter::RegisterForNotifications();
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc
index 0c5c76e..c751bd9 100644
--- a/chrome/browser/google/google_url_tracker.cc
+++ b/chrome/browser/google/google_url_tracker.cc
@@ -12,9 +12,11 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/infobars/infobar_tab_helper.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/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_notification_types.h"
@@ -159,11 +161,11 @@ const char GoogleURLTracker::kDefaultGoogleHomepage[] =
const char GoogleURLTracker::kSearchDomainCheckURL[] =
"https://www.google.com/searchdomaincheck?format=domain&type=chrome";
-GoogleURLTracker::GoogleURLTracker(Mode mode)
- : infobar_creator_(&CreateInfoBar),
+GoogleURLTracker::GoogleURLTracker(Profile* profile, Mode mode)
+ : profile_(profile),
+ infobar_creator_(&CreateInfoBar),
google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage :
- g_browser_process->local_state()->GetString(
- prefs::kLastKnownGoogleURL)),
+ profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
fetcher_id_(0),
in_startup_sleep_(true),
@@ -191,55 +193,48 @@ GoogleURLTracker::GoogleURLTracker(Mode mode)
}
GoogleURLTracker::~GoogleURLTracker() {
- net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
// We should only reach here after any tabs and their infobars have been torn
// down.
DCHECK(infobar_map_.empty());
}
// static
-GURL GoogleURLTracker::GoogleURL() {
- const GoogleURLTracker* tracker = g_browser_process->google_url_tracker();
+GURL GoogleURLTracker::GoogleURL(Profile* profile) {
+ const GoogleURLTracker* tracker =
+ GoogleURLTrackerFactory::GetForProfile(profile);
return tracker ? tracker->google_url_ : GURL(kDefaultGoogleHomepage);
}
// static
-void GoogleURLTracker::RequestServerCheck() {
- GoogleURLTracker* tracker = g_browser_process->google_url_tracker();
+void GoogleURLTracker::RequestServerCheck(Profile* profile) {
+ GoogleURLTracker* tracker = GoogleURLTrackerFactory::GetForProfile(profile);
if (tracker)
tracker->SetNeedToFetch();
}
// static
-void GoogleURLTracker::RegisterPrefs(PrefService* prefs) {
- prefs->RegisterStringPref(prefs::kLastKnownGoogleURL,
- kDefaultGoogleHomepage);
- prefs->RegisterStringPref(prefs::kLastPromptedGoogleURL, std::string());
-}
-
-// static
-void GoogleURLTracker::GoogleURLSearchCommitted() {
- GoogleURLTracker* tracker = g_browser_process->google_url_tracker();
+void GoogleURLTracker::GoogleURLSearchCommitted(Profile* profile) {
+ GoogleURLTracker* tracker = GoogleURLTrackerFactory::GetForProfile(profile);
if (tracker)
tracker->SearchCommitted();
}
void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) {
google_url_ = new_google_url;
- PrefService* prefs = g_browser_process->local_state();
+ PrefService* prefs = profile_->GetPrefs();
prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec());
prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec());
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
+ content::Source<Profile>(profile_),
+ content::Details<const GURL>(&new_google_url));
need_to_prompt_ = false;
CloseAllInfoBars(true);
}
void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) {
- g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL,
- new_google_url.spec());
+ profile_->GetPrefs()->SetString(prefs::kLastPromptedGoogleURL,
+ new_google_url.spec());
need_to_prompt_ = false;
CloseAllInfoBars(false);
}
@@ -287,7 +282,7 @@ void GoogleURLTracker::StartFetchIfDesirable() {
// we alarm the user.
fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE |
net::LOAD_DO_NOT_SAVE_COOKIES);
- fetcher_->SetRequestContext(g_browser_process->system_request_context());
+ fetcher_->SetRequestContext(profile_->GetRequestContext());
// Configure to max_retries at most kMaxRetries times for 5xx errors.
static const int kMaxRetries = 5;
@@ -317,8 +312,7 @@ void GoogleURLTracker::OnURLFetchComplete(const content::URLFetcher* source) {
fetched_google_url_ = GURL("http://www" + url_str);
GURL last_prompted_url(
- g_browser_process->local_state()->GetString(
- prefs::kLastPromptedGoogleURL));
+ profile_->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
if (last_prompted_url.is_empty()) {
// On the very first run of Chrome, when we've never looked up the URL at
@@ -408,6 +402,13 @@ void GoogleURLTracker::OnIPAddressChanged() {
StartFetchIfDesirable();
}
+void GoogleURLTracker::Shutdown() {
+ registrar_.RemoveAll();
+ weak_ptr_factory_.InvalidateWeakPtrs();
+ fetcher_.reset();
+ net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
+}
+
void GoogleURLTracker::SearchCommitted() {
if (need_to_prompt_) {
// This notification will fire a bit later in the same call chain we're
diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h
index b85fb66b..a30c84b 100644
--- a/chrome/browser/google/google_url_tracker.h
+++ b/chrome/browser/google/google_url_tracker.h
@@ -12,6 +12,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
#include "content/public/common/url_fetcher.h"
#include "content/public/common/url_fetcher_delegate.h"
@@ -22,6 +23,7 @@
class GoogleURLTrackerInfoBarDelegate;
class PrefService;
+class Profile;
namespace content {
class NavigationController;
@@ -43,7 +45,8 @@ class WebContents;
// RequestServerCheck().
class GoogleURLTracker : public content::URLFetcherDelegate,
public content::NotificationObserver,
- public net::NetworkChangeNotifier::IPAddressObserver {
+ public net::NetworkChangeNotifier::IPAddressObserver,
+ public ProfileKeyedService {
public:
// The constructor does different things depending on which of these values
// you pass it. Hopefully these are self-explanatory.
@@ -52,19 +55,18 @@ class GoogleURLTracker : public content::URLFetcherDelegate,
UNIT_TEST_MODE,
};
- // Only the main browser process loop and tests should call this, when setting
- // up g_browser_process->google_url_tracker_. No code other than the
- // GoogleURLTracker itself should actually use
- // g_browser_process->google_url_tracker().
- explicit GoogleURLTracker(Mode mode);
+ // Only the GoogleURLTrackerFactory and tests should call this. No code other
+ // than the GoogleURLTracker itself should actually use
+ // GoogleURLTrackerFactory::GetForProfile().
+ GoogleURLTracker(Profile* profile, Mode mode);
virtual ~GoogleURLTracker();
- // Returns the current Google URL. This will return a valid URL even in
- // unittest mode.
+ // Returns the current Google URL. This will return a valid URL even if
+ // |profile| is NULL or a testing profile.
//
// This is the only function most code should ever call.
- static GURL GoogleURL();
+ static GURL GoogleURL(Profile* profile);
// Requests that the tracker perform a server check to update the Google URL
// as necessary. This will happen at most once per network change, not
@@ -72,16 +74,16 @@ class GoogleURLTracker : public content::URLFetcherDelegate,
// will occur then; checks requested afterwards will occur immediately, if
// no other checks have been made during this run).
//
- // In unittest mode, this function does nothing.
- static void RequestServerCheck();
-
- static void RegisterPrefs(PrefService* prefs);
+ // When |profile| is NULL or a testing profile, this function does nothing.
+ static void RequestServerCheck(Profile* profile);
// Notifies the tracker that the user has started a Google search.
// If prompting is necessary, we then listen for the subsequent
// NAV_ENTRY_PENDING notification to get the appropriate NavigationController.
// When the load commits, we'll show the infobar.
- static void GoogleURLSearchCommitted();
+ //
+ // When |profile| is NULL or a testing profile, this function does nothing.
+ static void GoogleURLSearchCommitted(Profile* profile);
static const char kDefaultGoogleHomepage[];
static const char kSearchDomainCheckURL[];
@@ -115,17 +117,20 @@ class GoogleURLTracker : public content::URLFetcherDelegate,
// it and can currently do so.
void StartFetchIfDesirable();
- // content::URLFetcherDelegate
+ // content::URLFetcherDelegate:
virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
- // content::NotificationObserver
+ // content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // NetworkChangeNotifier::IPAddressObserver
+ // NetworkChangeNotifier::IPAddressObserver:
virtual void OnIPAddressChanged() OVERRIDE;
+ // ProfileKeyedService:
+ virtual void Shutdown() OVERRIDE;
+
// Called each time the user performs a search. This checks whether we need
// to prompt the user about a domain change, and if so, starts listening for
// the notifications sent when the actual load is triggered.
@@ -162,6 +167,7 @@ class GoogleURLTracker : public content::URLFetcherDelegate,
// each tab to re-perform the user's search, but on the new Google TLD.
void CloseAllInfoBars(bool redo_searches);
+ Profile* profile_;
content::NotificationRegistrar registrar_;
InfoBarCreator infobar_creator_;
// TODO(ukai): GoogleURLTracker should track google domain (e.g. google.co.uk)
diff --git a/chrome/browser/google/google_url_tracker_factory.cc b/chrome/browser/google/google_url_tracker_factory.cc
new file mode 100644
index 0000000..55adaf2
--- /dev/null
+++ b/chrome/browser/google/google_url_tracker_factory.cc
@@ -0,0 +1,54 @@
+// 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/google/google_url_tracker_factory.h"
+
+#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/common/pref_names.h"
+
+
+// static
+GoogleURLTracker* GoogleURLTrackerFactory::GetForProfile(Profile* profile) {
+ return static_cast<GoogleURLTracker*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+// static
+GoogleURLTrackerFactory* GoogleURLTrackerFactory::GetInstance() {
+ return Singleton<GoogleURLTrackerFactory>::get();
+}
+
+GoogleURLTrackerFactory::GoogleURLTrackerFactory()
+ : ProfileKeyedServiceFactory("GoogleURLTracker",
+ ProfileDependencyManager::GetInstance()) {
+}
+
+GoogleURLTrackerFactory::~GoogleURLTrackerFactory() {
+}
+
+ProfileKeyedService* GoogleURLTrackerFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ return new GoogleURLTracker(profile, GoogleURLTracker::NORMAL_MODE);
+}
+
+void GoogleURLTrackerFactory::RegisterUserPrefs(PrefService* user_prefs) {
+ user_prefs->RegisterStringPref(prefs::kLastKnownGoogleURL,
+ GoogleURLTracker::kDefaultGoogleHomepage, PrefService::UNSYNCABLE_PREF);
+ user_prefs->RegisterStringPref(prefs::kLastPromptedGoogleURL, std::string(),
+ PrefService::UNSYNCABLE_PREF);
+}
+
+bool GoogleURLTrackerFactory::ServiceRedirectedInIncognito() {
+ return true;
+}
+
+bool GoogleURLTrackerFactory::ServiceIsCreatedWithProfile() {
+ return true;
+}
+
+bool GoogleURLTrackerFactory::ServiceIsNULLWhileTesting() {
+ return true;
+}
diff --git a/chrome/browser/google/google_url_tracker_factory.h b/chrome/browser/google/google_url_tracker_factory.h
new file mode 100644
index 0000000..a294593
--- /dev/null
+++ b/chrome/browser/google/google_url_tracker_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_GOOGLE_GOOGLE_URL_TRACKER_FACTORY_H_
+#define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_FACTORY_H_
+
+#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile_keyed_service_factory.h"
+
+class GoogleURLTracker;
+class Profile;
+
+// Singleton that owns all GoogleURLTrackers and associates them with Profiles.
+class GoogleURLTrackerFactory : public ProfileKeyedServiceFactory {
+ public:
+ // Returns the GoogleURLTracker for |profile|. This may return NULL for a
+ // testing profile.
+ static GoogleURLTracker* GetForProfile(Profile* profile);
+
+ static GoogleURLTrackerFactory* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<GoogleURLTrackerFactory>;
+
+ GoogleURLTrackerFactory();
+ virtual ~GoogleURLTrackerFactory();
+
+ // ProfileKeyedServiceFactory:
+ virtual ProfileKeyedService* BuildServiceInstanceFor(
+ Profile* profile) const OVERRIDE;
+ virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE;
+ virtual bool ServiceRedirectedInIncognito() OVERRIDE;
+ virtual bool ServiceIsCreatedWithProfile() OVERRIDE;
+ virtual bool ServiceIsNULLWhileTesting() OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerFactory);
+};
+
+#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_FACTORY_H_
diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc
index ba70121..b5d6a08 100644
--- a/chrome/browser/google/google_url_tracker_unittest.cc
+++ b/chrome/browser/google/google_url_tracker_unittest.cc
@@ -3,12 +3,13 @@
// found in the LICENSE file.
#include "base/message_loop.h"
+#include "chrome/browser/infobars/infobar_delegate.h"
#include "chrome/browser/google/google_url_tracker.h"
-#include "chrome/browser/prefs/browser_prefs.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
-#include "chrome/test/base/testing_browser_process.h"
-#include "chrome/test/base/testing_pref_service.h"
+#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/url_fetcher.h"
#include "content/test/test_browser_thread.h"
@@ -144,17 +145,17 @@ class GoogleURLTrackerTest : public testing::Test {
// Creating this allows us to call
// net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
- ScopedTestingLocalState local_state_;
TestURLFetcherFactory fetcher_factory_;
content::NotificationRegistrar registrar_;
+ TestingProfile profile_;
scoped_ptr<GoogleURLTracker> google_url_tracker_;
};
GoogleURLTrackerTest::GoogleURLTrackerTest()
: observer_(new TestNotificationObserver),
message_loop_(MessageLoop::TYPE_IO),
- io_thread_(content::BrowserThread::IO, &message_loop_),
- local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) {
+ io_thread_(content::BrowserThread::IO, &message_loop_) {
+ GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_);
}
GoogleURLTrackerTest::~GoogleURLTrackerTest() {
@@ -163,7 +164,7 @@ GoogleURLTrackerTest::~GoogleURLTrackerTest() {
void GoogleURLTrackerTest::SetUp() {
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
google_url_tracker_.reset(
- new GoogleURLTracker(GoogleURLTracker::UNIT_TEST_MODE));
+ new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE));
google_url_tracker_->infobar_creator_ = &CreateTestInfobar;
}
@@ -194,9 +195,9 @@ void GoogleURLTrackerTest::MockSearchDomainCheckResponse(
void GoogleURLTrackerTest::RequestServerCheck() {
if (!registrar_.IsRegistered(observer_.get(),
chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllBrowserContextsAndSources())) {
+ content::Source<Profile>(&profile_))) {
registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllBrowserContextsAndSources());
+ content::Source<Profile>(&profile_));
}
google_url_tracker_->SetNeedToFetch();
}
@@ -213,13 +214,11 @@ void GoogleURLTrackerTest::NotifyIPAddressChanged() {
}
void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) {
- g_browser_process->local_state()->SetString(
- prefs::kLastPromptedGoogleURL, url.spec());
+ profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec());
}
GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() {
- return GURL(g_browser_process->local_state()->GetString(
- prefs::kLastPromptedGoogleURL));
+ return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
}
void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url,
diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc
index 22b17fc..e0edd2b 100644
--- a/chrome/browser/google/google_util.cc
+++ b/chrome/browser/google/google_util.cc
@@ -76,10 +76,10 @@ std::string StringAppendGoogleLocaleParam(const std::string& url) {
return localized_url.spec();
}
-GURL AppendGoogleTLDParam(const GURL& url) {
+GURL AppendGoogleTLDParam(Profile* profile, const GURL& url) {
const std::string google_domain(
net::RegistryControlledDomainService::GetDomainAndRegistry(
- GoogleURLTracker::GoogleURL()));
+ GoogleURLTracker::GoogleURL(profile)));
const size_t first_dot = google_domain.find('.');
if (first_dot == std::string::npos) {
NOTREACHED();
diff --git a/chrome/browser/google/google_util.h b/chrome/browser/google/google_util.h
index 670591a..3e6a0fc 100644
--- a/chrome/browser/google/google_util.h
+++ b/chrome/browser/google/google_util.h
@@ -13,6 +13,7 @@
#include <base/basictypes.h>
class GURL;
+class Profile;
// This namespace provides various helpers around handling Google-related URLs
// and state relating to Google Chrome distributions (such as RLZ).
@@ -27,9 +28,9 @@ GURL AppendGoogleLocaleParam(const GURL& url);
// String version of AppendGoogleLocaleParam.
std::string StringAppendGoogleLocaleParam(const std::string& url);
-// Adds the Google TLD string to the URL (e.g., sd=com). This does not
-// check to see if the param already exists.
-GURL AppendGoogleTLDParam(const GURL& url);
+// Adds the Google TLD string for the given profile to the URL (e.g., sd=com).
+// This does not check to see if the param already exists.
+GURL AppendGoogleTLDParam(Profile* profile, const GURL& url);
// Returns in |brand| the brand code or distribution tag that has been
// assigned to a partner. Returns false if the information is not available.
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 26c54ce..04a061a 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -23,6 +23,7 @@
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/geolocation/geolocation_prefs.h"
#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/intents/web_intents_util.h"
#include "chrome/browser/intranet_redirect_detector.h"
@@ -118,7 +119,6 @@ void RegisterLocalState(PrefService* local_state) {
browser_shutdown::RegisterPrefs(local_state);
ExternalProtocolHandler::RegisterPrefs(local_state);
geolocation::RegisterPrefs(local_state);
- GoogleURLTracker::RegisterPrefs(local_state);
IntranetRedirectDetector::RegisterPrefs(local_state);
KeywordEditorController::RegisterPrefs(local_state);
MetricsLog::RegisterPrefs(local_state);
@@ -255,7 +255,7 @@ void RegisterUserPrefs(PrefService* user_prefs) {
#endif
}
-void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state) {
+void MigrateBrowserPrefs(Profile* profile, PrefService* local_state) {
// Copy pref values which have been migrated to user_prefs from local_state,
// or remove them from local_state outright, if copying is not required.
int current_version =
@@ -275,6 +275,7 @@ void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state) {
current_version);
}
+ PrefService* user_prefs = profile->GetPrefs();
if (!(current_version & WINDOWS_PREFS)) {
local_state->RegisterIntegerPref(prefs::kDevToolsHSplitLocation, -1);
if (local_state->HasPrefPath(prefs::kDevToolsHSplitLocation)) {
@@ -296,6 +297,29 @@ void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state) {
local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
current_version);
}
+
+ if (!(current_version & GOOGLE_URL_TRACKER_PREFS)) {
+ GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(profile);
+ local_state->RegisterStringPref(prefs::kLastKnownGoogleURL,
+ GoogleURLTracker::kDefaultGoogleHomepage);
+ if (local_state->HasPrefPath(prefs::kLastKnownGoogleURL)) {
+ user_prefs->SetString(prefs::kLastKnownGoogleURL,
+ local_state->GetString(prefs::kLastKnownGoogleURL));
+ }
+ local_state->ClearPref(prefs::kLastKnownGoogleURL);
+
+ local_state->RegisterStringPref(prefs::kLastPromptedGoogleURL,
+ std::string());
+ if (local_state->HasPrefPath(prefs::kLastPromptedGoogleURL)) {
+ user_prefs->SetString(prefs::kLastPromptedGoogleURL,
+ local_state->GetString(prefs::kLastPromptedGoogleURL));
+ }
+ local_state->ClearPref(prefs::kLastPromptedGoogleURL);
+
+ current_version |= GOOGLE_URL_TRACKER_PREFS;
+ local_state->SetInteger(prefs::kMultipleProfilePrefMigration,
+ current_version);
+ }
}
} // namespace browser
diff --git a/chrome/browser/prefs/browser_prefs.h b/chrome/browser/prefs/browser_prefs.h
index bbee56d..28ca789 100644
--- a/chrome/browser/prefs/browser_prefs.h
+++ b/chrome/browser/prefs/browser_prefs.h
@@ -7,6 +7,7 @@
#pragma once
class PrefService;
+class Profile;
namespace browser {
@@ -15,13 +16,14 @@ enum MigratedPreferences {
NO_PREFS = 0,
DNS_PREFS = 1 << 0,
WINDOWS_PREFS = 1 << 1,
+ GOOGLE_URL_TRACKER_PREFS = 1 << 2,
};
// Makes the PrefService objects aware of all the prefs.
void RegisterLocalState(PrefService* local_state);
void RegisterUserPrefs(PrefService* user_prefs);
-// Migrate prefs from local_state to user_prefs.
-void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state);
+// Migrate prefs from local_state to |profile|'s pref store.
+void MigrateBrowserPrefs(Profile* profile, PrefService* local_state);
} // namespace browser
diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc
index c4057be..01bb223 100644
--- a/chrome/browser/profiles/profile_dependency_manager.cc
+++ b/chrome/browser/profiles/profile_dependency_manager.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/extensions/api/commands/extension_command_service_factory.h"
#include "chrome/browser/extensions/extension_system_factory.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/intents/web_intents_registry_factory.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/browser/password_manager/password_store_factory.h"
@@ -175,8 +176,17 @@ void ProfileDependencyManager::AssertFactoriesBuilt() {
return;
AutocompleteActionPredictorFactory::GetInstance();
+#if defined(ENABLE_BACKGROUND)
+ BackgroundContentsServiceFactory::GetInstance();
+#endif
ChromeURLDataManagerFactory::GetInstance();
+#if !defined(OS_ANDROID)
+ CloudPrintProxyServiceFactory::GetInstance();
+#endif
CookieSettings::Factory::GetInstance();
+#if defined(ENABLE_NOTIFICATIONS)
+ DesktopNotificationServiceFactory::GetInstance();
+#endif
DownloadServiceFactory::GetInstance();
ExtensionCommandServiceFactory::GetInstance();
ExtensionSystemFactory::GetInstance();
@@ -185,44 +195,38 @@ void ProfileDependencyManager::AssertFactoriesBuilt() {
GesturePrefsObserverFactoryAura::GetInstance();
#endif
GlobalErrorServiceFactory::GetInstance();
+ GoogleURLTrackerFactory::GetInstance();
NTPResourceCacheFactory::GetInstance();
PasswordStoreFactory::GetInstance();
PersonalDataManagerFactory::GetInstance();
- PluginPrefsFactory::GetInstance();
- prerender::PrerenderManagerFactory::GetInstance();
- ProfileSyncServiceFactory::GetInstance();
- SigninManagerFactory::GetInstance();
- SpellCheckFactory::GetInstance();
- TabRestoreServiceFactory::GetInstance();
- TemplateURLFetcherFactory::GetInstance();
- TemplateURLServiceFactory::GetInstance();
- TokenServiceFactory::GetInstance();
#if !defined(OS_ANDROID)
- CloudPrintProxyServiceFactory::GetInstance();
PinnedTabServiceFactory::GetInstance();
#endif
-#if defined(ENABLE_NOTIFICATIONS)
- DesktopNotificationServiceFactory::GetInstance();
-#endif
+ PluginPrefsFactory::GetInstance();
+ prerender::PrerenderManagerFactory::GetInstance();
+ ProfileSyncServiceFactory::GetInstance();
#if defined(ENABLE_PROTECTOR_SERVICE)
protector::ProtectorServiceFactory::GetInstance();
#endif
#if defined(ENABLE_SESSION_SERVICE)
SessionServiceFactory::GetInstance();
#endif
+ SigninManagerFactory::GetInstance();
#if defined(ENABLE_INPUT_SPEECH)
SpeechInputExtensionManager::InitializeFactory();
#endif
+ SpellCheckFactory::GetInstance();
+ TabRestoreServiceFactory::GetInstance();
+ TemplateURLFetcherFactory::GetInstance();
+ TemplateURLServiceFactory::GetInstance();
#if defined(ENABLE_THEMES)
ThemeServiceFactory::GetInstance();
#endif
+ TokenServiceFactory::GetInstance();
UserStyleSheetWatcherFactory::GetInstance();
#if defined(ENABLE_WEB_INTENTS)
WebIntentsRegistryFactory::GetInstance();
#endif
-#if defined(ENABLE_BACKGROUND)
- BackgroundContentsServiceFactory::GetInstance();
-#endif // defined(ENABLE_BACKGROUND)
built_factories_ = true;
}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 4b4ec49..1af794e 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -650,10 +650,8 @@ void ProfileImpl::OnPrefsLoaded(bool success) {
Profile::RegisterUserPrefs(prefs_.get());
browser::RegisterUserPrefs(prefs_.get());
// TODO(mirandac): remove migration code after 6 months (crbug.com/69995).
- if (g_browser_process->local_state()) {
- browser::MigrateBrowserPrefs(prefs_.get(),
- g_browser_process->local_state());
- }
+ if (g_browser_process->local_state())
+ browser::MigrateBrowserPrefs(this, g_browser_process->local_state());
// The last session exited cleanly if there is no pref for
// kSessionExitedCleanly or the value for kSessionExitedCleanly is true.
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 2a0aec0..81549df 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
@@ -39,7 +39,7 @@ void SearchHostToURLsMapTest::SetUp() {
template_urls.push_back(t_urls_[1].get());
provider_map_.reset(new SearchHostToURLsMap);
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(NULL);
provider_map_->Init(template_urls, search_terms_data);
}
@@ -48,7 +48,7 @@ TEST_F(SearchHostToURLsMapTest, Add) {
TemplateURLData data;
data.SetURL("http://" + new_host + "/");
TemplateURL new_t_url(NULL, data);
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(NULL);
provider_map_->Add(&new_t_url, search_terms_data);
ASSERT_EQ(&new_t_url, provider_map_->GetTemplateURLForHost(new_host));
@@ -72,7 +72,7 @@ TEST_F(SearchHostToURLsMapTest, Remove) {
}
TEST_F(SearchHostToURLsMapTest, UpdateGoogleBaseURLs) {
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(NULL);
std::string google_base_url = "google.com";
search_terms_data.SetGoogleBaseURL("http://" + google_base_url +"/");
diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc
index 28d691f..c50ad08 100644
--- a/chrome/browser/search_engines/search_provider_install_data.cc
+++ b/chrome/browser/search_engines/search_provider_install_data.cc
@@ -95,7 +95,8 @@ void GoogleURLChangeNotifier::OnChange(const std::string& google_base_url) {
// to the SearchProviderInstallData on the I/O thread.
class GoogleURLObserver : public content::NotificationObserver {
public:
- GoogleURLObserver(GoogleURLChangeNotifier* change_notifier,
+ GoogleURLObserver(Profile* profile,
+ GoogleURLChangeNotifier* change_notifier,
int ui_death_notification,
const content::NotificationSource& ui_death_source);
@@ -114,13 +115,14 @@ class GoogleURLObserver : public content::NotificationObserver {
};
GoogleURLObserver::GoogleURLObserver(
- GoogleURLChangeNotifier* change_notifier,
- int ui_death_notification,
- const content::NotificationSource& ui_death_source)
+ Profile* profile,
+ GoogleURLChangeNotifier* change_notifier,
+ int ui_death_notification,
+ const content::NotificationSource& ui_death_source)
: change_notifier_(change_notifier) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllSources());
+ content::Source<Profile>(profile->GetOriginalProfile()));
registrar_.Add(this, ui_death_notification, ui_death_source);
}
@@ -130,7 +132,7 @@ void GoogleURLObserver::Observe(int type,
if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&GoogleURLChangeNotifier::OnChange, change_notifier_.get(),
- UIThreadSearchTermsData().GoogleBaseURLValue()));
+ content::Details<const GURL>(details)->spec()));
} else {
// This must be the death notification.
delete this;
@@ -158,10 +160,10 @@ SearchProviderInstallData::SearchProviderInstallData(
const content::NotificationSource& ui_death_source)
: web_service_(profile->GetWebDataService(Profile::EXPLICIT_ACCESS)),
load_handle_(0),
- google_base_url_(UIThreadSearchTermsData().GoogleBaseURLValue()) {
+ google_base_url_(UIThreadSearchTermsData(profile).GoogleBaseURLValue()) {
// GoogleURLObserver is responsible for killing itself when
// the given notification occurs.
- new GoogleURLObserver(new GoogleURLChangeNotifier(AsWeakPtr()),
+ new GoogleURLObserver(profile, new GoogleURLChangeNotifier(AsWeakPtr()),
ui_death_notification, ui_death_source);
DetachFromThread();
}
diff --git a/chrome/browser/search_engines/search_terms_data.cc b/chrome/browser/search_engines/search_terms_data.cc
index 92c1ea5..e74b29a 100644
--- a/chrome/browser/search_engines/search_terms_data.cc
+++ b/chrome/browser/search_engines/search_terms_data.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/instant/instant_field_trial.h"
+#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
@@ -66,7 +67,8 @@ std::string SearchTermsData::InstantEnabledParam() const {
// static
std::string* UIThreadSearchTermsData::google_base_url_ = NULL;
-UIThreadSearchTermsData::UIThreadSearchTermsData() : profile_(NULL) {
+UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile)
+ : profile_(profile) {
DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -74,8 +76,10 @@ UIThreadSearchTermsData::UIThreadSearchTermsData() : profile_(NULL) {
std::string UIThreadSearchTermsData::GoogleBaseURLValue() const {
DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
- return google_base_url_ ?
- (*google_base_url_) : GoogleURLTracker::GoogleURL().spec();
+ if (google_base_url_)
+ return *google_base_url_;
+ return profile_ ? GoogleURLTracker::GoogleURL(profile_).spec() :
+ SearchTermsData::GoogleBaseURLValue();
}
std::string UIThreadSearchTermsData::GetApplicationLocale() const {
diff --git a/chrome/browser/search_engines/search_terms_data.h b/chrome/browser/search_engines/search_terms_data.h
index 5e3943a..e941b9e 100644
--- a/chrome/browser/search_engines/search_terms_data.h
+++ b/chrome/browser/search_engines/search_terms_data.h
@@ -54,21 +54,15 @@ class SearchTermsData {
// Implementation of SearchTermsData that is only usable on the UI thread.
class UIThreadSearchTermsData : public SearchTermsData {
public:
- UIThreadSearchTermsData();
+ // If |profile_| is NULL, the Google base URL accessors will return default
+ // values, and InstantEnabledParam() will return the empty string.
+ explicit UIThreadSearchTermsData(Profile* profile);
- // Callers who need an accurate answer from InstantEnabledParam() must set the
- // profile here before calling them.
- void set_profile(Profile* profile) { profile_ = profile; }
-
- // Implementation of SearchTermsData.
virtual std::string GoogleBaseURLValue() const OVERRIDE;
virtual std::string GetApplicationLocale() const OVERRIDE;
#if defined(ENABLE_RLZ)
virtual string16 GetRlzParameterValue() const OVERRIDE;
#endif
-
- // This returns the empty string unless set_profile() has been called with a
- // non-NULL Profile.
virtual std::string InstantEnabledParam() const OVERRIDE;
// Used by tests to override the value for the Google base URL. Passing the
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 986ebab..43ca590 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -101,7 +101,7 @@ std::string TemplateURLRef::GetURL() const {
}
bool TemplateURLRef::SupportsReplacement() const {
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(owner_->profile());
return SupportsReplacementUsingTermsData(search_terms_data);
}
@@ -115,8 +115,7 @@ std::string TemplateURLRef::ReplaceSearchTerms(
const string16& terms,
int accepted_suggestion,
const string16& original_query_for_suggestion) const {
- UIThreadSearchTermsData search_terms_data;
- search_terms_data.set_profile(owner_->profile());
+ UIThreadSearchTermsData search_terms_data(owner_->profile());
return ReplaceSearchTermsUsingTermsData(terms, accepted_suggestion,
original_query_for_suggestion, search_terms_data);
}
@@ -259,7 +258,7 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData(
}
bool TemplateURLRef::IsValid() const {
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(owner_->profile());
return IsValidUsingTermsData(search_terms_data);
}
@@ -454,7 +453,7 @@ std::string TemplateURLRef::ParseURL(const std::string& url,
}
void TemplateURLRef::ParseIfNecessary() const {
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(owner_->profile());
ParseIfNecessaryUsingTermsData(search_terms_data);
}
@@ -600,7 +599,7 @@ bool TemplateURL::ShowInDefaultList() const {
}
bool TemplateURL::SupportsReplacement() const {
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(profile_);
return SupportsReplacementUsingTermsData(search_terms_data);
}
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index 2b5db53..530c6d8 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -242,7 +242,7 @@ string16 TemplateURLService::CleanUserInputKeyword(const string16& keyword) {
// static
GURL TemplateURLService::GenerateSearchURL(TemplateURL* t_url) {
DCHECK(t_url);
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(t_url->profile());
return GenerateSearchURLUsingTermsData(t_url, search_terms_data);
}
@@ -1178,16 +1178,17 @@ void TemplateURLService::Init(const Initializer* initializers,
// db, which will mean we no longer need this notification and the history
// backend can handle automatically adding the search terms as the user
// navigates.
+ content::Source<Profile> profile_source(profile_->GetOriginalProfile());
notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
- content::Source<Profile>(profile_->GetOriginalProfile()));
+ profile_source);
+ notification_registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
+ profile_source);
pref_change_registrar_.Init(GetPrefs());
pref_change_registrar_.Add(prefs::kSyncedDefaultSearchProviderGUID, this);
}
notification_registrar_.Add(this,
chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED,
content::NotificationService::AllSources());
- notification_registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllSources());
if (num_initializers > 0) {
// This path is only hit by test code and is used to simulate a loaded
@@ -1222,12 +1223,12 @@ void TemplateURLService::Init(const Initializer* initializers,
// Request a server check for the correct Google URL if Google is the
// default search engine, not in headless mode and not in Chrome Frame.
- if (initial_default_search_provider_.get() &&
+ if (profile_ && initial_default_search_provider_.get() &&
initial_default_search_provider_->url_ref().HasGoogleBaseURLs()) {
scoped_ptr<base::Environment> env(base::Environment::Create());
if (!env->HasVar(env_vars::kHeadless) &&
!CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame))
- GoogleURLTracker::RequestServerCheck();
+ GoogleURLTracker::RequestServerCheck(profile_);
}
}
@@ -1316,7 +1317,7 @@ void TemplateURLService::AddToMaps(TemplateURL* template_url) {
if (!template_url->sync_guid().empty())
guid_to_template_map_[template_url->sync_guid()] = template_url;
if (loaded_) {
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(profile_);
provider_map_->Add(template_url, search_terms_data);
}
}
@@ -1345,7 +1346,7 @@ void TemplateURLService::SetTemplateURLs(const TemplateURLVector& urls) {
void TemplateURLService::ChangeToLoadedState() {
DCHECK(!loaded_);
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(profile_);
provider_map_->Init(template_urls_, search_terms_data);
loaded_ = true;
}
@@ -1541,7 +1542,7 @@ bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
TemplateURLID previous_id = existing_turl->id();
existing_turl->CopyFrom(new_values);
existing_turl->data_.id = previous_id;
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(profile_);
provider_map_->Add(existing_turl, search_terms_data);
const string16& keyword = existing_turl->keyword();
@@ -1739,7 +1740,7 @@ void TemplateURLService::GoogleBaseURLChanged() {
}
if (something_changed && loaded_) {
- UIThreadSearchTermsData search_terms_data;
+ UIThreadSearchTermsData search_terms_data(profile_);
provider_map_->UpdateGoogleBaseURLs(search_terms_data);
NotifyObservers();
}
@@ -1863,7 +1864,7 @@ bool TemplateURLService::SetDefaultSearchProviderNoNotify(TemplateURL* url) {
service_->UpdateKeyword(url->data());
if (url->url_ref().HasGoogleBaseURLs()) {
- GoogleURLTracker::RequestServerCheck();
+ GoogleURLTracker::RequestServerCheck(profile_);
#if defined(ENABLE_RLZ)
// Needs to be evaluated. See http://crbug.com/62328.
base::ThreadRestrictions::ScopedAllowIO allow_io;
diff --git a/chrome/browser/search_engines/template_url_service_factory.cc b/chrome/browser/search_engines/template_url_service_factory.cc
index cd5a4f7..5292074 100644
--- a/chrome/browser/search_engines/template_url_service_factory.cc
+++ b/chrome/browser/search_engines/template_url_service_factory.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/search_engines/template_url_service.h"
@@ -21,6 +22,7 @@ TemplateURLServiceFactory* TemplateURLServiceFactory::GetInstance() {
TemplateURLServiceFactory::TemplateURLServiceFactory()
: ProfileKeyedServiceFactory("TemplateURLServiceFactory",
ProfileDependencyManager::GetInstance()) {
+ DependsOn(GoogleURLTrackerFactory::GetInstance());
// TODO(erg): For Shutdown() order, we need to:
// DependsOn(WebDataServiceFactory::GetInstance());
// DependsOn(HistoryService::GetInstance());
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 5378817..04ec96c 100644
--- a/chrome/browser/search_engines/template_url_service_sync_unittest.cc
+++ b/chrome/browser/search_engines/template_url_service_sync_unittest.cc
@@ -1048,7 +1048,7 @@ TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) {
ASSERT_FALSE(key1 == NULL);
EXPECT_EQ(ASCIIToUTF16("key1.com"), key1->keyword());
std::string google_hostname(
- GURL(UIThreadSearchTermsData().GoogleBaseURLValue()).host());
+ GURL(UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host());
TemplateURL* key2 = model()->GetTemplateURLForHost(google_hostname);
ASSERT_FALSE(key2 == NULL);
string16 google_keyword(net::StripWWW(ASCIIToUTF16(google_hostname)));
@@ -1070,7 +1070,7 @@ TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) {
// Sync brings in some autogenerated keywords, but the generated keywords we
// try to create conflict with ones in the model.
string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL(
- UIThreadSearchTermsData().GoogleBaseURLValue()).host())));
+ UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host())));
TemplateURL* google = CreateTestTemplateURL(google_keyword,
"{google:baseURL}1/search?q={searchTerms}");
model()->Add(google);
@@ -1130,7 +1130,7 @@ TEST_F(TemplateURLServiceSyncTest, TwoAutogeneratedKeywordsUsingGoogleBaseURL) {
// We should still have coalesced the updates to one each.
string16 google_keyword(net::StripWWW(ASCIIToUTF16(GURL(
- UIThreadSearchTermsData().GoogleBaseURLValue()).host())));
+ UIThreadSearchTermsData(profile_a()).GoogleBaseURLValue()).host())));
TemplateURL* keyword1 =
model()->GetTemplateURLForKeyword(google_keyword + ASCIIToUTF16("_"));
ASSERT_FALSE(keyword1 == NULL);
diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc
index d0d6d42..881300c 100644
--- a/chrome/browser/search_engines/template_url_service_test_util.cc
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc
@@ -224,8 +224,8 @@ void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) const {
UIThreadSearchTermsData::SetGoogleBaseURL(base_url.spec());
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
+ content::Source<Profile>(profile_.get()),
+ content::Details<const GURL>(&base_url));
}
void TemplateURLServiceTestUtil::SetManagedDefaultSearchPreferences(
diff --git a/chrome/browser/ui/alternate_error_tab_observer.cc b/chrome/browser/ui/alternate_error_tab_observer.cc
index e45ebfd..e1d548a 100644
--- a/chrome/browser/ui/alternate_error_tab_observer.cc
+++ b/chrome/browser/ui/alternate_error_tab_observer.cc
@@ -28,7 +28,7 @@ AlternateErrorPageTabObserver::AlternateErrorPageTabObserver(
}
registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::NotificationService::AllSources());
+ content::Source<Profile>(profile_->GetOriginalProfile()));
}
AlternateErrorPageTabObserver::~AlternateErrorPageTabObserver() {
@@ -76,7 +76,7 @@ GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const {
if (profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
url = google_util::AppendGoogleLocaleParam(
GURL(google_util::kLinkDoctorBaseURL));
- url = google_util::AppendGoogleTLDParam(url);
+ url = google_util::AppendGoogleTLDParam(profile_, url);
}
return url;
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 28dc5a8..87e53e4 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1045,6 +1045,8 @@
'browser/google/google_update_settings_posix.cc',
'browser/google/google_url_tracker.cc',
'browser/google/google_url_tracker.h',
+ 'browser/google/google_url_tracker_factory.cc',
+ 'browser/google/google_url_tracker_factory.h',
'browser/google/google_util.cc',
'browser/google/google_util.h',
'browser/gpu_blacklist.cc',
diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h
index fe52020..50b3200 100644
--- a/chrome/common/chrome_notification_types.h
+++ b/chrome/common/chrome_notification_types.h
@@ -379,9 +379,15 @@ enum NotificationType {
// is the profile.
NOTIFICATION_OMNIBOX_OPENED_URL,
- // Sent when the main Google URL has been updated. Some services cache
- // this value and need to update themselves when it changes. See
- // google_util::GetGoogleURLAndUpdateIfNecessary().
+ // Sent when the Google URL for a profile has been updated. Some services
+ // cache this value and need to update themselves when it changes. See
+ // google_util::GetGoogleURLAndUpdateIfNecessary(). The source is the
+ // Profile, the details the new (const) GURL.
+ //
+ // Note that because incognito mode requests for the GoogleURLTracker are
+ // redirected to the non-incognito profile's copy, this notification will only
+ // ever fire on non-incognito profiles; thus listeners should use
+ // GetOriginalProfile() when constructing a Source to filter against.
NOTIFICATION_GOOGLE_URL_UPDATED,
// Printing ----------------------------------------------------------------
diff --git a/chrome/test/base/testing_browser_process.cc b/chrome/test/base/testing_browser_process.cc
index e399007..e1cd71c 100644
--- a/chrome/test/base/testing_browser_process.cc
+++ b/chrome/test/base/testing_browser_process.cc
@@ -5,7 +5,6 @@
#include "chrome/test/base/testing_browser_process.h"
#include "base/string_util.h"
-#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/policy/policy_service_impl.h"
@@ -147,10 +146,6 @@ NotificationUIManager* TestingBrowserProcess::notification_ui_manager() {
#endif
}
-GoogleURLTracker* TestingBrowserProcess::google_url_tracker() {
- return google_url_tracker_.get();
-}
-
IntranetRedirectDetector* TestingBrowserProcess::intranet_redirect_detector() {
return NULL;
}
@@ -254,11 +249,6 @@ void TestingBrowserProcess::SetLocalState(PrefService* local_state) {
local_state_ = local_state;
}
-void TestingBrowserProcess::SetGoogleURLTracker(
- GoogleURLTracker* google_url_tracker) {
- google_url_tracker_.reset(google_url_tracker);
-}
-
void TestingBrowserProcess::SetIOThread(IOThread* io_thread) {
io_thread_ = io_thread;
}
diff --git a/chrome/test/base/testing_browser_process.h b/chrome/test/base/testing_browser_process.h
index d63be05..50b308f 100644
--- a/chrome/test/base/testing_browser_process.h
+++ b/chrome/test/base/testing_browser_process.h
@@ -21,7 +21,6 @@
class BackgroundModeManager;
class CRLSetFetcher;
class IOThread;
-class GoogleURLTracker;
class MHTMLGenerationManager;
class NotificationUIManager;
class PrefService;
@@ -76,7 +75,6 @@ class TestingBrowserProcess : public BrowserProcess {
virtual ExtensionEventRouterForwarder*
extension_event_router_forwarder() OVERRIDE;
virtual NotificationUIManager* notification_ui_manager() OVERRIDE;
- virtual GoogleURLTracker* google_url_tracker() OVERRIDE;
virtual IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE;
virtual AutomationProviderList* GetAutomationProviderList() OVERRIDE;
virtual void InitDevToolsHttpProtocolHandler(
@@ -110,7 +108,6 @@ class TestingBrowserProcess : public BrowserProcess {
// Set the local state for tests. Consumer is responsible for cleaning it up
// afterwards (using ScopedTestingLocalState, for example).
void SetLocalState(PrefService* local_state);
- void SetGoogleURLTracker(GoogleURLTracker* google_url_tracker);
void SetProfileManager(ProfileManager* profile_manager);
void SetIOThread(IOThread* io_thread);
void SetBrowserPolicyConnector(policy::BrowserPolicyConnector* connector);
@@ -126,7 +123,6 @@ class TestingBrowserProcess : public BrowserProcess {
PrefService* local_state_;
scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
scoped_ptr<policy::PolicyService> policy_service_;
- scoped_ptr<GoogleURLTracker> google_url_tracker_;
scoped_ptr<ProfileManager> profile_manager_;
scoped_ptr<NotificationUIManager> notification_ui_manager_;
scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;