| 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 "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/history/top_sites.h" | 8 #include "chrome/browser/history/top_sites.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search/instant_io_context.h" | 10 #include "chrome/browser/search/instant_io_context.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 ResetInstantSearchPrerenderer(); | 86 ResetInstantSearchPrerenderer(); |
| 87 | 87 |
| 88 registrar_.Add(this, | 88 registrar_.Add(this, |
| 89 content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 89 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 90 content::NotificationService::AllSources()); | 90 content::NotificationService::AllSources()); |
| 91 registrar_.Add(this, | 91 registrar_.Add(this, |
| 92 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 92 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 93 content::NotificationService::AllSources()); | 93 content::NotificationService::AllSources()); |
| 94 | 94 |
| 95 history::TopSites* top_sites = profile_->GetTopSites(); | 95 history::TopSites* top_sites = profile_->GetTopSites(); |
| 96 if (top_sites) { | 96 if (top_sites) |
| 97 registrar_.Add(this, | 97 top_sites->AddObserver(this); |
| 98 chrome::NOTIFICATION_TOP_SITES_CHANGED, | |
| 99 content::Source<history::TopSites>(top_sites)); | |
| 100 } | |
| 101 | 98 |
| 102 if (profile_ && profile_->GetResourceContext()) { | 99 if (profile_ && profile_->GetResourceContext()) { |
| 103 content::BrowserThread::PostTask( | 100 content::BrowserThread::PostTask( |
| 104 content::BrowserThread::IO, FROM_HERE, | 101 content::BrowserThread::IO, FROM_HERE, |
| 105 base::Bind(&InstantIOContext::SetUserDataOnIO, | 102 base::Bind(&InstantIOContext::SetUserDataOnIO, |
| 106 profile->GetResourceContext(), instant_io_context_)); | 103 profile->GetResourceContext(), instant_io_context_)); |
| 107 } | 104 } |
| 108 | 105 |
| 109 // Set up the data sources that Instant uses on the NTP. | 106 // Set up the data sources that Instant uses on the NTP. |
| 110 #if defined(ENABLE_THEMES) | 107 #if defined(ENABLE_THEMES) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 196 |
| 200 void InstantService::Shutdown() { | 197 void InstantService::Shutdown() { |
| 201 process_ids_.clear(); | 198 process_ids_.clear(); |
| 202 | 199 |
| 203 if (instant_io_context_.get()) { | 200 if (instant_io_context_.get()) { |
| 204 content::BrowserThread::PostTask( | 201 content::BrowserThread::PostTask( |
| 205 content::BrowserThread::IO, FROM_HERE, | 202 content::BrowserThread::IO, FROM_HERE, |
| 206 base::Bind(&InstantIOContext::ClearInstantProcessesOnIO, | 203 base::Bind(&InstantIOContext::ClearInstantProcessesOnIO, |
| 207 instant_io_context_)); | 204 instant_io_context_)); |
| 208 } | 205 } |
| 206 |
| 207 history::TopSites* top_sites = profile_->GetTopSites(); |
| 208 if (top_sites) |
| 209 top_sites->RemoveObserver(this); |
| 210 |
| 209 instant_io_context_ = NULL; | 211 instant_io_context_ = NULL; |
| 210 } | 212 } |
| 211 | 213 |
| 212 void InstantService::Observe(int type, | 214 void InstantService::Observe(int type, |
| 213 const content::NotificationSource& source, | 215 const content::NotificationSource& source, |
| 214 const content::NotificationDetails& details) { | 216 const content::NotificationDetails& details) { |
| 215 switch (type) { | 217 switch (type) { |
| 216 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: | 218 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: |
| 217 SendSearchURLsToRenderer( | 219 SendSearchURLsToRenderer( |
| 218 content::Source<content::RenderProcessHost>(source).ptr()); | 220 content::Source<content::RenderProcessHost>(source).ptr()); |
| 219 break; | 221 break; |
| 220 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | 222 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
| 221 OnRendererProcessTerminated( | 223 OnRendererProcessTerminated( |
| 222 content::Source<content::RenderProcessHost>(source)->GetID()); | 224 content::Source<content::RenderProcessHost>(source)->GetID()); |
| 223 break; | 225 break; |
| 224 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { | |
| 225 history::TopSites* top_sites = profile_->GetTopSites(); | |
| 226 if (top_sites) { | |
| 227 top_sites->GetMostVisitedURLs( | |
| 228 base::Bind(&InstantService::OnMostVisitedItemsReceived, | |
| 229 weak_ptr_factory_.GetWeakPtr()), false); | |
| 230 } | |
| 231 break; | |
| 232 } | |
| 233 #if defined(ENABLE_THEMES) | 226 #if defined(ENABLE_THEMES) |
| 234 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 227 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
| 235 OnThemeChanged(content::Source<ThemeService>(source).ptr()); | 228 OnThemeChanged(content::Source<ThemeService>(source).ptr()); |
| 236 break; | 229 break; |
| 237 } | 230 } |
| 238 #endif // defined(ENABLE_THEMES) | 231 #endif // defined(ENABLE_THEMES) |
| 239 default: | 232 default: |
| 240 NOTREACHED() << "Unexpected notification type in InstantService."; | 233 NOTREACHED() << "Unexpected notification type in InstantService."; |
| 241 } | 234 } |
| 242 } | 235 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 default_search_provider_changed = true; | 409 default_search_provider_changed = true; |
| 417 } | 410 } |
| 418 | 411 |
| 419 if (default_search_provider_changed) { | 412 if (default_search_provider_changed) { |
| 420 ResetInstantSearchPrerenderer(); | 413 ResetInstantSearchPrerenderer(); |
| 421 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | 414 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, |
| 422 DefaultSearchProviderChanged()); | 415 DefaultSearchProviderChanged()); |
| 423 } | 416 } |
| 424 } | 417 } |
| 425 | 418 |
| 419 void InstantService::TopSitesLoaded(history::TopSites* top_sites) { |
| 420 } |
| 421 |
| 422 void InstantService::TopSitesChanged(history::TopSites* top_sites) { |
| 423 top_sites->GetMostVisitedURLs( |
| 424 base::Bind(&InstantService::OnMostVisitedItemsReceived, |
| 425 weak_ptr_factory_.GetWeakPtr()), |
| 426 false); |
| 427 } |
| 428 |
| 426 void InstantService::ResetInstantSearchPrerenderer() { | 429 void InstantService::ResetInstantSearchPrerenderer() { |
| 427 if (!chrome::ShouldPrefetchSearchResults()) | 430 if (!chrome::ShouldPrefetchSearchResults()) |
| 428 return; | 431 return; |
| 429 | 432 |
| 430 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); | 433 GURL url(chrome::GetSearchResultPrefetchBaseURL(profile_)); |
| 431 instant_prerenderer_.reset( | 434 instant_prerenderer_.reset( |
| 432 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); | 435 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); |
| 433 } | 436 } |
| OLD | NEW |