| 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 "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return base::StartsWith( | 63 return base::StartsWith( |
| 64 base::FieldTrialList::FindFullName(kLocalNTPSuggestionService), | 64 base::FieldTrialList::FindFullName(kLocalNTPSuggestionService), |
| 65 kLocalNTPSuggestionServiceEnabled, base::CompareCase::INSENSITIVE_ASCII); | 65 kLocalNTPSuggestionServiceEnabled, base::CompareCase::INSENSITIVE_ASCII); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 InstantService::InstantService(Profile* profile) | 70 InstantService::InstantService(Profile* profile) |
| 71 : profile_(profile), | 71 : profile_(profile), |
| 72 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), | 72 template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
| 73 omnibox_start_margin_(search::kDisableStartMargin), | |
| 74 suggestions_service_(NULL), | 73 suggestions_service_(NULL), |
| 75 weak_ptr_factory_(this) { | 74 weak_ptr_factory_(this) { |
| 76 // The initialization below depends on a typical set of browser threads. Skip | 75 // The initialization below depends on a typical set of browser threads. Skip |
| 77 // it if we are running in a unit test without the full suite. | 76 // it if we are running in a unit test without the full suite. |
| 78 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) | 77 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) |
| 79 return; | 78 return; |
| 80 | 79 |
| 81 // This depends on the existence of the typical browser threads. Therefore it | 80 // This depends on the existence of the typical browser threads. Therefore it |
| 82 // is only instantiated here (after the check for a UI thread above). | 81 // is only instantiated here (after the check for a UI thread above). |
| 83 instant_io_context_ = new InstantIOContext(); | 82 instant_io_context_ = new InstantIOContext(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 default: | 286 default: |
| 288 NOTREACHED() << "Unexpected notification type in InstantService."; | 287 NOTREACHED() << "Unexpected notification type in InstantService."; |
| 289 } | 288 } |
| 290 } | 289 } |
| 291 | 290 |
| 292 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) { | 291 void InstantService::SendSearchURLsToRenderer(content::RenderProcessHost* rph) { |
| 293 rph->Send(new ChromeViewMsg_SetSearchURLs( | 292 rph->Send(new ChromeViewMsg_SetSearchURLs( |
| 294 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_))); | 293 search::GetSearchURLs(profile_), search::GetNewTabPageURL(profile_))); |
| 295 } | 294 } |
| 296 | 295 |
| 297 void InstantService::OnOmniboxStartMarginChanged(int start_margin) { | |
| 298 omnibox_start_margin_ = start_margin; | |
| 299 FOR_EACH_OBSERVER(InstantServiceObserver, observers_, | |
| 300 OmniboxStartMarginChanged(omnibox_start_margin_)); | |
| 301 } | |
| 302 | |
| 303 void InstantService::OnRendererProcessTerminated(int process_id) { | 296 void InstantService::OnRendererProcessTerminated(int process_id) { |
| 304 process_ids_.erase(process_id); | 297 process_ids_.erase(process_id); |
| 305 | 298 |
| 306 if (instant_io_context_.get()) { | 299 if (instant_io_context_.get()) { |
| 307 content::BrowserThread::PostTask( | 300 content::BrowserThread::PostTask( |
| 308 content::BrowserThread::IO, FROM_HERE, | 301 content::BrowserThread::IO, FROM_HERE, |
| 309 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, | 302 base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, |
| 310 instant_io_context_, process_id)); | 303 instant_io_context_, process_id)); |
| 311 } | 304 } |
| 312 } | 305 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 } | 528 } |
| 536 | 529 |
| 537 void InstantService::ResetInstantSearchPrerenderer() { | 530 void InstantService::ResetInstantSearchPrerenderer() { |
| 538 if (!search::ShouldPrefetchSearchResults()) | 531 if (!search::ShouldPrefetchSearchResults()) |
| 539 return; | 532 return; |
| 540 | 533 |
| 541 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); | 534 GURL url(search::GetSearchResultPrefetchBaseURL(profile_)); |
| 542 instant_prerenderer_.reset( | 535 instant_prerenderer_.reset( |
| 543 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); | 536 url.is_valid() ? new InstantSearchPrerenderer(profile_, url) : NULL); |
| 544 } | 537 } |
| OLD | NEW |