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 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()) { | |
|
sky
2014/07/15 04:22:24
nit: no {}
Peter Kasting
2014/07/15 18:56:07
Done.
| |
| 843 return false; | |
| 844 } | |
| 842 double priority; | 845 double priority; |
| 843 if (!d->GetString("url", &url) || !d->GetDouble("likelihood", &priority) | 846 if (!d->GetDouble("likelihood", &priority) || priority < 0.0 || |
| 844 || !GURL(url).is_valid()) { | 847 priority > 1.0) { |
| 845 return false; | 848 return false; |
| 846 } | 849 } |
| 847 int in_index_timed_out = 0; | 850 int in_index_timed_out = 0; |
| 848 int in_index = 0; | 851 int in_index = 0; |
| 849 if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || | 852 if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || |
| 850 in_index_timed_out != 1) && | 853 in_index_timed_out != 1) && |
| 851 !d->GetInteger("in_index", &in_index)) { | 854 !d->GetInteger("in_index", &in_index)) { |
| 852 return false; | 855 return false; |
| 853 } | 856 } |
| 854 if (priority < 0.0 || priority > 1.0 || in_index < 0 || in_index > 1 || | 857 if (in_index < 0 || in_index > 1 || in_index_timed_out < 0 || |
| 855 in_index_timed_out < 0 || in_index_timed_out > 1) { | 858 in_index_timed_out > 1) { |
| 856 return false; | 859 return false; |
| 857 } | 860 } |
| 858 if (in_index_timed_out == 1) | 861 if (in_index_timed_out == 1) |
| 859 *hinting_url_lookup_timed_out = true; | 862 *hinting_url_lookup_timed_out = true; |
| 860 info->MaybeAddCandidateURLFromService(GURL(url), | 863 info->MaybeAddCandidateURLFromService(GURL(url), |
| 861 priority, | 864 priority, |
| 862 in_index == 1, | 865 in_index == 1, |
| 863 (1 - in_index_timed_out) == 1); | 866 !in_index_timed_out); |
| 864 } | 867 } |
| 865 if (list->GetSize() > 0) | 868 if (list->GetSize() > 0) |
| 866 RecordEvent(EVENT_PRERENDER_SERIVCE_RETURNED_HINTING_CANDIDATES); | 869 RecordEvent(EVENT_PRERENDER_SERIVCE_RETURNED_HINTING_CANDIDATES); |
| 867 } | 870 } |
| 868 } | 871 } |
| 869 | 872 |
| 870 return true; | 873 return true; |
| 871 } | 874 } |
| 872 | 875 |
| 873 void PrerenderLocalPredictor::OnURLFetchComplete( | 876 void PrerenderLocalPredictor::OnURLFetchComplete( |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1413 break; | 1416 break; |
| 1414 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: | 1417 case content::SessionStorageNamespace::MERGE_RESULT_MERGEABLE: |
| 1415 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); | 1418 RecordEvent(EVENT_NAMESPACE_MISMATCH_MERGE_RESULT_MERGEABLE); |
| 1416 break; | 1419 break; |
| 1417 default: | 1420 default: |
| 1418 NOTREACHED(); | 1421 NOTREACHED(); |
| 1419 } | 1422 } |
| 1420 } | 1423 } |
| 1421 | 1424 |
| 1422 } // namespace prerender | 1425 } // namespace prerender |
| OLD | NEW |