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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 DCHECK(request_url.is_valid()); | 129 DCHECK(request_url.is_valid()); |
130 | 130 |
131 // Reset will delete any previous fetcher, and we won't get any callback. | 131 // Reset will delete any previous fetcher, and we won't get any callback. |
132 search_term_fetcher_.reset( | 132 search_term_fetcher_.reset( |
133 net::URLFetcher::Create(kContextualSearchURLFetcherID, request_url, | 133 net::URLFetcher::Create(kContextualSearchURLFetcherID, request_url, |
134 net::URLFetcher::GET, this).release()); | 134 net::URLFetcher::GET, this).release()); |
135 search_term_fetcher_->SetRequestContext(url_request_context_); | 135 search_term_fetcher_->SetRequestContext(url_request_context_); |
136 | 136 |
137 // Add Chrome experiment state to the request headers. | 137 // Add Chrome experiment state to the request headers. |
138 net::HttpRequestHeaders headers; | 138 net::HttpRequestHeaders headers; |
139 // Note: It's fine to pass in |is_signed_in| false, which does not affect | |
140 // transmission of experiment ids coming from the variations server. | |
141 bool is_signed_in = false; | |
142 variations::AppendVariationHeaders( | 139 variations::AppendVariationHeaders( |
143 search_term_fetcher_->GetOriginalURL(), | 140 search_term_fetcher_->GetOriginalURL(), |
144 false, // Impossible to be incognito at this point. | 141 false, // Impossible to be incognito at this point. |
145 false, is_signed_in, &headers); | 142 false, &headers); |
146 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); | 143 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
147 | 144 |
148 SetDiscourseContextAndAddToHeader(*context_); | 145 SetDiscourseContextAndAddToHeader(*context_); |
149 | 146 |
150 search_term_fetcher_->Start(); | 147 search_term_fetcher_->Start(); |
151 } | 148 } |
152 | 149 |
153 void ContextualSearchDelegate::OnURLFetchComplete( | 150 void ContextualSearchDelegate::OnURLFetchComplete( |
154 const net::URLFetcher* source) { | 151 const net::URLFetcher* source) { |
155 DCHECK(source == search_term_fetcher_.get()); | 152 DCHECK(source == search_term_fetcher_.get()); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 end_offset -= trim; | 605 end_offset -= trim; |
609 } | 606 } |
610 if (result_text.length() > end_offset + padding_each_side_pinned) { | 607 if (result_text.length() > end_offset + padding_each_side_pinned) { |
611 // Trim the end. | 608 // Trim the end. |
612 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 609 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
613 } | 610 } |
614 *start = start_offset; | 611 *start = start_offset; |
615 *end = end_offset; | 612 *end = end_offset; |
616 return result_text; | 613 return result_text; |
617 } | 614 } |
OLD | NEW |