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

Unified Diff: chrome/browser/autocomplete/search_provider.cc

Issue 456843003: Remove protected virtual methods from BaseSearchProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/search_provider.cc
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 04b37a5a6092bfdf1c01e92a91d7a21963d3a863..1280d361c39c085fc9d86ae04b51737cdc142645 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -15,7 +15,6 @@
#include "base/json/json_string_value_serializer.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
-#include "base/metrics/user_metrics.h"
#include "base/prefs/pref_service.h"
#include "base/rand_util.h"
#include "base/strings/string_util.h"
@@ -72,6 +71,12 @@ enum SuggestRequestsHistogramValue {
// The verbatim score for an input which is not an URL.
const int kNonURLVerbatimRelevance = 1300;
+// User metrics action strings.
+const char kUserMetricsActionDeletionSuccess[] =
+ "Omnibox.ServerSuggestDelete.Success";
+const char kUserMetricsActionDeletionFailure[] =
+ "Omnibox.ServerSuggestDelete.Failure";
+
// Increments the appropriate value in the histogram by one.
void LogOmniboxSuggestRequest(
SuggestRequestsHistogramValue request_value) {
@@ -132,8 +137,11 @@ int SearchProvider::kMinimumTimeBetweenSuggestQueriesMs = 100;
SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
TemplateURLService* template_url_service,
Profile* profile)
- : BaseSearchProvider(template_url_service, profile,
- AutocompleteProvider::TYPE_SEARCH),
+ : BaseSearchProvider(
+ template_url_service, profile,
+ base::UserMetricsAction(kUserMetricsActionDeletionSuccess),
+ base::UserMetricsAction(kUserMetricsActionDeletionFailure),
+ AutocompleteProvider::TYPE_SEARCH),
listener_(listener),
suggest_results_pending_(0),
providers_(template_url_service) {
@@ -250,46 +258,12 @@ void SearchProvider::Start(const AutocompleteInput& input,
UpdateMatches();
}
-const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const {
- return is_keyword ? providers_.GetKeywordProviderURL()
- : providers_.GetDefaultProviderURL();
-}
-
-const AutocompleteInput SearchProvider::GetInput(bool is_keyword) const {
- return is_keyword ? keyword_input_ : input_;
-}
-
-bool SearchProvider::ShouldAppendExtraParams(
- const SearchSuggestionParser::SuggestResult& result) const {
- return !result.from_keyword_provider() ||
- providers_.default_provider().empty();
-}
-
-void SearchProvider::StopSuggest() {
- // Increment the appropriate field in the histogram by the number of
- // pending requests that were invalidated.
- for (int i = 0; i < suggest_results_pending_; ++i)
- LogOmniboxSuggestRequest(REQUEST_INVALIDATED);
- suggest_results_pending_ = 0;
- timer_.Stop();
- // Stop any in-progress URL fetches.
- keyword_fetcher_.reset();
- default_fetcher_.reset();
-}
-
-void SearchProvider::ClearAllResults() {
- keyword_results_.Clear();
- default_results_.Clear();
-}
+void SearchProvider::Stop(bool clear_cached_results) {
+ StopSuggest();
+ done_ = true;
-void SearchProvider::RecordDeletionResult(bool success) {
- if (success) {
- base::RecordAction(
- base::UserMetricsAction("Omnibox.ServerSuggestDelete.Success"));
- } else {
- base::RecordAction(
- base::UserMetricsAction("Omnibox.ServerSuggestDelete.Failure"));
- }
+ if (clear_cached_results)
+ ClearAllResults();
}
void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) {
@@ -314,7 +288,8 @@ void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) {
if (data) {
SearchSuggestionParser::Results* results =
is_keyword ? &keyword_results_ : &default_results_;
- results_updated = ParseSuggestResults(*data, -1, is_keyword, results);
+ results_updated = ParseSuggestResults(
+ *data, GetInput(is_keyword), -1, is_keyword, results);
if (results_updated)
SortResults(is_keyword, results);
}
@@ -324,6 +299,38 @@ void SearchProvider::OnURLFetchComplete(const net::URLFetcher* source) {
listener_->OnProviderUpdate(results_updated);
}
+const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const {
+ return is_keyword ? providers_.GetKeywordProviderURL()
Peter Kasting 2014/08/12 18:31:18 Nit: clang-format error, please break after ? and
hashimoto 2014/08/13 05:21:22 Done.
+ : providers_.GetDefaultProviderURL();
+}
+
+const AutocompleteInput& SearchProvider::GetInput(bool is_keyword) const {
+ return is_keyword ? keyword_input_ : input_;
+}
+
+bool SearchProvider::ShouldAppendExtraParams(
+ const SearchSuggestionParser::SuggestResult& result) const {
+ return !result.from_keyword_provider() ||
+ providers_.default_provider().empty();
+}
+
+void SearchProvider::StopSuggest() {
+ // Increment the appropriate field in the histogram by the number of
+ // pending requests that were invalidated.
+ for (int i = 0; i < suggest_results_pending_; ++i)
+ LogOmniboxSuggestRequest(REQUEST_INVALIDATED);
+ suggest_results_pending_ = 0;
+ timer_.Stop();
+ // Stop any in-progress URL fetches.
+ keyword_fetcher_.reset();
+ default_fetcher_.reset();
+}
+
+void SearchProvider::ClearAllResults() {
+ keyword_results_.Clear();
+ default_results_.Clear();
+}
+
void SearchProvider::UpdateMatchContentsClass(
const base::string16& input_text,
SearchSuggestionParser::Results* results) {
@@ -739,8 +746,9 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
base::string16(), std::string(), std::string(), false,
verbatim_relevance, relevance_from_server, false,
trimmed_verbatim);
- AddMatchToMap(verbatim, std::string(), did_not_accept_default_suggestion,
- false, &map);
+ AddMatchToMap(GetInput(false), verbatim, GetTemplateURL(false),
+ std::string(), did_not_accept_default_suggestion,
+ ShouldAppendExtraParams(verbatim), false, &map);
}
if (!keyword_input_.text().empty()) {
const TemplateURL* keyword_url = providers_.GetKeywordProviderURL();
@@ -764,8 +772,9 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
base::string16(), base::string16(), std::string(), std::string(),
true, keyword_verbatim_relevance, keyword_relevance_from_server,
false, trimmed_verbatim);
- AddMatchToMap(verbatim, std::string(),
- did_not_accept_keyword_suggestion, false, &map);
+ AddMatchToMap(GetInput(true), verbatim, keyword_url,
+ std::string(), did_not_accept_keyword_suggestion,
+ ShouldAppendExtraParams(verbatim), false, &map);
}
}
}
@@ -907,7 +916,9 @@ void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results,
is_keyword);
for (SearchSuggestionParser::SuggestResults::const_iterator i(
scored_results.begin()); i != scored_results.end(); ++i) {
- AddMatchToMap(*i, std::string(), did_not_accept_suggestion, true, map);
+ AddMatchToMap(GetInput(is_keyword), *i, GetTemplateURL(is_keyword),
+ std::string(), did_not_accept_suggestion,
+ ShouldAppendExtraParams(*i), true, map);
}
UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime",
base::TimeTicks::Now() - start_time);
@@ -1029,8 +1040,11 @@ void SearchProvider::AddSuggestResultsToMap(
const SearchSuggestionParser::SuggestResults& results,
const std::string& metadata,
MatchMap* map) {
- for (size_t i = 0; i < results.size(); ++i)
- AddMatchToMap(results[i], metadata, i, false, map);
+ for (size_t i = 0; i < results.size(); ++i) {
+ AddMatchToMap(GetInput(results[i].from_keyword_provider()), results[i],
+ GetTemplateURL(results[i].from_keyword_provider()), metadata,
+ i, ShouldAppendExtraParams(results[i]), false, map);
+ }
}
int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const {

Powered by Google App Engine
This is Rietveld 408576698