Chromium Code Reviews| 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/prerender/prerender_local_predictor.h" | 5 #include "chrome/browser/prerender/prerender_local_predictor.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 } | 635 } |
| 636 ] | 636 ] |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 */ | 640 */ |
| 641 DictionaryValue json_data; | 641 DictionaryValue json_data; |
| 642 DictionaryValue* req = new DictionaryValue(); | 642 DictionaryValue* req = new DictionaryValue(); |
| 643 req->SetInteger("version", 1); | 643 req->SetInteger("version", 1); |
| 644 req->SetInteger("behavior_id", GetPrerenderServiceBehaviorID()); | 644 req->SetInteger("behavior_id", GetPrerenderServiceBehaviorID()); |
| 645 if (info->source_url_.url_lookup_success) { | 645 if (ShouldQueryPrerenderServiceForCurrentURL() && |
| 646 info->source_url_.url_lookup_success) { | |
| 646 ListValue* browse_history = new ListValue(); | 647 ListValue* browse_history = new ListValue(); |
| 647 DictionaryValue* browse_item = new DictionaryValue(); | 648 DictionaryValue* browse_item = new DictionaryValue(); |
| 648 browse_item->SetString("url", info->source_url_.url.spec()); | 649 browse_item->SetString("url", info->source_url_.url.spec()); |
| 649 browse_history->Append(browse_item); | 650 browse_history->Append(browse_item); |
| 650 DictionaryValue* hint_request = new DictionaryValue(); | 651 DictionaryValue* hint_request = new DictionaryValue(); |
| 651 hint_request->Set("browse_history", browse_history); | 652 hint_request->Set("browse_history", browse_history); |
| 652 req->Set("hint_request", hint_request); | 653 req->Set("hint_request", hint_request); |
| 653 } | 654 } |
| 654 int num_candidate_urls = 0; | 655 int num_candidate_urls = 0; |
| 655 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { | 656 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { |
| 656 if (info->candidate_urls_[i].url_lookup_success) | 657 if (info->candidate_urls_[i].url_lookup_success) |
| 657 num_candidate_urls++; | 658 num_candidate_urls++; |
| 658 } | 659 } |
| 659 if (num_candidate_urls > 0) { | 660 if (ShouldQueryPrerenderServiceForCandidateURLs() && |
| 661 num_candidate_urls > 0) { | |
| 660 ListValue* candidates = new ListValue(); | 662 ListValue* candidates = new ListValue(); |
| 661 DictionaryValue* candidate; | 663 DictionaryValue* candidate; |
| 662 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { | 664 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { |
| 663 if (info->candidate_urls_[i].url_lookup_success) { | 665 if (info->candidate_urls_[i].url_lookup_success) { |
| 664 candidate = new DictionaryValue(); | 666 candidate = new DictionaryValue(); |
| 665 candidate->SetString("url", info->candidate_urls_[i].url.spec()); | 667 candidate->SetString("url", info->candidate_urls_[i].url.spec()); |
| 666 candidates->Append(candidate); | 668 candidates->Append(candidate); |
| 667 } | 669 } |
| 668 } | 670 } |
| 669 DictionaryValue* candidate_check_request = new DictionaryValue(); | 671 DictionaryValue* candidate_check_request = new DictionaryValue(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 } | 752 } |
| 751 */ | 753 */ |
| 752 ListValue* list = NULL; | 754 ListValue* list = NULL; |
| 753 int int_value; | 755 int int_value; |
| 754 if (!dict->GetInteger("prerender_response.behavior_id", &int_value) || | 756 if (!dict->GetInteger("prerender_response.behavior_id", &int_value) || |
| 755 int_value != GetPrerenderServiceBehaviorID()) { | 757 int_value != GetPrerenderServiceBehaviorID()) { |
| 756 return false; | 758 return false; |
| 757 } | 759 } |
| 758 if (!dict->GetList("prerender_response.candidate_check_response.candidates", | 760 if (!dict->GetList("prerender_response.candidate_check_response.candidates", |
| 759 &list)) { | 761 &list)) { |
| 760 if (info->candidate_urls_.size() > 0) | 762 if (ShouldQueryPrerenderServiceForCandidateURLs()) { |
| 761 return false; | 763 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { |
|
jam
2013/09/09 20:22:51
nit: size_t then you don't need cast...
| |
| 764 if (info->candidate_urls_[i].url_lookup_success) | |
| 765 return false; | |
| 766 } | |
| 767 } | |
| 762 } else { | 768 } else { |
| 763 for (size_t i = 0; i < list->GetSize(); i++) { | 769 for (size_t i = 0; i < list->GetSize(); i++) { |
| 764 DictionaryValue* d; | 770 DictionaryValue* d; |
| 765 if (!list->GetDictionary(i, &d)) | 771 if (!list->GetDictionary(i, &d)) |
| 766 return false; | 772 return false; |
| 767 string url_string; | 773 string url_string; |
| 768 if (!d->GetString("url", &url_string) || !GURL(url_string).is_valid()) | 774 if (!d->GetString("url", &url_string) || !GURL(url_string).is_valid()) |
| 769 return false; | 775 return false; |
| 770 GURL url(url_string); | 776 GURL url(url_string); |
| 771 int in_index_timed_out = 0; | 777 int in_index_timed_out = 0; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 784 for (size_t j = 0; j < info->candidate_urls_.size(); j++) { | 790 for (size_t j = 0; j < info->candidate_urls_.size(); j++) { |
| 785 if (info->candidate_urls_[j].url == url) { | 791 if (info->candidate_urls_[j].url == url) { |
| 786 info->candidate_urls_[j].service_whitelist_reported = true; | 792 info->candidate_urls_[j].service_whitelist_reported = true; |
| 787 info->candidate_urls_[j].service_whitelist = (in_index == 1); | 793 info->candidate_urls_[j].service_whitelist = (in_index == 1); |
| 788 info->candidate_urls_[j].service_whitelist_lookup_ok = | 794 info->candidate_urls_[j].service_whitelist_lookup_ok = |
| 789 ((1 - in_index_timed_out) == 1); | 795 ((1 - in_index_timed_out) == 1); |
| 790 } | 796 } |
| 791 } | 797 } |
| 792 } | 798 } |
| 793 for (size_t i = 0; i < info->candidate_urls_.size(); i++) { | 799 for (size_t i = 0; i < info->candidate_urls_.size(); i++) { |
| 794 if (!info->candidate_urls_[i].service_whitelist_reported) | 800 if (info->candidate_urls_[i].url_lookup_success && |
| 801 !info->candidate_urls_[i].service_whitelist_reported) { | |
| 795 return false; | 802 return false; |
| 803 } | |
| 796 } | 804 } |
| 797 } | 805 } |
| 798 | 806 |
| 799 list = NULL; | 807 if (ShouldQueryPrerenderServiceForCurrentURL() && |
| 800 if (dict->GetInteger("prerender_response.hint_response.hinting_timed_out", | 808 info->source_url_.url_lookup_success) { |
| 801 &int_value) && | 809 list = NULL; |
| 802 int_value == 1) { | 810 if (dict->GetInteger("prerender_response.hint_response.hinting_timed_out", |
| 803 *hinting_timed_out = true; | 811 &int_value) && |
| 804 } else if (!dict->GetList("prerender_response.hint_response.candidates", | 812 int_value == 1) { |
| 805 &list)) { | 813 *hinting_timed_out = true; |
| 806 return false; | 814 } else if (!dict->GetList("prerender_response.hint_response.candidates", |
| 807 } else { | 815 &list)) { |
| 808 for (int i = 0; i < static_cast<int>(list->GetSize()); i++) { | 816 return false; |
| 809 DictionaryValue* d; | 817 } else { |
| 810 if (!list->GetDictionary(i, &d)) | 818 for (int i = 0; i < static_cast<int>(list->GetSize()); i++) { |
|
jam
2013/09/09 20:22:51
ditto
| |
| 811 return false; | 819 DictionaryValue* d; |
| 812 string url; | 820 if (!list->GetDictionary(i, &d)) |
| 813 double priority; | 821 return false; |
| 814 if (!d->GetString("url", &url) || !d->GetDouble("likelihood", &priority) | 822 string url; |
| 815 || !GURL(url).is_valid()) { | 823 double priority; |
| 816 return false; | 824 if (!d->GetString("url", &url) || !d->GetDouble("likelihood", &priority) |
| 825 || !GURL(url).is_valid()) { | |
| 826 return false; | |
| 827 } | |
| 828 int in_index_timed_out = 0; | |
| 829 int in_index = 0; | |
| 830 if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || | |
| 831 in_index_timed_out != 1) && | |
| 832 !d->GetInteger("in_index", &in_index)) { | |
| 833 return false; | |
| 834 } | |
| 835 if (priority < 0.0 || priority > 1.0 || in_index < 0 || in_index > 1 || | |
| 836 in_index_timed_out < 0 || in_index_timed_out > 1) { | |
| 837 return false; | |
| 838 } | |
| 839 if (in_index_timed_out == 1) | |
| 840 *hinting_url_lookup_timed_out = true; | |
| 841 info->MaybeAddCandidateURLFromService(GURL(url), | |
| 842 priority, | |
| 843 in_index == 1, | |
| 844 (1 - in_index_timed_out) == 1); | |
| 817 } | 845 } |
| 818 int in_index_timed_out = 0; | |
| 819 int in_index = 0; | |
| 820 if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || | |
| 821 in_index_timed_out != 1) && | |
| 822 !d->GetInteger("in_index", &in_index)) { | |
| 823 return false; | |
| 824 } | |
| 825 if (priority < 0.0 || priority > 1.0 || in_index < 0 || in_index > 1 || | |
| 826 in_index_timed_out < 0 || in_index_timed_out > 1) { | |
| 827 return false; | |
| 828 } | |
| 829 if (in_index_timed_out == 1) | |
| 830 *hinting_url_lookup_timed_out = true; | |
| 831 info->MaybeAddCandidateURLFromService(GURL(url), | |
| 832 priority, | |
| 833 in_index == 1, | |
| 834 (1 - in_index_timed_out) == 1); | |
| 835 } | 846 } |
| 836 } | 847 } |
| 837 | 848 |
| 838 return true; | 849 return true; |
| 839 } | 850 } |
| 840 | 851 |
| 841 void PrerenderLocalPredictor::OnURLFetchComplete( | 852 void PrerenderLocalPredictor::OnURLFetchComplete( |
| 842 const net::URLFetcher* source) { | 853 const net::URLFetcher* source) { |
| 843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 844 RecordEvent(EVENT_PRERENDER_SERVICE_RECEIVED_RESULT); | 855 RecordEvent(EVENT_PRERENDER_SERVICE_RECEIVED_RESULT); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1272 } | 1283 } |
| 1273 if (best_matched_prerender) { | 1284 if (best_matched_prerender) { |
| 1274 RecordEvent(EVENT_TAB_HELPER_URL_SEEN_MATCH); | 1285 RecordEvent(EVENT_TAB_HELPER_URL_SEEN_MATCH); |
| 1275 best_matched_prerender->would_have_matched = true; | 1286 best_matched_prerender->would_have_matched = true; |
| 1276 if (session_storage_namespace_matches) | 1287 if (session_storage_namespace_matches) |
| 1277 RecordEvent(EVENT_TAB_HELPER_URL_SEEN_NAMESPACE_MATCH); | 1288 RecordEvent(EVENT_TAB_HELPER_URL_SEEN_NAMESPACE_MATCH); |
| 1278 } | 1289 } |
| 1279 } | 1290 } |
| 1280 | 1291 |
| 1281 } // namespace prerender | 1292 } // namespace prerender |
| OLD | NEW |