| 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/message_loop/message_loop.h" | 8 #include "base/location.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "components/google/core/browser/google_util.h" | 17 #include "components/google/core/browser/google_util.h" |
| 16 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 17 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 19 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
| 20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 21 | 23 |
| 22 // No anonymous namespace, because const variables automatically get internal | 24 // No anonymous namespace, because const variables automatically get internal |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Don't parse data if attempt to download was unsuccessful. | 87 // Don't parse data if attempt to download was unsuccessful. |
| 86 // Stop loading new web resource data, and silently exit. | 88 // Stop loading new web resource data, and silently exit. |
| 87 // We do not call ParseJSON(), so we need to call EndFetch() ourselves. | 89 // We do not call ParseJSON(), so we need to call EndFetch() ourselves. |
| 88 EndFetch(); | 90 EndFetch(); |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 | 93 |
| 92 // Delay initial load of resource data into cache so as not to interfere | 94 // Delay initial load of resource data into cache so as not to interfere |
| 93 // with startup time. | 95 // with startup time. |
| 94 void WebResourceService::ScheduleFetch(int64 delay_ms) { | 96 void WebResourceService::ScheduleFetch(int64 delay_ms) { |
| 95 base::MessageLoop::current()->PostDelayedTask( | 97 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 96 FROM_HERE, base::Bind(&WebResourceService::StartFetch, | 98 FROM_HERE, base::Bind(&WebResourceService::StartFetch, |
| 97 weak_ptr_factory_.GetWeakPtr()), | 99 weak_ptr_factory_.GetWeakPtr()), |
| 98 base::TimeDelta::FromMilliseconds(delay_ms)); | 100 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 99 } | 101 } |
| 100 | 102 |
| 101 // Initializes the fetching of data from the resource server. Data | 103 // Initializes the fetching of data from the resource server. Data |
| 102 // load calls OnURLFetchComplete. | 104 // load calls OnURLFetchComplete. |
| 103 void WebResourceService::StartFetch() { | 105 void WebResourceService::StartFetch() { |
| 104 // First, put our next cache load on the MessageLoop. | 106 // First, put our next cache load on the MessageLoop. |
| 105 ScheduleFetch(cache_update_delay_ms_); | 107 ScheduleFetch(cache_update_delay_ms_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // Wait at least |start_fetch_delay_ms_|. | 176 // Wait at least |start_fetch_delay_ms_|. |
| 175 if (ms_until_update > start_fetch_delay_ms_) | 177 if (ms_until_update > start_fetch_delay_ms_) |
| 176 delay = ms_until_update; | 178 delay = ms_until_update; |
| 177 } | 179 } |
| 178 } | 180 } |
| 179 // Start fetch and wait for UpdateResourceCache. | 181 // Start fetch and wait for UpdateResourceCache. |
| 180 ScheduleFetch(delay); | 182 ScheduleFetch(delay); |
| 181 } | 183 } |
| 182 | 184 |
| 183 } // namespace web_resource | 185 } // namespace web_resource |
| OLD | NEW |