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 #ifndef COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ | 5 #ifndef COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ |
6 #define COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ | 6 #define COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "components/web_resource/resource_request_allowed_notifier.h" | 17 #include "components/web_resource/resource_request_allowed_notifier.h" |
| 18 #include "net/traffic_annotation/network_traffic_annotation.h" |
18 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 class PrefService; | 22 class PrefService; |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class DictionaryValue; | 25 class DictionaryValue; |
25 class Value; | 26 class Value; |
26 } | 27 } |
27 | 28 |
(...skipping 12 matching lines...) Expand all Loading... |
40 public: | 41 public: |
41 // Callbacks for JSON parsing. | 42 // Callbacks for JSON parsing. |
42 using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>; | 43 using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>; |
43 using ErrorCallback = base::Callback<void(const std::string&)>; | 44 using ErrorCallback = base::Callback<void(const std::string&)>; |
44 using ParseJSONCallback = base::Callback< | 45 using ParseJSONCallback = base::Callback< |
45 void(const std::string&, const SuccessCallback&, const ErrorCallback&)>; | 46 void(const std::string&, const SuccessCallback&, const ErrorCallback&)>; |
46 | 47 |
47 // Creates a new WebResourceService. | 48 // Creates a new WebResourceService. |
48 // If |application_locale| is not empty, it will be appended as a locale | 49 // If |application_locale| is not empty, it will be appended as a locale |
49 // parameter to the resource URL. | 50 // parameter to the resource URL. |
50 WebResourceService(PrefService* prefs, | 51 WebResourceService( |
51 const GURL& web_resource_server, | 52 PrefService* prefs, |
52 const std::string& application_locale, // May be empty | 53 const GURL& web_resource_server, |
53 const char* last_update_time_pref_name, | 54 const std::string& application_locale, // May be empty |
54 int start_fetch_delay_ms, | 55 const char* last_update_time_pref_name, |
55 int cache_update_delay_ms, | 56 int start_fetch_delay_ms, |
56 net::URLRequestContextGetter* request_context, | 57 int cache_update_delay_ms, |
57 const char* disable_network_switch, | 58 net::URLRequestContextGetter* request_context, |
58 const ParseJSONCallback& parse_json_callback); | 59 const char* disable_network_switch, |
| 60 const ParseJSONCallback& parse_json_callback, |
| 61 const net::NetworkTrafficAnnotationTag& traffic_annotation); |
59 | 62 |
60 ~WebResourceService() override; | 63 ~WebResourceService() override; |
61 | 64 |
62 // Sleep until cache needs to be updated, but always for at least | 65 // Sleep until cache needs to be updated, but always for at least |
63 // |start_fetch_delay_ms| so we don't interfere with startup. | 66 // |start_fetch_delay_ms| so we don't interfere with startup. |
64 // Then begin updating resources. | 67 // Then begin updating resources. |
65 void StartAfterDelay(); | 68 void StartAfterDelay(); |
66 | 69 |
67 // Sets the ResourceRequestAllowedNotifier to make it configurable. | 70 // Sets the ResourceRequestAllowedNotifier to make it configurable. |
68 void SetResourceRequestAllowedNotifier( | 71 void SetResourceRequestAllowedNotifier( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Delay between calls to update the web resource cache. This delay may be | 135 // Delay between calls to update the web resource cache. This delay may be |
133 // different for different builds of Chrome. | 136 // different for different builds of Chrome. |
134 int cache_update_delay_ms_; | 137 int cache_update_delay_ms_; |
135 | 138 |
136 // The request context for the resource fetch. | 139 // The request context for the resource fetch. |
137 scoped_refptr<net::URLRequestContextGetter> request_context_; | 140 scoped_refptr<net::URLRequestContextGetter> request_context_; |
138 | 141 |
139 // Callback used to parse JSON. | 142 // Callback used to parse JSON. |
140 ParseJSONCallback parse_json_callback_; | 143 ParseJSONCallback parse_json_callback_; |
141 | 144 |
| 145 // Network traffic annotation for initialization of URLFetcher. |
| 146 const net::NetworkTrafficAnnotationTag traffic_annotation_; |
| 147 |
142 // So that we can delay our start so as not to affect start-up time; also, | 148 // So that we can delay our start so as not to affect start-up time; also, |
143 // so that we can schedule future cache updates. | 149 // so that we can schedule future cache updates. |
144 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; | 150 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; |
145 | 151 |
146 DISALLOW_COPY_AND_ASSIGN(WebResourceService); | 152 DISALLOW_COPY_AND_ASSIGN(WebResourceService); |
147 }; | 153 }; |
148 | 154 |
149 } // namespace web_resource | 155 } // namespace web_resource |
150 | 156 |
151 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ | 157 #endif // COMPONENTS_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ |
OLD | NEW |