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 #include "content/browser/service_worker/service_worker_cache.h" | 5 #include "content/browser/service_worker/service_worker_cache.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 scoped_refptr<net::IOBufferWithSize> buffer; | 48 scoped_refptr<net::IOBufferWithSize> buffer; |
49 scoped_refptr<storage::BlobData> blob_data; | 49 scoped_refptr<storage::BlobData> blob_data; |
50 int total_bytes_read; | 50 int total_bytes_read; |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(ResponseReadContext); | 52 DISALLOW_COPY_AND_ASSIGN(ResponseReadContext); |
53 }; | 53 }; |
54 | 54 |
55 // Streams data from a blob and writes it to a given disk_cache::Entry. | 55 // Streams data from a blob and writes it to a given disk_cache::Entry. |
56 class BlobReader : public net::URLRequest::Delegate { | 56 class BlobReader : public net::URLRequest::Delegate { |
57 public: | 57 public: |
58 typedef base::Callback<void(disk_cache::ScopedEntryPtr, bool)> | 58 typedef base::Callback<void(bool)> BoolCallback; |
59 EntryBoolCallback; | |
60 | 59 |
61 BlobReader(disk_cache::ScopedEntryPtr entry) | 60 BlobReader(disk_cache::ScopedEntryPtr entry) |
62 : cache_entry_offset_(0), | 61 : cache_entry_offset_(0), |
63 buffer_(new net::IOBufferWithSize(kBufferSize)), | 62 buffer_(new net::IOBufferWithSize(kBufferSize)), |
64 weak_ptr_factory_(this) { | 63 weak_ptr_factory_(this) { |
65 DCHECK(entry); | 64 DCHECK(entry); |
66 entry_ = entry.Pass(); | 65 entry_ = entry.Pass(); |
67 } | 66 } |
68 | 67 |
69 void StreamBlobToCache(net::URLRequestContext* request_context, | 68 void StreamBlobToCache(net::URLRequestContext* request_context, |
70 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 69 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
71 const EntryBoolCallback& callback) { | 70 const BoolCallback& callback) { |
72 callback_ = callback; | 71 callback_ = callback; |
73 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( | 72 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( |
74 blob_data_handle.Pass(), request_context, this); | 73 blob_data_handle.Pass(), request_context, this); |
75 blob_request_->Start(); | 74 blob_request_->Start(); |
76 } | 75 } |
77 | 76 |
78 // net::URLRequest::Delegate overrides for reading blobs. | 77 // net::URLRequest::Delegate overrides for reading blobs. |
79 virtual void OnReceivedRedirect(net::URLRequest* request, | 78 virtual void OnReceivedRedirect(net::URLRequest* request, |
80 const net::RedirectInfo& redirect_info, | 79 const net::RedirectInfo& redirect_info, |
81 bool* defer_redirect) OVERRIDE { | 80 bool* defer_redirect) OVERRIDE { |
(...skipping 13 matching lines...) Expand all Loading... |
95 bool fatal) OVERRIDE { | 94 bool fatal) OVERRIDE { |
96 NOTREACHED(); | 95 NOTREACHED(); |
97 } | 96 } |
98 virtual void OnBeforeNetworkStart(net::URLRequest* request, | 97 virtual void OnBeforeNetworkStart(net::URLRequest* request, |
99 bool* defer) OVERRIDE { | 98 bool* defer) OVERRIDE { |
100 NOTREACHED(); | 99 NOTREACHED(); |
101 } | 100 } |
102 | 101 |
103 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE { | 102 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE { |
104 if (!request->status().is_success()) { | 103 if (!request->status().is_success()) { |
105 callback_.Run(entry_.Pass(), false); | 104 callback_.Run(false); |
106 return; | 105 return; |
107 } | 106 } |
108 ReadFromBlob(); | 107 ReadFromBlob(); |
109 } | 108 } |
110 | 109 |
111 virtual void ReadFromBlob() { | 110 virtual void ReadFromBlob() { |
112 int bytes_read = 0; | 111 int bytes_read = 0; |
113 bool done = | 112 bool done = |
114 blob_request_->Read(buffer_.get(), buffer_->size(), &bytes_read); | 113 blob_request_->Read(buffer_.get(), buffer_->size(), &bytes_read); |
115 if (done) | 114 if (done) |
116 OnReadCompleted(blob_request_.get(), bytes_read); | 115 OnReadCompleted(blob_request_.get(), bytes_read); |
117 } | 116 } |
118 | 117 |
119 virtual void OnReadCompleted(net::URLRequest* request, | 118 virtual void OnReadCompleted(net::URLRequest* request, |
120 int bytes_read) OVERRIDE { | 119 int bytes_read) OVERRIDE { |
121 if (!request->status().is_success()) { | 120 if (!request->status().is_success()) { |
122 callback_.Run(entry_.Pass(), false); | 121 callback_.Run(false); |
123 return; | 122 return; |
124 } | 123 } |
125 | 124 |
126 if (bytes_read == 0) { | 125 if (bytes_read == 0) { |
127 callback_.Run(entry_.Pass(), true); | 126 callback_.Run(true); |
128 return; | 127 return; |
129 } | 128 } |
130 | 129 |
131 net::CompletionCallback cache_write_callback = | 130 net::CompletionCallback cache_write_callback = |
132 base::Bind(&BlobReader::DidWriteDataToEntry, | 131 base::Bind(&BlobReader::DidWriteDataToEntry, |
133 weak_ptr_factory_.GetWeakPtr(), | 132 weak_ptr_factory_.GetWeakPtr(), |
134 bytes_read); | 133 bytes_read); |
135 | 134 |
136 int rv = entry_->WriteData(INDEX_RESPONSE_BODY, | 135 int rv = entry_->WriteData(INDEX_RESPONSE_BODY, |
137 cache_entry_offset_, | 136 cache_entry_offset_, |
138 buffer_.get(), | 137 buffer_.get(), |
139 bytes_read, | 138 bytes_read, |
140 cache_write_callback, | 139 cache_write_callback, |
141 true /* truncate */); | 140 true /* truncate */); |
142 if (rv != net::ERR_IO_PENDING) | 141 if (rv != net::ERR_IO_PENDING) |
143 cache_write_callback.Run(rv); | 142 cache_write_callback.Run(rv); |
144 } | 143 } |
145 | 144 |
146 void DidWriteDataToEntry(int expected_bytes, int rv) { | 145 void DidWriteDataToEntry(int expected_bytes, int rv) { |
147 if (rv != expected_bytes) { | 146 if (rv != expected_bytes) { |
148 callback_.Run(entry_.Pass(), false); | 147 callback_.Run(false); |
149 return; | 148 return; |
150 } | 149 } |
151 | 150 |
152 cache_entry_offset_ += rv; | 151 cache_entry_offset_ += rv; |
153 ReadFromBlob(); | 152 ReadFromBlob(); |
154 } | 153 } |
155 | 154 |
156 private: | 155 private: |
157 int cache_entry_offset_; | 156 int cache_entry_offset_; |
158 disk_cache::ScopedEntryPtr entry_; | 157 disk_cache::ScopedEntryPtr entry_; |
159 scoped_ptr<net::URLRequest> blob_request_; | 158 scoped_ptr<net::URLRequest> blob_request_; |
160 EntryBoolCallback callback_; | 159 BoolCallback callback_; |
161 scoped_refptr<net::IOBufferWithSize> buffer_; | 160 scoped_refptr<net::IOBufferWithSize> buffer_; |
162 base::WeakPtrFactory<BlobReader> weak_ptr_factory_; | 161 base::WeakPtrFactory<BlobReader> weak_ptr_factory_; |
163 }; | 162 }; |
164 | 163 |
| 164 // The state needed to pass between ServiceWorkerCache::Put callbacks. |
| 165 struct PutContext { |
| 166 PutContext(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 167 scoped_ptr<ServiceWorkerResponse> response, |
| 168 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
| 169 const ServiceWorkerCache::ErrorCallback& callback, |
| 170 net::URLRequestContext* request_context) |
| 171 : request(request.Pass()), |
| 172 response(response.Pass()), |
| 173 blob_data_handle(blob_data_handle.Pass()), |
| 174 callback(callback), |
| 175 request_context(request_context), |
| 176 cache_entry(NULL) {} |
| 177 ~PutContext() { |
| 178 if (cache_entry) |
| 179 cache_entry->Close(); |
| 180 } |
| 181 |
| 182 // Input parameters to the Put function. |
| 183 scoped_ptr<ServiceWorkerFetchRequest> request; |
| 184 scoped_ptr<ServiceWorkerResponse> response; |
| 185 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 186 ServiceWorkerCache::ErrorCallback callback; |
| 187 |
| 188 net::URLRequestContext* request_context; |
| 189 |
| 190 // This isn't a scoped_ptr because the disk_cache needs an Entry** as input to |
| 191 // CreateEntry. |
| 192 disk_cache::Entry* cache_entry; |
| 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(PutContext); |
| 195 }; |
| 196 |
165 // Put callbacks | 197 // Put callbacks |
166 void PutDidCreateEntry(scoped_ptr<ServiceWorkerFetchRequest> request, | 198 void PutDidCreateEntry(scoped_ptr<PutContext> put_context, int rv); |
167 scoped_ptr<ServiceWorkerResponse> response, | 199 void PutDidWriteHeaders(scoped_ptr<PutContext> put_context, |
168 const ServiceWorkerCache::ErrorCallback& callback, | |
169 scoped_ptr<disk_cache::Entry*> entryptr, | |
170 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | |
171 net::URLRequestContext* request_context, | |
172 int rv); | |
173 void PutDidWriteHeaders(scoped_ptr<ServiceWorkerResponse> response, | |
174 const ServiceWorkerCache::ErrorCallback& callback, | |
175 disk_cache::ScopedEntryPtr entry, | |
176 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | |
177 net::URLRequestContext* request_context, | |
178 int expected_bytes, | 200 int expected_bytes, |
179 int rv); | 201 int rv); |
180 void PutDidWriteBlobToCache(const ServiceWorkerCache::ErrorCallback& callback, | 202 void PutDidWriteBlobToCache(scoped_ptr<PutContext> put_context, |
181 scoped_ptr<BlobReader> blob_reader, | 203 scoped_ptr<BlobReader> blob_reader, |
182 disk_cache::ScopedEntryPtr entry, | |
183 bool success); | 204 bool success); |
184 | 205 |
185 // Match callbacks | 206 // Match callbacks |
186 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, | 207 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
187 const ServiceWorkerCache::ResponseCallback& callback, | 208 const ServiceWorkerCache::ResponseCallback& callback, |
188 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 209 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
189 scoped_ptr<disk_cache::Entry*> entryptr, | 210 scoped_ptr<disk_cache::Entry*> entryptr, |
190 int rv); | 211 int rv); |
191 void MatchDidReadHeaderData( | 212 void MatchDidReadHeaderData( |
192 scoped_ptr<ServiceWorkerFetchRequest> request, | 213 scoped_ptr<ServiceWorkerFetchRequest> request, |
(...skipping 29 matching lines...) Expand all Loading... |
222 const HeadersCallback& callback, | 243 const HeadersCallback& callback, |
223 const scoped_refptr<net::IOBufferWithSize>& buffer, | 244 const scoped_refptr<net::IOBufferWithSize>& buffer, |
224 int rv); | 245 int rv); |
225 | 246 |
226 // CreateBackend callbacks | 247 // CreateBackend callbacks |
227 void CreateBackendDidCreate(const ServiceWorkerCache::ErrorCallback& callback, | 248 void CreateBackendDidCreate(const ServiceWorkerCache::ErrorCallback& callback, |
228 scoped_ptr<ScopedBackendPtr> backend_ptr, | 249 scoped_ptr<ScopedBackendPtr> backend_ptr, |
229 base::WeakPtr<ServiceWorkerCache> cache, | 250 base::WeakPtr<ServiceWorkerCache> cache, |
230 int rv); | 251 int rv); |
231 | 252 |
232 void PutDidCreateEntry(scoped_ptr<ServiceWorkerFetchRequest> request, | 253 void PutDidCreateEntry(scoped_ptr<PutContext> put_context, int rv) { |
233 scoped_ptr<ServiceWorkerResponse> response, | |
234 const ServiceWorkerCache::ErrorCallback& callback, | |
235 scoped_ptr<disk_cache::Entry*> entryptr, | |
236 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | |
237 net::URLRequestContext* request_context, | |
238 int rv) { | |
239 if (rv != net::OK) { | 254 if (rv != net::OK) { |
240 callback.Run(ServiceWorkerCache::ErrorTypeExists); | 255 put_context->callback.Run(ServiceWorkerCache::ErrorTypeExists); |
241 return; | 256 return; |
242 } | 257 } |
243 | 258 |
244 DCHECK(entryptr); | 259 DCHECK(put_context->cache_entry); |
245 disk_cache::ScopedEntryPtr entry(*entryptr); | |
246 | 260 |
247 ServiceWorkerRequestResponseHeaders headers; | 261 ServiceWorkerRequestResponseHeaders headers; |
248 headers.set_method(request->method); | 262 headers.set_method(put_context->request->method); |
249 | 263 |
250 headers.set_status_code(response->status_code); | 264 headers.set_status_code(put_context->response->status_code); |
251 headers.set_status_text(response->status_text); | 265 headers.set_status_text(put_context->response->status_text); |
252 for (ServiceWorkerHeaderMap::const_iterator it = request->headers.begin(); | 266 for (ServiceWorkerHeaderMap::const_iterator it = |
253 it != request->headers.end(); | 267 put_context->request->headers.begin(); |
| 268 it != put_context->request->headers.end(); |
254 ++it) { | 269 ++it) { |
255 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map = | 270 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map = |
256 headers.add_request_headers(); | 271 headers.add_request_headers(); |
257 header_map->set_name(it->first); | 272 header_map->set_name(it->first); |
258 header_map->set_value(it->second); | 273 header_map->set_value(it->second); |
259 } | 274 } |
260 | 275 |
261 for (ServiceWorkerHeaderMap::const_iterator it = response->headers.begin(); | 276 for (ServiceWorkerHeaderMap::const_iterator it = |
262 it != response->headers.end(); | 277 put_context->response->headers.begin(); |
| 278 it != put_context->response->headers.end(); |
263 ++it) { | 279 ++it) { |
264 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map = | 280 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map = |
265 headers.add_response_headers(); | 281 headers.add_response_headers(); |
266 header_map->set_name(it->first); | 282 header_map->set_name(it->first); |
267 header_map->set_value(it->second); | 283 header_map->set_value(it->second); |
268 } | 284 } |
269 | 285 |
270 scoped_ptr<std::string> serialized(new std::string()); | 286 scoped_ptr<std::string> serialized(new std::string()); |
271 if (!headers.SerializeToString(serialized.get())) { | 287 if (!headers.SerializeToString(serialized.get())) { |
272 callback.Run(ServiceWorkerCache::ErrorTypeStorage); | 288 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage); |
273 return; | 289 return; |
274 } | 290 } |
275 | 291 |
276 scoped_refptr<net::StringIOBuffer> buffer( | 292 scoped_refptr<net::StringIOBuffer> buffer( |
277 new net::StringIOBuffer(serialized.Pass())); | 293 new net::StringIOBuffer(serialized.Pass())); |
278 | 294 |
279 // Get a temporary copy of the entry pointer before passing it in base::Bind. | 295 // Get a temporary copy of the entry pointer before passing it in base::Bind. |
280 disk_cache::Entry* tmp_entry_ptr = entry.get(); | 296 disk_cache::Entry* tmp_entry_ptr = put_context->cache_entry; |
281 | 297 |
282 net::CompletionCallback write_headers_callback = | 298 net::CompletionCallback write_headers_callback = base::Bind( |
283 base::Bind(PutDidWriteHeaders, | 299 PutDidWriteHeaders, base::Passed(put_context.Pass()), buffer->size()); |
284 base::Passed(response.Pass()), | |
285 callback, | |
286 base::Passed(entry.Pass()), | |
287 base::Passed(blob_data_handle.Pass()), | |
288 request_context, | |
289 buffer->size()); | |
290 | 300 |
291 rv = tmp_entry_ptr->WriteData(INDEX_HEADERS, | 301 rv = tmp_entry_ptr->WriteData(INDEX_HEADERS, |
292 0 /* offset */, | 302 0 /* offset */, |
293 buffer.get(), | 303 buffer.get(), |
294 buffer->size(), | 304 buffer->size(), |
295 write_headers_callback, | 305 write_headers_callback, |
296 true /* truncate */); | 306 true /* truncate */); |
297 | 307 |
298 if (rv != net::ERR_IO_PENDING) | 308 if (rv != net::ERR_IO_PENDING) |
299 write_headers_callback.Run(rv); | 309 write_headers_callback.Run(rv); |
300 } | 310 } |
301 | 311 |
302 void PutDidWriteHeaders(scoped_ptr<ServiceWorkerResponse> response, | 312 void PutDidWriteHeaders(scoped_ptr<PutContext> put_context, |
303 const ServiceWorkerCache::ErrorCallback& callback, | |
304 disk_cache::ScopedEntryPtr entry, | |
305 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | |
306 net::URLRequestContext* request_context, | |
307 int expected_bytes, | 313 int expected_bytes, |
308 int rv) { | 314 int rv) { |
309 if (rv != expected_bytes) { | 315 if (rv != expected_bytes) { |
310 entry->Doom(); | 316 put_context->cache_entry->Doom(); |
311 callback.Run(ServiceWorkerCache::ErrorTypeStorage); | 317 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage); |
312 return; | 318 return; |
313 } | 319 } |
314 | 320 |
315 // The metadata is written, now for the response content. The data is streamed | 321 // The metadata is written, now for the response content. The data is streamed |
316 // from the blob into the cache entry. | 322 // from the blob into the cache entry. |
317 | 323 |
318 if (response->blob_uuid.empty()) { | 324 if (put_context->response->blob_uuid.empty()) { |
319 callback.Run(ServiceWorkerCache::ErrorTypeOK); | 325 put_context->callback.Run(ServiceWorkerCache::ErrorTypeOK); |
320 return; | 326 return; |
321 } | 327 } |
322 | 328 |
323 DCHECK(blob_data_handle); | 329 DCHECK(put_context->blob_data_handle); |
324 | 330 |
| 331 disk_cache::ScopedEntryPtr entry(put_context->cache_entry); |
| 332 put_context->cache_entry = NULL; |
325 scoped_ptr<BlobReader> reader(new BlobReader(entry.Pass())); | 333 scoped_ptr<BlobReader> reader(new BlobReader(entry.Pass())); |
| 334 |
326 BlobReader* reader_ptr = reader.get(); | 335 BlobReader* reader_ptr = reader.get(); |
327 | 336 |
328 reader_ptr->StreamBlobToCache( | 337 // Grab some pointers before passing put_context in Bind. |
329 request_context, | 338 net::URLRequestContext* request_context = put_context->request_context; |
330 blob_data_handle.Pass(), | 339 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
331 base::Bind( | 340 put_context->blob_data_handle.Pass(); |
332 PutDidWriteBlobToCache, callback, base::Passed(reader.Pass()))); | 341 |
| 342 reader_ptr->StreamBlobToCache(request_context, |
| 343 blob_data_handle.Pass(), |
| 344 base::Bind(PutDidWriteBlobToCache, |
| 345 base::Passed(put_context.Pass()), |
| 346 base::Passed(reader.Pass()))); |
333 } | 347 } |
334 | 348 |
335 void PutDidWriteBlobToCache(const ServiceWorkerCache::ErrorCallback& callback, | 349 void PutDidWriteBlobToCache(scoped_ptr<PutContext> put_context, |
336 scoped_ptr<BlobReader> blob_reader, | 350 scoped_ptr<BlobReader> blob_reader, |
337 disk_cache::ScopedEntryPtr entry, | |
338 bool success) { | 351 bool success) { |
339 if (!success) { | 352 if (!success) { |
340 entry->Doom(); | 353 put_context->cache_entry->Doom(); |
341 callback.Run(ServiceWorkerCache::ErrorTypeStorage); | 354 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage); |
342 return; | 355 return; |
343 } | 356 } |
344 | 357 |
345 callback.Run(ServiceWorkerCache::ErrorTypeOK); | 358 put_context->callback.Run(ServiceWorkerCache::ErrorTypeOK); |
346 } | 359 } |
347 | 360 |
348 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, | 361 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
349 const ServiceWorkerCache::ResponseCallback& callback, | 362 const ServiceWorkerCache::ResponseCallback& callback, |
350 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 363 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
351 scoped_ptr<disk_cache::Entry*> entryptr, | 364 scoped_ptr<disk_cache::Entry*> entryptr, |
352 int rv) { | 365 int rv) { |
353 if (rv != net::OK) { | 366 if (rv != net::OK) { |
354 callback.Run(ServiceWorkerCache::ErrorTypeNotFound, | 367 callback.Run(ServiceWorkerCache::ErrorTypeNotFound, |
355 scoped_ptr<ServiceWorkerResponse>(), | 368 scoped_ptr<ServiceWorkerResponse>(), |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 | 675 |
663 // The vector of open entries in the backend. | 676 // The vector of open entries in the backend. |
664 Entries entries; | 677 Entries entries; |
665 | 678 |
666 // The output of the Keys function. | 679 // The output of the Keys function. |
667 scoped_ptr<ServiceWorkerCache::Requests> out_keys; | 680 scoped_ptr<ServiceWorkerCache::Requests> out_keys; |
668 | 681 |
669 // Used for enumerating cache entries. | 682 // Used for enumerating cache entries. |
670 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; | 683 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; |
671 disk_cache::Entry* enumerated_entry; | 684 disk_cache::Entry* enumerated_entry; |
| 685 |
| 686 DISALLOW_COPY_AND_ASSIGN(KeysContext); |
672 }; | 687 }; |
673 | 688 |
674 // static | 689 // static |
675 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache( | 690 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache( |
676 net::URLRequestContext* request_context, | 691 net::URLRequestContext* request_context, |
677 base::WeakPtr<storage::BlobStorageContext> blob_context) { | 692 base::WeakPtr<storage::BlobStorageContext> blob_context) { |
678 return make_scoped_refptr( | 693 return make_scoped_refptr( |
679 new ServiceWorkerCache(base::FilePath(), request_context, blob_context)); | 694 new ServiceWorkerCache(base::FilePath(), request_context, blob_context)); |
680 } | 695 } |
681 | 696 |
(...skipping 10 matching lines...) Expand all Loading... |
692 } | 707 } |
693 | 708 |
694 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() { | 709 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() { |
695 return weak_ptr_factory_.GetWeakPtr(); | 710 return weak_ptr_factory_.GetWeakPtr(); |
696 } | 711 } |
697 | 712 |
698 void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request, | 713 void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request, |
699 scoped_ptr<ServiceWorkerResponse> response, | 714 scoped_ptr<ServiceWorkerResponse> response, |
700 const ErrorCallback& callback) { | 715 const ErrorCallback& callback) { |
701 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 716 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
702 | |
703 if (!response->blob_uuid.empty()) { | 717 if (!response->blob_uuid.empty()) { |
704 if (!blob_storage_context_) { | 718 if (!blob_storage_context_) { |
705 callback.Run(ErrorTypeStorage); | 719 callback.Run(ErrorTypeStorage); |
706 return; | 720 return; |
707 } | 721 } |
708 blob_data_handle = | 722 blob_data_handle = |
709 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); | 723 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); |
710 if (!blob_data_handle) { | 724 if (!blob_data_handle) { |
711 callback.Run(ErrorTypeStorage); | 725 callback.Run(ErrorTypeStorage); |
712 return; | 726 return; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 void ServiceWorkerCache::PutImpl( | 864 void ServiceWorkerCache::PutImpl( |
851 scoped_ptr<ServiceWorkerFetchRequest> request, | 865 scoped_ptr<ServiceWorkerFetchRequest> request, |
852 scoped_ptr<ServiceWorkerResponse> response, | 866 scoped_ptr<ServiceWorkerResponse> response, |
853 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 867 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
854 const ErrorCallback& callback) { | 868 const ErrorCallback& callback) { |
855 if (!backend_) { | 869 if (!backend_) { |
856 callback.Run(ErrorTypeStorage); | 870 callback.Run(ErrorTypeStorage); |
857 return; | 871 return; |
858 } | 872 } |
859 | 873 |
860 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 874 scoped_ptr<PutContext> put_context(new PutContext(request.Pass(), |
| 875 response.Pass(), |
| 876 blob_data_handle.Pass(), |
| 877 callback, |
| 878 request_context_)); |
861 | 879 |
862 disk_cache::Entry** entry_ptr = entry.get(); | 880 disk_cache::Entry** entry_ptr = &put_context->cache_entry; |
863 | 881 ServiceWorkerFetchRequest* request_ptr = put_context->request.get(); |
864 ServiceWorkerFetchRequest* request_ptr = request.get(); | |
865 | 882 |
866 net::CompletionCallback create_entry_callback = | 883 net::CompletionCallback create_entry_callback = |
867 base::Bind(PutDidCreateEntry, | 884 base::Bind(PutDidCreateEntry, base::Passed(put_context.Pass())); |
868 base::Passed(request.Pass()), | |
869 base::Passed(response.Pass()), | |
870 callback, | |
871 base::Passed(entry.Pass()), | |
872 base::Passed(blob_data_handle.Pass()), | |
873 request_context_); | |
874 | 885 |
875 int rv = backend_->CreateEntry( | 886 int rv = backend_->CreateEntry( |
876 request_ptr->url.spec(), entry_ptr, create_entry_callback); | 887 request_ptr->url.spec(), entry_ptr, create_entry_callback); |
877 | 888 |
878 if (rv != net::ERR_IO_PENDING) | 889 if (rv != net::ERR_IO_PENDING) |
879 create_entry_callback.Run(rv); | 890 create_entry_callback.Run(rv); |
880 } | 891 } |
881 | 892 |
882 // static | 893 // static |
883 void ServiceWorkerCache::KeysDidOpenNextEntry( | 894 void ServiceWorkerCache::KeysDidOpenNextEntry( |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 initialized_ = true; | 1027 initialized_ = true; |
1017 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); | 1028 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); |
1018 it != init_callbacks_.end(); | 1029 it != init_callbacks_.end(); |
1019 ++it) { | 1030 ++it) { |
1020 it->Run(); | 1031 it->Run(); |
1021 } | 1032 } |
1022 init_callbacks_.clear(); | 1033 init_callbacks_.clear(); |
1023 } | 1034 } |
1024 | 1035 |
1025 } // namespace content | 1036 } // namespace content |
OLD | NEW |