| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ |
| 6 #define CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ | 6 #define CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const char* last_update_time_pref_name, | 39 const char* last_update_time_pref_name, |
| 40 int start_fetch_delay_ms, | 40 int start_fetch_delay_ms, |
| 41 int cache_update_delay_ms); | 41 int cache_update_delay_ms); |
| 42 | 42 |
| 43 // Sleep until cache needs to be updated, but always for at least | 43 // Sleep until cache needs to be updated, but always for at least |
| 44 // |start_fetch_delay_ms| so we don't interfere with startup. | 44 // |start_fetch_delay_ms| so we don't interfere with startup. |
| 45 // Then begin updating resources. | 45 // Then begin updating resources. |
| 46 void StartAfterDelay(); | 46 void StartAfterDelay(); |
| 47 | 47 |
| 48 // JSONAsynchronousUnpackerDelegate methods. | 48 // JSONAsynchronousUnpackerDelegate methods. |
| 49 virtual void OnUnpackFinished( | 49 void OnUnpackFinished(const base::DictionaryValue& parsed_json) override; |
| 50 const base::DictionaryValue& parsed_json) override; | 50 void OnUnpackError(const std::string& error_message) override; |
| 51 virtual void OnUnpackError(const std::string& error_message) override; | |
| 52 | 51 |
| 53 protected: | 52 protected: |
| 54 virtual ~WebResourceService(); | 53 ~WebResourceService() override; |
| 55 | 54 |
| 56 // For the subclasses to process the result of a fetch. | 55 // For the subclasses to process the result of a fetch. |
| 57 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0; | 56 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0; |
| 58 | 57 |
| 59 PrefService* prefs_; | 58 PrefService* prefs_; |
| 60 | 59 |
| 61 private: | 60 private: |
| 62 class UnpackerClient; | 61 class UnpackerClient; |
| 63 friend class base::RefCountedThreadSafe<WebResourceService>; | 62 friend class base::RefCountedThreadSafe<WebResourceService>; |
| 64 | 63 |
| 65 // net::URLFetcherDelegate implementation: | 64 // net::URLFetcherDelegate implementation: |
| 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 65 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 67 | 66 |
| 68 // Schedules a fetch after |delay_ms| milliseconds. | 67 // Schedules a fetch after |delay_ms| milliseconds. |
| 69 void ScheduleFetch(int64 delay_ms); | 68 void ScheduleFetch(int64 delay_ms); |
| 70 | 69 |
| 71 // Starts fetching data from the server. | 70 // Starts fetching data from the server. |
| 72 void StartFetch(); | 71 void StartFetch(); |
| 73 | 72 |
| 74 // Set |in_fetch_| to false, clean up temp directories (in the future). | 73 // Set |in_fetch_| to false, clean up temp directories (in the future). |
| 75 void EndFetch(); | 74 void EndFetch(); |
| 76 | 75 |
| 77 // Implements ResourceRequestAllowedNotifier::Observer. | 76 // Implements ResourceRequestAllowedNotifier::Observer. |
| 78 virtual void OnResourceRequestsAllowed() override; | 77 void OnResourceRequestsAllowed() override; |
| 79 | 78 |
| 80 // Helper class used to tell this service if it's allowed to make network | 79 // Helper class used to tell this service if it's allowed to make network |
| 81 // resource requests. | 80 // resource requests. |
| 82 ResourceRequestAllowedNotifier resource_request_allowed_notifier_; | 81 ResourceRequestAllowedNotifier resource_request_allowed_notifier_; |
| 83 | 82 |
| 84 // The tool that fetches the url data from the server. | 83 // The tool that fetches the url data from the server. |
| 85 scoped_ptr<net::URLFetcher> url_fetcher_; | 84 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 86 | 85 |
| 87 // The tool that parses and transforms the json data. Weak reference as it | 86 // The tool that parses and transforms the json data. Weak reference as it |
| 88 // deletes itself once the unpack is done. | 87 // deletes itself once the unpack is done. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 int cache_update_delay_ms_; | 109 int cache_update_delay_ms_; |
| 111 | 110 |
| 112 // So that we can delay our start so as not to affect start-up time; also, | 111 // So that we can delay our start so as not to affect start-up time; also, |
| 113 // so that we can schedule future cache updates. | 112 // so that we can schedule future cache updates. |
| 114 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; | 113 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; |
| 115 | 114 |
| 116 DISALLOW_COPY_AND_ASSIGN(WebResourceService); | 115 DISALLOW_COPY_AND_ASSIGN(WebResourceService); |
| 117 }; | 116 }; |
| 118 | 117 |
| 119 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ | 118 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ |
| OLD | NEW |