| OLD | NEW |
| 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> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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_response.h" |
| 24 #include "webkit/appcache/appcache_storage.h" | 24 #include "webkit/appcache/appcache_storage.h" |
| 25 | 25 |
| 26 namespace appcache { | 26 namespace appcache { |
| 27 | 27 |
| 28 class UpdateJobInfo; | 28 class UpdateJobInfo; |
| 29 class HostNotifier; | 29 class HostNotifier; |
| 30 | 30 |
| 31 // Application cache Update algorithm and state. | 31 // Application cache Update algorithm and state. |
| 32 class AppCacheUpdateJob : public URLRequest::Delegate, | 32 class AppCacheUpdateJob : public net::URLRequest::Delegate, |
| 33 public AppCacheStorage::Delegate, | 33 public AppCacheStorage::Delegate, |
| 34 public AppCacheHost::Observer { | 34 public AppCacheHost::Observer { |
| 35 public: | 35 public: |
| 36 AppCacheUpdateJob(AppCacheService* service, AppCacheGroup* group); | 36 AppCacheUpdateJob(AppCacheService* service, AppCacheGroup* group); |
| 37 ~AppCacheUpdateJob(); | 37 ~AppCacheUpdateJob(); |
| 38 | 38 |
| 39 // 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 |
| 40 // in progress. | 40 // in progress. |
| 41 void StartUpdate(AppCacheHost* host, const GURL& new_master_resource); | 41 void StartUpdate(AppCacheHost* host, const GURL& new_master_resource); |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 friend class ScopedRunnableMethodFactory<AppCacheUpdateJob>; | 44 friend class ScopedRunnableMethodFactory<AppCacheUpdateJob>; |
| 45 friend class AppCacheUpdateJobTest; | 45 friend class AppCacheUpdateJobTest; |
| 46 friend class UpdateJobInfo; | 46 friend class UpdateJobInfo; |
| 47 | 47 |
| 48 // 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 |
| 49 // in different tabs. | 49 // in different tabs. |
| 50 typedef std::vector<AppCacheHost*> PendingHosts; | 50 typedef std::vector<AppCacheHost*> PendingHosts; |
| 51 typedef std::map<GURL, PendingHosts> PendingMasters; | 51 typedef std::map<GURL, PendingHosts> PendingMasters; |
| 52 typedef std::map<GURL, URLRequest*> PendingUrlFetches; | 52 typedef std::map<GURL, net::URLRequest*> PendingUrlFetches; |
| 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 21 matching lines...) Expand all Loading... |
| 84 | 84 |
| 85 struct UrlToFetch { | 85 struct UrlToFetch { |
| 86 UrlToFetch(const GURL& url, bool checked, AppCacheResponseInfo* info); | 86 UrlToFetch(const GURL& url, bool checked, AppCacheResponseInfo* info); |
| 87 ~UrlToFetch(); | 87 ~UrlToFetch(); |
| 88 | 88 |
| 89 GURL url; | 89 GURL url; |
| 90 bool storage_checked; | 90 bool storage_checked; |
| 91 scoped_refptr<AppCacheResponseInfo> existing_response_info; | 91 scoped_refptr<AppCacheResponseInfo> existing_response_info; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 UpdateJobInfo* GetUpdateJobInfo(URLRequest* request); | 94 UpdateJobInfo* GetUpdateJobInfo(net::URLRequest* request); |
| 95 | 95 |
| 96 // Methods for URLRequest::Delegate. | 96 // Overridden from net::URLRequest::Delegate: |
| 97 void OnResponseStarted(URLRequest* request); | 97 virtual void OnResponseStarted(net::URLRequest* request); |
| 98 void OnReadCompleted(URLRequest* request, int bytes_read); | 98 virtual void OnReadCompleted(net::URLRequest* request, int bytes_read); |
| 99 void OnReceivedRedirect(URLRequest* request, | 99 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 100 const GURL& new_url, | 100 const GURL& new_url, |
| 101 bool* defer_redirect); | 101 bool* defer_redirect); |
| 102 // TODO(jennb): any other delegate callbacks to handle? certificate? | 102 // TODO(jennb): any other delegate callbacks to handle? certificate? |
| 103 | 103 |
| 104 // Methods for AppCacheStorage::Delegate. | 104 // Methods for AppCacheStorage::Delegate. |
| 105 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, | 105 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, |
| 106 int64 response_id); | 106 int64 response_id); |
| 107 void OnGroupAndNewestCacheStored(AppCacheGroup* group, AppCache* newest_cache, | 107 void OnGroupAndNewestCacheStored(AppCacheGroup* group, AppCache* newest_cache, |
| 108 bool success, bool would_exceed_quota); | 108 bool success, bool would_exceed_quota); |
| 109 void OnGroupMadeObsolete(AppCacheGroup* group, bool success); | 109 void OnGroupMadeObsolete(AppCacheGroup* group, bool success); |
| 110 | 110 |
| 111 // Methods for AppCacheHost::Observer. | 111 // Methods for AppCacheHost::Observer. |
| 112 void OnCacheSelectionComplete(AppCacheHost* host) {} // N/A | 112 void OnCacheSelectionComplete(AppCacheHost* host) {} // N/A |
| 113 void OnDestructionImminent(AppCacheHost* host); | 113 void OnDestructionImminent(AppCacheHost* host); |
| 114 | 114 |
| 115 void CheckPolicy(); | 115 void CheckPolicy(); |
| 116 void OnPolicyCheckComplete(int rv); | 116 void OnPolicyCheckComplete(int rv); |
| 117 | 117 |
| 118 void HandleCacheFailure(const std::string& error_message); | 118 void HandleCacheFailure(const std::string& error_message); |
| 119 | 119 |
| 120 void FetchManifest(bool is_first_fetch); | 120 void FetchManifest(bool is_first_fetch); |
| 121 | 121 |
| 122 // Add extra conditional HTTP headers to the request based on the | 122 // Add extra conditional HTTP headers to the request based on the |
| 123 // currently cached response headers. | 123 // currently cached response headers. |
| 124 void AddConditionalHeaders(URLRequest* request, | 124 void AddConditionalHeaders(net::URLRequest* request, |
| 125 const net::HttpResponseInfo* info); | 125 const net::HttpResponseInfo* info); |
| 126 | 126 |
| 127 void OnResponseCompleted(URLRequest* request); | 127 void OnResponseCompleted(net::URLRequest* request); |
| 128 | 128 |
| 129 // Retries a 503 request with retry-after header of 0. | 129 // Retries a 503 request with retry-after header of 0. |
| 130 // Returns true if request should be retried and deletes original request. | 130 // Returns true if request should be retried and deletes original request. |
| 131 bool RetryRequest(URLRequest* request); | 131 bool RetryRequest(net::URLRequest* request); |
| 132 | 132 |
| 133 void ReadResponseData(URLRequest* request); | 133 void ReadResponseData(net::URLRequest* request); |
| 134 | 134 |
| 135 // Returns false if response data is processed asynchronously, in which | 135 // Returns false if response data is processed asynchronously, in which |
| 136 // case ReadResponseData will be invoked when it is safe to continue | 136 // case ReadResponseData will be invoked when it is safe to continue |
| 137 // reading more response data from the request. | 137 // reading more response data from the request. |
| 138 bool ConsumeResponseData(URLRequest* request, | 138 bool ConsumeResponseData(net::URLRequest* request, |
| 139 UpdateJobInfo* info, | 139 UpdateJobInfo* info, |
| 140 int bytes_read); | 140 int bytes_read); |
| 141 void OnWriteResponseComplete(int result, URLRequest* request, | 141 void OnWriteResponseComplete(int result, net::URLRequest* request, |
| 142 UpdateJobInfo* info); | 142 UpdateJobInfo* info); |
| 143 | 143 |
| 144 void HandleManifestFetchCompleted(URLRequest* request); | 144 void HandleManifestFetchCompleted(net::URLRequest* request); |
| 145 void ContinueHandleManifestFetchCompleted(bool changed); | 145 void ContinueHandleManifestFetchCompleted(bool changed); |
| 146 | 146 |
| 147 void HandleUrlFetchCompleted(URLRequest* request); | 147 void HandleUrlFetchCompleted(net::URLRequest* request); |
| 148 void HandleMasterEntryFetchCompleted(URLRequest* request); | 148 void HandleMasterEntryFetchCompleted(net::URLRequest* request); |
| 149 | 149 |
| 150 void HandleManifestRefetchCompleted(URLRequest* request); | 150 void HandleManifestRefetchCompleted(net::URLRequest* request); |
| 151 void OnManifestInfoWriteComplete(int result); | 151 void OnManifestInfoWriteComplete(int result); |
| 152 void OnManifestDataWriteComplete(int result); | 152 void OnManifestDataWriteComplete(int result); |
| 153 | 153 |
| 154 void StoreGroupAndCache(); | 154 void StoreGroupAndCache(); |
| 155 | 155 |
| 156 void NotifySingleHost(AppCacheHost* host, EventID event_id); | 156 void NotifySingleHost(AppCacheHost* host, EventID event_id); |
| 157 void NotifyAllAssociatedHosts(EventID event_id); | 157 void NotifyAllAssociatedHosts(EventID event_id); |
| 158 void NotifyAllProgress(const GURL& url); | 158 void NotifyAllProgress(const GURL& url); |
| 159 void NotifyAllFinalProgress(); | 159 void NotifyAllFinalProgress(); |
| 160 void NotifyAllError(const std::string& error_message); | 160 void NotifyAllError(const std::string& error_message); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // Helper container to track which urls have not been fetched yet. URLs are | 245 // Helper container to track which urls have not been fetched yet. URLs are |
| 246 // removed when the fetch is initiated. Flag indicates whether an attempt | 246 // removed when the fetch is initiated. Flag indicates whether an attempt |
| 247 // to load the URL from storage has already been tried and failed. | 247 // to load the URL from storage has already been tried and failed. |
| 248 std::deque<UrlToFetch> urls_to_fetch_; | 248 std::deque<UrlToFetch> urls_to_fetch_; |
| 249 | 249 |
| 250 // Helper container to track which urls are being loaded from response | 250 // Helper container to track which urls are being loaded from response |
| 251 // storage. | 251 // storage. |
| 252 LoadingResponses loading_responses_; | 252 LoadingResponses loading_responses_; |
| 253 | 253 |
| 254 // Keep track of pending URL requests so we can cancel them if necessary. | 254 // Keep track of pending URL requests so we can cancel them if necessary. |
| 255 URLRequest* manifest_url_request_; | 255 net::URLRequest* manifest_url_request_; |
| 256 PendingUrlFetches pending_url_fetches_; | 256 PendingUrlFetches pending_url_fetches_; |
| 257 | 257 |
| 258 // Temporary storage of manifest response data for parsing and comparison. | 258 // Temporary storage of manifest response data for parsing and comparison. |
| 259 std::string manifest_data_; | 259 std::string manifest_data_; |
| 260 std::string manifest_refetch_data_; | 260 std::string manifest_refetch_data_; |
| 261 scoped_ptr<net::HttpResponseInfo> manifest_response_info_; | 261 scoped_ptr<net::HttpResponseInfo> manifest_response_info_; |
| 262 scoped_ptr<AppCacheResponseWriter> manifest_response_writer_; | 262 scoped_ptr<AppCacheResponseWriter> manifest_response_writer_; |
| 263 scoped_refptr<net::IOBuffer> read_manifest_buffer_; | 263 scoped_refptr<net::IOBuffer> read_manifest_buffer_; |
| 264 std::string loaded_manifest_data_; | 264 std::string loaded_manifest_data_; |
| 265 scoped_ptr<AppCacheResponseReader> manifest_response_reader_; | 265 scoped_ptr<AppCacheResponseReader> manifest_response_reader_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 290 policy_callback_; | 290 policy_callback_; |
| 291 | 291 |
| 292 FRIEND_TEST_ALL_PREFIXES(AppCacheGroupTest, QueueUpdate); | 292 FRIEND_TEST_ALL_PREFIXES(AppCacheGroupTest, QueueUpdate); |
| 293 | 293 |
| 294 DISALLOW_COPY_AND_ASSIGN(AppCacheUpdateJob); | 294 DISALLOW_COPY_AND_ASSIGN(AppCacheUpdateJob); |
| 295 }; | 295 }; |
| 296 | 296 |
| 297 } // namespace appcache | 297 } // namespace appcache |
| 298 | 298 |
| 299 #endif // WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_ | 299 #endif // WEBKIT_APPCACHE_APPCACHE_UPDATE_JOB_H_ |
| OLD | NEW |