OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/chrome/browser/ui/contextual_search/contextual_search_delegate.h" | 5 #include "ios/chrome/browser/ui/contextual_search/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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 GURL request_url(BuildRequestUrl()); | 166 GURL request_url(BuildRequestUrl()); |
167 DCHECK(request_url.is_valid()); | 167 DCHECK(request_url.is_valid()); |
168 | 168 |
169 // Reset will delete any previous fetcher, and we won't get any callback. | 169 // Reset will delete any previous fetcher, and we won't get any callback. |
170 search_term_fetcher_ = net::URLFetcher::Create( | 170 search_term_fetcher_ = net::URLFetcher::Create( |
171 kContextualSearchURLFetcherID, request_url, net::URLFetcher::GET, this); | 171 kContextualSearchURLFetcherID, request_url, net::URLFetcher::GET, this); |
172 search_term_fetcher_->SetRequestContext(browser_state_->GetRequestContext()); | 172 search_term_fetcher_->SetRequestContext(browser_state_->GetRequestContext()); |
173 | 173 |
174 // Add Chrome experiment state to the request headers. | 174 // Add Chrome experiment state to the request headers. |
175 net::HttpRequestHeaders headers; | 175 net::HttpRequestHeaders headers; |
176 // Note: It's fine to pass in |is_signed_in| false, which does not affect | 176 // Note: It's OK to pass |is_signed_in| false if it's unknown, as it does |
177 // transmission of experiment ids coming from the variations server. | 177 // not affect transmission of experiments coming from the variations server. |
178 bool is_signed_in = false; | 178 bool is_signed_in = false; |
179 variations::AppendVariationHeaders(search_term_fetcher_->GetOriginalURL(), | 179 variations::AppendVariationHeaders(search_term_fetcher_->GetOriginalURL(), |
180 browser_state_->IsOffTheRecord(), false, | 180 browser_state_->IsOffTheRecord(), false, |
181 is_signed_in, &headers); | 181 is_signed_in, &headers); |
182 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); | 182 search_term_fetcher_->SetExtraRequestHeaders(headers.ToString()); |
183 | 183 |
184 SetDiscourseContextAndAddToHeader(*context_); | 184 SetDiscourseContextAndAddToHeader(*context_); |
185 | 185 |
186 search_term_fetcher_->Start(); | 186 search_term_fetcher_->Start(); |
187 } | 187 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 proto.SerializeToString(&serialized); | 324 proto.SerializeToString(&serialized); |
325 | 325 |
326 std::string encoded_context; | 326 std::string encoded_context; |
327 base::Base64Encode(serialized, &encoded_context); | 327 base::Base64Encode(serialized, &encoded_context); |
328 // The server memoizer expects a web-safe encoding. | 328 // The server memoizer expects a web-safe encoding. |
329 std::replace(encoded_context.begin(), encoded_context.end(), '+', '-'); | 329 std::replace(encoded_context.begin(), encoded_context.end(), '+', '-'); |
330 std::replace(encoded_context.begin(), encoded_context.end(), '/', '_'); | 330 std::replace(encoded_context.begin(), encoded_context.end(), '/', '_'); |
331 search_term_fetcher_->AddExtraRequestHeader(kDiscourseContextHeaderPrefix + | 331 search_term_fetcher_->AddExtraRequestHeader(kDiscourseContextHeaderPrefix + |
332 encoded_context); | 332 encoded_context); |
333 } | 333 } |
OLD | NEW |