| 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 29 matching lines...) Expand all Loading... |
| 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 virtual void OnUnpackFinished( |
| 50 const base::DictionaryValue& parsed_json) OVERRIDE; | 50 const base::DictionaryValue& parsed_json) override; |
| 51 virtual void OnUnpackError(const std::string& error_message) OVERRIDE; | 51 virtual void OnUnpackError(const std::string& error_message) override; |
| 52 | 52 |
| 53 protected: | 53 protected: |
| 54 virtual ~WebResourceService(); | 54 virtual ~WebResourceService(); |
| 55 | 55 |
| 56 // For the subclasses to process the result of a fetch. | 56 // For the subclasses to process the result of a fetch. |
| 57 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0; | 57 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0; |
| 58 | 58 |
| 59 PrefService* prefs_; | 59 PrefService* prefs_; |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 class UnpackerClient; | 62 class UnpackerClient; |
| 63 friend class base::RefCountedThreadSafe<WebResourceService>; | 63 friend class base::RefCountedThreadSafe<WebResourceService>; |
| 64 | 64 |
| 65 // net::URLFetcherDelegate implementation: | 65 // net::URLFetcherDelegate implementation: |
| 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 66 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 67 | 67 |
| 68 // Schedules a fetch after |delay_ms| milliseconds. | 68 // Schedules a fetch after |delay_ms| milliseconds. |
| 69 void ScheduleFetch(int64 delay_ms); | 69 void ScheduleFetch(int64 delay_ms); |
| 70 | 70 |
| 71 // Starts fetching data from the server. | 71 // Starts fetching data from the server. |
| 72 void StartFetch(); | 72 void StartFetch(); |
| 73 | 73 |
| 74 // Set |in_fetch_| to false, clean up temp directories (in the future). | 74 // Set |in_fetch_| to false, clean up temp directories (in the future). |
| 75 void EndFetch(); | 75 void EndFetch(); |
| 76 | 76 |
| 77 // Implements ResourceRequestAllowedNotifier::Observer. | 77 // Implements ResourceRequestAllowedNotifier::Observer. |
| 78 virtual void OnResourceRequestsAllowed() OVERRIDE; | 78 virtual void OnResourceRequestsAllowed() override; |
| 79 | 79 |
| 80 // Helper class used to tell this service if it's allowed to make network | 80 // Helper class used to tell this service if it's allowed to make network |
| 81 // resource requests. | 81 // resource requests. |
| 82 ResourceRequestAllowedNotifier resource_request_allowed_notifier_; | 82 ResourceRequestAllowedNotifier resource_request_allowed_notifier_; |
| 83 | 83 |
| 84 // The tool that fetches the url data from the server. | 84 // The tool that fetches the url data from the server. |
| 85 scoped_ptr<net::URLFetcher> url_fetcher_; | 85 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 86 | 86 |
| 87 // The tool that parses and transforms the json data. Weak reference as it | 87 // The tool that parses and transforms the json data. Weak reference as it |
| 88 // deletes itself once the unpack is done. | 88 // deletes itself once the unpack is done. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 int cache_update_delay_ms_; | 110 int cache_update_delay_ms_; |
| 111 | 111 |
| 112 // So that we can delay our start so as not to affect start-up time; also, | 112 // 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. | 113 // so that we can schedule future cache updates. |
| 114 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; | 114 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; |
| 115 | 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(WebResourceService); | 116 DISALLOW_COPY_AND_ASSIGN(WebResourceService); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ | 119 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ |
| OLD | NEW |