| OLD | NEW |
| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, | 122 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, |
| 123 Profile* profile) | 123 Profile* profile) |
| 124 : AutocompleteProvider(listener, profile, "Search"), | 124 : AutocompleteProvider(listener, profile, "Search"), |
| 125 providers_(TemplateURLServiceFactory::GetForProfile(profile)), | 125 providers_(TemplateURLServiceFactory::GetForProfile(profile)), |
| 126 suggest_results_pending_(0), | 126 suggest_results_pending_(0), |
| 127 suggest_field_trial_group_number_( | 127 suggest_field_trial_group_number_( |
| 128 AutocompleteFieldTrial::GetSuggestNumberOfGroups()), | 128 AutocompleteFieldTrial::GetSuggestNumberOfGroups()), |
| 129 has_suggested_relevance_(false), | 129 has_suggested_relevance_(false), |
| 130 verbatim_relevance_(-1), | 130 verbatim_relevance_(-1), |
| 131 have_suggest_results_(false), | 131 have_suggest_results_(false), |
| 132 instant_finalized_(false) { | 132 instant_finalized_(false), |
| 133 instant_suggest_enabled_(false) { |
| 133 // Above, we default |suggest_field_trial_group_number_| to the number of | 134 // Above, we default |suggest_field_trial_group_number_| to the number of |
| 134 // groups to mean "not in field trial." Field trial groups run from 0 to | 135 // groups to mean "not in field trial." Field trial groups run from 0 to |
| 135 // GetSuggestNumberOfGroups() - 1 (inclusive). | 136 // GetSuggestNumberOfGroups() - 1 (inclusive). |
| 136 if (AutocompleteFieldTrial::InSuggestFieldTrial()) { | 137 if (AutocompleteFieldTrial::InSuggestFieldTrial()) { |
| 137 suggest_field_trial_group_number_ = | 138 suggest_field_trial_group_number_ = |
| 138 AutocompleteFieldTrial::GetSuggestGroupNameAsNumber(); | 139 AutocompleteFieldTrial::GetSuggestGroupNameAsNumber(); |
| 139 } | 140 } |
| 140 // Add a beacon to the logs that'll allow us to identify later what | 141 // Add a beacon to the logs that'll allow us to identify later what |
| 141 // suggest field trial group a user is in. Do this by incrementing a | 142 // suggest field trial group a user is in. Do this by incrementing a |
| 142 // bucket in a histogram, where the bucket represents the user's | 143 // bucket in a histogram, where the bucket represents the user's |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } | 686 } |
| 686 | 687 |
| 687 // 5th element: Optional key-value pairs from the Suggest server. | 688 // 5th element: Optional key-value pairs from the Suggest server. |
| 688 ListValue* types = NULL; | 689 ListValue* types = NULL; |
| 689 ListValue* relevances = NULL; | 690 ListValue* relevances = NULL; |
| 690 DictionaryValue* extras = NULL; | 691 DictionaryValue* extras = NULL; |
| 691 if (root_list->GetDictionary(4, &extras)) { | 692 if (root_list->GetDictionary(4, &extras)) { |
| 692 extras->GetList("google:suggesttype", &types); | 693 extras->GetList("google:suggesttype", &types); |
| 693 | 694 |
| 694 // Only accept relevance suggestions if Instant is disabled. | 695 // Only accept relevance suggestions if Instant is disabled. |
| 695 if (!is_keyword && !InstantController::IsEnabled(profile_)) { | 696 if (!is_keyword && !instant_suggest_enabled_) { |
| 696 // Discard this list if its size does not match that of the suggestions. | 697 // Discard this list if its size does not match that of the suggestions. |
| 697 if (extras->GetList("google:suggestrelevance", &relevances) && | 698 if (extras->GetList("google:suggestrelevance", &relevances) && |
| 698 relevances->GetSize() != results->GetSize()) | 699 relevances->GetSize() != results->GetSize()) |
| 699 relevances = NULL; | 700 relevances = NULL; |
| 700 | 701 |
| 701 extras->GetInteger("google:verbatimrelevance", &verbatim_relevance_); | 702 extras->GetInteger("google:verbatimrelevance", &verbatim_relevance_); |
| 702 } | 703 } |
| 703 } | 704 } |
| 704 | 705 |
| 705 SuggestResults* suggest_results = | 706 SuggestResults* suggest_results = |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 match.description = navigation.description(); | 1241 match.description = navigation.description(); |
| 1241 AutocompleteMatch::ClassifyMatchInString(input, match.description, | 1242 AutocompleteMatch::ClassifyMatchInString(input, match.description, |
| 1242 ACMatchClassification::NONE, &match.description_class); | 1243 ACMatchClassification::NONE, &match.description_class); |
| 1243 return match; | 1244 return match; |
| 1244 } | 1245 } |
| 1245 | 1246 |
| 1246 void SearchProvider::UpdateDone() { | 1247 void SearchProvider::UpdateDone() { |
| 1247 // We're done when there are no more suggest queries pending (this is set to 1 | 1248 // We're done when there are no more suggest queries pending (this is set to 1 |
| 1248 // when the timer is started) and we're not waiting on instant. | 1249 // when the timer is started) and we're not waiting on instant. |
| 1249 done_ = ((suggest_results_pending_ == 0) && | 1250 done_ = ((suggest_results_pending_ == 0) && |
| 1250 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 1251 (instant_finalized_ || !instant_suggest_enabled_)); |
| 1251 } | 1252 } |
| OLD | NEW |