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" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/profiler/scoped_tracker.h" | 12 #include "base/profiler/scoped_tracker.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "content/browser/service_worker/service_worker_cache.pb.h" | 14 #include "content/browser/service_worker/service_worker_cache.pb.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/disk_cache/disk_cache.h" | 18 #include "net/disk_cache/disk_cache.h" |
19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 20 #include "storage/browser/blob/blob_data_builder.h" |
20 #include "storage/browser/blob/blob_data_handle.h" | 21 #include "storage/browser/blob/blob_data_handle.h" |
21 #include "storage/browser/blob/blob_storage_context.h" | 22 #include "storage/browser/blob/blob_storage_context.h" |
22 #include "storage/browser/blob/blob_url_request_job_factory.h" | 23 #include "storage/browser/blob/blob_url_request_job_factory.h" |
23 #include "storage/browser/quota/quota_manager_proxy.h" | 24 #include "storage/browser/quota/quota_manager_proxy.h" |
24 #include "third_party/WebKit/public/platform/WebServiceWorkerResponseType.h" | 25 #include "third_party/WebKit/public/platform/WebServiceWorkerResponseType.h" |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 337 } |
337 | 338 |
338 // Input | 339 // Input |
339 scoped_ptr<ServiceWorkerFetchRequest> request; | 340 scoped_ptr<ServiceWorkerFetchRequest> request; |
340 ServiceWorkerCache::ResponseCallback original_callback; | 341 ServiceWorkerCache::ResponseCallback original_callback; |
341 base::WeakPtr<storage::BlobStorageContext> blob_storage_context; | 342 base::WeakPtr<storage::BlobStorageContext> blob_storage_context; |
342 disk_cache::Entry* entry; | 343 disk_cache::Entry* entry; |
343 | 344 |
344 // Output | 345 // Output |
345 scoped_ptr<ServiceWorkerResponse> response; | 346 scoped_ptr<ServiceWorkerResponse> response; |
346 scoped_refptr<storage::BlobData> blob_data; | 347 scoped_ptr<storage::BlobDataBuilder> blob_data; |
347 | 348 |
348 // For reading the cache entry data into a blob. | 349 // For reading the cache entry data into a blob. |
349 scoped_refptr<net::IOBufferWithSize> response_body_buffer; | 350 scoped_refptr<net::IOBufferWithSize> response_body_buffer; |
350 size_t total_bytes_read; | 351 size_t total_bytes_read; |
351 | 352 |
352 DISALLOW_COPY_AND_ASSIGN(MatchContext); | 353 DISALLOW_COPY_AND_ASSIGN(MatchContext); |
353 }; | 354 }; |
354 | 355 |
355 // The state needed to pass between ServiceWorkerCache::Put callbacks. | 356 // The state needed to pass between ServiceWorkerCache::Put callbacks. |
356 struct ServiceWorkerCache::PutContext { | 357 struct ServiceWorkerCache::PutContext { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 // Stream the response body into a blob. | 729 // Stream the response body into a blob. |
729 if (!match_context->blob_storage_context) { | 730 if (!match_context->blob_storage_context) { |
730 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 731 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, |
731 scoped_ptr<ServiceWorkerResponse>(), | 732 scoped_ptr<ServiceWorkerResponse>(), |
732 scoped_ptr<storage::BlobDataHandle>()); | 733 scoped_ptr<storage::BlobDataHandle>()); |
733 return; | 734 return; |
734 } | 735 } |
735 | 736 |
736 response->blob_uuid = base::GenerateGUID(); | 737 response->blob_uuid = base::GenerateGUID(); |
737 | 738 |
738 match_context->blob_data = new storage::BlobData(response->blob_uuid); | 739 match_context->blob_data.reset( |
| 740 new storage::BlobDataBuilder(response->blob_uuid)); |
739 match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize); | 741 match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize); |
740 | 742 |
741 disk_cache::Entry* tmp_entry_ptr = match_context->entry; | 743 disk_cache::Entry* tmp_entry_ptr = match_context->entry; |
742 net::IOBufferWithSize* response_body_buffer = | 744 net::IOBufferWithSize* response_body_buffer = |
743 match_context->response_body_buffer.get(); | 745 match_context->response_body_buffer.get(); |
744 | 746 |
745 net::CompletionCallback read_callback = base::Bind( | 747 net::CompletionCallback read_callback = base::Bind( |
746 &ServiceWorkerCache::MatchDidReadResponseBodyData, | 748 &ServiceWorkerCache::MatchDidReadResponseBodyData, |
747 weak_ptr_factory_.GetWeakPtr(), base::Passed(match_context.Pass())); | 749 weak_ptr_factory_.GetWeakPtr(), base::Passed(match_context.Pass())); |
748 | 750 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 scoped_ptr<MatchContext> match_context) { | 805 scoped_ptr<MatchContext> match_context) { |
804 if (!match_context->blob_storage_context) { | 806 if (!match_context->blob_storage_context) { |
805 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 807 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage, |
806 scoped_ptr<ServiceWorkerResponse>(), | 808 scoped_ptr<ServiceWorkerResponse>(), |
807 scoped_ptr<storage::BlobDataHandle>()); | 809 scoped_ptr<storage::BlobDataHandle>()); |
808 return; | 810 return; |
809 } | 811 } |
810 | 812 |
811 scoped_ptr<storage::BlobDataHandle> blob_data_handle( | 813 scoped_ptr<storage::BlobDataHandle> blob_data_handle( |
812 match_context->blob_storage_context->AddFinishedBlob( | 814 match_context->blob_storage_context->AddFinishedBlob( |
813 match_context->blob_data.get())); | 815 *match_context->blob_data.get())); |
814 | 816 |
815 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK, | 817 match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK, |
816 match_context->response.Pass(), | 818 match_context->response.Pass(), |
817 blob_data_handle.Pass()); | 819 blob_data_handle.Pass()); |
818 } | 820 } |
819 | 821 |
820 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { | 822 void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) { |
821 if (backend_state_ != BACKEND_OPEN) { | 823 if (backend_state_ != BACKEND_OPEN) { |
822 put_context->callback.Run(ErrorTypeStorage, | 824 put_context->callback.Run(ErrorTypeStorage, |
823 scoped_ptr<ServiceWorkerResponse>(), | 825 scoped_ptr<ServiceWorkerResponse>(), |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 | 1217 |
1216 void ServiceWorkerCache::PendingRequestsCallback( | 1218 void ServiceWorkerCache::PendingRequestsCallback( |
1217 const RequestsCallback& callback, | 1219 const RequestsCallback& callback, |
1218 ErrorType error, | 1220 ErrorType error, |
1219 scoped_ptr<Requests> requests) { | 1221 scoped_ptr<Requests> requests) { |
1220 callback.Run(error, requests.Pass()); | 1222 callback.Run(error, requests.Pass()); |
1221 DecPendingOps(); | 1223 DecPendingOps(); |
1222 } | 1224 } |
1223 | 1225 |
1224 } // namespace content | 1226 } // namespace content |
OLD | NEW |