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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/search_engines/search_provider_install_data.h" 5 #include "chrome/browser/search_engines/search_provider_install_data.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/sequenced_task_runner_helpers.h" 16 #include "base/sequenced_task_runner_helpers.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/google/google_url_tracker.h" 18 #include "chrome/browser/google/google_url_tracker.h"
19 #include "chrome/browser/google/google_url_tracker_factory.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 21 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
21 #include "chrome/browser/search_engines/search_terms_data.h" 22 #include "chrome/browser/search_engines/search_terms_data.h"
22 #include "chrome/browser/search_engines/template_url.h" 23 #include "chrome/browser/search_engines/template_url.h"
23 #include "chrome/browser/search_engines/template_url_service.h" 24 #include "chrome/browser/search_engines/template_url_service.h"
24 #include "chrome/browser/search_engines/template_url_service_factory.h" 25 #include "chrome/browser/search_engines/template_url_service_factory.h"
25 #include "chrome/browser/search_engines/util.h" 26 #include "chrome/browser/search_engines/util.h"
26 #include "chrome/browser/webdata/web_data_service.h" 27 #include "chrome/browser/webdata/web_data_service.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/notification_observer.h"
29 #include "content/public/browser/notification_registrar.h"
30 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/notification_source.h"
32 #include "content/public/browser/render_process_host.h" 29 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/render_process_host_observer.h" 30 #include "content/public/browser/render_process_host_observer.h"
34 31
35 using content::BrowserThread; 32 using content::BrowserThread;
36 33
37 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet; 34 typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
38 35
39 namespace { 36 namespace {
40 37
41 void LoadDataOnUIThread(TemplateURLService* template_url_service, 38 void LoadDataOnUIThread(TemplateURLService* template_url_service,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 112 }
116 113
117 void GoogleURLChangeNotifier::OnChange(const std::string& google_base_url) { 114 void GoogleURLChangeNotifier::OnChange(const std::string& google_base_url) {
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
119 if (install_data_.get()) 116 if (install_data_.get())
120 install_data_->OnGoogleURLChange(google_base_url); 117 install_data_->OnGoogleURLChange(google_base_url);
121 } 118 }
122 119
123 // Notices changes in the Google base URL and sends them along 120 // Notices changes in the Google base URL and sends them along
124 // to the SearchProviderInstallData on the I/O thread. 121 // to the SearchProviderInstallData on the I/O thread.
125 class GoogleURLObserver : public content::NotificationObserver, 122 class GoogleURLObserver : public content::RenderProcessHostObserver {
126 public content::RenderProcessHostObserver {
127 public: 123 public:
128 GoogleURLObserver(Profile* profile, 124 GoogleURLObserver(Profile* profile,
129 GoogleURLChangeNotifier* change_notifier, 125 GoogleURLChangeNotifier* change_notifier,
130 content::RenderProcessHost* host); 126 content::RenderProcessHost* host);
131 127
132 // Implementation of content::NotificationObserver. 128 // Callback that is called when the Google URL is updated.
133 virtual void Observe(int type, 129 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.
134 const content::NotificationSource& source,
135 const content::NotificationDetails& details) OVERRIDE;
136 130
137 // Implementation of content::RenderProcessHostObserver. 131 // Implementation of content::RenderProcessHostObserver.
138 virtual void RenderProcessHostDestroyed( 132 virtual void RenderProcessHostDestroyed(
139 content::RenderProcessHost* host) OVERRIDE; 133 content::RenderProcessHost* host) OVERRIDE;
140 134
141 private: 135 private:
142 virtual ~GoogleURLObserver() {} 136 virtual ~GoogleURLObserver() {}
143 137
144 scoped_refptr<GoogleURLChangeNotifier> change_notifier_; 138 scoped_refptr<GoogleURLChangeNotifier> change_notifier_;
145 content::NotificationRegistrar registrar_; 139
140 scoped_ptr<base::CallbackList<void(GURL, GURL)>::Subscription>
141 google_url_updated_subscription_;
146 142
147 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver); 143 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver);
148 }; 144 };
149 145
150 GoogleURLObserver::GoogleURLObserver( 146 GoogleURLObserver::GoogleURLObserver(
151 Profile* profile, 147 Profile* profile,
152 GoogleURLChangeNotifier* change_notifier, 148 GoogleURLChangeNotifier* change_notifier,
153 content::RenderProcessHost* host) 149 content::RenderProcessHost* host)
154 : change_notifier_(change_notifier) { 150 : change_notifier_(change_notifier) {
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
156 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 152 GoogleURLTracker* google_url_tracker =
157 content::Source<Profile>(profile->GetOriginalProfile())); 153 GoogleURLTrackerFactory::GetForProfile(profile);
154 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.
155 google_url_updated_subscription_ =
156 google_url_tracker->RegisterCallback(base::Bind(
157 &GoogleURLObserver::OnGoogleURLUpdated, base::Unretained(this)));
158 }
158 host->AddObserver(this); 159 host->AddObserver(this);
159 } 160 }
160 161
161 void GoogleURLObserver::Observe(int type, 162 void GoogleURLObserver::OnGoogleURLUpdated(GURL old_url, GURL new_url) {
162 const content::NotificationSource& source, 163 BrowserThread::PostTask(BrowserThread::IO,
163 const content::NotificationDetails& details) { 164 FROM_HERE,
164 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); 165 base::Bind(&GoogleURLChangeNotifier::OnChange,
165 BrowserThread::PostTask( 166 change_notifier_.get(),
166 BrowserThread::IO, FROM_HERE, 167 new_url.spec()));
167 base::Bind(&GoogleURLChangeNotifier::OnChange,
168 change_notifier_.get(),
169 content::Details<GoogleURLTracker::UpdatedDetails>(details)->
170 second.spec()));
171 } 168 }
172 169
173 void GoogleURLObserver::RenderProcessHostDestroyed( 170 void GoogleURLObserver::RenderProcessHostDestroyed(
174 content::RenderProcessHost* host) { 171 content::RenderProcessHost* host) {
175 delete this; 172 delete this;
176 } 173 }
177 174
178 // Indicates if the two inputs have the same security origin. 175 // Indicates if the two inputs have the same security origin.
179 // |requested_origin| should only be a security origin (no path, etc.). 176 // |requested_origin| should only be a security origin (no path, etc.).
180 // It is ok if |template_url| is NULL. 177 // It is ok if |template_url| is NULL.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 313
317 std::for_each(closure_queue.begin(), 314 std::for_each(closure_queue.begin(),
318 closure_queue.end(), 315 closure_queue.end(),
319 std::mem_fun_ref(&base::Closure::Run)); 316 std::mem_fun_ref(&base::Closure::Run));
320 317
321 // Since we expect this request to be rare, clear out the information. This 318 // Since we expect this request to be rare, clear out the information. This
322 // also keeps the responses current as the search providers change. 319 // also keeps the responses current as the search providers change.
323 provider_map_.reset(); 320 provider_map_.reset();
324 SetDefault(NULL); 321 SetDefault(NULL);
325 } 322 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698