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