OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/search/instant_controller.h" | 5 #include "chrome/browser/ui/search/instant_controller.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 // suggestion or reset the existing "gray text". | 541 // suggestion or reset the existing "gray text". |
542 browser_->SetInstantSuggestion(last_suggestion_); | 542 browser_->SetInstantSuggestion(last_suggestion_); |
543 | 543 |
544 // Record the time of the first keypress for logging histograms. | 544 // Record the time of the first keypress for logging histograms. |
545 if (!first_interaction_time_recorded_ && first_interaction_time_.is_null()) | 545 if (!first_interaction_time_recorded_ && first_interaction_time_.is_null()) |
546 first_interaction_time_ = base::Time::Now(); | 546 first_interaction_time_ = base::Time::Now(); |
547 | 547 |
548 return true; | 548 return true; |
549 } | 549 } |
550 | 550 |
551 bool InstantController::WillFetchCompletions() const { | |
552 if (!extended_enabled()) | |
553 return false; | |
554 | |
555 return !UsingLocalPage(); | |
556 } | |
557 | |
558 scoped_ptr<content::WebContents> InstantController::ReleaseNTPContents() { | 551 scoped_ptr<content::WebContents> InstantController::ReleaseNTPContents() { |
559 if (!extended_enabled() || !browser_->profile() || | 552 if (!extended_enabled() || !browser_->profile() || |
560 browser_->profile()->IsOffTheRecord() || | 553 browser_->profile()->IsOffTheRecord() || |
561 !chrome::ShouldShowInstantNTP()) | 554 !chrome::ShouldShowInstantNTP()) |
562 return scoped_ptr<content::WebContents>(); | 555 return scoped_ptr<content::WebContents>(); |
563 | 556 |
564 LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents"); | 557 LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents"); |
565 | 558 |
566 if (ShouldSwitchToLocalNTP()) | 559 if (ShouldSwitchToLocalNTP()) |
567 ResetNTP(GetLocalInstantURL()); | 560 ResetNTP(GetLocalInstantURL()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 return; | 610 return; |
618 | 611 |
619 if (!UseTabForSuggestions() && !overlay_) | 612 if (!UseTabForSuggestions() && !overlay_) |
620 return; | 613 return; |
621 | 614 |
622 // The omnibox sends suggestions when its possibly imaginary popup closes | 615 // The omnibox sends suggestions when its possibly imaginary popup closes |
623 // as it stops autocomplete. Ignore these. | 616 // as it stops autocomplete. Ignore these. |
624 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) | 617 if (omnibox_focus_state_ == OMNIBOX_FOCUS_NONE) |
625 return; | 618 return; |
626 | 619 |
627 for (ACProviders::const_iterator provider = providers.begin(); | |
628 provider != providers.end(); ++provider) { | |
629 const bool from_search_provider = | |
630 (*provider)->type() == AutocompleteProvider::TYPE_SEARCH; | |
631 | |
632 // TODO(jeremycho): Pass search_provider() as a parameter to this function | |
633 // and remove the static cast. | |
634 const bool provider_done = from_search_provider ? | |
635 static_cast<SearchProvider*>(*provider)->IsNonInstantSearchDone() : | |
636 (*provider)->done(); | |
637 if (!provider_done) { | |
638 DVLOG(1) << "Waiting for " << (*provider)->GetName(); | |
639 return; | |
640 } | |
641 } | |
642 | |
643 DVLOG(1) << "AutocompleteResults:"; | 620 DVLOG(1) << "AutocompleteResults:"; |
644 std::vector<InstantAutocompleteResult> results; | 621 std::vector<InstantAutocompleteResult> results; |
645 if (UsingLocalPage()) { | 622 if (UsingLocalPage()) { |
646 for (AutocompleteResult::const_iterator match(autocomplete_result.begin()); | 623 for (AutocompleteResult::const_iterator match(autocomplete_result.begin()); |
647 match != autocomplete_result.end(); ++match) { | 624 match != autocomplete_result.end(); ++match) { |
648 InstantAutocompleteResult result; | 625 InstantAutocompleteResult result; |
649 PopulateInstantAutocompleteResultFromMatch( | 626 PopulateInstantAutocompleteResultFromMatch( |
650 *match, std::distance(autocomplete_result.begin(), match), &result); | 627 *match, std::distance(autocomplete_result.begin(), match), &result); |
651 results.push_back(result); | 628 results.push_back(result); |
652 } | 629 } |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 | 1899 |
1923 bool InstantController::InStartup() const { | 1900 bool InstantController::InStartup() const { |
1924 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1901 // TODO(shishir): This is not completely reliable. Find a better way to detect |
1925 // startup time. | 1902 // startup time. |
1926 return !browser_->GetActiveWebContents(); | 1903 return !browser_->GetActiveWebContents(); |
1927 } | 1904 } |
1928 | 1905 |
1929 InstantService* InstantController::GetInstantService() const { | 1906 InstantService* InstantController::GetInstantService() const { |
1930 return InstantServiceFactory::GetForProfile(profile()); | 1907 return InstantServiceFactory::GetForProfile(profile()); |
1931 } | 1908 } |
OLD | NEW |