| Index: chrome/browser/web_resource/web_resource_service.h
|
| diff --git a/chrome/browser/web_resource/web_resource_service.h b/chrome/browser/web_resource/web_resource_service.h
|
| index c8f9632d73f36253cd1a144a59b5c9021f3b749b..c72a0f7a02d86127f2ebd7eacd35db11000b4918 100644
|
| --- a/chrome/browser/web_resource/web_resource_service.h
|
| +++ b/chrome/browser/web_resource/web_resource_service.h
|
| @@ -8,8 +8,10 @@
|
|
|
| #include <string>
|
|
|
| -#include "content/browser/utility_process_host.h"
|
| -#include "content/public/browser/notification_types.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "content/public/common/url_fetcher_delegate.h"
|
|
|
| class PrefService;
|
| class ResourceDispatcherHost;
|
| @@ -18,69 +20,64 @@ namespace base {
|
| class DictionaryValue;
|
| }
|
|
|
| -// A WebResourceService fetches data from a web resource server and store
|
| -// locally as user preference.
|
| -class WebResourceService : public UtilityProcessHost::Client {
|
| +// A WebResourceService fetches JSON data from a web server and periodically
|
| +// refreshes it.
|
| +class WebResourceService
|
| + : public base::RefCountedThreadSafe<WebResourceService>,
|
| + public content::URLFetcherDelegate {
|
| public:
|
| - // Pass notification_type = NOTIFICATION_TYPE_COUNT if notification is not
|
| - // required.
|
| WebResourceService(PrefService* prefs,
|
| const char* web_resource_server,
|
| bool apply_locale_to_url_,
|
| - int notification_type,
|
| const char* last_update_time_pref_name,
|
| - int start_fetch_delay,
|
| - int cache_update_delay);
|
| + int start_fetch_delay_ms,
|
| + int cache_update_delay_ms);
|
|
|
| - // Sleep until cache needs to be updated, but always for at least 5 seconds
|
| - // so we don't interfere with startup. Then begin updating resources.
|
| - void StartAfterDelay();
|
| -
|
| - // We have successfully pulled data from a resource server; now launch
|
| - // the process that will parse the JSON, and then update the cache.
|
| - void UpdateResourceCache(const std::string& json_data);
|
| + // Sleep until cache needs to be updated, but always for at least
|
| + // |start_fetch_delay_ms| so we don't interfere with startup.
|
| + // Then begin updating resources.
|
| + // TODO(bauerb): Comment
|
| + bool StartAfterDelay(bool only_if_necessary);
|
|
|
| protected:
|
| virtual ~WebResourceService();
|
| + friend class base::RefCountedThreadSafe<WebResourceService>;
|
|
|
| - virtual void Unpack(const base::DictionaryValue& parsed_json) = 0;
|
| + // TODO(bauerb): comment
|
| + static void RegisterLastUpdateTimePref(PrefService* prefs,
|
| + const char* pref_name);
|
|
|
| - // If delay_ms is positive, schedule notification with the delay.
|
| - // If delay_ms is 0, notify immediately by calling WebResourceStateChange().
|
| - // If delay_ms is negative, do nothing.
|
| - void PostNotification(int64 delay_ms);
|
| + virtual void Unpack(const base::DictionaryValue& parsed_json) = 0;
|
|
|
| // We need to be able to load parsed resource data into preferences file,
|
| // and get proper install directory.
|
| PrefService* prefs_;
|
|
|
| private:
|
| - class WebResourceFetcher;
|
| - friend class WebResourceFetcher;
|
| -
|
| class UnpackerClient;
|
|
|
| - // Set in_fetch_ to false, clean up temp directories (in the future).
|
| - void EndFetch();
|
| + // content::URLFetcherDelegate implementation:
|
| + virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
|
|
|
| - // Puts parsed json data in the right places, and writes to prefs file.
|
| - void OnWebResourceUnpacked(const base::DictionaryValue& parsed_json);
|
| + // Schedules a fetch after |delay_ms| milliseconds.
|
| + void ScheduleFetch(int64 delay_ms);
|
|
|
| - // Notify listeners that the state of a web resource has changed.
|
| - void WebResourceStateChange();
|
| + // Starts fetching data from the server.
|
| + void StartFetch();
|
|
|
| - scoped_ptr<WebResourceFetcher> web_resource_fetcher_;
|
| + // Set |in_fetch_| to false, clean up temp directories (in the future).
|
| + void EndFetch();
|
|
|
| - ResourceDispatcherHost* resource_dispatcher_host_;
|
| + // So that we can delay our start so as not to affect start-up time; also,
|
| + // so that we can schedule future cache updates.
|
| + base::WeakPtrFactory<WebResourceService> weak_ptr_factory_;
|
|
|
| - // Allows the creation of tasks to send a WEB_RESOURCE_STATE_CHANGED
|
| - // notification. This allows the WebResourceService to notify the New Tab
|
| - // Page immediately when a new web resource should be shown or removed.
|
| - ScopedRunnableMethodFactory<WebResourceService> service_factory_;
|
| + // The tool that fetches the url data from the server.
|
| + scoped_ptr<content::URLFetcher> url_fetcher_;
|
|
|
| - // True if we are currently mid-fetch. If we are asked to start a fetch
|
| - // when we are still fetching resource data, schedule another one in
|
| - // kCacheUpdateDelay time, and silently exit.
|
| + // True if we are currently fetching or unpacking data. If we are asked to
|
| + // start a fetch when we are still fetching resource data, schedule another
|
| + // one in |cache_update_delay_ms_| time, and silently exit.
|
| bool in_fetch_;
|
|
|
| // URL that hosts the web resource.
|
| @@ -89,22 +86,15 @@ class WebResourceService : public UtilityProcessHost::Client {
|
| // Indicates whether we should append locale to the web resource server URL.
|
| bool apply_locale_to_url_;
|
|
|
| - // Notification type when an update is done.
|
| - int notification_type_;
|
| -
|
| // Pref name to store the last update's time.
|
| const char* last_update_time_pref_name_;
|
|
|
| // Delay on first fetch so we don't interfere with startup.
|
| - int start_fetch_delay_;
|
| + int start_fetch_delay_ms_;
|
|
|
| // Delay between calls to update the web resource cache. This delay may be
|
| // different for different builds of Chrome.
|
| - int cache_update_delay_;
|
| -
|
| - // True if a task has been set to update the cache when a new web resource
|
| - // becomes available.
|
| - bool web_resource_update_scheduled_;
|
| + int cache_update_delay_ms_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(WebResourceService);
|
| };
|
|
|