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

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

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. 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
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 9
9 #include "base/base64.h" 10 #include "base/base64.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/json/json_string_value_serializer.h" 12 #include "base/json/json_string_value_serializer.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/android/contextualsearch/contextual_search_field_trial. h" 16 #include "chrome/browser/android/contextualsearch/contextual_search_field_trial. h"
16 #include "chrome/browser/android/contextualsearch/resolved_search_term.h" 17 #include "chrome/browser/android/contextualsearch/resolved_search_term.h"
17 #include "chrome/browser/android/proto/client_discourse_context.pb.h" 18 #include "chrome/browser/android/proto/client_discourse_context.pb.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const char kXssiEscape[] = ")]}'\n"; 54 const char kXssiEscape[] = ")]}'\n";
54 const char kDiscourseContextHeaderPrefix[] = "X-Additional-Discourse-Context: "; 55 const char kDiscourseContextHeaderPrefix[] = "X-Additional-Discourse-Context: ";
55 const char kDoPreventPreloadValue[] = "1"; 56 const char kDoPreventPreloadValue[] = "1";
56 57
57 // The number of characters that should be shown after the selected expression. 58 // The number of characters that should be shown after the selected expression.
58 const int kSurroundingSizeForUI = 60; 59 const int kSurroundingSizeForUI = 60;
59 60
60 // The version of the Contextual Cards API that we want to invoke. 61 // The version of the Contextual Cards API that we want to invoke.
61 const int kContextualCardsVersion = 1; 62 const int kContextualCardsVersion = 1;
62 63
63 } // namespace 64 } // namespace
64 65
65 // URLFetcher ID, only used for tests: we only have one kind of fetcher. 66 // URLFetcher ID, only used for tests: we only have one kind of fetcher.
66 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1; 67 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1;
67 68
68 // Handles tasks for the ContextualSearchManager in a separable, testable way. 69 // Handles tasks for the ContextualSearchManager in a separable, testable way.
69 ContextualSearchDelegate::ContextualSearchDelegate( 70 ContextualSearchDelegate::ContextualSearchDelegate(
70 net::URLRequestContextGetter* url_request_context, 71 net::URLRequestContextGetter* url_request_context,
71 TemplateURLService* template_url_service, 72 TemplateURLService* template_url_service,
72 const ContextualSearchDelegate::SearchTermResolutionCallback& 73 const ContextualSearchDelegate::SearchTermResolutionCallback&
73 search_term_callback, 74 search_term_callback,
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 403
403 // Only allow HTTP URLs or HTTPS URLs. 404 // Only allow HTTP URLs or HTTPS URLs.
404 if (current_page_url.scheme() != url::kHttpScheme && 405 if (current_page_url.scheme() != url::kHttpScheme &&
405 (current_page_url.scheme() != url::kHttpsScheme)) 406 (current_page_url.scheme() != url::kHttpsScheme))
406 return false; 407 return false;
407 408
408 // Check that the user has sync enabled, is logged in, and syncs their Chrome 409 // Check that the user has sync enabled, is logged in, and syncs their Chrome
409 // History. 410 // History.
410 browser_sync::ProfileSyncService* service = 411 browser_sync::ProfileSyncService* service =
411 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); 412 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
412 sync_driver::SyncPrefs sync_prefs(profile->GetPrefs()); 413 syncer::SyncPrefs sync_prefs(profile->GetPrefs());
413 if (service == NULL || !service->CanSyncStart() || 414 if (service == NULL || !service->CanSyncStart() ||
414 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()) 415 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes())
415 .Has(syncer::PROXY_TABS) || 416 .Has(syncer::PROXY_TABS) ||
416 !service->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES)) { 417 !service->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES)) {
417 return false; 418 return false;
418 } 419 }
419 420
420 return true; 421 return true;
421 } 422 }
422 423
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 end_offset -= trim; 538 end_offset -= trim;
538 } 539 }
539 if (result_text.length() > end_offset + padding_each_side_pinned) { 540 if (result_text.length() > end_offset + padding_each_side_pinned) {
540 // Trim the end. 541 // Trim the end.
541 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); 542 result_text = result_text.substr(0, end_offset + padding_each_side_pinned);
542 } 543 }
543 *start = start_offset; 544 *start = start_offset;
544 *end = end_offset; 545 *end = end_offset;
545 return result_text; 546 return result_text;
546 } 547 }
OLDNEW
« no previous file with comments | « chrome/browser/android/contextualsearch/contextual_search_delegate.h ('k') | chrome/browser/android/foreign_session_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698