| 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; |
| 139 variations::AppendVariationHeaders( | 142 variations::AppendVariationHeaders( |
| 140 search_term_fetcher_->GetOriginalURL(), | 143 search_term_fetcher_->GetOriginalURL(), |
| 141 false, // Impossible to be incognito at this point. | 144 false, // Impossible to be incognito at this point. |
| 142 false, &headers); | 145 false, is_signed_in, &headers); |
| 143 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); | 146 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
| 144 | 147 |
| 145 SetDiscourseContextAndAddToHeader(*context_); | 148 SetDiscourseContextAndAddToHeader(*context_); |
| 146 | 149 |
| 147 search_term_fetcher_->Start(); | 150 search_term_fetcher_->Start(); |
| 148 } | 151 } |
| 149 | 152 |
| 150 void ContextualSearchDelegate::OnURLFetchComplete( | 153 void ContextualSearchDelegate::OnURLFetchComplete( |
| 151 const net::URLFetcher* source) { | 154 const net::URLFetcher* source) { |
| 152 DCHECK(source == search_term_fetcher_.get()); | 155 DCHECK(source == search_term_fetcher_.get()); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 end_offset -= trim; | 610 end_offset -= trim; |
| 608 } | 611 } |
| 609 if (result_text.length() > end_offset + padding_each_side_pinned) { | 612 if (result_text.length() > end_offset + padding_each_side_pinned) { |
| 610 // Trim the end. | 613 // Trim the end. |
| 611 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 614 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
| 612 } | 615 } |
| 613 *start = start_offset; | 616 *start = start_offset; |
| 614 *end = end_offset; | 617 *end = end_offset; |
| 615 return result_text; | 618 return result_text; |
| 616 } | 619 } |
| OLD | NEW |