| OLD | NEW |
| 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" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 &match.contents_class); | 86 &match.contents_class); |
| 87 if (app.should_match_against_launch_url) { | 87 if (app.should_match_against_launch_url) { |
| 88 match.description = app.launch_url; | 88 match.description = app.launch_url; |
| 89 AutocompleteMatch::ClassifyLocationInString(url_match_index, | 89 AutocompleteMatch::ClassifyLocationInString(url_match_index, |
| 90 input.text().length(), app.launch_url.length(), | 90 input.text().length(), app.launch_url.length(), |
| 91 ACMatchClassification::URL, &match.description_class); | 91 ACMatchClassification::URL, &match.description_class); |
| 92 } | 92 } |
| 93 match.relevance = CalculateRelevance( | 93 match.relevance = CalculateRelevance( |
| 94 input.type(), | 94 input.type(), |
| 95 input.text().length(), | 95 input.text().length(), |
| 96 name_match_index != string16::npos ? | 96 name_match_index != base::string16::npos ? |
| 97 app.name.length() : app.launch_url.length(), | 97 app.name.length() : app.launch_url.length(), |
| 98 match.destination_url); | 98 match.destination_url); |
| 99 return match; | 99 return match; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void ExtensionAppProvider::Start(const AutocompleteInput& input, | 102 void ExtensionAppProvider::Start(const AutocompleteInput& input, |
| 103 bool minimal_changes) { | 103 bool minimal_changes) { |
| 104 matches_.clear(); | 104 matches_.clear(); |
| 105 | 105 |
| 106 if ((input.type() == AutocompleteInput::INVALID) || | 106 if ((input.type() == AutocompleteInput::INVALID) || |
| 107 (input.type() == AutocompleteInput::FORCED_QUERY)) | 107 (input.type() == AutocompleteInput::FORCED_QUERY)) |
| 108 return; | 108 return; |
| 109 | 109 |
| 110 if (input.text().empty()) | 110 if (input.text().empty()) |
| 111 return; | 111 return; |
| 112 | 112 |
| 113 for (ExtensionApps::const_iterator app = extension_apps_.begin(); | 113 for (ExtensionApps::const_iterator app = extension_apps_.begin(); |
| 114 app != extension_apps_.end(); ++app) { | 114 app != extension_apps_.end(); ++app) { |
| 115 // See if the input matches this extension application. | 115 // See if the input matches this extension application. |
| 116 const string16& name = app->name; | 116 const base::string16& name = app->name; |
| 117 string16::const_iterator name_iter = std::search(name.begin(), name.end(), | 117 base::string16::const_iterator name_iter = |
| 118 input.text().begin(), input.text().end(), | 118 std::search(name.begin(), name.end(), |
| 119 base::CaseInsensitiveCompare<char16>()); | 119 input.text().begin(), input.text().end(), |
| 120 base::CaseInsensitiveCompare<char16>()); |
| 120 bool matches_name = name_iter != name.end(); | 121 bool matches_name = name_iter != name.end(); |
| 121 size_t name_match_index = matches_name ? | 122 size_t name_match_index = matches_name ? |
| 122 static_cast<size_t>(name_iter - name.begin()) : string16::npos; | 123 static_cast<size_t>(name_iter - name.begin()) : base::string16::npos; |
| 123 | 124 |
| 124 bool matches_url = false; | 125 bool matches_url = false; |
| 125 size_t url_match_index = string16::npos; | 126 size_t url_match_index = base::string16::npos; |
| 126 if (app->should_match_against_launch_url) { | 127 if (app->should_match_against_launch_url) { |
| 127 const string16& url = app->launch_url; | 128 const base::string16& url = app->launch_url; |
| 128 string16::const_iterator url_iter = std::search(url.begin(), url.end(), | 129 base::string16::const_iterator url_iter = |
| 129 input.text().begin(), input.text().end(), | 130 std::search(url.begin(), url.end(), |
| 130 base::CaseInsensitiveCompare<char16>()); | 131 input.text().begin(), input.text().end(), |
| 132 base::CaseInsensitiveCompare<char16>()); |
| 131 matches_url = url_iter != url.end() && | 133 matches_url = url_iter != url.end() && |
| 132 input.type() != AutocompleteInput::FORCED_QUERY; | 134 input.type() != AutocompleteInput::FORCED_QUERY; |
| 133 url_match_index = matches_url ? | 135 url_match_index = matches_url ? |
| 134 static_cast<size_t>(url_iter - url.begin()) : string16::npos; | 136 static_cast<size_t>(url_iter - url.begin()) : base::string16::npos; |
| 135 } | 137 } |
| 136 | 138 |
| 137 if (matches_name || matches_url) { | 139 if (matches_name || matches_url) { |
| 138 // We have a match, might be a partial match. | 140 // We have a match, might be a partial match. |
| 139 matches_.push_back(CreateAutocompleteMatch( | 141 matches_.push_back(CreateAutocompleteMatch( |
| 140 input, *app, name_match_index, url_match_index)); | 142 input, *app, name_match_index, url_match_index)); |
| 141 } | 143 } |
| 142 } | 144 } |
| 143 } | 145 } |
| 144 | 146 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 history::URLRow info; | 218 history::URLRow info; |
| 217 url_db->GetRowForURL(url, &info); | 219 url_db->GetRowForURL(url, &info); |
| 218 type_count_boost = | 220 type_count_boost = |
| 219 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); | 221 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); |
| 220 } | 222 } |
| 221 int relevance = 575 + static_cast<int>(type_count_boost) + | 223 int relevance = 575 + static_cast<int>(type_count_boost) + |
| 222 static_cast<int>(fraction_boost); | 224 static_cast<int>(fraction_boost); |
| 223 DCHECK_LE(relevance, kMaxRelevance); | 225 DCHECK_LE(relevance, kMaxRelevance); |
| 224 return relevance; | 226 return relevance; |
| 225 } | 227 } |
| OLD | NEW |