| 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/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 DCHECK(!(operation.response.response_type == | 901 DCHECK(!(operation.response.response_type == |
| 902 blink::WebServiceWorkerResponseTypeOpaqueRedirect && | 902 blink::WebServiceWorkerResponseTypeOpaqueRedirect && |
| 903 operation.response.blob_size)); | 903 operation.response.blob_size)); |
| 904 std::unique_ptr<ServiceWorkerResponse> response(new ServiceWorkerResponse( | 904 std::unique_ptr<ServiceWorkerResponse> response(new ServiceWorkerResponse( |
| 905 operation.response.url, operation.response.status_code, | 905 operation.response.url, operation.response.status_code, |
| 906 operation.response.status_text, operation.response.response_type, | 906 operation.response.status_text, operation.response.response_type, |
| 907 operation.response.headers, operation.response.blob_uuid, | 907 operation.response.headers, operation.response.blob_uuid, |
| 908 operation.response.blob_size, operation.response.stream_url, | 908 operation.response.blob_size, operation.response.stream_url, |
| 909 operation.response.error, operation.response.response_time, | 909 operation.response.error, operation.response.response_time, |
| 910 false /* is_in_cache_storage */, | 910 false /* is_in_cache_storage */, |
| 911 std::string() /* cache_storage_cache_name */)); | 911 std::string() /* cache_storage_cache_name */, |
| 912 operation.response.cors_exposed_header_names)); |
| 912 | 913 |
| 913 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; | 914 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; |
| 914 | 915 |
| 915 if (!response->blob_uuid.empty()) { | 916 if (!response->blob_uuid.empty()) { |
| 916 if (!blob_storage_context_) { | 917 if (!blob_storage_context_) { |
| 917 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 918 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| 918 return; | 919 return; |
| 919 } | 920 } |
| 920 blob_data_handle = | 921 blob_data_handle = |
| 921 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); | 922 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 put_context->response->response_time.ToInternalValue()); | 1039 put_context->response->response_time.ToInternalValue()); |
| 1039 for (ServiceWorkerHeaderMap::const_iterator it = | 1040 for (ServiceWorkerHeaderMap::const_iterator it = |
| 1040 put_context->response->headers.begin(); | 1041 put_context->response->headers.begin(); |
| 1041 it != put_context->response->headers.end(); ++it) { | 1042 it != put_context->response->headers.end(); ++it) { |
| 1042 DCHECK_EQ(std::string::npos, it->first.find('\0')); | 1043 DCHECK_EQ(std::string::npos, it->first.find('\0')); |
| 1043 DCHECK_EQ(std::string::npos, it->second.find('\0')); | 1044 DCHECK_EQ(std::string::npos, it->second.find('\0')); |
| 1044 CacheHeaderMap* header_map = response_metadata->add_headers(); | 1045 CacheHeaderMap* header_map = response_metadata->add_headers(); |
| 1045 header_map->set_name(it->first); | 1046 header_map->set_name(it->first); |
| 1046 header_map->set_value(it->second); | 1047 header_map->set_value(it->second); |
| 1047 } | 1048 } |
| 1049 for (const auto& header : put_context->response->cors_exposed_header_names) |
| 1050 response_metadata->add_cors_exposed_header_names(header); |
| 1048 | 1051 |
| 1049 std::unique_ptr<std::string> serialized(new std::string()); | 1052 std::unique_ptr<std::string> serialized(new std::string()); |
| 1050 if (!metadata.SerializeToString(serialized.get())) { | 1053 if (!metadata.SerializeToString(serialized.get())) { |
| 1051 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 1054 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| 1052 return; | 1055 return; |
| 1053 } | 1056 } |
| 1054 | 1057 |
| 1055 scoped_refptr<net::StringIOBuffer> buffer( | 1058 scoped_refptr<net::StringIOBuffer> buffer( |
| 1056 new net::StringIOBuffer(std::move(serialized))); | 1059 new net::StringIOBuffer(std::move(serialized))); |
| 1057 | 1060 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 void CacheStorageCache::PopulateResponseMetadata( | 1513 void CacheStorageCache::PopulateResponseMetadata( |
| 1511 const CacheMetadata& metadata, | 1514 const CacheMetadata& metadata, |
| 1512 ServiceWorkerResponse* response) { | 1515 ServiceWorkerResponse* response) { |
| 1513 *response = ServiceWorkerResponse( | 1516 *response = ServiceWorkerResponse( |
| 1514 GURL(metadata.response().url()), metadata.response().status_code(), | 1517 GURL(metadata.response().url()), metadata.response().status_code(), |
| 1515 metadata.response().status_text(), | 1518 metadata.response().status_text(), |
| 1516 ProtoResponseTypeToWebResponseType(metadata.response().response_type()), | 1519 ProtoResponseTypeToWebResponseType(metadata.response().response_type()), |
| 1517 ServiceWorkerHeaderMap(), "", 0, GURL(), | 1520 ServiceWorkerHeaderMap(), "", 0, GURL(), |
| 1518 blink::WebServiceWorkerResponseErrorUnknown, | 1521 blink::WebServiceWorkerResponseErrorUnknown, |
| 1519 base::Time::FromInternalValue(metadata.response().response_time()), | 1522 base::Time::FromInternalValue(metadata.response().response_time()), |
| 1520 true /* is_in_cache_storage */, cache_name_); | 1523 true /* is_in_cache_storage */, cache_name_, |
| 1524 ServiceWorkerHeaderList( |
| 1525 metadata.response().cors_exposed_header_names().begin(), |
| 1526 metadata.response().cors_exposed_header_names().end())); |
| 1521 | 1527 |
| 1522 for (int i = 0; i < metadata.response().headers_size(); ++i) { | 1528 for (int i = 0; i < metadata.response().headers_size(); ++i) { |
| 1523 const CacheHeaderMap header = metadata.response().headers(i); | 1529 const CacheHeaderMap header = metadata.response().headers(i); |
| 1524 DCHECK_EQ(std::string::npos, header.name().find('\0')); | 1530 DCHECK_EQ(std::string::npos, header.name().find('\0')); |
| 1525 DCHECK_EQ(std::string::npos, header.value().find('\0')); | 1531 DCHECK_EQ(std::string::npos, header.value().find('\0')); |
| 1526 response->headers.insert(std::make_pair(header.name(), header.value())); | 1532 response->headers.insert(std::make_pair(header.name(), header.value())); |
| 1527 } | 1533 } |
| 1528 } | 1534 } |
| 1529 | 1535 |
| 1530 std::unique_ptr<storage::BlobDataHandle> | 1536 std::unique_ptr<storage::BlobDataHandle> |
| 1531 CacheStorageCache::PopulateResponseBody(disk_cache::ScopedEntryPtr entry, | 1537 CacheStorageCache::PopulateResponseBody(disk_cache::ScopedEntryPtr entry, |
| 1532 ServiceWorkerResponse* response) { | 1538 ServiceWorkerResponse* response) { |
| 1533 DCHECK(blob_storage_context_); | 1539 DCHECK(blob_storage_context_); |
| 1534 | 1540 |
| 1535 // Create a blob with the response body data. | 1541 // Create a blob with the response body data. |
| 1536 response->blob_size = entry->GetDataSize(INDEX_RESPONSE_BODY); | 1542 response->blob_size = entry->GetDataSize(INDEX_RESPONSE_BODY); |
| 1537 response->blob_uuid = base::GenerateGUID(); | 1543 response->blob_uuid = base::GenerateGUID(); |
| 1538 storage::BlobDataBuilder blob_data(response->blob_uuid); | 1544 storage::BlobDataBuilder blob_data(response->blob_uuid); |
| 1539 | 1545 |
| 1540 disk_cache::Entry* temp_entry = entry.get(); | 1546 disk_cache::Entry* temp_entry = entry.get(); |
| 1541 blob_data.AppendDiskCacheEntryWithSideData( | 1547 blob_data.AppendDiskCacheEntryWithSideData( |
| 1542 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, | 1548 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, |
| 1543 INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); | 1549 INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); |
| 1544 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1550 return blob_storage_context_->AddFinishedBlob(&blob_data); |
| 1545 } | 1551 } |
| 1546 | 1552 |
| 1547 } // namespace content | 1553 } // namespace content |
| OLD | NEW |