| 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 "modules/cachestorage/InspectorCacheStorageAgent.h" | 5 #include "modules/cachestorage/InspectorCacheStorageAgent.h" |
| 6 | 6 |
| 7 #include "platform/JSONValues.h" | 7 #include "platform/JSONValues.h" |
| 8 #include "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" |
| 9 #include "platform/inspector_protocol/Dispatcher.h" | 9 #include "platform/inspector_protocol/Dispatcher.h" |
| 10 #include "platform/inspector_protocol/TypeBuilder.h" | 10 #include "platform/inspector_protocol/TypeBuilder.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 RequestCacheNames(const String& securityOrigin, PassRefPtr<RequestCacheNames
Callback> callback) | 116 RequestCacheNames(const String& securityOrigin, PassRefPtr<RequestCacheNames
Callback> callback) |
| 117 : m_securityOrigin(securityOrigin) | 117 : m_securityOrigin(securityOrigin) |
| 118 , m_callback(callback) | 118 , m_callback(callback) |
| 119 { | 119 { |
| 120 } | 120 } |
| 121 | 121 |
| 122 ~RequestCacheNames() override { } | 122 ~RequestCacheNames() override { } |
| 123 | 123 |
| 124 void onSuccess(const WebVector<WebString>& caches) override | 124 void onSuccess(const WebVector<WebString>& caches) override |
| 125 { | 125 { |
| 126 RefPtr<Array<Cache>> array = Array<Cache>::create(); | 126 OwnPtr<Array<Cache>> array = Array<Cache>::create(); |
| 127 for (size_t i = 0; i < caches.size(); i++) { | 127 for (size_t i = 0; i < caches.size(); i++) { |
| 128 String name = String(caches[i]); | 128 String name = String(caches[i]); |
| 129 RefPtr<Cache> entry = Cache::create() | 129 OwnPtr<Cache> entry = Cache::create() |
| 130 .setSecurityOrigin(m_securityOrigin) | 130 .setSecurityOrigin(m_securityOrigin) |
| 131 .setCacheName(name) | 131 .setCacheName(name) |
| 132 .setCacheId(buildCacheId(m_securityOrigin, name)); | 132 .setCacheId(buildCacheId(m_securityOrigin, name)).build(); |
| 133 array->addItem(entry); | 133 array->addItem(entry.release()); |
| 134 } | 134 } |
| 135 m_callback->sendSuccess(array); | 135 m_callback->sendSuccess(array.release()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void onError(WebServiceWorkerCacheError error) override | 138 void onError(WebServiceWorkerCacheError error) override |
| 139 { | 139 { |
| 140 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); | 140 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); |
| 141 } | 141 } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 String m_securityOrigin; | 144 String m_securityOrigin; |
| 145 RefPtr<RequestCacheNamesCallback> m_callback; | 145 RefPtr<RequestCacheNamesCallback> m_callback; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 { | 189 { |
| 190 return WTF::codePointCompareLessThan(a.request, b.request); | 190 return WTF::codePointCompareLessThan(a.request, b.request); |
| 191 }); | 191 }); |
| 192 if (m_params.skipCount > 0) | 192 if (m_params.skipCount > 0) |
| 193 m_responses.remove(0, m_params.skipCount); | 193 m_responses.remove(0, m_params.skipCount); |
| 194 bool hasMore = false; | 194 bool hasMore = false; |
| 195 if (static_cast<size_t>(m_params.pageSize) < m_responses.size()) { | 195 if (static_cast<size_t>(m_params.pageSize) < m_responses.size()) { |
| 196 m_responses.remove(m_params.pageSize, m_responses.size() - m_params.
pageSize); | 196 m_responses.remove(m_params.pageSize, m_responses.size() - m_params.
pageSize); |
| 197 hasMore = true; | 197 hasMore = true; |
| 198 } | 198 } |
| 199 RefPtr<Array<DataEntry>> array = Array<DataEntry>::create(); | 199 OwnPtr<Array<DataEntry>> array = Array<DataEntry>::create(); |
| 200 for (const auto& requestResponse : m_responses) { | 200 for (const auto& requestResponse : m_responses) { |
| 201 RefPtr<DataEntry> entry = DataEntry::create() | 201 OwnPtr<DataEntry> entry = DataEntry::create() |
| 202 .setRequest(requestResponse.request) | 202 .setRequest(requestResponse.request) |
| 203 .setResponse(requestResponse.response); | 203 .setResponse(requestResponse.response).build(); |
| 204 array->addItem(entry); | 204 array->addItem(entry.release()); |
| 205 } | 205 } |
| 206 m_callback->sendSuccess(array, hasMore); | 206 m_callback->sendSuccess(array.release(), hasMore); |
| 207 } | 207 } |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 DataRequestParams m_params; | 210 DataRequestParams m_params; |
| 211 int m_numResponsesLeft; | 211 int m_numResponsesLeft; |
| 212 Vector<RequestResponse> m_responses; | 212 Vector<RequestResponse> m_responses; |
| 213 RefPtr<RequestEntriesCallback> m_callback; | 213 RefPtr<RequestEntriesCallback> m_callback; |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 class GetCacheResponsesForRequestData : public WebServiceWorkerCache::CacheMatch
Callbacks { | 216 class GetCacheResponsesForRequestData : public WebServiceWorkerCache::CacheMatch
Callbacks { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 , m_cache(cache) | 254 , m_cache(cache) |
| 255 , m_callback(callback) | 255 , m_callback(callback) |
| 256 { | 256 { |
| 257 } | 257 } |
| 258 ~GetCacheKeysForRequestData() override { } | 258 ~GetCacheKeysForRequestData() override { } |
| 259 | 259 |
| 260 WebServiceWorkerCache* cache() { return m_cache.get(); } | 260 WebServiceWorkerCache* cache() { return m_cache.get(); } |
| 261 void onSuccess(const WebVector<WebServiceWorkerRequest>& requests) override | 261 void onSuccess(const WebVector<WebServiceWorkerRequest>& requests) override |
| 262 { | 262 { |
| 263 if (requests.isEmpty()) { | 263 if (requests.isEmpty()) { |
| 264 RefPtr<Array<DataEntry>> array = Array<DataEntry>::create(); | 264 OwnPtr<Array<DataEntry>> array = Array<DataEntry>::create(); |
| 265 m_callback->sendSuccess(array, false); | 265 m_callback->sendSuccess(array.release(), false); |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumul
ator(requests.size(), m_params, m_callback)); | 268 RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumul
ator(requests.size(), m_params, m_callback)); |
| 269 | 269 |
| 270 for (size_t i = 0; i < requests.size(); i++) { | 270 for (size_t i = 0; i < requests.size(); i++) { |
| 271 const auto& request = requests[i]; | 271 const auto& request = requests[i]; |
| 272 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r
equest, accumulator, m_callback); | 272 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r
equest, accumulator, m_callback); |
| 273 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache:
:QueryParams()); | 273 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache:
:QueryParams()); |
| 274 } | 274 } |
| 275 } | 275 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId(
errorString, cacheId, &cacheName); | 461 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId(
errorString, cacheId, &cacheName); |
| 462 if (!cache) { | 462 if (!cache) { |
| 463 callback->sendFailure(*errorString); | 463 callback->sendFailure(*errorString); |
| 464 return; | 464 return; |
| 465 } | 465 } |
| 466 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback)
, WebString(cacheName)); | 466 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback)
, WebString(cacheName)); |
| 467 } | 467 } |
| 468 | 468 |
| 469 | 469 |
| 470 } // namespace blink | 470 } // namespace blink |
| OLD | NEW |