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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 URLFetcher::GET, this); | 445 URLFetcher::GET, this); |
446 fetcher->set_request_context(profile_->GetRequestContext()); | 446 fetcher->set_request_context(profile_->GetRequestContext()); |
447 fetcher->Start(); | 447 fetcher->Start(); |
448 return fetcher; | 448 return fetcher; |
449 } | 449 } |
450 | 450 |
451 bool SearchProvider::ParseSuggestResults(Value* root_val, | 451 bool SearchProvider::ParseSuggestResults(Value* root_val, |
452 bool is_keyword, | 452 bool is_keyword, |
453 const string16& input_text, | 453 const string16& input_text, |
454 SuggestResults* suggest_results) { | 454 SuggestResults* suggest_results) { |
455 ListValue* root_list = root_val->AsList(); | 455 if (!root_val->IsType(Value::TYPE_LIST)) |
456 if (!root_list) | |
457 return false; | 456 return false; |
| 457 ListValue* root_list = static_cast<ListValue*>(root_val); |
458 | 458 |
459 Value* query_val; | 459 Value* query_val; |
460 string16 query_str; | 460 string16 query_str; |
461 Value* result_val; | 461 Value* result_val; |
462 if ((root_list->GetSize() < 2) || !root_list->Get(0, &query_val) || | 462 if ((root_list->GetSize() < 2) || !root_list->Get(0, &query_val) || |
463 !query_val->GetAsString(&query_str) || | 463 !query_val->GetAsString(&query_str) || |
464 (query_str != input_text) || | 464 (query_str != input_text) || |
465 !root_list->Get(1, &result_val) || !result_val->AsList()) | 465 !root_list->Get(1, &result_val) || !result_val->IsType(Value::TYPE_LIST)) |
466 return false; | 466 return false; |
467 | 467 |
468 ListValue* description_list = NULL; | 468 ListValue* description_list = NULL; |
469 if (root_list->GetSize() > 2) { | 469 if (root_list->GetSize() > 2) { |
470 // 3rd element: Description list. | 470 // 3rd element: Description list. |
471 Value* description_val; | 471 Value* description_val; |
472 if (root_list->Get(2, &description_val)) | 472 if (root_list->Get(2, &description_val) && |
473 description_list = description_val->AsList(); | 473 description_val->IsType(Value::TYPE_LIST)) |
| 474 description_list = static_cast<ListValue*>(description_val); |
474 } | 475 } |
475 | 476 |
476 // We don't care about the query URL list (the fourth element in the | 477 // We don't care about the query URL list (the fourth element in the |
477 // response) for now. | 478 // response) for now. |
478 | 479 |
479 // Parse optional data in the results from the Suggest server if any. | 480 // Parse optional data in the results from the Suggest server if any. |
480 ListValue* type_list = NULL; | 481 ListValue* type_list = NULL; |
481 // 5th argument: Optional key-value pairs. | 482 // 5th argument: Optional key-value pairs. |
482 // TODO: We may iterate the 5th+ arguments of the root_list if any other | 483 // TODO: We may iterate the 5th+ arguments of the root_list if any other |
483 // optional data are defined. | 484 // optional data are defined. |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 | 944 |
944 return match; | 945 return match; |
945 } | 946 } |
946 | 947 |
947 void SearchProvider::UpdateDone() { | 948 void SearchProvider::UpdateDone() { |
948 // We're done when there are no more suggest queries pending (this is set to 1 | 949 // 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. | 950 // when the timer is started) and we're not waiting on instant. |
950 done_ = ((suggest_results_pending_ == 0) && | 951 done_ = ((suggest_results_pending_ == 0) && |
951 (instant_finalized_ || !InstantController::IsEnabled(profile_))); | 952 (instant_finalized_ || !InstantController::IsEnabled(profile_))); |
952 } | 953 } |
OLD | NEW |