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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 562603002: Move PageTransition from //content/public/common to //ui/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_edit_model.h ('k') | chrome/browser/ui/panels/panel_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/omnibox/omnibox_edit_model.h" 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // between focusing and opening an omnibox match. 112 // between focusing and opening an omnibox match.
113 const char kFocusToOpenTimeHistogram[] = "Omnibox.FocusToOpenTimeAnyPopupState"; 113 const char kFocusToOpenTimeHistogram[] = "Omnibox.FocusToOpenTimeAnyPopupState";
114 114
115 // Split the percentage match histograms into buckets based on the width of the 115 // Split the percentage match histograms into buckets based on the width of the
116 // omnibox. 116 // omnibox.
117 const int kPercentageMatchHistogramWidthBuckets[] = { 400, 700, 1200 }; 117 const int kPercentageMatchHistogramWidthBuckets[] = { 400, 700, 1200 };
118 118
119 void RecordPercentageMatchHistogram(const base::string16& old_text, 119 void RecordPercentageMatchHistogram(const base::string16& old_text,
120 const base::string16& new_text, 120 const base::string16& new_text,
121 bool url_replacement_active, 121 bool url_replacement_active,
122 content::PageTransition transition, 122 ui::PageTransition transition,
123 int omnibox_width) { 123 int omnibox_width) {
124 size_t avg_length = (old_text.length() + new_text.length()) / 2; 124 size_t avg_length = (old_text.length() + new_text.length()) / 2;
125 125
126 int percent = 0; 126 int percent = 0;
127 if (!old_text.empty() && !new_text.empty()) { 127 if (!old_text.empty() && !new_text.empty()) {
128 size_t shorter_length = std::min(old_text.length(), new_text.length()); 128 size_t shorter_length = std::min(old_text.length(), new_text.length());
129 base::string16::const_iterator end(old_text.begin() + shorter_length); 129 base::string16::const_iterator end(old_text.begin() + shorter_length);
130 base::string16::const_iterator mismatch( 130 base::string16::const_iterator mismatch(
131 std::mismatch(old_text.begin(), end, new_text.begin()).first); 131 std::mismatch(old_text.begin(), end, new_text.begin()).first);
132 size_t matching_characters = mismatch - old_text.begin(); 132 size_t matching_characters = mismatch - old_text.begin();
133 percent = static_cast<float>(matching_characters) / avg_length * 100; 133 percent = static_cast<float>(matching_characters) / avg_length * 100;
134 } 134 }
135 135
136 std::string histogram_name; 136 std::string histogram_name;
137 if (url_replacement_active) { 137 if (url_replacement_active) {
138 if (transition == content::PAGE_TRANSITION_TYPED) { 138 if (transition == ui::PAGE_TRANSITION_TYPED) {
139 histogram_name = "InstantExtended.PercentageMatchV2_QuerytoURL"; 139 histogram_name = "InstantExtended.PercentageMatchV2_QuerytoURL";
140 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent); 140 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent);
141 } else { 141 } else {
142 histogram_name = "InstantExtended.PercentageMatchV2_QuerytoQuery"; 142 histogram_name = "InstantExtended.PercentageMatchV2_QuerytoQuery";
143 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent); 143 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent);
144 } 144 }
145 } else { 145 } else {
146 if (transition == content::PAGE_TRANSITION_TYPED) { 146 if (transition == ui::PAGE_TRANSITION_TYPED) {
147 histogram_name = "InstantExtended.PercentageMatchV2_URLtoURL"; 147 histogram_name = "InstantExtended.PercentageMatchV2_URLtoURL";
148 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent); 148 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent);
149 } else { 149 } else {
150 histogram_name = "InstantExtended.PercentageMatchV2_URLtoQuery"; 150 histogram_name = "InstantExtended.PercentageMatchV2_URLtoQuery";
151 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent); 151 UMA_HISTOGRAM_PERCENTAGE(histogram_name, percent);
152 } 152 }
153 } 153 }
154 154
155 std::string suffix = "large"; 155 std::string suffix = "large";
156 for (size_t i = 0; i < arraysize(kPercentageMatchHistogramWidthBuckets); 156 for (size_t i = 0; i < arraysize(kPercentageMatchHistogramWidthBuckets);
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 if (url_match.destination_url.is_valid()) { 662 if (url_match.destination_url.is_valid()) {
663 // We have a valid URL, we use this newly generated AutocompleteMatch. 663 // We have a valid URL, we use this newly generated AutocompleteMatch.
664 match = url_match; 664 match = url_match;
665 alternate_nav_url = GURL(); 665 alternate_nav_url = GURL();
666 } 666 }
667 } 667 }
668 668
669 if (!match.destination_url.is_valid()) 669 if (!match.destination_url.is_valid())
670 return; 670 return;
671 671
672 if ((match.transition == content::PAGE_TRANSITION_TYPED) && 672 if ((match.transition == ui::PAGE_TRANSITION_TYPED) &&
673 (match.destination_url == PermanentURL())) { 673 (match.destination_url == PermanentURL())) {
674 // When the user hit enter on the existing permanent URL, treat it like a 674 // When the user hit enter on the existing permanent URL, treat it like a
675 // reload for scoring purposes. We could detect this by just checking 675 // reload for scoring purposes. We could detect this by just checking
676 // user_input_in_progress_, but it seems better to treat "edits" that end 676 // user_input_in_progress_, but it seems better to treat "edits" that end
677 // up leaving the URL unchanged (e.g. deleting the last character and then 677 // up leaving the URL unchanged (e.g. deleting the last character and then
678 // retyping it) as reloads too. We exclude non-TYPED transitions because if 678 // retyping it) as reloads too. We exclude non-TYPED transitions because if
679 // the transition is GENERATED, the user input something that looked 679 // the transition is GENERATED, the user input something that looked
680 // different from the current URL, even if it wound up at the same place 680 // different from the current URL, even if it wound up at the same place
681 // (e.g. manually retyping the same search query), and it seems wrong to 681 // (e.g. manually retyping the same search query), and it seems wrong to
682 // treat this as a reload. 682 // treat this as a reload.
683 match.transition = content::PAGE_TRANSITION_RELOAD; 683 match.transition = ui::PAGE_TRANSITION_RELOAD;
684 } else if (for_drop || ((paste_state_ != NONE) && 684 } else if (for_drop || ((paste_state_ != NONE) &&
685 match.is_history_what_you_typed_match)) { 685 match.is_history_what_you_typed_match)) {
686 // When the user pasted in a URL and hit enter, score it like a link click 686 // When the user pasted in a URL and hit enter, score it like a link click
687 // rather than a normal typed URL, so it doesn't get inline autocompleted 687 // rather than a normal typed URL, so it doesn't get inline autocompleted
688 // as aggressively later. 688 // as aggressively later.
689 match.transition = content::PAGE_TRANSITION_LINK; 689 match.transition = ui::PAGE_TRANSITION_LINK;
690 } 690 }
691 691
692 TemplateURLService* service = 692 TemplateURLService* service =
693 TemplateURLServiceFactory::GetForProfile(profile_); 693 TemplateURLServiceFactory::GetForProfile(profile_);
694 const TemplateURL* template_url = match.GetTemplateURL(service, false); 694 const TemplateURL* template_url = match.GetTemplateURL(service, false);
695 if (template_url && template_url->url_ref().HasGoogleBaseURLs( 695 if (template_url && template_url->url_ref().HasGoogleBaseURLs(
696 UIThreadSearchTermsData(profile_))) { 696 UIThreadSearchTermsData(profile_))) {
697 GoogleURLTracker* tracker = 697 GoogleURLTracker* tracker =
698 GoogleURLTrackerFactory::GetForProfile(profile_); 698 GoogleURLTrackerFactory::GetForProfile(profile_);
699 if (tracker) 699 if (tracker)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 content::Details<OmniboxLog>(&log)); 785 content::Details<OmniboxLog>(&log));
786 LOCAL_HISTOGRAM_BOOLEAN("Omnibox.EventCount", true); 786 LOCAL_HISTOGRAM_BOOLEAN("Omnibox.EventCount", true);
787 DCHECK(!last_omnibox_focus_.is_null()) 787 DCHECK(!last_omnibox_focus_.is_null())
788 << "An omnibox focus should have occurred before opening a match."; 788 << "An omnibox focus should have occurred before opening a match.";
789 UMA_HISTOGRAM_TIMES(kFocusToOpenTimeHistogram, now - last_omnibox_focus_); 789 UMA_HISTOGRAM_TIMES(kFocusToOpenTimeHistogram, now - last_omnibox_focus_);
790 790
791 TemplateURLService* service = 791 TemplateURLService* service =
792 TemplateURLServiceFactory::GetForProfile(profile_); 792 TemplateURLServiceFactory::GetForProfile(profile_);
793 TemplateURL* template_url = match.GetTemplateURL(service, false); 793 TemplateURL* template_url = match.GetTemplateURL(service, false);
794 if (template_url) { 794 if (template_url) {
795 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { 795 if (match.transition == ui::PAGE_TRANSITION_KEYWORD) {
796 // The user is using a non-substituting keyword or is explicitly in 796 // The user is using a non-substituting keyword or is explicitly in
797 // keyword mode. 797 // keyword mode.
798 798
799 // Don't increment usage count for extension keywords. 799 // Don't increment usage count for extension keywords.
800 if (delegate_->ProcessExtensionKeyword(template_url, match, 800 if (delegate_->ProcessExtensionKeyword(template_url, match,
801 disposition)) { 801 disposition)) {
802 observer->OnSuccessfulNavigation(); 802 observer->OnSuccessfulNavigation();
803 if (disposition != NEW_BACKGROUND_TAB) 803 if (disposition != NEW_BACKGROUND_TAB)
804 view_->RevertAll(); 804 view_->RevertAll();
805 return; 805 return;
806 } 806 }
807 807
808 content::RecordAction(base::UserMetricsAction("AcceptedKeyword")); 808 content::RecordAction(base::UserMetricsAction("AcceptedKeyword"));
809 TemplateURLServiceFactory::GetForProfile(profile_)->IncrementUsageCount( 809 TemplateURLServiceFactory::GetForProfile(profile_)->IncrementUsageCount(
810 template_url); 810 template_url);
811 } else { 811 } else {
812 DCHECK_EQ(content::PAGE_TRANSITION_GENERATED, match.transition); 812 DCHECK_EQ(ui::PAGE_TRANSITION_GENERATED, match.transition);
813 // NOTE: We purposefully don't increment the usage count of the default 813 // NOTE: We purposefully don't increment the usage count of the default
814 // search engine here like we do for explicit keywords above; see comments 814 // search engine here like we do for explicit keywords above; see comments
815 // in template_url.h. 815 // in template_url.h.
816 } 816 }
817 817
818 UMA_HISTOGRAM_ENUMERATION( 818 UMA_HISTOGRAM_ENUMERATION(
819 "Omnibox.SearchEngineType", 819 "Omnibox.SearchEngineType",
820 TemplateURLPrepopulateData::GetEngineType( 820 TemplateURLPrepopulateData::GetEngineType(
821 *template_url, UIThreadSearchTermsData(profile_)), 821 *template_url, UIThreadSearchTermsData(profile_)),
822 SEARCH_ENGINE_MAX); 822 SEARCH_ENGINE_MAX);
(...skipping 18 matching lines...) Expand all
841 IsSearchResultsPageFromDefaultSearchProvider(match.destination_url)) { 841 IsSearchResultsPageFromDefaultSearchProvider(match.destination_url)) {
842 content::RecordAction( 842 content::RecordAction(
843 base::UserMetricsAction("OmniboxDestinationURLIsSearchOnDSP")); 843 base::UserMetricsAction("OmniboxDestinationURLIsSearchOnDSP"));
844 } 844 }
845 845
846 if (match.destination_url.is_valid()) { 846 if (match.destination_url.is_valid()) {
847 // This calls RevertAll again. 847 // This calls RevertAll again.
848 base::AutoReset<bool> tmp(&in_revert_, true); 848 base::AutoReset<bool> tmp(&in_revert_, true);
849 controller_->OnAutocompleteAccept( 849 controller_->OnAutocompleteAccept(
850 match.destination_url, disposition, 850 match.destination_url, disposition,
851 content::PageTransitionFromInt( 851 ui::PageTransitionFromInt(
852 match.transition | content::PAGE_TRANSITION_FROM_ADDRESS_BAR)); 852 match.transition | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR));
853 if (observer->load_state() != OmniboxNavigationObserver::LOAD_NOT_SEEN) 853 if (observer->load_state() != OmniboxNavigationObserver::LOAD_NOT_SEEN)
854 ignore_result(observer.release()); // The observer will delete itself. 854 ignore_result(observer.release()); // The observer will delete itself.
855 } 855 }
856 856
857 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); 857 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_);
858 if (bookmark_model && bookmark_model->IsBookmarked(match.destination_url)) 858 if (bookmark_model && bookmark_model->IsBookmarked(match.destination_url))
859 RecordBookmarkLaunch(NULL, BOOKMARK_LAUNCH_LOCATION_OMNIBOX); 859 RecordBookmarkLaunch(NULL, BOOKMARK_LAUNCH_LOCATION_OMNIBOX);
860 } 860 }
861 861
862 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { 862 bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) {
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 // explicitly set up a match that will reload here. 1332 // explicitly set up a match that will reload here.
1333 1333
1334 // It's important that we fetch the current visible URL to reload instead of 1334 // It's important that we fetch the current visible URL to reload instead of
1335 // just getting a "search what you typed" URL from 1335 // just getting a "search what you typed" URL from
1336 // SearchProvider::CreateSearchSuggestion(), since the user may be in a 1336 // SearchProvider::CreateSearchSuggestion(), since the user may be in a
1337 // non-default search mode such as image search. 1337 // non-default search mode such as image search.
1338 match->type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED; 1338 match->type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED;
1339 match->provider = autocomplete_controller()->search_provider(); 1339 match->provider = autocomplete_controller()->search_provider();
1340 match->destination_url = 1340 match->destination_url =
1341 delegate_->GetNavigationController().GetVisibleEntry()->GetURL(); 1341 delegate_->GetNavigationController().GetVisibleEntry()->GetURL();
1342 match->transition = content::PAGE_TRANSITION_RELOAD; 1342 match->transition = ui::PAGE_TRANSITION_RELOAD;
1343 } else if (query_in_progress() || 1343 } else if (query_in_progress() ||
1344 (popup_model() && popup_model()->IsOpen())) { 1344 (popup_model() && popup_model()->IsOpen())) {
1345 if (query_in_progress()) { 1345 if (query_in_progress()) {
1346 // It's technically possible for |result| to be empty if no provider 1346 // It's technically possible for |result| to be empty if no provider
1347 // returns a synchronous result but the query has not completed 1347 // returns a synchronous result but the query has not completed
1348 // synchronously; pratically, however, that should never actually happen. 1348 // synchronously; pratically, however, that should never actually happen.
1349 if (result().empty()) 1349 if (result().empty())
1350 return; 1350 return;
1351 // The user cannot have manually selected a match, or the query would have 1351 // The user cannot have manually selected a match, or the query would have
1352 // stopped. So the default match must be the desired selection. 1352 // stopped. So the default match must be the desired selection.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 // Update state and notify view if the omnibox has focus and the caret 1475 // Update state and notify view if the omnibox has focus and the caret
1476 // visibility changed. 1476 // visibility changed.
1477 const bool was_caret_visible = is_caret_visible(); 1477 const bool was_caret_visible = is_caret_visible();
1478 focus_state_ = state; 1478 focus_state_ = state;
1479 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1479 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1480 is_caret_visible() != was_caret_visible) 1480 is_caret_visible() != was_caret_visible)
1481 view_->ApplyCaretVisibility(); 1481 view_->ApplyCaretVisibility();
1482 1482
1483 delegate_->OnFocusChanged(focus_state_, reason); 1483 delegate_->OnFocusChanged(focus_state_, reason);
1484 } 1484 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_edit_model.h ('k') | chrome/browser/ui/panels/panel_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698