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

Unified Diff: content/browser/service_worker/service_worker_write_to_cache_job.h

Issue 1166433003: Service Worker: Don't write to disk during update until proven necessary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_write_to_cache_job.h
diff --git a/content/browser/service_worker/service_worker_write_to_cache_job.h b/content/browser/service_worker/service_worker_write_to_cache_job.h
index 507b78b50a4637908b0b4765b1ab63e01b27cf6b..38b040d3168ea09c4ba714b6bbd441f766249e94 100644
--- a/content/browser/service_worker/service_worker_write_to_cache_job.h
+++ b/content/browser/service_worker/service_worker_write_to_cache_job.h
@@ -30,18 +30,25 @@ class ServiceWorkerVersions;
// request is written to the service worker script cache and piped
// to the consumer of the ServiceWorkerWriteToCacheJob for delivery
// to the renderer process housing the worker.
+//
+// For updates, the main script is not written to disk until a change with the
+// incumbent script is detected. The incumbent script is progressively compared
+// with the new script as it is read from network. Once a change is detected,
+// everything that matched is copied to disk, and from then on the script is
+// written as it continues to be read from network. If the scripts were
+// identical, the job fails so the worker can be discarded.
class CONTENT_EXPORT ServiceWorkerWriteToCacheJob
: public net::URLRequestJob,
public net::URLRequest::Delegate {
public:
- ServiceWorkerWriteToCacheJob(
- net::URLRequest* request,
- net::NetworkDelegate* network_delegate,
- ResourceType resource_type,
- base::WeakPtr<ServiceWorkerContextCore> context,
- ServiceWorkerVersion* version,
- int extra_load_flags,
- int64 response_id);
+ ServiceWorkerWriteToCacheJob(net::URLRequest* request,
+ net::NetworkDelegate* network_delegate,
+ ResourceType resource_type,
+ base::WeakPtr<ServiceWorkerContextCore> context,
+ ServiceWorkerVersion* version,
+ int extra_load_flags,
+ int64 response_id,
+ int64 incumbent_response_id);
private:
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
@@ -50,6 +57,10 @@ class CONTENT_EXPORT ServiceWorkerWriteToCacheJob
UpdateAfter24Hours);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest,
UpdateForceBypassCache);
+ class NetDataConsumer;
+ class PassThroughConsumer;
+ class Comparer;
+ class Copier;
~ServiceWorkerWriteToCacheJob() override;
@@ -70,14 +81,18 @@ class CONTENT_EXPORT ServiceWorkerWriteToCacheJob
// write data to the disk cache.
void InitNetRequest(int extra_load_flags);
void StartNetRequest();
- net::URLRequestStatus ReadNetData(
- net::IOBuffer* buf,
- int buf_size,
- int *bytes_read);
- void WriteHeadersToCache();
- void OnWriteHeadersComplete(int result);
- void WriteDataToCache(int bytes_to_write);
- void OnWriteDataComplete(int result);
+ net::URLRequestStatus ReadNetData(net::IOBuffer* buf,
+ int buf_size,
+ int* bytes_read);
+
+ void CommitHeadersAndNotifyHeadersComplete();
+ void WriteHeaders(const base::Closure& callback);
+ void OnWriteHeadersComplete(const base::Closure& callback, int result);
+ void WriteData(net::IOBuffer* buf,
+ int amount_to_write,
+ const base::Callback<void(int result)>& callback);
+ void OnWriteDataComplete(const base::Callback<void(int result)>& callback,
+ int result);
// net::URLRequest::Delegate overrides that observe the net request.
void OnReceivedRedirect(net::URLRequest* request,
@@ -97,19 +112,32 @@ class CONTENT_EXPORT ServiceWorkerWriteToCacheJob
bool CheckPathRestriction(net::URLRequest* request);
+ void SetPendingIO();
+ void ClearPendingIO();
+ void OnPassThroughComplete();
+ void OnCompareComplete(int bytes_matched, bool is_equal);
+ void CopyIncumbent(int bytes_to_copy);
+ void OnCopyComplete(ServiceWorkerStatusCode status);
+ void HandleNetData(int bytes_read);
+
void AsyncNotifyDoneHelper(const net::URLRequestStatus& status,
const std::string& status_message);
+ void NotifyFinishedCaching(net::URLRequestStatus status,
+ const std::string& status_message);
+
ResourceType resource_type_; // Differentiate main script and imports
scoped_refptr<net::IOBuffer> io_buffer_;
- scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_;
+ int io_buffer_bytes_;
base::WeakPtr<ServiceWorkerContextCore> context_;
GURL url_;
int64 response_id_;
+ int64 incumbent_response_id_;
scoped_ptr<net::URLRequest> net_request_;
scoped_ptr<net::HttpResponseInfo> http_info_;
scoped_ptr<ServiceWorkerResponseWriter> writer_;
scoped_refptr<ServiceWorkerVersion> version_;
+ scoped_ptr<NetDataConsumer> consumer_;
bool has_been_killed_;
bool did_notify_started_;
bool did_notify_finished_;

Powered by Google App Engine
This is Rietveld 408576698