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

Side by Side Diff: chrome/browser/autocomplete/extension_app_provider.cc

Issue 320713002: Revert of Omnibox: Combine Two Input Type Enums into One (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/autocomplete/extension_app_provider.h" 5 #include "chrome/browser/autocomplete/extension_app_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_ui_util.h" 14 #include "chrome/browser/extensions/extension_ui_util.h"
15 #include "chrome/browser/extensions/extension_util.h" 15 #include "chrome/browser/extensions/extension_util.h"
16 #include "chrome/browser/history/history_service.h" 16 #include "chrome/browser/history/history_service.h"
17 #include "chrome/browser/history/history_service_factory.h" 17 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/history/url_database.h" 18 #include "chrome/browser/history/url_database.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/extensions/application_launch.h" 20 #include "chrome/browser/ui/extensions/application_launch.h"
21 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" 21 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
23 #include "components/metrics/proto/omnibox_input_type.pb.h"
24 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
25 #include "extensions/browser/extension_registry.h" 24 #include "extensions/browser/extension_registry.h"
26 #include "extensions/browser/extension_system.h" 25 #include "extensions/browser/extension_system.h"
27 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
28 #include "extensions/common/extension_set.h" 27 #include "extensions/common/extension_set.h"
29 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
30 29
31 ExtensionAppProvider::ExtensionAppProvider( 30 ExtensionAppProvider::ExtensionAppProvider(
32 AutocompleteProviderListener* listener, 31 AutocompleteProviderListener* listener,
33 Profile* profile) 32 Profile* profile)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 name_match_index != base::string16::npos ? 99 name_match_index != base::string16::npos ?
101 app.name.length() : app.launch_url.length(), 100 app.name.length() : app.launch_url.length(),
102 match.destination_url); 101 match.destination_url);
103 return match; 102 return match;
104 } 103 }
105 104
106 void ExtensionAppProvider::Start(const AutocompleteInput& input, 105 void ExtensionAppProvider::Start(const AutocompleteInput& input,
107 bool minimal_changes) { 106 bool minimal_changes) {
108 matches_.clear(); 107 matches_.clear();
109 108
110 if ((input.type() == metrics::OmniboxInputType::INVALID) || 109 if ((input.type() == AutocompleteInput::INVALID) ||
111 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) 110 (input.type() == AutocompleteInput::FORCED_QUERY))
112 return; 111 return;
113 112
114 if (input.text().empty()) 113 if (input.text().empty())
115 return; 114 return;
116 115
117 for (ExtensionApps::const_iterator app = extension_apps_.begin(); 116 for (ExtensionApps::const_iterator app = extension_apps_.begin();
118 app != extension_apps_.end(); ++app) { 117 app != extension_apps_.end(); ++app) {
119 // See if the input matches this extension application. 118 // See if the input matches this extension application.
120 const base::string16& name = app->name; 119 const base::string16& name = app->name;
121 base::string16::const_iterator name_iter = 120 base::string16::const_iterator name_iter =
122 std::search(name.begin(), name.end(), 121 std::search(name.begin(), name.end(),
123 input.text().begin(), input.text().end(), 122 input.text().begin(), input.text().end(),
124 base::CaseInsensitiveCompare<base::char16>()); 123 base::CaseInsensitiveCompare<base::char16>());
125 bool matches_name = name_iter != name.end(); 124 bool matches_name = name_iter != name.end();
126 size_t name_match_index = matches_name ? 125 size_t name_match_index = matches_name ?
127 static_cast<size_t>(name_iter - name.begin()) : base::string16::npos; 126 static_cast<size_t>(name_iter - name.begin()) : base::string16::npos;
128 127
129 bool matches_url = false; 128 bool matches_url = false;
130 size_t url_match_index = base::string16::npos; 129 size_t url_match_index = base::string16::npos;
131 if (app->should_match_against_launch_url) { 130 if (app->should_match_against_launch_url) {
132 const base::string16& url = app->launch_url; 131 const base::string16& url = app->launch_url;
133 base::string16::const_iterator url_iter = 132 base::string16::const_iterator url_iter =
134 std::search(url.begin(), url.end(), 133 std::search(url.begin(), url.end(),
135 input.text().begin(), input.text().end(), 134 input.text().begin(), input.text().end(),
136 base::CaseInsensitiveCompare<base::char16>()); 135 base::CaseInsensitiveCompare<base::char16>());
137 matches_url = (url_iter != url.end()) && 136 matches_url = url_iter != url.end() &&
138 (input.type() != metrics::OmniboxInputType::FORCED_QUERY); 137 input.type() != AutocompleteInput::FORCED_QUERY;
139 url_match_index = matches_url ? 138 url_match_index = matches_url ?
140 static_cast<size_t>(url_iter - url.begin()) : base::string16::npos; 139 static_cast<size_t>(url_iter - url.begin()) : base::string16::npos;
141 } 140 }
142 141
143 if (matches_name || matches_url) { 142 if (matches_name || matches_url) {
144 // We have a match, might be a partial match. 143 // We have a match, might be a partial match.
145 matches_.push_back(CreateAutocompleteMatch( 144 matches_.push_back(CreateAutocompleteMatch(
146 input, *app, name_match_index, url_match_index)); 145 input, *app, name_match_index, url_match_index));
147 } 146 }
148 } 147 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 extension_apps_.push_back(extension_app); 184 extension_apps_.push_back(extension_app);
186 } 185 }
187 } 186 }
188 187
189 void ExtensionAppProvider::Observe(int type, 188 void ExtensionAppProvider::Observe(int type,
190 const content::NotificationSource& source, 189 const content::NotificationSource& source,
191 const content::NotificationDetails& details) { 190 const content::NotificationDetails& details) {
192 RefreshAppList(); 191 RefreshAppList();
193 } 192 }
194 193
195 int ExtensionAppProvider::CalculateRelevance( 194 int ExtensionAppProvider::CalculateRelevance(AutocompleteInput::Type type,
196 metrics::OmniboxInputType::Type type, 195 int input_length,
197 int input_length, 196 int target_length,
198 int target_length, 197 const GURL& url) {
199 const GURL& url) {
200 // If you update the algorithm here, please remember to update the tables in 198 // If you update the algorithm here, please remember to update the tables in
201 // autocomplete.h also. 199 // autocomplete.h also.
202 const int kMaxRelevance = 1425; 200 const int kMaxRelevance = 1425;
203 201
204 if (input_length == target_length) 202 if (input_length == target_length)
205 return kMaxRelevance; 203 return kMaxRelevance;
206 204
207 // We give a boost proportionally based on how much of the input matches the 205 // We give a boost proportionally based on how much of the input matches the
208 // app name, up to a maximum close to 200 (we can be close to, but we'll never 206 // app name, up to a maximum close to 200 (we can be close to, but we'll never
209 // reach 200 because the 100% match is taken care of above). 207 // reach 200 because the 100% match is taken care of above).
(...skipping 12 matching lines...) Expand all
222 history::URLRow info; 220 history::URLRow info;
223 url_db->GetRowForURL(url, &info); 221 url_db->GetRowForURL(url, &info);
224 type_count_boost = 222 type_count_boost =
225 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); 223 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count())));
226 } 224 }
227 int relevance = 575 + static_cast<int>(type_count_boost) + 225 int relevance = 575 + static_cast<int>(type_count_boost) +
228 static_cast<int>(fraction_boost); 226 static_cast<int>(fraction_boost);
229 DCHECK_LE(relevance, kMaxRelevance); 227 DCHECK_LE(relevance, kMaxRelevance);
230 return relevance; 228 return relevance;
231 } 229 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/extension_app_provider.h ('k') | chrome/browser/autocomplete/history_quick_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698