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

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: Handle TemplateURL change Created 7 years, 3 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/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/history/history_notifications.h" 12 #include "chrome/browser/history/history_notifications.h"
13 #include "chrome/browser/history/most_visited_tiles_experiment.h" 13 #include "chrome/browser/history/most_visited_tiles_experiment.h"
14 #include "chrome/browser/history/top_sites.h" 14 #include "chrome/browser/history/top_sites.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search/instant_io_context.h" 16 #include "chrome/browser/search/instant_io_context.h"
17 #include "chrome/browser/search/instant_service_factory.h" 17 #include "chrome/browser/search/instant_service_factory.h"
18 #include "chrome/browser/search/instant_service_observer.h" 18 #include "chrome/browser/search/instant_service_observer.h"
19 #include "chrome/browser/search/local_ntp_source.h" 19 #include "chrome/browser/search/local_ntp_source.h"
20 #include "chrome/browser/search/most_visited_iframe_source.h" 20 #include "chrome/browser/search/most_visited_iframe_source.h"
21 #include "chrome/browser/search/search.h" 21 #include "chrome/browser/search/search.h"
22 #include "chrome/browser/themes/theme_properties.h" 22 #include "chrome/browser/themes/theme_properties.h"
23 #include "chrome/browser/themes/theme_service.h" 23 #include "chrome/browser/themes/theme_service.h"
24 #include "chrome/browser/themes/theme_service_factory.h" 24 #include "chrome/browser/themes/theme_service_factory.h"
25 #include "chrome/browser/ui/webui/favicon_source.h" 25 #include "chrome/browser/ui/webui/favicon_source.h"
26 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" 26 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
27 #include "chrome/browser/ui/webui/theme_source.h" 27 #include "chrome/browser/ui/webui/theme_source.h"
28 #include "chrome/common/render_messages.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
31 #include "content/public/browser/render_process_host.h" 32 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/url_data_source.h" 33 #include "content/public/browser/url_data_source.h"
33 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
34 #include "net/url_request/url_request.h" 35 #include "net/url_request/url_request.h"
35 #include "ui/gfx/color_utils.h" 36 #include "ui/gfx/color_utils.h"
36 #include "ui/gfx/image/image_skia.h" 37 #include "ui/gfx/image/image_skia.h"
37 #include "ui/gfx/sys_color_change_listener.h" 38 #include "ui/gfx/sys_color_change_listener.h"
(...skipping 20 matching lines...) Expand all
58 InstantService::InstantService(Profile* profile) 59 InstantService::InstantService(Profile* profile)
59 : profile_(profile), 60 : profile_(profile),
60 ntp_prerenderer_(profile, profile->GetPrefs()), 61 ntp_prerenderer_(profile, profile->GetPrefs()),
61 browser_instant_controller_object_count_(0), 62 browser_instant_controller_object_count_(0),
62 weak_ptr_factory_(this) { 63 weak_ptr_factory_(this) {
63 // Stub for unit tests. 64 // Stub for unit tests.
64 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) 65 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
65 return; 66 return;
66 67
67 registrar_.Add(this, 68 registrar_.Add(this,
69 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
70 content::NotificationService::AllSources());
71 registrar_.Add(this,
68 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 72 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
69 content::NotificationService::AllSources()); 73 content::NotificationService::AllSources());
70 74
71 history::TopSites* top_sites = profile_->GetTopSites(); 75 history::TopSites* top_sites = profile_->GetTopSites();
72 if (top_sites) { 76 if (top_sites) {
73 registrar_.Add(this, 77 registrar_.Add(this,
74 chrome::NOTIFICATION_TOP_SITES_CHANGED, 78 chrome::NOTIFICATION_TOP_SITES_CHANGED,
75 content::Source<history::TopSites>(top_sites)); 79 content::Source<history::TopSites>(top_sites));
76 } 80 }
77 instant_io_context_ = new InstantIOContext(); 81 instant_io_context_ = new InstantIOContext();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // All browser windows have closed, so release the InstantNTP resources to 212 // All browser windows have closed, so release the InstantNTP resources to
209 // work around http://crbug.com/180810. 213 // work around http://crbug.com/180810.
210 if (browser_instant_controller_object_count_ == 0) 214 if (browser_instant_controller_object_count_ == 0)
211 ntp_prerenderer_.DeleteNTPContents(); 215 ntp_prerenderer_.DeleteNTPContents();
212 } 216 }
213 217
214 void InstantService::Observe(int type, 218 void InstantService::Observe(int type,
215 const content::NotificationSource& source, 219 const content::NotificationSource& source,
216 const content::NotificationDetails& details) { 220 const content::NotificationDetails& details) {
217 switch (type) { 221 switch (type) {
218 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { 222 case content::NOTIFICATION_RENDERER_PROCESS_CREATED:
219 int process_id = 223 SendSearchURLsToRenderer(
220 content::Source<content::RenderProcessHost>(source)->GetID(); 224 content::Source<content::RenderProcessHost>(source).ptr());
221 process_ids_.erase(process_id);
222
223 if (instant_io_context_.get()) {
224 BrowserThread::PostTask(
225 BrowserThread::IO,
226 FROM_HERE,
227 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
228 instant_io_context_,
229 process_id));
230 }
231 break; 225 break;
232 } 226 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
227 OnRendererProcessTerminated(
228 content::Source<content::RenderProcessHost>(source)->GetID());
229 break;
233 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { 230 case chrome::NOTIFICATION_TOP_SITES_CHANGED: {
234 history::TopSites* top_sites = profile_->GetTopSites(); 231 history::TopSites* top_sites = profile_->GetTopSites();
235 if (top_sites) { 232 if (top_sites) {
236 top_sites->GetMostVisitedURLs( 233 top_sites->GetMostVisitedURLs(
237 base::Bind(&InstantService::OnMostVisitedItemsReceived, 234 base::Bind(&InstantService::OnMostVisitedItemsReceived,
238 weak_ptr_factory_.GetWeakPtr())); 235 weak_ptr_factory_.GetWeakPtr()));
239 } 236 }
240 break; 237 break;
241 } 238 }
242 #if defined(ENABLE_THEMES) 239 #if defined(ENABLE_THEMES)
(...skipping 10 matching lines...) Expand all
253 // and Profile destruction. 250 // and Profile destruction.
254 if (GetNTPContents()) 251 if (GetNTPContents())
255 ntp_prerenderer_.DeleteNTPContents(); 252 ntp_prerenderer_.DeleteNTPContents();
256 break; 253 break;
257 } 254 }
258 default: 255 default:
259 NOTREACHED() << "Unexpected notification type in InstantService."; 256 NOTREACHED() << "Unexpected notification type in InstantService.";
260 } 257 }
261 } 258 }
262 259
260 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) {
samarth 2013/09/20 16:43:40 Test please. Anuj's pending change adds a unit tes
Jered 2013/09/20 20:55:49 I added a simple test. I'll merge up to Anuj's cha
261 rph->Send(new ChromeViewMsg_SetSearchURLs(
262 chrome::GetSearchURLs(profile_), chrome::GetNewTabPageURL(profile_)));
263 }
264
265 void InstantService::OnRendererProcessTerminated(int process_id) {
266 process_ids_.erase(process_id);
267
268 if (instant_io_context_.get()) {
269 BrowserThread::PostTask(
270 BrowserThread::IO,
271 FROM_HERE,
272 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
273 instant_io_context_,
274 process_id));
275 }
276 }
277
263 void InstantService::OnMostVisitedItemsReceived( 278 void InstantService::OnMostVisitedItemsReceived(
264 const history::MostVisitedURLList& data) { 279 const history::MostVisitedURLList& data) {
265 history::MostVisitedURLList reordered_data(data); 280 history::MostVisitedURLList reordered_data(data);
266 history::MostVisitedTilesExperiment::MaybeShuffle(&reordered_data); 281 history::MostVisitedTilesExperiment::MaybeShuffle(&reordered_data);
267 282
268 std::vector<InstantMostVisitedItem> new_most_visited_items; 283 std::vector<InstantMostVisitedItem> new_most_visited_items;
269 for (size_t i = 0; i < reordered_data.size(); i++) { 284 for (size_t i = 0; i < reordered_data.size(); i++) {
270 const history::MostVisitedURL& url = reordered_data[i]; 285 const history::MostVisitedURL& url = reordered_data[i];
271 InstantMostVisitedItem item; 286 InstantMostVisitedItem item;
272 item.url = url.url; 287 item.url = url.url;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); 402 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION);
388 } 403 }
389 404
390 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, 405 FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
391 ThemeInfoChanged(*theme_info_)); 406 ThemeInfoChanged(*theme_info_));
392 } 407 }
393 408
394 InstantNTPPrerenderer* InstantService::ntp_prerenderer() { 409 InstantNTPPrerenderer* InstantService::ntp_prerenderer() {
395 return &ntp_prerenderer_; 410 return &ntp_prerenderer_;
396 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698