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

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

Issue 287103002: Introduce ability to register callback with GoogleURLTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/search_provider_install_data.cc
diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc
index 95d5a77a0d7b84e77a60bdb67d3c6f70f2d2f22a..2c5655eb49c1ae8f312888a9517edb2348297abc 100644
--- a/chrome/browser/search_engines/search_provider_install_data.cc
+++ b/chrome/browser/search_engines/search_provider_install_data.cc
@@ -16,6 +16,7 @@
#include "base/sequenced_task_runner_helpers.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/search_host_to_urls_map.h"
#include "chrome/browser/search_engines/search_terms_data.h"
@@ -25,10 +26,6 @@
#include "chrome/browser/search_engines/util.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_process_host_observer.h"
@@ -122,17 +119,14 @@ void GoogleURLChangeNotifier::OnChange(const std::string& google_base_url) {
// Notices changes in the Google base URL and sends them along
// to the SearchProviderInstallData on the I/O thread.
-class GoogleURLObserver : public content::NotificationObserver,
- public content::RenderProcessHostObserver {
+class GoogleURLObserver : public content::RenderProcessHostObserver {
public:
GoogleURLObserver(Profile* profile,
GoogleURLChangeNotifier* change_notifier,
content::RenderProcessHost* host);
- // Implementation of content::NotificationObserver.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
+ // Callback that is called when the Google URL is updated.
+ void OnGoogleURLUpdated(GURL old_url, GURL new_url);
Peter Kasting 2014/05/15 21:12:52 Both this function and the TemplateURLService one
blundell 2014/05/16 09:09:55 Done.
// Implementation of content::RenderProcessHostObserver.
virtual void RenderProcessHostDestroyed(
@@ -142,7 +136,9 @@ class GoogleURLObserver : public content::NotificationObserver,
virtual ~GoogleURLObserver() {}
scoped_refptr<GoogleURLChangeNotifier> change_notifier_;
- content::NotificationRegistrar registrar_;
+
+ scoped_ptr<base::CallbackList<void(GURL, GURL)>::Subscription>
+ google_url_updated_subscription_;
DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver);
};
@@ -153,21 +149,22 @@ GoogleURLObserver::GoogleURLObserver(
content::RenderProcessHost* host)
: change_notifier_(change_notifier) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
- content::Source<Profile>(profile->GetOriginalProfile()));
+ GoogleURLTracker* google_url_tracker =
+ GoogleURLTrackerFactory::GetForProfile(profile);
+ if (google_url_tracker) {
Peter Kasting 2014/05/15 21:12:52 Will this ever actually be NULL? Perhaps in tests
blundell 2014/05/16 09:09:55 In tests, yep. On 2014/05/15 21:12:52, Peter Kast
Peter Kasting 2014/05/16 22:24:23 Can you add a comment to that effect?
blundell 2014/05/17 11:32:53 Done.
+ google_url_updated_subscription_ =
+ google_url_tracker->RegisterCallback(base::Bind(
+ &GoogleURLObserver::OnGoogleURLUpdated, base::Unretained(this)));
+ }
host->AddObserver(this);
}
-void GoogleURLObserver::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&GoogleURLChangeNotifier::OnChange,
- change_notifier_.get(),
- content::Details<GoogleURLTracker::UpdatedDetails>(details)->
- second.spec()));
+void GoogleURLObserver::OnGoogleURLUpdated(GURL old_url, GURL new_url) {
+ BrowserThread::PostTask(BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GoogleURLChangeNotifier::OnChange,
+ change_notifier_.get(),
+ new_url.spec()));
}
void GoogleURLObserver::RenderProcessHostDestroyed(

Powered by Google App Engine
This is Rietveld 408576698