OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/omnibox/browser/clipboard_url_provider.h" | 5 #include "components/omnibox/browser/clipboard_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 current_url_suggested_ = url; | 79 current_url_suggested_ = url; |
80 current_url_suggested_times_ = 1; | 80 current_url_suggested_times_ = 1; |
81 } | 81 } |
82 UMA_HISTOGRAM_SPARSE_SLOWLY( | 82 UMA_HISTOGRAM_SPARSE_SLOWLY( |
83 "Omnibox.ClipboardSuggestionShownNumTimes", | 83 "Omnibox.ClipboardSuggestionShownNumTimes", |
84 std::min(current_url_suggested_times_, static_cast<size_t>(20))); | 84 std::min(current_url_suggested_times_, static_cast<size_t>(20))); |
85 | 85 |
86 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. | 86 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. |
87 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); | 87 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); |
88 match.destination_url = url; | 88 match.destination_url = url; |
89 match.contents.assign(url_formatter::FormatUrl( | 89 match.contents.assign(AutocompleteMatch::FormatUrlForSuggestionDisplay( |
90 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, | 90 url, true /* trim_scheme */, nullptr)); |
91 nullptr, nullptr, nullptr)); | |
92 AutocompleteMatch::ClassifyLocationInString( | 91 AutocompleteMatch::ClassifyLocationInString( |
93 base::string16::npos, 0, match.contents.length(), | 92 base::string16::npos, 0, match.contents.length(), |
94 ACMatchClassification::URL, &match.contents_class); | 93 ACMatchClassification::URL, &match.contents_class); |
95 | 94 |
96 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); | 95 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); |
97 AutocompleteMatch::ClassifyLocationInString( | 96 AutocompleteMatch::ClassifyLocationInString( |
98 base::string16::npos, 0, match.description.length(), | 97 base::string16::npos, 0, match.description.length(), |
99 ACMatchClassification::NONE, &match.description_class); | 98 ACMatchClassification::NONE, &match.description_class); |
100 | 99 |
101 matches_.push_back(match); | 100 matches_.push_back(match); |
102 } | 101 } |
103 | 102 |
104 void ClipboardURLProvider::AddProviderInfo(ProvidersInfo* provider_info) const { | 103 void ClipboardURLProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
105 // If a URL wasn't suggested on this most recent focus event, don't bother | 104 // If a URL wasn't suggested on this most recent focus event, don't bother |
106 // setting |times_returned_results_in_session|, as in effect this URL has | 105 // setting |times_returned_results_in_session|, as in effect this URL has |
107 // never been suggested during the current session. (For the purpose of | 106 // never been suggested during the current session. (For the purpose of |
108 // this provider, we define a session as intervals between when a URL | 107 // this provider, we define a session as intervals between when a URL |
109 // clipboard suggestion changes.) | 108 // clipboard suggestion changes.) |
110 if (current_url_suggested_times_ == 0) | 109 if (current_url_suggested_times_ == 0) |
111 return; | 110 return; |
112 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); | 111 provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo()); |
113 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); | 112 metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back(); |
114 new_entry.set_provider(AsOmniboxEventProviderType()); | 113 new_entry.set_provider(AsOmniboxEventProviderType()); |
115 new_entry.set_times_returned_results_in_session(current_url_suggested_times_); | 114 new_entry.set_times_returned_results_in_session(current_url_suggested_times_); |
116 } | 115 } |
OLD | NEW |