OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/web_resource/web_resource_service.h" | 5 #include "chrome/browser/web_resource/web_resource_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/sync/sync_ui_util.h" | 17 #include "chrome/browser/sync/sync_ui_util.h" |
| 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/chrome_utility_messages.h" | 20 #include "chrome/common/chrome_utility_messages.h" |
20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/web_resource/web_resource_unpacker.h" | 22 #include "chrome/common/web_resource/web_resource_unpacker.h" |
22 #include "content/browser/browser_thread.h" | 23 #include "content/browser/browser_thread.h" |
23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
24 #include "content/common/url_fetcher.h" | 25 #include "content/common/url_fetcher.h" |
25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
26 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
27 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 207 |
207 // True if we got a response from the utility process and have cleaned up | 208 // True if we got a response from the utility process and have cleaned up |
208 // already. | 209 // already. |
209 bool got_response_; | 210 bool got_response_; |
210 }; | 211 }; |
211 | 212 |
212 WebResourceService::WebResourceService( | 213 WebResourceService::WebResourceService( |
213 PrefService* prefs, | 214 PrefService* prefs, |
214 const char* web_resource_server, | 215 const char* web_resource_server, |
215 bool apply_locale_to_url, | 216 bool apply_locale_to_url, |
216 NotificationType::Type notification_type, | 217 int notification_type, |
217 const char* last_update_time_pref_name, | 218 const char* last_update_time_pref_name, |
218 int start_fetch_delay, | 219 int start_fetch_delay, |
219 int cache_update_delay) | 220 int cache_update_delay) |
220 : prefs_(prefs), | 221 : prefs_(prefs), |
221 ALLOW_THIS_IN_INITIALIZER_LIST(service_factory_(this)), | 222 ALLOW_THIS_IN_INITIALIZER_LIST(service_factory_(this)), |
222 in_fetch_(false), | 223 in_fetch_(false), |
223 web_resource_server_(web_resource_server), | 224 web_resource_server_(web_resource_server), |
224 apply_locale_to_url_(apply_locale_to_url), | 225 apply_locale_to_url_(apply_locale_to_url), |
225 notification_type_(notification_type), | 226 notification_type_(notification_type), |
226 last_update_time_pref_name_(last_update_time_pref_name), | 227 last_update_time_pref_name_(last_update_time_pref_name), |
(...skipping 28 matching lines...) Expand all Loading... |
255 } | 256 } |
256 | 257 |
257 void WebResourceService::OnWebResourceUnpacked( | 258 void WebResourceService::OnWebResourceUnpacked( |
258 const DictionaryValue& parsed_json) { | 259 const DictionaryValue& parsed_json) { |
259 Unpack(parsed_json); | 260 Unpack(parsed_json); |
260 EndFetch(); | 261 EndFetch(); |
261 } | 262 } |
262 | 263 |
263 void WebResourceService::WebResourceStateChange() { | 264 void WebResourceService::WebResourceStateChange() { |
264 web_resource_update_scheduled_ = false; | 265 web_resource_update_scheduled_ = false; |
265 if (notification_type_ == NotificationType::NOTIFICATION_TYPE_COUNT) | 266 if (notification_type_ == chrome::NOTIFICATION_CHROME_END) |
266 return; | 267 return; |
267 NotificationService* service = NotificationService::current(); | 268 NotificationService* service = NotificationService::current(); |
268 service->Notify(notification_type_, | 269 service->Notify(notification_type_, |
269 Source<WebResourceService>(this), | 270 Source<WebResourceService>(this), |
270 NotificationService::NoDetails()); | 271 NotificationService::NoDetails()); |
271 } | 272 } |
272 | 273 |
273 void WebResourceService::StartAfterDelay() { | 274 void WebResourceService::StartAfterDelay() { |
274 int64 delay = start_fetch_delay_; | 275 int64 delay = start_fetch_delay_; |
275 // Check whether we have ever put a value in the web resource cache; | 276 // Check whether we have ever put a value in the web resource cache; |
(...skipping 17 matching lines...) Expand all Loading... |
293 } | 294 } |
294 | 295 |
295 void WebResourceService::UpdateResourceCache(const std::string& json_data) { | 296 void WebResourceService::UpdateResourceCache(const std::string& json_data) { |
296 UnpackerClient* client = new UnpackerClient(this, json_data); | 297 UnpackerClient* client = new UnpackerClient(this, json_data); |
297 client->Start(); | 298 client->Start(); |
298 | 299 |
299 // Set cache update time in preferences. | 300 // Set cache update time in preferences. |
300 prefs_->SetString(last_update_time_pref_name_, | 301 prefs_->SetString(last_update_time_pref_name_, |
301 base::DoubleToString(base::Time::Now().ToDoubleT())); | 302 base::DoubleToString(base::Time::Now().ToDoubleT())); |
302 } | 303 } |
OLD | NEW |