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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 336 } |
337 | 337 |
338 // Input | 338 // Input |
339 scoped_ptr<ServiceWorkerFetchRequest> request; | 339 scoped_ptr<ServiceWorkerFetchRequest> request; |
340 ServiceWorkerCache::ResponseCallback original_callback; | 340 ServiceWorkerCache::ResponseCallback original_callback; |
341 base::WeakPtr<storage::BlobStorageContext> blob_storage_context; | 341 base::WeakPtr<storage::BlobStorageContext> blob_storage_context; |
342 disk_cache::Entry* entry; | 342 disk_cache::Entry* entry; |
343 | 343 |
344 // Output | 344 // Output |
345 scoped_ptr<ServiceWorkerResponse> response; | 345 scoped_ptr<ServiceWorkerResponse> response; |
346 scoped_refptr<storage::BlobData> blob_data; | 346 scoped_ptr<storage::BlobDataBuilder> blob_data; |
347 | 347 |
348 // For reading the cache entry data into a blob. | 348 // For reading the cache entry data into a blob. |
349 scoped_refptr<net::IOBufferWithSize> response_body_buffer; | 349 scoped_refptr<net::IOBufferWithSize> response_body_buffer; |
350 size_t total_bytes_read; | 350 size_t total_bytes_read; |
351 | 351 |
352 DISALLOW_COPY_AND_ASSIGN(MatchContext); | 352 DISALLOW_COPY_AND_ASSIGN(MatchContext); |
353 }; | 353 }; |
354 | 354 |
355 // The state needed to pass between ServiceWorkerCache::Put callbacks. | 355 // The state needed to pass between ServiceWorkerCache::Put callbacks. |
356 struct ServiceWorkerCache::PutContext { | 356 struct ServiceWorkerCache::PutContext { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 // Stream the response body into a blob. | 728 // Stream the response body into a blob. |
729 if (!match_context->blob_storage_context) { | 729 if (!match_context->blob_storage_context) { |
730 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 730 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, |
731 scoped_ptr<ServiceWorkerResponse>(), | 731 scoped_ptr<ServiceWorkerResponse>(), |
732 scoped_ptr<storage::BlobDataHandle>()); | 732 scoped_ptr<storage::BlobDataHandle>()); |
733 return; | 733 return; |
734 } | 734 } |
735 | 735 |
736 response->blob_uuid = base::GenerateGUID(); | 736 response->blob_uuid = base::GenerateGUID(); |
737 | 737 |
738 match_context->blob_data = new storage::BlobData(response->blob_uuid); | 738 match_context->blob_data.reset( |
| 739 new storage::BlobDataBuilder(response->blob_uuid)); |
739 match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize); | 740 match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize); |
740 | 741 |
741 disk_cache::Entry* tmp_entry_ptr = match_context->entry; | 742 disk_cache::Entry* tmp_entry_ptr = match_context->entry; |
742 net::IOBufferWithSize* response_body_buffer = | 743 net::IOBufferWithSize* response_body_buffer = |
743 match_context->response_body_buffer.get(); | 744 match_context->response_body_buffer.get(); |
744 | 745 |
745 net::CompletionCallback read_callback = base::Bind( | 746 net::CompletionCallback read_callback = base::Bind( |
746 &ServiceWorkerCache::MatchDidReadResponseBodyData, | 747 &ServiceWorkerCache::MatchDidReadResponseBodyData, |
747 weak_ptr_factory_.GetWeakPtr(), base::Passed(match_context.Pass())); | 748 weak_ptr_factory_.GetWeakPtr(), base::Passed(match_context.Pass())); |
748 | 749 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 scoped_ptr<MatchContext> match_context) { | 804 scoped_ptr<MatchContext> match_context) { |
804 if (!match_context->blob_storage_context) { | 805 if (!match_context->blob_storage_context) { |
805 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 806 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, |
806 scoped_ptr<ServiceWorkerResponse>(), | 807 scoped_ptr<ServiceWorkerResponse>(), |
807 scoped_ptr<storage::BlobDataHandle>()); | 808 scoped_ptr<storage::BlobDataHandle>()); |
808 return; | 809 return; |
809 } | 810 } |
810 | 811 |
811 scoped_ptr<storage::BlobDataHandle> blob_data_handle( | 812 scoped_ptr<storage::BlobDataHandle> blob_data_handle( |
812 match_context->blob_storage_context->AddFinishedBlob( | 813 match_context->blob_storage_context->AddFinishedBlob( |
813 match_context->blob_data.get())); | 814 *match_context->blob_data.get())); |
814 | 815 |
815 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK, | 816 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK, |
816 match_context->response.Pass(), | 817 match_context->response.Pass(), |
817 blob_data_handle.Pass()); | 818 blob_data_handle.Pass()); |
818 } | 819 } |
819 | 820 |
820 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { | 821 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { |
821 if (backend_state_ != BACKEND_OPEN) { | 822 if (backend_state_ != BACKEND_OPEN) { |
822 put_context->callback.Run(ErrorTypeStorage, | 823 put_context->callback.Run(ErrorTypeStorage, |
823 scoped_ptr<ServiceWorkerResponse>(), | 824 scoped_ptr<ServiceWorkerResponse>(), |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 | 1216 |
1216 void ServiceWorkerCache::PendingRequestsCallback( | 1217 void ServiceWorkerCache::PendingRequestsCallback( |
1217 const RequestsCallback& callback, | 1218 const RequestsCallback& callback, |
1218 ErrorType error, | 1219 ErrorType error, |
1219 scoped_ptr<Requests> requests) { | 1220 scoped_ptr<Requests> requests) { |
1220 callback.Run(error, requests.Pass()); | 1221 callback.Run(error, requests.Pass()); |
1221 DecPendingOps(); | 1222 DecPendingOps(); |
1222 } | 1223 } |
1223 | 1224 |
1224 } // namespace content | 1225 } // namespace content |
OLD | NEW |