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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 *hinting_timed_out = true; | 832 *hinting_timed_out = true; |
833 } else if (!dict->GetList("prerender_response.hint_response.candidates", | 833 } else if (!dict->GetList("prerender_response.hint_response.candidates", |
834 &list)) { | 834 &list)) { |
835 return false; | 835 return false; |
836 } else { | 836 } else { |
837 for (int i = 0; i < static_cast<int>(list->GetSize()); i++) { | 837 for (int i = 0; i < static_cast<int>(list->GetSize()); i++) { |
838 base::DictionaryValue* d; | 838 base::DictionaryValue* d; |
839 if (!list->GetDictionary(i, &d)) | 839 if (!list->GetDictionary(i, &d)) |
840 return false; | 840 return false; |
841 string url; | 841 string url; |
| 842 if (!d->GetString("url", &url) || !GURL(url).is_valid()) |
| 843 return false; |
842 double priority; | 844 double priority; |
843 if (!d->GetString("url", &url) || !d->GetDouble("likelihood", &priority) | 845 if (!d->GetDouble("likelihood", &priority) || priority < 0.0 || |
844 || !GURL(url).is_valid()) { | 846 priority > 1.0) { |
845 return false; | 847 return false; |
846 } | 848 } |
847 int in_index_timed_out = 0; | 849 int in_index_timed_out = 0; |
848 int in_index = 0; | 850 int in_index = 0; |
849 if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || | 851 if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || |
850 in_index_timed_out != 1) && | 852 in_index_timed_out != 1) && |
851 !d->GetInteger("in_index", &in_index)) { | 853 !d->GetInteger("in_index", &in_index)) { |
852 return false; | 854 return false; |
853 } | 855 } |
854 if (priority < 0.0 || priority > 1.0 || in_index < 0 || in_index > 1 || | 856 if (in_index < 0 || in_index > 1 || in_index_timed_out < 0 || |
855 in_index_timed_out < 0 || in_index_timed_out > 1) { | 857 in_index_timed_out > 1) { |
856 return false; | 858 return false; |
857 } | 859 } |
858 if (in_index_timed_out == 1) | 860 if (in_index_timed_out == 1) |
859 *hinting_url_lookup_timed_out = true; | 861 *hinting_url_lookup_timed_out = true; |
860 info->MaybeAddCandidateURLFromService(GURL(url), | 862 info->MaybeAddCandidateURLFromService(GURL(url), |
861 priority, | 863 priority, |
862 in_index == 1, | 864 in_index == 1, |
863 (1 - in_index_timed_out) == 1); | 865 !in_index_timed_out); |
864 } | 866 } |
865 if (list->GetSize() > 0) | 867 if (list->GetSize() > 0) |
866 RecordEvent(EVENT_PRERENDER_SERIVCE_RETURNED_HINTING_CANDIDATES); | 868 RecordEvent(EVENT_PRERENDER_SERIVCE_RETURNED_HINTING_CANDIDATES); |
867 } | 869 } |
868 } | 870 } |
869 | 871 |
870 return true; | 872 return true; |
871 } | 873 } |
872 | 874 |
873 void PrerenderLocalPredictor::OnURLFetchComplete( | 875 void PrerenderLocalPredictor::OnURLFetchComplete( |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 break; | 1415 break; |
1414 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: | 1416 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: |
1415 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); | 1417 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); |
1416 break; | 1418 break; |
1417 default: | 1419 default: |
1418 NOTREACHED(); | 1420 NOTREACHED(); |
1419 } | 1421 } |
1420 } | 1422 } |
1421 | 1423 |
1422 } // namespace prerender | 1424 } // namespace prerender |
OLD | NEW |