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 "chrome/browser/android/contextualsearch/contextual_search_delegate.h" | 5 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/android/contextualsearch/resolved_search_term.h" | 16 #include "chrome/browser/android/contextualsearch/resolved_search_term.h" |
17 #include "chrome/browser/android/proto/client_discourse_context.pb.h" | 17 #include "chrome/browser/android/proto/client_discourse_context.pb.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
21 #include "chrome/browser/translate/translate_service.h" | 21 #include "chrome/browser/translate/translate_service.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "components/browser_sync/browser/profile_sync_service.h" | 23 #include "components/browser_sync/browser/profile_sync_service.h" |
24 #include "components/search_engines/template_url_service.h" | 24 #include "components/search_engines/template_url_service.h" |
25 #include "components/variations/net/variations_http_header_provider.h" | 25 #include "components/variations/net/variations_http_headers.h" |
26 #include "components/variations/variations_associated_data.h" | 26 #include "components/variations/variations_associated_data.h" |
27 #include "content/public/browser/android/content_view_core.h" | 27 #include "content/public/browser/android/content_view_core.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
29 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
30 #include "net/url_request/url_fetcher.h" | 30 #include "net/url_request/url_fetcher.h" |
31 #include "url/gurl.h" | 31 #include "url/gurl.h" |
32 | 32 |
33 using content::ContentViewCore; | 33 using content::ContentViewCore; |
34 | 34 |
35 namespace { | 35 namespace { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 DCHECK(request_url.is_valid()); | 121 DCHECK(request_url.is_valid()); |
122 | 122 |
123 // Reset will delete any previous fetcher, and we won't get any callback. | 123 // Reset will delete any previous fetcher, and we won't get any callback. |
124 search_term_fetcher_.reset( | 124 search_term_fetcher_.reset( |
125 net::URLFetcher::Create(kContextualSearchURLFetcherID, request_url, | 125 net::URLFetcher::Create(kContextualSearchURLFetcherID, request_url, |
126 net::URLFetcher::GET, this).release()); | 126 net::URLFetcher::GET, this).release()); |
127 search_term_fetcher_->SetRequestContext(url_request_context_); | 127 search_term_fetcher_->SetRequestContext(url_request_context_); |
128 | 128 |
129 // Add Chrome experiment state to the request headers. | 129 // Add Chrome experiment state to the request headers. |
130 net::HttpRequestHeaders headers; | 130 net::HttpRequestHeaders headers; |
131 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders( | 131 variations::AppendVariationHeaders( |
132 search_term_fetcher_->GetOriginalURL(), | 132 search_term_fetcher_->GetOriginalURL(), |
133 false, // Impossible to be incognito at this point. | 133 false, // Impossible to be incognito at this point. |
134 false, | 134 false, &headers); |
135 &headers); | |
136 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); | 135 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
137 | 136 |
138 SetDiscourseContextAndAddToHeader(*context_); | 137 SetDiscourseContextAndAddToHeader(*context_); |
139 | 138 |
140 search_term_fetcher_->Start(); | 139 search_term_fetcher_->Start(); |
141 } | 140 } |
142 | 141 |
143 void ContextualSearchDelegate::OnURLFetchComplete( | 142 void ContextualSearchDelegate::OnURLFetchComplete( |
144 const net::URLFetcher* source) { | 143 const net::URLFetcher* source) { |
145 DCHECK(source == search_term_fetcher_.get()); | 144 DCHECK(source == search_term_fetcher_.get()); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 end_offset -= trim; | 550 end_offset -= trim; |
552 } | 551 } |
553 if (result_text.length() > end_offset + padding_each_side_pinned) { | 552 if (result_text.length() > end_offset + padding_each_side_pinned) { |
554 // Trim the end. | 553 // Trim the end. |
555 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 554 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
556 } | 555 } |
557 *start = start_offset; | 556 *start = start_offset; |
558 *end = end_offset; | 557 *end = end_offset; |
559 return result_text; | 558 return result_text; |
560 } | 559 } |
OLD | NEW |