| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/web_resource/web_resource_service.h" | 5 #include "components/web_resource/web_resource_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 if (source->GetStatus().is_success() && source->GetResponseCode() == 200) { | 73 if (source->GetStatus().is_success() && source->GetResponseCode() == 200) { |
| 74 std::string data; | 74 std::string data; |
| 75 source->GetResponseAsString(&data); | 75 source->GetResponseAsString(&data); |
| 76 // Calls EndFetch() on completion. | 76 // Calls EndFetch() on completion. |
| 77 // Full JSON parsing might spawn a utility process (for security). | 77 // Full JSON parsing might spawn a utility process (for security). |
| 78 // To limit the the number of simultaneously active processes | 78 // To limit the the number of simultaneously active processes |
| 79 // (on Android in particular) we short-cut the full parsing in the case of | 79 // (on Android in particular) we short-cut the full parsing in the case of |
| 80 // trivially "empty" JSONs. | 80 // trivially "empty" JSONs. |
| 81 if (data.empty() || data == "{}") { | 81 if (data.empty() || data == "{}") { |
| 82 OnUnpackFinished(base::WrapUnique(new base::DictionaryValue())); | 82 OnUnpackFinished(base::MakeUnique<base::DictionaryValue>()); |
| 83 } else { | 83 } else { |
| 84 parse_json_callback_.Run(data, | 84 parse_json_callback_.Run(data, |
| 85 base::Bind(&WebResourceService::OnUnpackFinished, | 85 base::Bind(&WebResourceService::OnUnpackFinished, |
| 86 weak_ptr_factory_.GetWeakPtr()), | 86 weak_ptr_factory_.GetWeakPtr()), |
| 87 base::Bind(&WebResourceService::OnUnpackError, | 87 base::Bind(&WebResourceService::OnUnpackError, |
| 88 weak_ptr_factory_.GetWeakPtr())); | 88 weak_ptr_factory_.GetWeakPtr())); |
| 89 } | 89 } |
| 90 } else { | 90 } else { |
| 91 // Don't parse data if attempt to download was unsuccessful. | 91 // Don't parse data if attempt to download was unsuccessful. |
| 92 // Stop loading new web resource data, and silently exit. | 92 // Stop loading new web resource data, and silently exit. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // Wait at least |start_fetch_delay_ms_|. | 181 // Wait at least |start_fetch_delay_ms_|. |
| 182 if (ms_until_update > start_fetch_delay_ms_) | 182 if (ms_until_update > start_fetch_delay_ms_) |
| 183 delay = ms_until_update; | 183 delay = ms_until_update; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 // Start fetch and wait for UpdateResourceCache. | 186 // Start fetch and wait for UpdateResourceCache. |
| 187 ScheduleFetch(delay); | 187 ScheduleFetch(delay); |
| 188 } | 188 } |
| 189 | 189 |
| 190 } // namespace web_resource | 190 } // namespace web_resource |
| OLD | NEW |