Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Unified Diff: chrome/browser/search_engines/template_url_service.cc

Issue 287103002: Introduce ability to register callback with GoogleURLTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search_engines/template_url_service.cc
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index b191de6bbe39ff2a4d70b5ae5b04830b9f122ee1..bc44c0207813b8c465ddf306f65d08640da25647 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -24,7 +24,7 @@
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
@@ -980,19 +980,12 @@ base::string16 TemplateURLService::GetKeywordShortName(
void TemplateURLService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_HISTORY_URL_VISITED) {
- content::Details<history::URLVisitedDetails> visit_details(details);
- if (!loaded_)
- visits_to_add_.push_back(*visit_details.ptr());
- else
- UpdateKeywordSearchTermsForURL(*visit_details.ptr());
- } else {
- DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
- if (loaded_) {
- GoogleBaseURLChanged(
- content::Details<GoogleURLTracker::UpdatedDetails>(details)->first);
- }
- }
+ DCHECK_EQ(type, chrome::NOTIFICATION_HISTORY_URL_VISITED);
+ content::Details<history::URLVisitedDetails> visit_details(details);
+ if (!loaded_)
+ visits_to_add_.push_back(*visit_details.ptr());
+ else
+ UpdateKeywordSearchTermsForURL(*visit_details.ptr());
}
void TemplateURLService::Shutdown() {
@@ -1508,8 +1501,15 @@ void TemplateURLService::Init(const Initializer* initializers,
content::Source<Profile> profile_source(profile_->GetOriginalProfile());
notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED,
profile_source);
- notification_registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- profile_source);
+ GoogleURLTracker* google_url_tracker =
+ GoogleURLTrackerFactory::GetForProfile(profile_);
+
+ // GoogleURLTracker is not created in tests.
+ if (google_url_tracker) {
+ google_url_updated_subscription_ =
+ google_url_tracker->RegisterCallback(base::Bind(
+ &TemplateURLService::OnGoogleURLUpdated, base::Unretained(this)));
+ }
pref_change_registrar_.Init(GetPrefs());
pref_change_registrar_.Add(
prefs::kSyncedDefaultSearchProviderGUID,
@@ -1915,6 +1915,11 @@ void TemplateURLService::GoogleBaseURLChanged(const GURL& old_base_url) {
NotifyObservers();
}
+void TemplateURLService::OnGoogleURLUpdated(GURL old_url, GURL new_url) {
+ if (loaded_)
+ GoogleBaseURLChanged(old_url);
+}
+
void TemplateURLService::OnDefaultSearchChange(
const TemplateURLData* data,
DefaultSearchManager::Source source) {
« no previous file with comments | « chrome/browser/search_engines/template_url_service.h ('k') | chrome/browser/search_engines/template_url_service_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698