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

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: Response to review + fix for instant unittests 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.
133 virtual void Observe(int type,
134 const content::NotificationSource& source,
135 const content::NotificationDetails& details) OVERRIDE;
136
137 // Implementation of content::RenderProcessHostObserver. 128 // Implementation of content::RenderProcessHostObserver.
138 virtual void RenderProcessHostDestroyed( 129 virtual void RenderProcessHostDestroyed(
139 content::RenderProcessHost* host) OVERRIDE; 130 content::RenderProcessHost* host) OVERRIDE;
140 131
141 private: 132 private:
142 virtual ~GoogleURLObserver() {} 133 virtual ~GoogleURLObserver() {}
143 134
135 // Callback that is called when the Google URL is updated.
136 void OnGoogleURLUpdated(GURL old_url, GURL new_url);
137
144 scoped_refptr<GoogleURLChangeNotifier> change_notifier_; 138 scoped_refptr<GoogleURLChangeNotifier> change_notifier_;
145 content::NotificationRegistrar registrar_; 139
140 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_;
146 141
147 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver); 142 DISALLOW_COPY_AND_ASSIGN(GoogleURLObserver);
148 }; 143 };
149 144
150 GoogleURLObserver::GoogleURLObserver( 145 GoogleURLObserver::GoogleURLObserver(
151 Profile* profile, 146 Profile* profile,
152 GoogleURLChangeNotifier* change_notifier, 147 GoogleURLChangeNotifier* change_notifier,
153 content::RenderProcessHost* host) 148 content::RenderProcessHost* host)
154 : change_notifier_(change_notifier) { 149 : change_notifier_(change_notifier) {
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
156 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 151 GoogleURLTracker* google_url_tracker =
157 content::Source<Profile>(profile->GetOriginalProfile())); 152 GoogleURLTrackerFactory::GetForProfile(profile);
153 if (google_url_tracker) {
154 google_url_updated_subscription_ =
155 google_url_tracker->RegisterCallback(base::Bind(
156 &GoogleURLObserver::OnGoogleURLUpdated, base::Unretained(this)));
157 }
158 host->AddObserver(this); 158 host->AddObserver(this);
159 } 159 }
160 160
161 void GoogleURLObserver::Observe(int type, 161 void GoogleURLObserver::OnGoogleURLUpdated(GURL old_url, GURL new_url) {
162 const content::NotificationSource& source, 162 BrowserThread::PostTask(BrowserThread::IO,
163 const content::NotificationDetails& details) { 163 FROM_HERE,
164 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); 164 base::Bind(&GoogleURLChangeNotifier::OnChange,
165 BrowserThread::PostTask( 165 change_notifier_.get(),
166 BrowserThread::IO, FROM_HERE, 166 new_url.spec()));
167 base::Bind(&GoogleURLChangeNotifier::OnChange,
168 change_notifier_.get(),
169 content::Details<GoogleURLTracker::UpdatedDetails>(details)->
170 second.spec()));
171 } 167 }
172 168
173 void GoogleURLObserver::RenderProcessHostDestroyed( 169 void GoogleURLObserver::RenderProcessHostDestroyed(
174 content::RenderProcessHost* host) { 170 content::RenderProcessHost* host) {
175 delete this; 171 delete this;
176 } 172 }
177 173
178 // Indicates if the two inputs have the same security origin. 174 // Indicates if the two inputs have the same security origin.
179 // |requested_origin| should only be a security origin (no path, etc.). 175 // |requested_origin| should only be a security origin (no path, etc.).
180 // It is ok if |template_url| is NULL. 176 // It is ok if |template_url| is NULL.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 312
317 std::for_each(closure_queue.begin(), 313 std::for_each(closure_queue.begin(),
318 closure_queue.end(), 314 closure_queue.end(),
319 std::mem_fun_ref(&base::Closure::Run)); 315 std::mem_fun_ref(&base::Closure::Run));
320 316
321 // Since we expect this request to be rare, clear out the information. This 317 // Since we expect this request to be rare, clear out the information. This
322 // also keeps the responses current as the search providers change. 318 // also keeps the responses current as the search providers change.
323 provider_map_.reset(); 319 provider_map_.reset();
324 SetDefault(NULL); 320 SetDefault(NULL);
325 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698