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

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

Issue 2437193003: [WIP] Log request, start and end offsets.
Patch Set: Created 4 years, 2 months 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 | no next file » | 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 std::string replacement_url = field_trial_->GetResolverURLPrefix(); 233 std::string replacement_url = field_trial_->GetResolverURLPrefix();
234 234
235 // If a replacement URL was specified above, do the substitution. 235 // If a replacement URL was specified above, do the substitution.
236 if (!replacement_url.empty()) { 236 if (!replacement_url.empty()) {
237 size_t pos = request.find(kContextualSearchServerEndpoint); 237 size_t pos = request.find(kContextualSearchServerEndpoint);
238 if (pos != std::string::npos) { 238 if (pos != std::string::npos) {
239 request.replace(0, pos + strlen(kContextualSearchServerEndpoint), 239 request.replace(0, pos + strlen(kContextualSearchServerEndpoint),
240 replacement_url); 240 replacement_url);
241 } 241 }
242 } 242 }
243 VLOG(0) << "ctxs request: " << request;
243 return request; 244 return request;
244 } 245 }
245 246
246 void ContextualSearchDelegate::GatherSurroundingTextWithCallback( 247 void ContextualSearchDelegate::GatherSurroundingTextWithCallback(
247 const std::string& selection, 248 const std::string& selection,
248 bool use_resolved_search_term, 249 bool use_resolved_search_term,
249 content::WebContents* web_contents, 250 content::WebContents* web_contents,
250 bool may_send_base_page_url, 251 bool may_send_base_page_url,
251 HandleSurroundingsCallback callback) { 252 HandleSurroundingsCallback callback) {
252 // Immediately cancel any request that's in flight, since we're building a new 253 // Immediately cancel any request that's in flight, since we're building a new
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } else { 297 } else {
297 DVLOG(1) << "ctxs: Null context, ignored!"; 298 DVLOG(1) << "ctxs: Null context, ignored!";
298 } 299 }
299 } 300 }
300 301
301 void ContextualSearchDelegate::SaveSurroundingText( 302 void ContextualSearchDelegate::SaveSurroundingText(
302 const base::string16& surrounding_text, 303 const base::string16& surrounding_text,
303 int start_offset, 304 int start_offset,
304 int end_offset) { 305 int end_offset) {
305 DCHECK(context_.get()); 306 DCHECK(context_.get());
307 VLOG(0) << "ctxs offsets start " << start_offset << ", end " << end_offset << ", length " << surrounding_text.length();
306 // Sometimes the surroundings are 0, 0, '', so fall back on the selection. 308 // Sometimes the surroundings are 0, 0, '', so fall back on the selection.
307 // See crbug.com/393100. 309 // See crbug.com/393100.
308 if (start_offset == 0 && end_offset == 0 && surrounding_text.length() == 0) { 310 if (start_offset == 0 && end_offset == 0 && surrounding_text.length() == 0) {
309 context_->surrounding_text = base::UTF8ToUTF16(context_->selected_text); 311 context_->surrounding_text = base::UTF8ToUTF16(context_->selected_text);
310 context_->start_offset = 0; 312 context_->start_offset = 0;
311 context_->end_offset = context_->selected_text.length(); 313 context_->end_offset = context_->selected_text.length();
312 } else { 314 } else {
313 context_->surrounding_text = surrounding_text; 315 context_->surrounding_text = surrounding_text;
314 context_->start_offset = start_offset; 316 context_->start_offset = start_offset;
315 context_->end_offset = end_offset; 317 context_->end_offset = end_offset;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 end_offset -= trim; 553 end_offset -= trim;
552 } 554 }
553 if (result_text.length() > end_offset + padding_each_side_pinned) { 555 if (result_text.length() > end_offset + padding_each_side_pinned) {
554 // Trim the end. 556 // Trim the end.
555 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); 557 result_text = result_text.substr(0, end_offset + padding_each_side_pinned);
556 } 558 }
557 *start = start_offset; 559 *start = start_offset;
558 *end = end_offset; 560 *end = end_offset;
559 return result_text; 561 return result_text;
560 } 562 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698