Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 // All browser windows have closed, so release the InstantNTP resources to | 211 // All browser windows have closed, so release the InstantNTP resources to |
| 208 // work around http://crbug.com/180810. | 212 // work around http://crbug.com/180810. |
| 209 if (browser_instant_controller_object_count_ == 0) | 213 if (browser_instant_controller_object_count_ == 0) |
| 210 ntp_prerenderer_.DeleteNTPContents(); | 214 ntp_prerenderer_.DeleteNTPContents(); |
| 211 } | 215 } |
| 212 | 216 |
| 213 void InstantService::Observe(int type, | 217 void InstantService::Observe(int type, |
| 214 const content::NotificationSource& source, | 218 const content::NotificationSource& source, |
| 215 const content::NotificationDetails& details) { | 219 const content::NotificationDetails& details) { |
| 216 switch (type) { | 220 switch (type) { |
| 217 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | 221 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: |
| 218 int process_id = | 222 OnRendererProcessCreated( |
| 219 content::Source<content::RenderProcessHost>(source)->GetID(); | 223 content::Source<content::RenderProcessHost>(source).ptr()); |
| 220 process_ids_.erase(process_id); | |
| 221 | |
| 222 if (instant_io_context_.get()) { | |
| 223 BrowserThread::PostTask( | |
| 224 BrowserThread::IO, | |
| 225 FROM_HERE, | |
| 226 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, | |
| 227 instant_io_context_, | |
| 228 process_id)); | |
| 229 } | |
| 230 break; | 224 break; |
| 231 } | 225 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
| 226 OnRendererProcessTerminated( | |
| 227 content::Source<content::RenderProcessHost>(source)->GetID()); | |
| 228 break; | |
| 232 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { | 229 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { |
| 233 history::TopSites* top_sites = profile_->GetTopSites(); | 230 history::TopSites* top_sites = profile_->GetTopSites(); |
| 234 if (top_sites) { | 231 if (top_sites) { |
| 235 top_sites->GetMostVisitedURLs( | 232 top_sites->GetMostVisitedURLs( |
| 236 base::Bind(&InstantService::OnMostVisitedItemsReceived, | 233 base::Bind(&InstantService::OnMostVisitedItemsReceived, |
| 237 weak_ptr_factory_.GetWeakPtr())); | 234 weak_ptr_factory_.GetWeakPtr())); |
| 238 } | 235 } |
| 239 break; | 236 break; |
| 240 } | 237 } |
| 241 #if defined(ENABLE_THEMES) | 238 #if defined(ENABLE_THEMES) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 252 // and Profile destruction. | 249 // and Profile destruction. |
| 253 if (GetNTPContents()) | 250 if (GetNTPContents()) |
| 254 ntp_prerenderer_.DeleteNTPContents(); | 251 ntp_prerenderer_.DeleteNTPContents(); |
| 255 break; | 252 break; |
| 256 } | 253 } |
| 257 default: | 254 default: |
| 258 NOTREACHED() << "Unexpected notification type in InstantService."; | 255 NOTREACHED() << "Unexpected notification type in InstantService."; |
| 259 } | 256 } |
| 260 } | 257 } |
| 261 | 258 |
| 259 void InstantService::OnRendererProcessCreated(content::RenderProcessHost* rph) { | |
| 260 rph->Send(new ChromeViewMsg_SetSearchURLs( | |
|
samarth
2013/09/17 20:51:00
You need to send these on template url updates as
Jered
2013/09/18 21:35:05
Done.
| |
| 261 chrome::GetSearchURLs(profile_), chrome::GetNewTabPageURL(profile_))); | |
| 262 } | |
| 263 | |
| 264 void InstantService::OnRendererProcessTerminated(int process_id) { | |
| 265 process_ids_.erase(process_id); | |
| 266 | |
| 267 if (instant_io_context_.get()) { | |
| 268 BrowserThread::PostTask( | |
| 269 BrowserThread::IO, | |
| 270 FROM_HERE, | |
| 271 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, | |
| 272 instant_io_context_, | |
| 273 process_id)); | |
| 274 } | |
| 275 } | |
| 276 | |
| 262 void InstantService::OnMostVisitedItemsReceived( | 277 void InstantService::OnMostVisitedItemsReceived( |
| 263 const history::MostVisitedURLList& data) { | 278 const history::MostVisitedURLList& data) { |
| 264 history::MostVisitedURLList reordered_data(data); | 279 history::MostVisitedURLList reordered_data(data); |
| 265 history::MostVisitedTilesExperiment::MaybeShuffle(&reordered_data); | 280 history::MostVisitedTilesExperiment::MaybeShuffle(&reordered_data); |
| 266 | 281 |
| 267 std::vector<InstantMostVisitedItem> new_most_visited_items; | 282 std::vector<InstantMostVisitedItem> new_most_visited_items; |
| 268 for (size_t i = 0; i < reordered_data.size(); i++) { | 283 for (size_t i = 0; i < reordered_data.size(); i++) { |
| 269 const history::MostVisitedURL& url = reordered_data[i]; | 284 const history::MostVisitedURL& url = reordered_data[i]; |
| 270 InstantMostVisitedItem item; | 285 InstantMostVisitedItem item; |
| 271 item.url = url.url; | 286 item.url = url.url; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); | 401 theme_service->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION); |
| 387 } | 402 } |
| 388 | 403 |
| 389 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 404 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 390 ThemeInfoChanged(*theme_info_)); | 405 ThemeInfoChanged(*theme_info_)); |
| 391 } | 406 } |
| 392 | 407 |
| 393 InstantNTPPrerenderer* InstantService::ntp_prerenderer() { | 408 InstantNTPPrerenderer* InstantService::ntp_prerenderer() { |
| 394 return &ntp_prerenderer_; | 409 return &ntp_prerenderer_; |
| 395 } | 410 } |
| OLD | NEW |