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

Side by Side Diff: chrome/browser/search/instant_service.cc

Issue 23455047: InstantExtended: Send search URLs to renderers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More browsertest fixes Created 7 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/instant_service.h" 5 #include "chrome/browser/search/instant_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/search_engines/template_url.h" 23 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/search_engines/template_url_service.h" 24 #include "chrome/browser/search_engines/template_url_service.h"
25 #include "chrome/browser/search_engines/template_url_service_factory.h" 25 #include "chrome/browser/search_engines/template_url_service_factory.h"
26 #include "chrome/browser/themes/theme_properties.h" 26 #include "chrome/browser/themes/theme_properties.h"
27 #include "chrome/browser/themes/theme_service.h" 27 #include "chrome/browser/themes/theme_service.h"
28 #include "chrome/browser/themes/theme_service_factory.h" 28 #include "chrome/browser/themes/theme_service_factory.h"
29 #include "chrome/browser/ui/webui/favicon_source.h" 29 #include "chrome/browser/ui/webui/favicon_source.h"
30 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" 30 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
31 #include "chrome/browser/ui/webui/theme_source.h" 31 #include "chrome/browser/ui/webui/theme_source.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "chrome/common/render_messages.h"
33 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/notification_types.h" 38 #include "content/public/browser/notification_types.h"
38 #include "content/public/browser/render_process_host.h" 39 #include "content/public/browser/render_process_host.h"
39 #include "content/public/browser/url_data_source.h" 40 #include "content/public/browser/url_data_source.h"
40 #include "grit/theme_resources.h" 41 #include "grit/theme_resources.h"
41 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
42 #include "net/url_request/url_request.h" 43 #include "net/url_request/url_request.h"
(...skipping 23 matching lines...) Expand all
66 InstantService::InstantService(Profile* profile) 67 InstantService::InstantService(Profile* profile)
67 : profile_(profile), 68 : profile_(profile),
68 ntp_prerenderer_(profile, this, profile->GetPrefs()), 69 ntp_prerenderer_(profile, this, profile->GetPrefs()),
69 browser_instant_controller_object_count_(0), 70 browser_instant_controller_object_count_(0),
70 weak_ptr_factory_(this) { 71 weak_ptr_factory_(this) {
71 // Stub for unit tests. 72 // Stub for unit tests.
72 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) 73 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
73 return; 74 return;
74 75
75 registrar_.Add(this, 76 registrar_.Add(this,
77 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
78 content::NotificationService::AllSources());
79 registrar_.Add(this,
76 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 80 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
77 content::NotificationService::AllSources()); 81 content::NotificationService::AllSources());
78 82
79 history::TopSites* top_sites = profile_->GetTopSites(); 83 history::TopSites* top_sites = profile_->GetTopSites();
80 if (top_sites) { 84 if (top_sites) {
81 registrar_.Add(this, 85 registrar_.Add(this,
82 chrome::NOTIFICATION_TOP_SITES_CHANGED, 86 chrome::NOTIFICATION_TOP_SITES_CHANGED,
83 content::Source<history::TopSites>(top_sites)); 87 content::Source<history::TopSites>(top_sites));
84 } 88 }
85 instant_io_context_ = new InstantIOContext(); 89 instant_io_context_ = new InstantIOContext();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // All browser windows have closed, so release the InstantNTP resources to 230 // All browser windows have closed, so release the InstantNTP resources to
227 // work around http://crbug.com/180810. 231 // work around http://crbug.com/180810.
228 if (browser_instant_controller_object_count_ == 0) 232 if (browser_instant_controller_object_count_ == 0)
229 ntp_prerenderer_.DeleteNTPContents(); 233 ntp_prerenderer_.DeleteNTPContents();
230 } 234 }
231 235
232 void InstantService::Observe(int type, 236 void InstantService::Observe(int type,
233 const content::NotificationSource& source, 237 const content::NotificationSource& source,
234 const content::NotificationDetails& details) { 238 const content::NotificationDetails& details) {
235 switch (type) { 239 switch (type) {
236 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { 240 case content::NOTIFICATION_RENDERER_PROCESS_CREATED:
237 int process_id = 241 SendSearchURLsToRenderer(
238 content::Source<content::RenderProcessHost>(source)->GetID(); 242 content::Source<content::RenderProcessHost>(source).ptr());
239 process_ids_.erase(process_id);
240
241 if (instant_io_context_.get()) {
242 BrowserThread::PostTask(
243 BrowserThread::IO,
244 FROM_HERE,
245 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
246 instant_io_context_,
247 process_id));
248 }
249 break; 243 break;
250 } 244 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
245 OnRendererProcessTerminated(
246 content::Source<content::RenderProcessHost>(source)->GetID());
247 break;
251 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { 248 case chrome::NOTIFICATION_TOP_SITES_CHANGED: {
252 history::TopSites* top_sites = profile_->GetTopSites(); 249 history::TopSites* top_sites = profile_->GetTopSites();
253 if (top_sites) { 250 if (top_sites) {
254 top_sites->GetMostVisitedURLs( 251 top_sites->GetMostVisitedURLs(
255 base::Bind(&InstantService::OnMostVisitedItemsReceived, 252 base::Bind(&InstantService::OnMostVisitedItemsReceived,
256 weak_ptr_factory_.GetWeakPtr())); 253 weak_ptr_factory_.GetWeakPtr()));
257 } 254 }
258 break; 255 break;
259 } 256 }
260 #if defined(ENABLE_THEMES) 257 #if defined(ENABLE_THEMES)
(...skipping 16 matching lines...) Expand all
277 OnGoogleURLUpdated( 274 OnGoogleURLUpdated(
278 content::Source<Profile>(source).ptr(), 275 content::Source<Profile>(source).ptr(),
279 content::Details<GoogleURLTracker::UpdatedDetails>(details).ptr()); 276 content::Details<GoogleURLTracker::UpdatedDetails>(details).ptr());
280 break; 277 break;
281 } 278 }
282 default: 279 default:
283 NOTREACHED() << "Unexpected notification type in InstantService."; 280 NOTREACHED() << "Unexpected notification type in InstantService.";
284 } 281 }
285 } 282 }
286 283
284 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) {
285 rph->Send(new ChromeViewMsg_SetSearchURLs(
286 chrome::GetSearchURLs(profile_), chrome::GetNewTabPageURL(profile_)));
287 }
288
289 void InstantService::OnRendererProcessTerminated(int process_id) {
290 process_ids_.erase(process_id);
291
292 if (instant_io_context_.get()) {
293 BrowserThread::PostTask(
294 BrowserThread::IO,
295 FROM_HERE,
296 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
297 instant_io_context_,
298 process_id));
299 }
300 }
301
287 void InstantService::OnMostVisitedItemsReceived( 302 void InstantService::OnMostVisitedItemsReceived(
288 const history::MostVisitedURLList& data) { 303 const history::MostVisitedURLList& data) {
289 history::MostVisitedURLList reordered_data(data); 304 history::MostVisitedURLList reordered_data(data);
290 history::MostVisitedTilesExperiment::MaybeShuffle(&reordered_data); 305 history::MostVisitedTilesExperiment::MaybeShuffle(&reordered_data);
291 306
292 std::vector<InstantMostVisitedItem> new_most_visited_items; 307 std::vector<InstantMostVisitedItem> new_most_visited_items;
293 for (size_t i = 0; i < reordered_data.size(); i++) { 308 for (size_t i = 0; i < reordered_data.size(); i++) {
294 const history::MostVisitedURL& url = reordered_data[i]; 309 const history::MostVisitedURL& url = reordered_data[i];
295 InstantMostVisitedItem item; 310 InstantMostVisitedItem item;
296 item.url = url.url; 311 item.url = url.url;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // could cause that, neither of which we support. 464 // could cause that, neither of which we support.
450 return; 465 return;
451 } 466 }
452 FOR_EACH_OBSERVER( 467 FOR_EACH_OBSERVER(
453 InstantServiceObserver, observers_, DefaultSearchProviderChanged()); 468 InstantServiceObserver, observers_, DefaultSearchProviderChanged());
454 } 469 }
455 470
456 InstantNTPPrerenderer* InstantService::ntp_prerenderer() { 471 InstantNTPPrerenderer* InstantService::ntp_prerenderer() {
457 return &ntp_prerenderer_; 472 return &ntp_prerenderer_;
458 } 473 }
OLDNEW
« no previous file with comments | « chrome/browser/search/instant_service.h ('k') | chrome/browser/search/instant_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698