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/renderer/cache_storage/cache_storage_dispatcher.h" | 5 #include "content/renderer/cache_storage/cache_storage_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 | 71 |
72 blink::WebVector<blink::WebServiceWorkerRequest> WebRequestsFromRequests( | 72 blink::WebVector<blink::WebServiceWorkerRequest> WebRequestsFromRequests( |
73 const std::vector<ServiceWorkerFetchRequest>& requests) { | 73 const std::vector<ServiceWorkerFetchRequest>& requests) { |
74 blink::WebVector<blink::WebServiceWorkerRequest> web_requests( | 74 blink::WebVector<blink::WebServiceWorkerRequest> web_requests( |
75 requests.size()); | 75 requests.size()); |
76 for (size_t i = 0; i < requests.size(); ++i) | 76 for (size_t i = 0; i < requests.size(); ++i) |
77 PopulateWebRequestFromFetchRequest(requests[i], &(web_requests[i])); | 77 PopulateWebRequestFromFetchRequest(requests[i], &(web_requests[i])); |
78 return web_requests; | 78 return web_requests; |
79 } | 79 } |
80 | 80 |
81 ServiceWorkerResponse ResponseFromWebResponse( | |
82 const blink::WebServiceWorkerResponse& web_response) { | |
83 ServiceWorkerHeaderMap headers; | |
84 GetServiceWorkerHeaderMapFromWebResponse(web_response, &headers); | |
85 ServiceWorkerHeaderList cors_exposed_header_names; | |
86 GetCorsExposedHeaderNamesFromWebResponse(web_response, | |
87 &cors_exposed_header_names); | |
88 // We don't support streaming for cache. | |
89 DCHECK(web_response.streamURL().isEmpty()); | |
90 return ServiceWorkerResponse( | |
91 web_response.url(), web_response.status(), | |
92 web_response.statusText().ascii(), web_response.responseType(), headers, | |
93 web_response.blobUUID().ascii(), web_response.blobSize(), | |
94 web_response.streamURL(), blink::WebServiceWorkerResponseErrorUnknown, | |
95 base::Time::FromInternalValue(web_response.responseTime()), | |
96 !web_response.cacheStorageCacheName().isNull(), | |
97 web_response.cacheStorageCacheName().utf8(), cors_exposed_header_names); | |
98 } | |
falken
2016/11/30 14:57:37
nice cleanup
| |
99 | |
100 CacheStorageCacheQueryParams QueryParamsFromWebQueryParams( | 81 CacheStorageCacheQueryParams QueryParamsFromWebQueryParams( |
101 const blink::WebServiceWorkerCache::QueryParams& web_query_params) { | 82 const blink::WebServiceWorkerCache::QueryParams& web_query_params) { |
102 CacheStorageCacheQueryParams query_params; | 83 CacheStorageCacheQueryParams query_params; |
103 query_params.ignore_search = web_query_params.ignoreSearch; | 84 query_params.ignore_search = web_query_params.ignoreSearch; |
104 query_params.ignore_method = web_query_params.ignoreMethod; | 85 query_params.ignore_method = web_query_params.ignoreMethod; |
105 query_params.ignore_vary = web_query_params.ignoreVary; | 86 query_params.ignore_vary = web_query_params.ignoreVary; |
106 query_params.cache_name = web_query_params.cacheName; | 87 query_params.cache_name = web_query_params.cacheName; |
107 return query_params; | 88 return query_params; |
108 } | 89 } |
109 | 90 |
110 CacheStorageCacheOperationType CacheOperationTypeFromWebCacheOperationType( | 91 CacheStorageCacheOperationType CacheOperationTypeFromWebCacheOperationType( |
111 blink::WebServiceWorkerCache::OperationType operation_type) { | 92 blink::WebServiceWorkerCache::OperationType operation_type) { |
112 switch (operation_type) { | 93 switch (operation_type) { |
113 case blink::WebServiceWorkerCache::OperationTypePut: | 94 case blink::WebServiceWorkerCache::OperationTypePut: |
114 return CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; | 95 return CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT; |
115 case blink::WebServiceWorkerCache::OperationTypeDelete: | 96 case blink::WebServiceWorkerCache::OperationTypeDelete: |
116 return CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE; | 97 return CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE; |
117 default: | 98 default: |
118 return CACHE_STORAGE_CACHE_OPERATION_TYPE_UNDEFINED; | 99 return CACHE_STORAGE_CACHE_OPERATION_TYPE_UNDEFINED; |
119 } | 100 } |
120 } | 101 } |
121 | 102 |
122 CacheStorageBatchOperation BatchOperationFromWebBatchOperation( | 103 CacheStorageBatchOperation BatchOperationFromWebBatchOperation( |
123 const blink::WebServiceWorkerCache::BatchOperation& web_operation) { | 104 const blink::WebServiceWorkerCache::BatchOperation& web_operation) { |
105 // We don't support streaming for cache. | |
106 DCHECK(web_operation.response.streamURL().isEmpty()); | |
107 | |
124 CacheStorageBatchOperation operation; | 108 CacheStorageBatchOperation operation; |
125 operation.operation_type = | 109 operation.operation_type = |
126 CacheOperationTypeFromWebCacheOperationType(web_operation.operationType); | 110 CacheOperationTypeFromWebCacheOperationType(web_operation.operationType); |
127 operation.request = FetchRequestFromWebRequest(web_operation.request); | 111 operation.request = FetchRequestFromWebRequest(web_operation.request); |
128 operation.response = ResponseFromWebResponse(web_operation.response); | 112 operation.response = |
113 GetServiceWorkerResponseFromWebResponse(web_operation.response); | |
129 operation.match_params = | 114 operation.match_params = |
130 QueryParamsFromWebQueryParams(web_operation.matchParams); | 115 QueryParamsFromWebQueryParams(web_operation.matchParams); |
131 return operation; | 116 return operation; |
132 } | 117 } |
133 | 118 |
134 template <typename T> | 119 template <typename T> |
135 void ClearCallbacksMapWithErrors(T* callbacks_map) { | 120 void ClearCallbacksMapWithErrors(T* callbacks_map) { |
136 typename T::iterator iter(callbacks_map); | 121 typename T::iterator iter(callbacks_map); |
137 while (!iter.IsAtEnd()) { | 122 while (!iter.IsAtEnd()) { |
138 iter.GetCurrentValue()->onError(blink::WebServiceWorkerCacheErrorNotFound); | 123 iter.GetCurrentValue()->onError(blink::WebServiceWorkerCacheErrorNotFound); |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 } | 610 } |
626 | 611 |
627 void CacheStorageDispatcher::OnWebCacheDestruction(int cache_id) { | 612 void CacheStorageDispatcher::OnWebCacheDestruction(int cache_id) { |
628 web_caches_.Remove(cache_id); | 613 web_caches_.Remove(cache_id); |
629 Send(new CacheStorageHostMsg_CacheClosed(cache_id)); | 614 Send(new CacheStorageHostMsg_CacheClosed(cache_id)); |
630 } | 615 } |
631 | 616 |
632 void CacheStorageDispatcher::PopulateWebResponseFromResponse( | 617 void CacheStorageDispatcher::PopulateWebResponseFromResponse( |
633 const ServiceWorkerResponse& response, | 618 const ServiceWorkerResponse& response, |
634 blink::WebServiceWorkerResponse* web_response) { | 619 blink::WebServiceWorkerResponse* web_response) { |
635 web_response->setURL(response.url); | 620 blink::WebVector<blink::WebURL> url_list(response.url_list.size()); |
621 std::transform(response.url_list.begin(), response.url_list.end(), | |
622 url_list.begin(), [](const GURL& url) { return url; }); | |
623 web_response->setURLList(url_list); | |
624 | |
636 web_response->setStatus(response.status_code); | 625 web_response->setStatus(response.status_code); |
637 web_response->setStatusText(WebString::fromASCII(response.status_text)); | 626 web_response->setStatusText(WebString::fromASCII(response.status_text)); |
638 web_response->setResponseType(response.response_type); | 627 web_response->setResponseType(response.response_type); |
639 web_response->setResponseTime(response.response_time.ToInternalValue()); | 628 web_response->setResponseTime(response.response_time.ToInternalValue()); |
640 web_response->setCacheStorageCacheName( | 629 web_response->setCacheStorageCacheName( |
641 response.is_in_cache_storage | 630 response.is_in_cache_storage |
642 ? blink::WebString::fromUTF8(response.cache_storage_cache_name) | 631 ? blink::WebString::fromUTF8(response.cache_storage_cache_name) |
643 : blink::WebString()); | 632 : blink::WebString()); |
644 blink::WebVector<blink::WebString> headers( | 633 blink::WebVector<blink::WebString> headers( |
645 response.cors_exposed_header_names.size()); | 634 response.cors_exposed_header_names.size()); |
(...skipping 20 matching lines...) Expand all Loading... | |
666 CacheStorageDispatcher::WebResponsesFromResponses( | 655 CacheStorageDispatcher::WebResponsesFromResponses( |
667 const std::vector<ServiceWorkerResponse>& responses) { | 656 const std::vector<ServiceWorkerResponse>& responses) { |
668 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( | 657 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( |
669 responses.size()); | 658 responses.size()); |
670 for (size_t i = 0; i < responses.size(); ++i) | 659 for (size_t i = 0; i < responses.size(); ++i) |
671 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); | 660 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); |
672 return web_responses; | 661 return web_responses; |
673 } | 662 } |
674 | 663 |
675 } // namespace content | 664 } // namespace content |
OLD | NEW |