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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 10173001: Add a Profile* member to TemplateURL. This makes some invocations of ReplaceSearchTerms() a bit le… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 // static 83 // static
84 const int SearchProvider::kDefaultProviderURLFetcherID = 1; 84 const int SearchProvider::kDefaultProviderURLFetcherID = 1;
85 // static 85 // static
86 const int SearchProvider::kKeywordProviderURLFetcherID = 2; 86 const int SearchProvider::kKeywordProviderURLFetcherID = 2;
87 // static 87 // static
88 bool SearchProvider::query_suggest_immediately_ = false; 88 bool SearchProvider::query_suggest_immediately_ = false;
89 89
90 SearchProvider::SearchProvider(ACProviderListener* listener, Profile* profile) 90 SearchProvider::SearchProvider(ACProviderListener* listener, Profile* profile)
91 : AutocompleteProvider(listener, profile, "Search"), 91 : AutocompleteProvider(listener, profile, "Search"),
92 providers_(profile),
92 suggest_results_pending_(0), 93 suggest_results_pending_(0),
93 have_suggest_results_(false), 94 have_suggest_results_(false),
94 instant_finalized_(false) { 95 instant_finalized_(false) {
95 // We use GetSuggestNumberOfGroups() as the group ID to mean "not in field 96 // We use GetSuggestNumberOfGroups() as the group ID to mean "not in field
96 // trial." Field trial groups run from 0 to GetSuggestNumberOfGroups() - 1 97 // trial." Field trial groups run from 0 to GetSuggestNumberOfGroups() - 1
97 // (inclusive). 98 // (inclusive).
98 int suggest_field_trial_group_number = 99 int suggest_field_trial_group_number =
99 AutocompleteFieldTrial::GetSuggestNumberOfGroups(); 100 AutocompleteFieldTrial::GetSuggestNumberOfGroups();
100 if (AutocompleteFieldTrial::InSuggestFieldTrial()) { 101 if (AutocompleteFieldTrial::InSuggestFieldTrial()) {
101 suggest_field_trial_group_number = 102 suggest_field_trial_group_number =
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 default_navigation_results_.clear(); 455 default_navigation_results_.clear();
455 have_suggest_results_ = false; 456 have_suggest_results_ = false;
456 } 457 }
457 458
458 content::URLFetcher* SearchProvider::CreateSuggestFetcher( 459 content::URLFetcher* SearchProvider::CreateSuggestFetcher(
459 int id, 460 int id,
460 const TemplateURLRef& suggestions_url, 461 const TemplateURLRef& suggestions_url,
461 const string16& text) { 462 const string16& text) {
462 DCHECK(suggestions_url.SupportsReplacement()); 463 DCHECK(suggestions_url.SupportsReplacement());
463 content::URLFetcher* fetcher = content::URLFetcher::Create(id, 464 content::URLFetcher* fetcher = content::URLFetcher::Create(id,
464 GURL(suggestions_url.ReplaceSearchTermsUsingProfile( 465 GURL(suggestions_url.ReplaceSearchTerms(text,
465 profile_, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 466 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())),
466 string16())),
467 content::URLFetcher::GET, this); 467 content::URLFetcher::GET, this);
468 fetcher->SetRequestContext(profile_->GetRequestContext()); 468 fetcher->SetRequestContext(profile_->GetRequestContext());
469 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 469 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
470 fetcher->Start(); 470 fetcher->Start();
471 return fetcher; 471 return fetcher;
472 } 472 }
473 473
474 bool SearchProvider::ParseSuggestResults(Value* root_val, 474 bool SearchProvider::ParseSuggestResults(Value* root_val,
475 bool is_keyword, 475 bool is_keyword,
476 const string16& input_text, 476 const string16& input_text,
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 } 899 }
900 match.fill_into_edit.append(query_string); 900 match.fill_into_edit.append(query_string);
901 // Not all suggestions start with the original input. 901 // Not all suggestions start with the original input.
902 if (!prevent_inline_autocomplete && 902 if (!prevent_inline_autocomplete &&
903 !match.fill_into_edit.compare(search_start, input_text.length(), 903 !match.fill_into_edit.compare(search_start, input_text.length(),
904 input_text)) 904 input_text))
905 match.inline_autocomplete_offset = search_start + input_text.length(); 905 match.inline_autocomplete_offset = search_start + input_text.length();
906 906
907 const TemplateURLRef& search_url = provider.url_ref(); 907 const TemplateURLRef& search_url = provider.url_ref();
908 DCHECK(search_url.SupportsReplacement()); 908 DCHECK(search_url.SupportsReplacement());
909 match.destination_url = GURL(search_url.ReplaceSearchTermsUsingProfile( 909 match.destination_url = GURL(search_url.ReplaceSearchTerms(query_string,
910 profile_, query_string, accepted_suggestion, input_text)); 910 accepted_suggestion, input_text));
911 911
912 // Search results don't look like URLs. 912 // Search results don't look like URLs.
913 match.transition = is_keyword ? 913 match.transition = is_keyword ?
914 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED; 914 content::PAGE_TRANSITION_KEYWORD : content::PAGE_TRANSITION_GENERATED;
915 915
916 // Try to add |match| to |map|. If a match for |query_string| is already in 916 // Try to add |match| to |map|. If a match for |query_string| is already in
917 // |map|, replace it if |match| is more relevant. 917 // |map|, replace it if |match| is more relevant.
918 // NOTE: Keep this ToLower() call in sync with url_database.cc. 918 // NOTE: Keep this ToLower() call in sync with url_database.cc.
919 const std::pair<MatchMap::iterator, bool> i = map->insert( 919 const std::pair<MatchMap::iterator, bool> i = map->insert(
920 std::pair<string16, AutocompleteMatch>( 920 std::pair<string16, AutocompleteMatch>(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 964
965 return match; 965 return match;
966 } 966 }
967 967
968 void SearchProvider::UpdateDone() { 968 void SearchProvider::UpdateDone() {
969 // We're done when there are no more suggest queries pending (this is set to 1 969 // We're done when there are no more suggest queries pending (this is set to 1
970 // when the timer is started) and we're not waiting on instant. 970 // when the timer is started) and we're not waiting on instant.
971 done_ = ((suggest_results_pending_ == 0) && 971 done_ = ((suggest_results_pending_ == 0) &&
972 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 972 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
973 } 973 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698