Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: chrome/browser/web_resource/web_resource_service.h

Issue 10392192: Remove content::URLFetcherDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "content/public/common/url_fetcher_delegate.h"
15 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 16
17 class PrefService; 17 class PrefService;
18 class ResourceDispatcherHost; 18 class ResourceDispatcherHost;
19 19
20 namespace base { 20 namespace base {
21 class DictionaryValue; 21 class DictionaryValue;
22 } 22 }
23 23
24 namespace net {
25 class URLFetcher;
26 }
27
24 // A WebResourceService fetches JSON data from a web server and periodically 28 // A WebResourceService fetches JSON data from a web server and periodically
25 // refreshes it. 29 // refreshes it.
26 class WebResourceService 30 class WebResourceService
27 : public base::RefCountedThreadSafe<WebResourceService>, 31 : public base::RefCountedThreadSafe<WebResourceService>,
28 public content::URLFetcherDelegate { 32 public net::URLFetcherDelegate {
29 public: 33 public:
30 WebResourceService(PrefService* prefs, 34 WebResourceService(PrefService* prefs,
31 const GURL& web_resource_server, 35 const GURL& web_resource_server,
32 bool apply_locale_to_url_, 36 bool apply_locale_to_url_,
33 const char* last_update_time_pref_name, 37 const char* last_update_time_pref_name,
34 int start_fetch_delay_ms, 38 int start_fetch_delay_ms,
35 int cache_update_delay_ms); 39 int cache_update_delay_ms);
36 40
37 // Sleep until cache needs to be updated, but always for at least 41 // Sleep until cache needs to be updated, but always for at least
38 // |start_fetch_delay_ms| so we don't interfere with startup. 42 // |start_fetch_delay_ms| so we don't interfere with startup.
39 // Then begin updating resources. 43 // Then begin updating resources.
40 void StartAfterDelay(); 44 void StartAfterDelay();
41 45
42 protected: 46 protected:
43 virtual ~WebResourceService(); 47 virtual ~WebResourceService();
44 48
45 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0; 49 virtual void Unpack(const base::DictionaryValue& parsed_json) = 0;
46 50
47 PrefService* prefs_; 51 PrefService* prefs_;
48 52
49 private: 53 private:
50 class UnpackerClient; 54 class UnpackerClient;
51 friend class base::RefCountedThreadSafe<WebResourceService>; 55 friend class base::RefCountedThreadSafe<WebResourceService>;
52 56
53 // content::URLFetcherDelegate implementation: 57 // net::URLFetcherDelegate implementation:
54 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 58 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
55 59
56 // Schedules a fetch after |delay_ms| milliseconds. 60 // Schedules a fetch after |delay_ms| milliseconds.
57 void ScheduleFetch(int64 delay_ms); 61 void ScheduleFetch(int64 delay_ms);
58 62
59 // Starts fetching data from the server. 63 // Starts fetching data from the server.
60 void StartFetch(); 64 void StartFetch();
61 65
62 // Set |in_fetch_| to false, clean up temp directories (in the future). 66 // Set |in_fetch_| to false, clean up temp directories (in the future).
63 void EndFetch(); 67 void EndFetch();
64 68
65 // So that we can delay our start so as not to affect start-up time; also, 69 // So that we can delay our start so as not to affect start-up time; also,
66 // so that we can schedule future cache updates. 70 // so that we can schedule future cache updates.
67 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_; 71 base::WeakPtrFactory<WebResourceService> weak_ptr_factory_;
68 72
69 // The tool that fetches the url data from the server. 73 // The tool that fetches the url data from the server.
70 scoped_ptr<content::URLFetcher> url_fetcher_; 74 scoped_ptr<net::URLFetcher> url_fetcher_;
71 75
72 // True if we are currently fetching or unpacking data. If we are asked to 76 // True if we are currently fetching or unpacking data. If we are asked to
73 // start a fetch when we are still fetching resource data, schedule another 77 // start a fetch when we are still fetching resource data, schedule another
74 // one in |cache_update_delay_ms_| time, and silently exit. 78 // one in |cache_update_delay_ms_| time, and silently exit.
75 bool in_fetch_; 79 bool in_fetch_;
76 80
77 // URL that hosts the web resource. 81 // URL that hosts the web resource.
78 GURL web_resource_server_; 82 GURL web_resource_server_;
79 83
80 // Indicates whether we should append locale to the web resource server URL. 84 // Indicates whether we should append locale to the web resource server URL.
81 bool apply_locale_to_url_; 85 bool apply_locale_to_url_;
82 86
83 // Pref name to store the last update's time. 87 // Pref name to store the last update's time.
84 const char* last_update_time_pref_name_; 88 const char* last_update_time_pref_name_;
85 89
86 // Delay on first fetch so we don't interfere with startup. 90 // Delay on first fetch so we don't interfere with startup.
87 int start_fetch_delay_ms_; 91 int start_fetch_delay_ms_;
88 92
89 // Delay between calls to update the web resource cache. This delay may be 93 // Delay between calls to update the web resource cache. This delay may be
90 // different for different builds of Chrome. 94 // different for different builds of Chrome.
91 int cache_update_delay_ms_; 95 int cache_update_delay_ms_;
92 96
93 DISALLOW_COPY_AND_ASSIGN(WebResourceService); 97 DISALLOW_COPY_AND_ASSIGN(WebResourceService);
94 }; 98 };
95 99
96 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_ 100 #endif // CHROME_BROWSER_WEB_RESOURCE_WEB_RESOURCE_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/suggestions_source_discovery.cc ('k') | chrome/browser/web_resource/web_resource_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698