Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 15041004: Replace PruneAllButActive with PruneAllButVisible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update tests, mark TODOs Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/string_util.h" 10 #include "base/string_util.h"
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 return false; 818 return false;
819 819
820 if (type == INSTANT_COMMIT_FOCUS_LOST) { 820 if (type == INSTANT_COMMIT_FOCUS_LOST) {
821 // Extended mode doesn't need or use the Cancel message. 821 // Extended mode doesn't need or use the Cancel message.
822 if (!extended_enabled_) 822 if (!extended_enabled_)
823 overlay_->Cancel(last_omnibox_text_); 823 overlay_->Cancel(last_omnibox_text_);
824 } else if (type != INSTANT_COMMIT_NAVIGATED) { 824 } else if (type != INSTANT_COMMIT_NAVIGATED) {
825 overlay_->Submit(last_omnibox_text_); 825 overlay_->Submit(last_omnibox_text_);
826 } 826 }
827 827
828 // Make sure the overlay WebContents is in a valid state (i.e., has a last
829 // committed entry, no transient entry, and no existing pending entry).
828 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents(); 830 scoped_ptr<content::WebContents> overlay = overlay_->ReleaseContents();
831 if (!overlay || !overlay->GetController().CanPruneAllButVisible())
832 return false;
829 833
830 // If the overlay page has navigated since the last Update(), we need to add 834 // If the overlay page has navigated since the last Update(), we need to add
831 // the navigation to history ourselves. Else, the page will navigate after 835 // the navigation to history ourselves. Else, the page will navigate after
832 // commit, and it will be added to history in the usual manner. 836 // commit, and it will be added to history in the usual manner.
833 const history::HistoryAddPageArgs& last_navigation = 837 const history::HistoryAddPageArgs& last_navigation =
834 overlay_->last_navigation(); 838 overlay_->last_navigation();
835 if (!last_navigation.url.is_empty()) { 839 if (!last_navigation.url.is_empty()) {
836 content::NavigationEntry* entry = overlay->GetController().GetActiveEntry(); 840 content::NavigationEntry* entry = overlay->GetController().GetActiveEntry();
837 841
838 // The last navigation should be the same as the active entry if the overlay 842 // The last navigation should be the same as the active entry if the overlay
(...skipping 19 matching lines...) Expand all
858 HistoryService* history = HistoryServiceFactory::GetForProfile( 862 HistoryService* history = HistoryServiceFactory::GetForProfile(
859 Profile::FromBrowserContext(overlay->GetBrowserContext()), 863 Profile::FromBrowserContext(overlay->GetBrowserContext()),
860 Profile::EXPLICIT_ACCESS); 864 Profile::EXPLICIT_ACCESS);
861 if (history) { 865 if (history) {
862 history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(), 866 history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(),
863 history::RedirectList(), last_transition_type_, 867 history::RedirectList(), last_transition_type_,
864 history::SOURCE_BROWSED, false); 868 history::SOURCE_BROWSED, false);
865 } 869 }
866 870
867 if (type == INSTANT_COMMIT_PRESSED_ALT_ENTER) { 871 if (type == INSTANT_COMMIT_PRESSED_ALT_ENTER) {
868 overlay->GetController().PruneAllButActive(); 872 CHECK(overlay->GetController().PruneAllButVisible());
869 } else { 873 } else {
870 content::WebContents* active_tab = browser_->GetActiveWebContents(); 874 content::WebContents* active_tab = browser_->GetActiveWebContents();
871 AddSessionStorageHistogram(extended_enabled_, active_tab, overlay.get()); 875 AddSessionStorageHistogram(extended_enabled_, active_tab, overlay.get());
872 overlay->GetController().CopyStateFromAndPrune( 876 CHECK(overlay->GetController().CopyStateFromAndPrune(
873 &active_tab->GetController()); 877 &active_tab->GetController()));
874 } 878 }
875 879
876 if (extended_enabled_) { 880 if (extended_enabled_) {
877 // Adjust the search terms shown in the omnibox for this query. Hitting 881 // Adjust the search terms shown in the omnibox for this query. Hitting
878 // ENTER searches for what the user typed, so use last_omnibox_text_. 882 // ENTER searches for what the user typed, so use last_omnibox_text_.
879 // Clicking on the overlay commits what is currently showing, so add in the 883 // Clicking on the overlay commits what is currently showing, so add in the
880 // gray text in that case. 884 // gray text in that case.
881 if (type == INSTANT_COMMIT_FOCUS_LOST && 885 if (type == INSTANT_COMMIT_FOCUS_LOST &&
882 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER) { 886 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER) {
883 // Update |last_omnibox_text_| so that the controller commits the proper 887 // Update |last_omnibox_text_| so that the controller commits the proper
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 1835
1832 result->transition = match.transition; 1836 result->transition = match.transition;
1833 result->relevance = match.relevance; 1837 result->relevance = match.relevance;
1834 result->autocomplete_match_index = autocomplete_match_index; 1838 result->autocomplete_match_index = autocomplete_match_index;
1835 1839
1836 DVLOG(1) << " " << result->relevance << " " << result->type << " " 1840 DVLOG(1) << " " << result->relevance << " " << result->type << " "
1837 << result->provider << " " << result->destination_url << " '" 1841 << result->provider << " " << result->destination_url << " '"
1838 << result->description << "' '" << result->search_query << "' " 1842 << result->description << "' '" << result->search_query << "' "
1839 << result->transition << " " << result->autocomplete_match_index; 1843 << result->transition << " " << result->autocomplete_match_index;
1840 } 1844 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698