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_notification_types.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/chrome_utility_messages.h" | 20 #include "chrome/common/chrome_utility_messages.h" |
21 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/common/web_resource/web_resource_unpacker.h" | 22 #include "chrome/common/web_resource/web_resource_unpacker.h" |
23 #include "content/browser/browser_thread.h" | 23 #include "content/browser/browser_thread.h" |
24 #include "content/common/net/url_fetcher.h" | 24 #include "content/common/net/url_fetcher.h" |
25 #include "content/common/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
27 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
28 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
29 | 29 |
30 class WebResourceService::WebResourceFetcher | 30 class WebResourceService::WebResourceFetcher |
31 : public URLFetcher::Delegate { | 31 : public URLFetcher::Delegate { |
32 public: | 32 public: |
33 explicit WebResourceFetcher(WebResourceService* web_resource_service) : | 33 explicit WebResourceFetcher(WebResourceService* web_resource_service) : |
34 ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)), | 34 ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_factory_(this)), |
35 web_resource_service_(web_resource_service) { | 35 web_resource_service_(web_resource_service) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void WebResourceService::OnWebResourceUnpacked( | 258 void WebResourceService::OnWebResourceUnpacked( |
259 const DictionaryValue& parsed_json) { | 259 const DictionaryValue& parsed_json) { |
260 Unpack(parsed_json); | 260 Unpack(parsed_json); |
261 EndFetch(); | 261 EndFetch(); |
262 } | 262 } |
263 | 263 |
264 void WebResourceService::WebResourceStateChange() { | 264 void WebResourceService::WebResourceStateChange() { |
265 web_resource_update_scheduled_ = false; | 265 web_resource_update_scheduled_ = false; |
266 if (notification_type_ == chrome::NOTIFICATION_CHROME_END) | 266 if (notification_type_ == chrome::NOTIFICATION_CHROME_END) |
267 return; | 267 return; |
268 NotificationService* service = NotificationService::current(); | 268 content::NotificationService* service = |
| 269 content::NotificationService::current(); |
269 service->Notify(notification_type_, | 270 service->Notify(notification_type_, |
270 content::Source<WebResourceService>(this), | 271 content::Source<WebResourceService>(this), |
271 NotificationService::NoDetails()); | 272 content::NotificationService::NoDetails()); |
272 } | 273 } |
273 | 274 |
274 void WebResourceService::StartAfterDelay() { | 275 void WebResourceService::StartAfterDelay() { |
275 int64 delay = start_fetch_delay_; | 276 int64 delay = start_fetch_delay_; |
276 // Check whether we have ever put a value in the web resource cache; | 277 // Check whether we have ever put a value in the web resource cache; |
277 // if so, pull it out and see if it's time to update again. | 278 // if so, pull it out and see if it's time to update again. |
278 if (prefs_->HasPrefPath(last_update_time_pref_name_)) { | 279 if (prefs_->HasPrefPath(last_update_time_pref_name_)) { |
279 std::string last_update_pref = | 280 std::string last_update_pref = |
280 prefs_->GetString(last_update_time_pref_name_); | 281 prefs_->GetString(last_update_time_pref_name_); |
281 if (!last_update_pref.empty()) { | 282 if (!last_update_pref.empty()) { |
(...skipping 12 matching lines...) Expand all Loading... |
294 } | 295 } |
295 | 296 |
296 void WebResourceService::UpdateResourceCache(const std::string& json_data) { | 297 void WebResourceService::UpdateResourceCache(const std::string& json_data) { |
297 UnpackerClient* client = new UnpackerClient(this, json_data); | 298 UnpackerClient* client = new UnpackerClient(this, json_data); |
298 client->Start(); | 299 client->Start(); |
299 | 300 |
300 // Set cache update time in preferences. | 301 // Set cache update time in preferences. |
301 prefs_->SetString(last_update_time_pref_name_, | 302 prefs_->SetString(last_update_time_pref_name_, |
302 base::DoubleToString(base::Time::Now().ToDoubleT())); | 303 base::DoubleToString(base::Time::Now().ToDoubleT())); |
303 } | 304 } |
OLD | NEW |