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

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

Issue 2127373006: Use base::StartWith() in more places when appropriate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // the value of the given parameters. 420 // the value of the given parameters.
421 void ContextualSearchDelegate::DecodeSearchTermFromJsonResponse( 421 void ContextualSearchDelegate::DecodeSearchTermFromJsonResponse(
422 const std::string& response, 422 const std::string& response,
423 std::string* search_term, 423 std::string* search_term,
424 std::string* display_text, 424 std::string* display_text,
425 std::string* alternate_term, 425 std::string* alternate_term,
426 std::string* prevent_preload, 426 std::string* prevent_preload,
427 int* mention_start, 427 int* mention_start,
428 int* mention_end, 428 int* mention_end,
429 std::string* lang) { 429 std::string* lang) {
430 bool contains_xssi_escape = response.find(kXssiEscape) == 0; 430 bool contains_xssi_escape =
431 base::StartsWith(response, kXssiEscape, base::CompareCase::SENSITIVE);
431 const std::string& proper_json = 432 const std::string& proper_json =
432 contains_xssi_escape ? response.substr(strlen(kXssiEscape)) : response; 433 contains_xssi_escape ? response.substr(strlen(kXssiEscape)) : response;
433 JSONStringValueDeserializer deserializer(proper_json); 434 JSONStringValueDeserializer deserializer(proper_json);
434 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL); 435 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, NULL);
435 436
436 if (root.get() != NULL && root->IsType(base::Value::TYPE_DICTIONARY)) { 437 if (root.get() != NULL && root->IsType(base::Value::TYPE_DICTIONARY)) {
437 base::DictionaryValue* dict = 438 base::DictionaryValue* dict =
438 static_cast<base::DictionaryValue*>(root.get()); 439 static_cast<base::DictionaryValue*>(root.get());
439 dict->GetString(kContextualSearchPreventPreload, prevent_preload); 440 dict->GetString(kContextualSearchPreventPreload, prevent_preload);
440 dict->GetString(kContextualSearchResponseSearchTermParam, search_term); 441 dict->GetString(kContextualSearchResponseSearchTermParam, search_term);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 end_offset -= trim; 502 end_offset -= trim;
502 } 503 }
503 if (result_text.length() > end_offset + padding_each_side_pinned) { 504 if (result_text.length() > end_offset + padding_each_side_pinned) {
504 // Trim the end. 505 // Trim the end.
505 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); 506 result_text = result_text.substr(0, end_offset + padding_each_side_pinned);
506 } 507 }
507 *start = start_offset; 508 *start = start_offset;
508 *end = end_offset; 509 *end = end_offset;
509 return result_text; 510 return result_text;
510 } 511 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698