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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 WebResourceService::WebResourceService( | 36 WebResourceService::WebResourceService( |
37 PrefService* prefs, | 37 PrefService* prefs, |
38 const GURL& web_resource_server, | 38 const GURL& web_resource_server, |
39 const std::string& application_locale, | 39 const std::string& application_locale, |
40 const char* last_update_time_pref_name, | 40 const char* last_update_time_pref_name, |
41 int start_fetch_delay_ms, | 41 int start_fetch_delay_ms, |
42 int cache_update_delay_ms, | 42 int cache_update_delay_ms, |
43 net::URLRequestContextGetter* request_context, | 43 net::URLRequestContextGetter* request_context, |
44 const char* disable_network_switch, | 44 const char* disable_network_switch, |
45 const ParseJSONCallback& parse_json_callback) | 45 const ParseJSONCallback& parse_json_callback, |
| 46 const net::NetworkTrafficAnnotationTag& traffic_annotation) |
46 : prefs_(prefs), | 47 : prefs_(prefs), |
47 resource_request_allowed_notifier_( | 48 resource_request_allowed_notifier_( |
48 new ResourceRequestAllowedNotifier(prefs, disable_network_switch)), | 49 new ResourceRequestAllowedNotifier(prefs, disable_network_switch)), |
49 fetch_scheduled_(false), | 50 fetch_scheduled_(false), |
50 in_fetch_(false), | 51 in_fetch_(false), |
51 web_resource_server_(web_resource_server), | 52 web_resource_server_(web_resource_server), |
52 application_locale_(application_locale), | 53 application_locale_(application_locale), |
53 last_update_time_pref_name_(last_update_time_pref_name), | 54 last_update_time_pref_name_(last_update_time_pref_name), |
54 start_fetch_delay_ms_(start_fetch_delay_ms), | 55 start_fetch_delay_ms_(start_fetch_delay_ms), |
55 cache_update_delay_ms_(cache_update_delay_ms), | 56 cache_update_delay_ms_(cache_update_delay_ms), |
56 request_context_(request_context), | 57 request_context_(request_context), |
57 parse_json_callback_(parse_json_callback), | 58 parse_json_callback_(parse_json_callback), |
| 59 traffic_annotation_(traffic_annotation), |
58 weak_ptr_factory_(this) { | 60 weak_ptr_factory_(this) { |
59 resource_request_allowed_notifier_->Init(this); | 61 resource_request_allowed_notifier_->Init(this); |
60 DCHECK(prefs); | 62 DCHECK(prefs); |
61 } | 63 } |
62 | 64 |
63 void WebResourceService::StartAfterDelay() { | 65 void WebResourceService::StartAfterDelay() { |
64 // If resource requests are not allowed, we'll get a callback when they are. | 66 // If resource requests are not allowed, we'll get a callback when they are. |
65 if (resource_request_allowed_notifier_->ResourceRequestsAllowed()) | 67 if (resource_request_allowed_notifier_->ResourceRequestsAllowed()) |
66 OnResourceRequestsAllowed(); | 68 OnResourceRequestsAllowed(); |
67 } | 69 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return; | 145 return; |
144 in_fetch_ = true; | 146 in_fetch_ = true; |
145 | 147 |
146 GURL web_resource_server = | 148 GURL web_resource_server = |
147 application_locale_.empty() | 149 application_locale_.empty() |
148 ? web_resource_server_ | 150 ? web_resource_server_ |
149 : google_util::AppendGoogleLocaleParam(web_resource_server_, | 151 : google_util::AppendGoogleLocaleParam(web_resource_server_, |
150 application_locale_); | 152 application_locale_); |
151 | 153 |
152 DVLOG(1) << "WebResourceService StartFetch " << web_resource_server; | 154 DVLOG(1) << "WebResourceService StartFetch " << web_resource_server; |
153 url_fetcher_ = | 155 url_fetcher_ = net::URLFetcher::Create( |
154 net::URLFetcher::Create(web_resource_server, net::URLFetcher::GET, this); | 156 web_resource_server, net::URLFetcher::GET, this, traffic_annotation_); |
155 data_use_measurement::DataUseUserData::AttachToFetcher( | 157 data_use_measurement::DataUseUserData::AttachToFetcher( |
156 url_fetcher_.get(), | 158 url_fetcher_.get(), |
157 data_use_measurement::DataUseUserData::WEB_RESOURCE_SERVICE); | 159 data_use_measurement::DataUseUserData::WEB_RESOURCE_SERVICE); |
158 // Do not let url fetcher affect existing state in system context | 160 // Do not let url fetcher affect existing state in system context |
159 // (by setting cookies, for example). | 161 // (by setting cookies, for example). |
160 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 162 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
161 net::LOAD_DO_NOT_SEND_COOKIES | | 163 net::LOAD_DO_NOT_SEND_COOKIES | |
162 net::LOAD_DO_NOT_SAVE_COOKIES); | 164 net::LOAD_DO_NOT_SAVE_COOKIES); |
163 url_fetcher_->SetRequestContext(request_context_.get()); | 165 url_fetcher_->SetRequestContext(request_context_.get()); |
164 url_fetcher_->Start(); | 166 url_fetcher_->Start(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // Wait at least |start_fetch_delay_ms_|. | 209 // Wait at least |start_fetch_delay_ms_|. |
208 if (ms_until_update > start_fetch_delay_ms_) | 210 if (ms_until_update > start_fetch_delay_ms_) |
209 delay = ms_until_update; | 211 delay = ms_until_update; |
210 } | 212 } |
211 } | 213 } |
212 // Start fetch and wait for UpdateResourceCache. | 214 // Start fetch and wait for UpdateResourceCache. |
213 ScheduleFetch(delay); | 215 ScheduleFetch(delay); |
214 } | 216 } |
215 | 217 |
216 } // namespace web_resource | 218 } // namespace web_resource |
OLD | NEW |