OLD | NEW |
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 "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/i18n/break_iterator.h" | 13 #include "base/i18n/break_iterator.h" |
14 #include "base/i18n/case_conversion.h" | 14 #include "base/i18n/case_conversion.h" |
15 #include "base/json/json_string_value_serializer.h" | 15 #include "base/json/json_string_value_serializer.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/metrics/user_metrics.h" | 17 #include "base/metrics/user_metrics.h" |
18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "components/data_use_measurement/core/data_use_user_data.h" |
21 #include "components/history/core/browser/in_memory_database.h" | 22 #include "components/history/core/browser/in_memory_database.h" |
22 #include "components/history/core/browser/keyword_search_term.h" | 23 #include "components/history/core/browser/keyword_search_term.h" |
23 #include "components/metrics/proto/omnibox_input_type.pb.h" | 24 #include "components/metrics/proto/omnibox_input_type.pb.h" |
24 #include "components/omnibox/browser/autocomplete_provider_client.h" | 25 #include "components/omnibox/browser/autocomplete_provider_client.h" |
25 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 26 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
26 #include "components/omnibox/browser/autocomplete_result.h" | 27 #include "components/omnibox/browser/autocomplete_result.h" |
27 #include "components/omnibox/browser/keyword_provider.h" | 28 #include "components/omnibox/browser/keyword_provider.h" |
28 #include "components/omnibox/browser/omnibox_field_trial.h" | 29 #include "components/omnibox/browser/omnibox_field_trial.h" |
29 #include "components/omnibox/browser/suggestion_answer.h" | 30 #include "components/omnibox/browser/suggestion_answer.h" |
30 #include "components/omnibox/browser/url_prefix.h" | 31 #include "components/omnibox/browser/url_prefix.h" |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 search_term_args.current_page_url = input.current_url().spec(); | 857 search_term_args.current_page_url = input.current_url().spec(); |
857 // Create the suggest URL again with the current page URL. | 858 // Create the suggest URL again with the current page URL. |
858 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( | 859 suggest_url = GURL(template_url->suggestions_url_ref().ReplaceSearchTerms( |
859 search_term_args, template_url_service->search_terms_data())); | 860 search_term_args, template_url_service->search_terms_data())); |
860 } | 861 } |
861 | 862 |
862 LogOmniboxSuggestRequest(REQUEST_SENT); | 863 LogOmniboxSuggestRequest(REQUEST_SENT); |
863 | 864 |
864 scoped_ptr<net::URLFetcher> fetcher = | 865 scoped_ptr<net::URLFetcher> fetcher = |
865 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this); | 866 net::URLFetcher::Create(id, suggest_url, net::URLFetcher::GET, this); |
| 867 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 868 fetcher.get(), data_use_measurement::DataUseUserData::OMNIBOX); |
866 fetcher->SetRequestContext(client()->GetRequestContext()); | 869 fetcher->SetRequestContext(client()->GetRequestContext()); |
867 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 870 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
868 // Add Chrome experiment state to the request headers. | 871 // Add Chrome experiment state to the request headers. |
869 net::HttpRequestHeaders headers; | 872 net::HttpRequestHeaders headers; |
870 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( | 873 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( |
871 fetcher->GetOriginalURL(), client()->IsOffTheRecord(), false, &headers); | 874 fetcher->GetOriginalURL(), client()->IsOffTheRecord(), false, &headers); |
872 fetcher->SetExtraRequestHeaders(headers.ToString()); | 875 fetcher->SetExtraRequestHeaders(headers.ToString()); |
873 fetcher->Start(); | 876 fetcher->Start(); |
874 return fetcher; | 877 return fetcher; |
875 } | 878 } |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1500 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
1498 matches.push_back(i->second); | 1501 matches.push_back(i->second); |
1499 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1502 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1500 | 1503 |
1501 // If there is a top scoring entry, find the corresponding answer. | 1504 // If there is a top scoring entry, find the corresponding answer. |
1502 if (!matches.empty()) | 1505 if (!matches.empty()) |
1503 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1506 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
1504 | 1507 |
1505 return AnswersQueryData(); | 1508 return AnswersQueryData(); |
1506 } | 1509 } |
OLD | NEW |