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 WEBKIT_BROWSER_APPCACHE_APPCACHE_UPDATE_JOB_H_ | 5 #ifndef WEBKIT_BROWSER_APPCACHE_APPCACHE_UPDATE_JOB_H_ |
6 #define WEBKIT_BROWSER_APPCACHE_APPCACHE_UPDATE_JOB_H_ | 6 #define WEBKIT_BROWSER_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/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/time/time.h" |
16 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "net/url_request/url_request.h" | 19 #include "net/url_request/url_request.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 #include "webkit/browser/appcache/appcache.h" | 21 #include "webkit/browser/appcache/appcache.h" |
21 #include "webkit/browser/appcache/appcache_host.h" | 22 #include "webkit/browser/appcache/appcache_host.h" |
22 #include "webkit/browser/appcache/appcache_response.h" | 23 #include "webkit/browser/appcache/appcache_response.h" |
23 #include "webkit/browser/appcache/appcache_service.h" | 24 #include "webkit/browser/appcache/appcache_service.h" |
24 #include "webkit/browser/appcache/appcache_storage.h" | 25 #include "webkit/browser/appcache/appcache_storage.h" |
25 #include "webkit/browser/webkit_storage_browser_export.h" | 26 #include "webkit/browser/webkit_storage_browser_export.h" |
26 #include "webkit/common/appcache/appcache_interfaces.h" | 27 #include "webkit/common/appcache/appcache_interfaces.h" |
27 | 28 |
28 namespace appcache { | 29 namespace appcache { |
29 | 30 |
30 class HostNotifier; | 31 class HostNotifier; |
31 | 32 |
32 // Application cache Update algorithm and state. | 33 // Application cache Update algorithm and state. |
33 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheUpdateJob | 34 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheUpdateJob |
34 : public AppCacheStorage::Delegate, | 35 : public AppCacheStorage::Delegate, |
35 public AppCacheHost::Observer, | 36 public AppCacheHost::Observer, |
36 public AppCacheService::Observer { | 37 public AppCacheService::Observer { |
37 public: | 38 public: |
38 // Used for uma stats only for now, so new values are append only. | 39 // Used for uma stats only for now, so new values are append only. |
39 enum ResultType { | 40 enum ResultType { |
40 UPDATE_OK, DB_ERROR, DISKCACHE_ERROR, QUOTA_ERROR, REDIRECT_ERROR, | 41 UPDATE_OK, DB_ERROR, DISKCACHE_ERROR, QUOTA_ERROR, REDIRECT_ERROR, |
41 MANIFEST_ERROR, NETWORK_ERROR, SERVER_ERROR, | 42 MANIFEST_ERROR, NETWORK_ERROR, SERVER_ERROR, CANCELLED_ERROR, |
42 NUM_UPDATE_JOB_RESULT_TYPES | 43 NUM_UPDATE_JOB_RESULT_TYPES |
43 }; | 44 }; |
44 | 45 |
45 AppCacheUpdateJob(AppCacheService* service, AppCacheGroup* group); | 46 AppCacheUpdateJob(AppCacheService* service, AppCacheGroup* group); |
46 virtual ~AppCacheUpdateJob(); | 47 virtual ~AppCacheUpdateJob(); |
47 | 48 |
48 // Triggers the update process or adds more info if this update is already | 49 // Triggers the update process or adds more info if this update is already |
49 // in progress. | 50 // in progress. |
50 void StartUpdate(AppCacheHost* host, const GURL& new_master_resource); | 51 void StartUpdate(AppCacheHost* host, const GURL& new_master_resource); |
51 | 52 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 virtual void OnGroupMadeObsolete(AppCacheGroup* group, bool success) OVERRIDE; | 169 virtual void OnGroupMadeObsolete(AppCacheGroup* group, bool success) OVERRIDE; |
169 | 170 |
170 // Methods for AppCacheHost::Observer. | 171 // Methods for AppCacheHost::Observer. |
171 virtual void OnCacheSelectionComplete(AppCacheHost* host) OVERRIDE {} // N/A | 172 virtual void OnCacheSelectionComplete(AppCacheHost* host) OVERRIDE {} // N/A |
172 virtual void OnDestructionImminent(AppCacheHost* host) OVERRIDE; | 173 virtual void OnDestructionImminent(AppCacheHost* host) OVERRIDE; |
173 | 174 |
174 // Methods for AppCacheService::Observer. | 175 // Methods for AppCacheService::Observer. |
175 virtual void OnServiceReinitialized( | 176 virtual void OnServiceReinitialized( |
176 AppCacheStorageReference* old_storage) OVERRIDE; | 177 AppCacheStorageReference* old_storage) OVERRIDE; |
177 | 178 |
178 void HandleCacheFailure(const std::string& error_message, ResultType result); | 179 void HandleCacheFailure(const std::string& error_message, |
| 180 ResultType result, |
| 181 const GURL& failed_resource_url); |
179 | 182 |
180 void FetchManifest(bool is_first_fetch); | 183 void FetchManifest(bool is_first_fetch); |
181 void HandleManifestFetchCompleted(URLFetcher* fetcher); | 184 void HandleManifestFetchCompleted(URLFetcher* fetcher); |
182 void ContinueHandleManifestFetchCompleted(bool changed); | 185 void ContinueHandleManifestFetchCompleted(bool changed); |
183 | 186 |
184 void HandleUrlFetchCompleted(URLFetcher* fetcher); | 187 void HandleUrlFetchCompleted(URLFetcher* fetcher); |
185 void HandleMasterEntryFetchCompleted(URLFetcher* fetcher); | 188 void HandleMasterEntryFetchCompleted(URLFetcher* fetcher); |
186 | 189 |
187 void HandleManifestRefetchCompleted(URLFetcher* fetcher); | 190 void HandleManifestRefetchCompleted(URLFetcher* fetcher); |
188 void OnManifestInfoWriteComplete(int result); | 191 void OnManifestInfoWriteComplete(int result); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 241 |
239 // Schedules a rerun of the entire update with the same parameters as | 242 // Schedules a rerun of the entire update with the same parameters as |
240 // this update job after a short delay. | 243 // this update job after a short delay. |
241 void ScheduleUpdateRetry(int delay_ms); | 244 void ScheduleUpdateRetry(int delay_ms); |
242 | 245 |
243 void Cancel(); | 246 void Cancel(); |
244 void ClearPendingMasterEntries(); | 247 void ClearPendingMasterEntries(); |
245 void DiscardInprogressCache(); | 248 void DiscardInprogressCache(); |
246 void DiscardDuplicateResponses(); | 249 void DiscardDuplicateResponses(); |
247 | 250 |
| 251 void LogHistogramStats(ResultType result, const GURL& failed_resource_url); |
| 252 void MadeProgress() { last_progress_time_ = base::Time::Now(); } |
| 253 |
248 // Deletes this object after letting the stack unwind. | 254 // Deletes this object after letting the stack unwind. |
249 void DeleteSoon(); | 255 void DeleteSoon(); |
250 | 256 |
251 bool IsTerminating() { return internal_state_ >= REFETCH_MANIFEST || | 257 bool IsTerminating() { return internal_state_ >= REFETCH_MANIFEST || |
252 stored_state_ != UNSTORED; } | 258 stored_state_ != UNSTORED; } |
253 | 259 |
254 AppCacheService* service_; | 260 AppCacheService* service_; |
255 const GURL manifest_url_; // here for easier access | 261 const GURL manifest_url_; // here for easier access |
256 | 262 |
257 // Defined prior to refs to AppCaches and Groups because destruction | 263 // Defined prior to refs to AppCaches and Groups because destruction |
258 // order matters, the disabled_storage_reference_ must outlive those | 264 // order matters, the disabled_storage_reference_ must outlive those |
259 // objects. | 265 // objects. |
260 scoped_refptr<AppCacheStorageReference> disabled_storage_reference_; | 266 scoped_refptr<AppCacheStorageReference> disabled_storage_reference_; |
261 | 267 |
262 scoped_refptr<AppCache> inprogress_cache_; | 268 scoped_refptr<AppCache> inprogress_cache_; |
263 | 269 |
264 AppCacheGroup* group_; | 270 AppCacheGroup* group_; |
265 | 271 |
266 UpdateType update_type_; | 272 UpdateType update_type_; |
267 InternalUpdateState internal_state_; | 273 InternalUpdateState internal_state_; |
| 274 base::Time last_progress_time_; |
268 | 275 |
269 PendingMasters pending_master_entries_; | 276 PendingMasters pending_master_entries_; |
270 size_t master_entries_completed_; | 277 size_t master_entries_completed_; |
271 | 278 |
272 // TODO(jennb): Delete when update no longer fetches master entries directly. | 279 // TODO(jennb): Delete when update no longer fetches master entries directly. |
273 // Helper containers to track which pending master entries have yet to be | 280 // Helper containers to track which pending master entries have yet to be |
274 // fetched and which are currently being fetched. Master entries that | 281 // fetched and which are currently being fetched. Master entries that |
275 // are listed in the manifest may be fetched as a regular URL instead of | 282 // are listed in the manifest may be fetched as a regular URL instead of |
276 // as a separate master entry fetch to optimize against duplicate fetches. | 283 // as a separate master entry fetch to optimize against duplicate fetches. |
277 std::set<GURL> master_entries_to_fetch_; | 284 std::set<GURL> master_entries_to_fetch_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 AppCacheStorage* storage_; | 330 AppCacheStorage* storage_; |
324 | 331 |
325 FRIEND_TEST_ALL_PREFIXES(AppCacheGroupTest, QueueUpdate); | 332 FRIEND_TEST_ALL_PREFIXES(AppCacheGroupTest, QueueUpdate); |
326 | 333 |
327 DISALLOW_COPY_AND_ASSIGN(AppCacheUpdateJob); | 334 DISALLOW_COPY_AND_ASSIGN(AppCacheUpdateJob); |
328 }; | 335 }; |
329 | 336 |
330 } // namespace appcache | 337 } // namespace appcache |
331 | 338 |
332 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_UPDATE_JOB_H_ | 339 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_UPDATE_JOB_H_ |
OLD | NEW |