OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (providers_.valid_default_provider()) { | 323 if (providers_.valid_default_provider()) { |
324 url_db->GetMostRecentKeywordSearchTerms(providers_.default_provider().id(), | 324 url_db->GetMostRecentKeywordSearchTerms(providers_.default_provider().id(), |
325 input_.text(), num_matches, &default_history_results_); | 325 input_.text(), num_matches, &default_history_results_); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) { | 329 void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) { |
330 // Don't send any queries to the server until some time has elapsed after | 330 // Don't send any queries to the server until some time has elapsed after |
331 // the last keypress, to avoid flooding the server with requests we are | 331 // the last keypress, to avoid flooding the server with requests we are |
332 // likely to end up throwing away anyway. | 332 // likely to end up throwing away anyway. |
333 static const int kQueryDelayMs = 200; | 333 const int kQueryDelayMs = 200; |
334 | 334 |
335 if (!IsQuerySuitableForSuggest()) { | 335 if (!IsQuerySuitableForSuggest()) { |
336 StopSuggest(); | 336 StopSuggest(); |
337 return; | 337 return; |
338 } | 338 } |
339 | 339 |
340 // For the minimal_changes case, if we finished the previous query and still | 340 // For the minimal_changes case, if we finished the previous query and still |
341 // have its results, or are allowed to keep running it, just do that, rather | 341 // have its results, or are allowed to keep running it, just do that, rather |
342 // than starting a new query. | 342 // than starting a new query. |
343 if (minimal_changes && | 343 if (minimal_changes && |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 // 5th argument: Optional key-value pairs. | 484 // 5th argument: Optional key-value pairs. |
485 // TODO: We may iterate the 5th+ arguments of the root_list if any other | 485 // TODO: We may iterate the 5th+ arguments of the root_list if any other |
486 // optional data are defined. | 486 // optional data are defined. |
487 if (root_list->GetSize() > 4) { | 487 if (root_list->GetSize() > 4) { |
488 Value* optional_val; | 488 Value* optional_val; |
489 if (root_list->Get(4, &optional_val) && | 489 if (root_list->Get(4, &optional_val) && |
490 optional_val->IsType(Value::TYPE_DICTIONARY)) { | 490 optional_val->IsType(Value::TYPE_DICTIONARY)) { |
491 DictionaryValue* dict_val = static_cast<DictionaryValue*>(optional_val); | 491 DictionaryValue* dict_val = static_cast<DictionaryValue*>(optional_val); |
492 | 492 |
493 // Parse Google Suggest specific type extension. | 493 // Parse Google Suggest specific type extension. |
494 static const std::string kGoogleSuggestType("google:suggesttype"); | 494 const std::string kGoogleSuggestType("google:suggesttype"); |
495 if (dict_val->HasKey(kGoogleSuggestType)) | 495 if (dict_val->HasKey(kGoogleSuggestType)) |
496 dict_val->GetList(kGoogleSuggestType, &type_list); | 496 dict_val->GetList(kGoogleSuggestType, &type_list); |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
500 ListValue* result_list = static_cast<ListValue*>(result_val); | 500 ListValue* result_list = static_cast<ListValue*>(result_val); |
501 for (size_t i = 0; i < result_list->GetSize(); ++i) { | 501 for (size_t i = 0; i < result_list->GetSize(); ++i) { |
502 Value* suggestion_val; | 502 Value* suggestion_val; |
503 string16 suggestion_str; | 503 string16 suggestion_str; |
504 if (!result_list->Get(i, &suggestion_val) || | 504 if (!result_list->Get(i, &suggestion_val) || |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 | 943 |
944 return match; | 944 return match; |
945 } | 945 } |
946 | 946 |
947 void SearchProvider::UpdateDone() { | 947 void SearchProvider::UpdateDone() { |
948 // We're done when there are no more suggest queries pending (this is set to 1 | 948 // We're done when there are no more suggest queries pending (this is set to 1 |
949 // when the timer is started) and we're not waiting on instant. | 949 // when the timer is started) and we're not waiting on instant. |
950 done_ = ((suggest_results_pending_ == 0) && | 950 done_ = ((suggest_results_pending_ == 0) && |
951 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 951 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
952 } | 952 } |
OLD | NEW |