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

Side by Side Diff: webkit/appcache/appcache_update_job.h

Issue 3033003: Make conditional requests when updating the appcache.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_ 5 #ifndef WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_
6 #define WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_ 6 #define WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "base/task.h" 15 #include "base/task.h"
16 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 #include "net/base/completion_callback.h" 17 #include "net/base/completion_callback.h"
18 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
19 #include "testing/gtest/include/gtest/gtest_prod.h" 19 #include "testing/gtest/include/gtest/gtest_prod.h"
20 #include "webkit/appcache/appcache.h" 20 #include "webkit/appcache/appcache.h"
21 #include "webkit/appcache/appcache_host.h" 21 #include "webkit/appcache/appcache_host.h"
22 #include "webkit/appcache/appcache_interfaces.h" 22 #include "webkit/appcache/appcache_interfaces.h"
23 #include "webkit/appcache/appcache_response.h"
23 #include "webkit/appcache/appcache_storage.h" 24 #include "webkit/appcache/appcache_storage.h"
24 25
25 namespace appcache { 26 namespace appcache {
26 27
27 class UpdateJobInfo; 28 class UpdateJobInfo;
28 class HostNotifier; 29 class HostNotifier;
29 30
30 // Application cache Update algorithm and state. 31 // Application cache Update algorithm and state.
31 class AppCacheUpdateJob : public URLRequest::Delegate, 32 class AppCacheUpdateJob : public URLRequest::Delegate,
32 public AppCacheStorage::Delegate, 33 public AppCacheStorage::Delegate,
33 public AppCacheHost::Observer { 34 public AppCacheHost::Observer {
34 public: 35 public:
35 AppCacheUpdateJob(AppCacheService* service, AppCacheGroup* group); 36 AppCacheUpdateJob(AppCacheService* service, AppCacheGroup* group);
36 ~AppCacheUpdateJob(); 37 ~AppCacheUpdateJob();
37 38
38 // Triggers the update process or adds more info if this update is already 39 // Triggers the update process or adds more info if this update is already
39 // in progress. 40 // in progress.
40 void StartUpdate(AppCacheHost* host, const GURL& new_master_resource); 41 void StartUpdate(AppCacheHost* host, const GURL& new_master_resource);
41 42
42 private: 43 private:
43 friend class ScopedRunnableMethodFactory<AppCacheUpdateJob>; 44 friend class ScopedRunnableMethodFactory<AppCacheUpdateJob>;
44 friend class AppCacheUpdateJobTest; 45 friend class AppCacheUpdateJobTest;
45 friend class UpdateJobInfo; 46 friend class UpdateJobInfo;
46 47
47 // Master entries have multiple hosts, for example, the same page is opened 48 // Master entries have multiple hosts, for example, the same page is opened
48 // in different tabs. 49 // in different tabs.
49 typedef std::vector<AppCacheHost*> PendingHosts; 50 typedef std::vector<AppCacheHost*> PendingHosts;
50 typedef std::map<GURL, PendingHosts> PendingMasters; 51 typedef std::map<GURL, PendingHosts> PendingMasters;
51 typedef std::map<GURL, URLRequest*> PendingUrlFetches; 52 typedef std::map<GURL, URLRequest*> PendingUrlFetches;
52 typedef std::pair<GURL, bool> UrlsToFetch; // flag TRUE if storage checked
53 typedef std::map<int64, GURL> LoadingResponses; 53 typedef std::map<int64, GURL> LoadingResponses;
54 54
55 static const int kRerunDelayMs = 1000; 55 static const int kRerunDelayMs = 1000;
56 56
57 // TODO(michaeln): Rework the set of states vs update types vs stored states. 57 // TODO(michaeln): Rework the set of states vs update types vs stored states.
58 // The NO_UPDATE state is really more of an update type. For all update types 58 // The NO_UPDATE state is really more of an update type. For all update types
59 // storing the results is relevant. 59 // storing the results is relevant.
60 60
61 enum UpdateType { 61 enum UpdateType {
62 UNKNOWN_TYPE, 62 UNKNOWN_TYPE,
(...skipping 12 matching lines...) Expand all
75 CANCELLED, 75 CANCELLED,
76 COMPLETED, 76 COMPLETED,
77 }; 77 };
78 78
79 enum StoredState { 79 enum StoredState {
80 UNSTORED, 80 UNSTORED,
81 STORING, 81 STORING,
82 STORED, 82 STORED,
83 }; 83 };
84 84
85 struct UrlToFetch {
86 GURL url;
87 bool storage_checked;
88 scoped_refptr<AppCacheResponseInfo> existing_response_info;
89 UrlToFetch(const GURL& url, bool checked, AppCacheResponseInfo* info)
90 : url(url), storage_checked(checked), existing_response_info(info) {}
91 };
92
93 UpdateJobInfo* GetUpdateJobInfo(URLRequest* request);
94
85 // Methods for URLRequest::Delegate. 95 // Methods for URLRequest::Delegate.
86 void OnResponseStarted(URLRequest* request); 96 void OnResponseStarted(URLRequest* request);
87 void OnReadCompleted(URLRequest* request, int bytes_read); 97 void OnReadCompleted(URLRequest* request, int bytes_read);
88 void OnReceivedRedirect(URLRequest* request, 98 void OnReceivedRedirect(URLRequest* request,
89 const GURL& new_url, 99 const GURL& new_url,
90 bool* defer_redirect); 100 bool* defer_redirect);
91 // TODO(jennb): any other delegate callbacks to handle? certificate? 101 // TODO(jennb): any other delegate callbacks to handle? certificate?
92 102
93 // Methods for AppCacheStorage::Delegate. 103 // Methods for AppCacheStorage::Delegate.
94 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, 104 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info,
95 int64 response_id); 105 int64 response_id);
96 void OnGroupAndNewestCacheStored(AppCacheGroup* group, AppCache* newest_cache, 106 void OnGroupAndNewestCacheStored(AppCacheGroup* group, AppCache* newest_cache,
97 bool success); 107 bool success);
98 void OnGroupMadeObsolete(AppCacheGroup* group, bool success); 108 void OnGroupMadeObsolete(AppCacheGroup* group, bool success);
99 109
100 // Methods for AppCacheHost::Observer. 110 // Methods for AppCacheHost::Observer.
101 void OnCacheSelectionComplete(AppCacheHost* host) {} // N/A 111 void OnCacheSelectionComplete(AppCacheHost* host) {} // N/A
102 void OnDestructionImminent(AppCacheHost* host); 112 void OnDestructionImminent(AppCacheHost* host);
103 113
104 void CheckPolicy(); 114 void CheckPolicy();
105 void OnPolicyCheckComplete(int rv); 115 void OnPolicyCheckComplete(int rv);
106 116
107 void HandleCacheFailure(const std::string& error_message); 117 void HandleCacheFailure(const std::string& error_message);
108 118
109 void FetchManifest(bool is_first_fetch); 119 void FetchManifest(bool is_first_fetch);
110 120
111 // Add extra HTTP headers to the request based on the response info and 121 // Add extra conditional HTTP headers to the request based on the
112 // start the URL request. 122 // currently cached response headers.
113 void AddHttpHeadersAndFetch(URLRequest* request, 123 void AddConditionalHeaders(URLRequest* request,
114 const net::HttpResponseInfo* info); 124 const net::HttpResponseInfo* info);
115 125
116 void OnResponseCompleted(URLRequest* request); 126 void OnResponseCompleted(URLRequest* request);
117 127
118 // Retries a 503 request with retry-after header of 0. 128 // Retries a 503 request with retry-after header of 0.
119 // Returns true if request should be retried and deletes original request. 129 // Returns true if request should be retried and deletes original request.
120 bool RetryRequest(URLRequest* request); 130 bool RetryRequest(URLRequest* request);
121 131
122 void ReadResponseData(URLRequest* request); 132 void ReadResponseData(URLRequest* request);
123 133
124 // Returns false if response data is processed asynchronously, in which 134 // Returns false if response data is processed asynchronously, in which
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 void AddMasterEntryToFetchList(AppCacheHost* host, const GURL& url, 183 void AddMasterEntryToFetchList(AppCacheHost* host, const GURL& url,
174 bool is_new); 184 bool is_new);
175 void FetchMasterEntries(); 185 void FetchMasterEntries();
176 void CancelAllMasterEntryFetches(const std::string& error_message); 186 void CancelAllMasterEntryFetches(const std::string& error_message);
177 187
178 // Asynchronously loads the entry from the newest complete cache if the 188 // Asynchronously loads the entry from the newest complete cache if the
179 // HTTP caching semantics allow. 189 // HTTP caching semantics allow.
180 // Returns false if immediately obvious that data cannot be loaded from 190 // Returns false if immediately obvious that data cannot be loaded from
181 // newest complete cache. 191 // newest complete cache.
182 bool MaybeLoadFromNewestCache(const GURL& url, AppCacheEntry& entry); 192 bool MaybeLoadFromNewestCache(const GURL& url, AppCacheEntry& entry);
183 void LoadFromNewestCacheFailed(const GURL& url); 193 void LoadFromNewestCacheFailed(const GURL& url,
194 AppCacheResponseInfo* newest_response_info);
184 195
185 // Does nothing if update process is still waiting for pending master 196 // Does nothing if update process is still waiting for pending master
186 // entries or URL fetches to complete downloading. Otherwise, completes 197 // entries or URL fetches to complete downloading. Otherwise, completes
187 // the update process. 198 // the update process.
188 void MaybeCompleteUpdate(); 199 void MaybeCompleteUpdate();
189 200
190 // Schedules a rerun of the entire update with the same parameters as 201 // Schedules a rerun of the entire update with the same parameters as
191 // this update job after a short delay. 202 // this update job after a short delay.
192 void ScheduleUpdateRetry(int delay_ms); 203 void ScheduleUpdateRetry(int delay_ms);
193 204
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 std::set<GURL> master_entries_to_fetch_; 237 std::set<GURL> master_entries_to_fetch_;
227 PendingUrlFetches master_entry_fetches_; 238 PendingUrlFetches master_entry_fetches_;
228 239
229 // URLs of files to fetch along with their flags. 240 // URLs of files to fetch along with their flags.
230 AppCache::EntryMap url_file_list_; 241 AppCache::EntryMap url_file_list_;
231 size_t url_fetches_completed_; 242 size_t url_fetches_completed_;
232 243
233 // Helper container to track which urls have not been fetched yet. URLs are 244 // Helper container to track which urls have not been fetched yet. URLs are
234 // removed when the fetch is initiated. Flag indicates whether an attempt 245 // removed when the fetch is initiated. Flag indicates whether an attempt
235 // to load the URL from storage has already been tried and failed. 246 // to load the URL from storage has already been tried and failed.
236 std::deque<UrlsToFetch> urls_to_fetch_; 247 std::deque<UrlToFetch> urls_to_fetch_;
237 248
238 // Helper container to track which urls are being loaded from response 249 // Helper container to track which urls are being loaded from response
239 // storage. 250 // storage.
240 LoadingResponses loading_responses_; 251 LoadingResponses loading_responses_;
241 252
242 // Keep track of pending URL requests so we can cancel them if necessary. 253 // Keep track of pending URL requests so we can cancel them if necessary.
243 URLRequest* manifest_url_request_; 254 URLRequest* manifest_url_request_;
244 PendingUrlFetches pending_url_fetches_; 255 PendingUrlFetches pending_url_fetches_;
245 256
246 // Temporary storage of manifest response data for parsing and comparison. 257 // Temporary storage of manifest response data for parsing and comparison.
(...skipping 26 matching lines...) Expand all
273 scoped_refptr<net::CancelableCompletionCallback<AppCacheUpdateJob> > 284 scoped_refptr<net::CancelableCompletionCallback<AppCacheUpdateJob> >
274 policy_callback_; 285 policy_callback_;
275 286
276 FRIEND_TEST(AppCacheGroupTest, QueueUpdate); 287 FRIEND_TEST(AppCacheGroupTest, QueueUpdate);
277 DISALLOW_COPY_AND_ASSIGN(AppCacheUpdateJob); 288 DISALLOW_COPY_AND_ASSIGN(AppCacheUpdateJob);
278 }; 289 };
279 290
280 } // namespace appcache 291 } // namespace appcache
281 292
282 #endif // WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_ 293 #endif // WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/appcache/appcache_update_job.cc » ('j') | webkit/appcache/appcache_update_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698