OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_WRITE_TO_CACHE_JOB_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_WRITE_TO_CACHE_JOB_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_WRITE_TO_CACHE_JOB_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_WRITE_TO_CACHE_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 UpdateBefore24Hours); | 57 UpdateBefore24Hours); |
58 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 58 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
59 UpdateAfter24Hours); | 59 UpdateAfter24Hours); |
60 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 60 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
61 UpdateForceBypassCache); | 61 UpdateForceBypassCache); |
62 | 62 |
63 ~ServiceWorkerWriteToCacheJob() override; | 63 ~ServiceWorkerWriteToCacheJob() override; |
64 | 64 |
65 // net::URLRequestJob overrides | 65 // net::URLRequestJob overrides |
66 void Start() override; | 66 void Start() override; |
67 void StartAsync(); | |
68 void Kill() override; | 67 void Kill() override; |
69 net::LoadState GetLoadState() const override; | 68 net::LoadState GetLoadState() const override; |
70 bool GetCharset(std::string* charset) override; | 69 bool GetCharset(std::string* charset) override; |
71 bool GetMimeType(std::string* mime_type) const override; | 70 bool GetMimeType(std::string* mime_type) const override; |
72 void GetResponseInfo(net::HttpResponseInfo* info) override; | 71 void GetResponseInfo(net::HttpResponseInfo* info) override; |
73 int GetResponseCode() const override; | 72 int GetResponseCode() const override; |
74 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; | 73 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; |
75 int ReadRawData(net::IOBuffer* buf, int buf_size) override; | 74 bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) override; |
76 | 75 |
77 const net::HttpResponseInfo* http_info() const; | 76 const net::HttpResponseInfo* http_info() const; |
78 | 77 |
79 // Methods to drive the net request forward and | 78 // Methods to drive the net request forward and |
80 // write data to the disk cache. | 79 // write data to the disk cache. |
81 void InitNetRequest(int extra_load_flags); | 80 void InitNetRequest(int extra_load_flags); |
82 void StartNetRequest(); | 81 void StartNetRequest(); |
83 net::URLRequestStatus ReadNetData(net::IOBuffer* buf, | 82 net::URLRequestStatus ReadNetData(net::IOBuffer* buf, |
84 int buf_size, | 83 int buf_size, |
85 int* bytes_read); | 84 int* bytes_read); |
(...skipping 17 matching lines...) Expand all Loading... |
103 void OnSSLCertificateError(net::URLRequest* request, | 102 void OnSSLCertificateError(net::URLRequest* request, |
104 const net::SSLInfo& ssl_info, | 103 const net::SSLInfo& ssl_info, |
105 bool fatal) override; | 104 bool fatal) override; |
106 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override; | 105 void OnBeforeNetworkStart(net::URLRequest* request, bool* defer) override; |
107 void OnResponseStarted(net::URLRequest* request) override; | 106 void OnResponseStarted(net::URLRequest* request) override; |
108 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 107 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
109 | 108 |
110 bool CheckPathRestriction(net::URLRequest* request); | 109 bool CheckPathRestriction(net::URLRequest* request); |
111 | 110 |
112 // Writes network data back to the script cache if needed, and notifies the | 111 // Writes network data back to the script cache if needed, and notifies the |
113 // script cache of fetch completion at EOF. This function returns | 112 // script cache of fetch completion at EOF. This function might need to do |
114 // net::IO_PENDING if the IO is to be completed asynchronously, returns a | 113 // asynchronous IO; if so, it signals this through setting the URLRequestJob's |
115 // negative number that represents a corresponding net error code (other than | 114 // status to IO_PENDING. After this function returns, if the URLRequestJob |
116 // net::IO_PENDING) if an error occurred, or returns a non-negative number | 115 // isn't IO_PENDING, all of the data in |io_buffer_| has been written back to |
117 // that represents the number of network bytes read. If the return value is | 116 // the script cache if necessary. |
118 // non-negative, all of the data in |io_buffer_| has been written back to the | 117 void HandleNetData(int bytes_read); |
119 // script cache if necessary. | |
120 int HandleNetData(int bytes_read); | |
121 | 118 |
122 void NotifyStartErrorHelper(const net::URLRequestStatus& status, | 119 void NotifyDoneHelper(const net::URLRequestStatus& status, |
123 const std::string& status_message); | 120 const std::string& status_message); |
124 | 121 |
125 // Returns an error code that is passed in through |status| or a new one if an | 122 void NotifyFinishedCaching(net::URLRequestStatus status, |
126 // additional error is found. | 123 const std::string& status_message); |
127 net::Error NotifyFinishedCaching(net::URLRequestStatus status, | |
128 const std::string& status_message); | |
129 | 124 |
130 scoped_ptr<ServiceWorkerResponseReader> CreateCacheResponseReader(); | 125 scoped_ptr<ServiceWorkerResponseReader> CreateCacheResponseReader(); |
131 scoped_ptr<ServiceWorkerResponseWriter> CreateCacheResponseWriter(); | 126 scoped_ptr<ServiceWorkerResponseWriter> CreateCacheResponseWriter(); |
132 | 127 |
133 ResourceType resource_type_; // Differentiate main script and imports | 128 ResourceType resource_type_; // Differentiate main script and imports |
134 scoped_refptr<net::IOBuffer> io_buffer_; | 129 scoped_refptr<net::IOBuffer> io_buffer_; |
135 int io_buffer_bytes_; | 130 int io_buffer_bytes_; |
136 base::WeakPtr<ServiceWorkerContextCore> context_; | 131 base::WeakPtr<ServiceWorkerContextCore> context_; |
137 GURL url_; | 132 GURL url_; |
138 int64 resource_id_; | 133 int64 resource_id_; |
139 int64 incumbent_resource_id_; | 134 int64 incumbent_resource_id_; |
140 scoped_ptr<net::URLRequest> net_request_; | 135 scoped_ptr<net::URLRequest> net_request_; |
141 scoped_ptr<net::HttpResponseInfo> http_info_; | 136 scoped_ptr<net::HttpResponseInfo> http_info_; |
142 scoped_ptr<ServiceWorkerResponseWriter> writer_; | 137 scoped_ptr<ServiceWorkerResponseWriter> writer_; |
143 scoped_refptr<ServiceWorkerVersion> version_; | 138 scoped_refptr<ServiceWorkerVersion> version_; |
144 scoped_ptr<ServiceWorkerCacheWriter> cache_writer_; | 139 scoped_ptr<ServiceWorkerCacheWriter> cache_writer_; |
145 bool has_been_killed_; | 140 bool has_been_killed_; |
146 bool did_notify_started_; | 141 bool did_notify_started_; |
147 bool did_notify_finished_; | 142 bool did_notify_finished_; |
148 | |
149 base::WeakPtrFactory<ServiceWorkerWriteToCacheJob> weak_factory_; | 143 base::WeakPtrFactory<ServiceWorkerWriteToCacheJob> weak_factory_; |
150 | 144 |
151 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerWriteToCacheJob); | 145 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerWriteToCacheJob); |
152 }; | 146 }; |
153 | 147 |
154 } // namespace content | 148 } // namespace content |
155 | 149 |
156 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_WRITE_TO_CACHE_JOB_H_ | 150 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_WRITE_TO_CACHE_JOB_H_ |
OLD | NEW |