Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_delegate.cc

Issue 1530133005: Refactor VariationsHttpHeaderProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing include to srt_fetcher_win.cc. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698