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