| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/cachestorage/InspectorCacheStorageAgent.h" | 6 #include "modules/cachestorage/InspectorCacheStorageAgent.h" |
| 7 | 7 |
| 8 #include "core/InspectorBackendDispatcher.h" | 8 #include "core/InspectorBackendDispatcher.h" |
| 9 #include "core/InspectorTypeBuilder.h" | 9 #include "core/InspectorTypeBuilder.h" |
| 10 #include "platform/JSONValues.h" | 10 #include "platform/JSONValues.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId(ErrorStr
ing* errorString, const String& cacheId, String* cacheName) | 80 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId(ErrorStr
ing* errorString, const String& cacheId, String* cacheName) |
| 81 { | 81 { |
| 82 String securityOrigin; | 82 String securityOrigin; |
| 83 if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName)) { | 83 if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName)) { |
| 84 return nullptr; | 84 return nullptr; |
| 85 } | 85 } |
| 86 return assertCacheStorage(errorString, securityOrigin); | 86 return assertCacheStorage(errorString, securityOrigin); |
| 87 } | 87 } |
| 88 | 88 |
| 89 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) | 89 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError error) |
| 90 { | 90 { |
| 91 switch (*error) { | 91 switch (error) { |
| 92 case WebServiceWorkerCacheErrorNotImplemented: | 92 case WebServiceWorkerCacheErrorNotImplemented: |
| 93 return CString("not implemented."); | 93 return CString("not implemented."); |
| 94 break; | 94 break; |
| 95 case WebServiceWorkerCacheErrorNotFound: | 95 case WebServiceWorkerCacheErrorNotFound: |
| 96 return CString("not found."); | 96 return CString("not found."); |
| 97 break; | 97 break; |
| 98 case WebServiceWorkerCacheErrorExists: | 98 case WebServiceWorkerCacheErrorExists: |
| 99 return CString("cache already exists."); | 99 return CString("cache already exists."); |
| 100 break; | 100 break; |
| 101 default: | 101 default: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 126 .setSecurityOrigin(m_securityOrigin) | 126 .setSecurityOrigin(m_securityOrigin) |
| 127 .setCacheName(name) | 127 .setCacheName(name) |
| 128 .setCacheId(buildCacheId(m_securityOrigin, name)); | 128 .setCacheId(buildCacheId(m_securityOrigin, name)); |
| 129 array->addItem(entry); | 129 array->addItem(entry); |
| 130 } | 130 } |
| 131 m_callback->sendSuccess(array); | 131 m_callback->sendSuccess(array); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void onError(WebServiceWorkerCacheError* error) | 134 void onError(WebServiceWorkerCacheError* error) |
| 135 { | 135 { |
| 136 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); | 136 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(*error).data())); |
| 137 } | 137 } |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 String m_securityOrigin; | 140 String m_securityOrigin; |
| 141 RefPtrWillBePersistent<RequestCacheNamesCallback> m_callback; | 141 RefPtrWillBePersistent<RequestCacheNamesCallback> m_callback; |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 struct DataRequestParams { | 144 struct DataRequestParams { |
| 145 String cacheName; | 145 String cacheName; |
| 146 int skipCount; | 146 int skipCount; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 224 } |
| 225 ~GetCacheResponsesForRequestData() override { } | 225 ~GetCacheResponsesForRequestData() override { } |
| 226 | 226 |
| 227 void onSuccess(WebServiceWorkerResponse* response) | 227 void onSuccess(WebServiceWorkerResponse* response) |
| 228 { | 228 { |
| 229 m_accumulator->addRequestResponsePair(m_request, *response); | 229 m_accumulator->addRequestResponsePair(m_request, *response); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void onError(WebServiceWorkerCacheError* error) | 232 void onError(WebServiceWorkerCacheError* error) |
| 233 { | 233 { |
| 234 m_callback->sendFailure(String::format("Error requesting responses for c
ache %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(e
rror).data())); | 234 m_callback->sendFailure(String::format("Error requesting responses for c
ache %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(*
error).data())); |
| 235 } | 235 } |
| 236 | 236 |
| 237 private: | 237 private: |
| 238 DataRequestParams m_params; | 238 DataRequestParams m_params; |
| 239 WebServiceWorkerRequest m_request; | 239 WebServiceWorkerRequest m_request; |
| 240 RefPtr<ResponsesAccumulator> m_accumulator; | 240 RefPtr<ResponsesAccumulator> m_accumulator; |
| 241 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; | 241 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 class GetCacheKeysForRequestData : public WebServiceWorkerCache::CacheWithReques
tsCallbacks { | 244 class GetCacheKeysForRequestData : public WebServiceWorkerCache::CacheWithReques
tsCallbacks { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 264 | 264 |
| 265 for (size_t i = 0; i < requests->size(); i++) { | 265 for (size_t i = 0; i < requests->size(); i++) { |
| 266 const auto& request = (*requests)[i]; | 266 const auto& request = (*requests)[i]; |
| 267 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r
equest, accumulator, m_callback); | 267 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r
equest, accumulator, m_callback); |
| 268 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache:
:QueryParams()); | 268 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache:
:QueryParams()); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 void onError(WebServiceWorkerCacheError* error) | 272 void onError(WebServiceWorkerCacheError* error) |
| 273 { | 273 { |
| 274 m_callback->sendFailure(String::format("Error requesting requests for ca
che %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(err
or).data())); | 274 m_callback->sendFailure(String::format("Error requesting requests for ca
che %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(*er
ror).data())); |
| 275 } | 275 } |
| 276 | 276 |
| 277 private: | 277 private: |
| 278 DataRequestParams m_params; | 278 DataRequestParams m_params; |
| 279 OwnPtr<WebServiceWorkerCache> m_cache; | 279 OwnPtr<WebServiceWorkerCache> m_cache; |
| 280 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; | 280 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 class GetCacheForRequestData | 283 class GetCacheForRequestData |
| 284 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { | 284 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { |
| 285 WTF_MAKE_NONCOPYABLE(GetCacheForRequestData); | 285 WTF_MAKE_NONCOPYABLE(GetCacheForRequestData); |
| 286 | 286 |
| 287 public: | 287 public: |
| 288 GetCacheForRequestData(const DataRequestParams& params, PassRefPtrWillBeRawP
tr<RequestEntriesCallback> callback) | 288 GetCacheForRequestData(const DataRequestParams& params, PassRefPtrWillBeRawP
tr<RequestEntriesCallback> callback) |
| 289 : m_params(params) | 289 : m_params(params) |
| 290 , m_callback(callback) | 290 , m_callback(callback) |
| 291 { | 291 { |
| 292 } | 292 } |
| 293 ~GetCacheForRequestData() override { } | 293 ~GetCacheForRequestData() override { } |
| 294 | 294 |
| 295 void onSuccess(WebServiceWorkerCache* cache) | 295 void onSuccess(WebServiceWorkerCache* cache) |
| 296 { | 296 { |
| 297 auto* cacheRequest = new GetCacheKeysForRequestData(m_params, adoptPtr(c
ache), m_callback); | 297 auto* cacheRequest = new GetCacheKeysForRequestData(m_params, adoptPtr(c
ache), m_callback); |
| 298 cache->dispatchKeys(cacheRequest, nullptr, WebServiceWorkerCache::QueryP
arams()); | 298 cache->dispatchKeys(cacheRequest, nullptr, WebServiceWorkerCache::QueryP
arams()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void onError(WebServiceWorkerCacheError* error) | 301 void onError(WebServiceWorkerCacheError* error) |
| 302 { | 302 { |
| 303 m_callback->sendFailure(String::format("Error requesting cache %s: %s",
m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(error).data())); | 303 m_callback->sendFailure(String::format("Error requesting cache %s: %s",
m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(*error).data()))
; |
| 304 } | 304 } |
| 305 | 305 |
| 306 private: | 306 private: |
| 307 DataRequestParams m_params; | 307 DataRequestParams m_params; |
| 308 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; | 308 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; |
| 309 }; | 309 }; |
| 310 | 310 |
| 311 class DeleteCache : public WebServiceWorkerCacheStorage::CacheStorageCallbacks { | 311 class DeleteCache : public WebServiceWorkerCacheStorage::CacheStorageCallbacks { |
| 312 WTF_MAKE_NONCOPYABLE(DeleteCache); | 312 WTF_MAKE_NONCOPYABLE(DeleteCache); |
| 313 | 313 |
| 314 public: | 314 public: |
| 315 DeleteCache(PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) | 315 DeleteCache(PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) |
| 316 : m_callback(callback) | 316 : m_callback(callback) |
| 317 { | 317 { |
| 318 } | 318 } |
| 319 ~DeleteCache() override { } | 319 ~DeleteCache() override { } |
| 320 | 320 |
| 321 void onSuccess() | 321 void onSuccess() |
| 322 { | 322 { |
| 323 m_callback->sendSuccess(); | 323 m_callback->sendSuccess(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void onError(WebServiceWorkerCacheError* error) | 326 void onError(WebServiceWorkerCacheError* error) |
| 327 { | 327 { |
| 328 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); | 328 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(*error).data())); |
| 329 } | 329 } |
| 330 | 330 |
| 331 private: | 331 private: |
| 332 RefPtrWillBePersistent<DeleteCacheCallback> m_callback; | 332 RefPtrWillBePersistent<DeleteCacheCallback> m_callback; |
| 333 }; | 333 }; |
| 334 | 334 |
| 335 class DeleteCacheEntry : public WebServiceWorkerCache::CacheBatchCallbacks { | 335 class DeleteCacheEntry : public WebServiceWorkerCache::CacheBatchCallbacks { |
| 336 WTF_MAKE_NONCOPYABLE(DeleteCacheEntry); | 336 WTF_MAKE_NONCOPYABLE(DeleteCacheEntry); |
| 337 public: | 337 public: |
| 338 | 338 |
| 339 DeleteCacheEntry(PassRefPtrWillBeRawPtr<DeleteEntryCallback> callback) | 339 DeleteCacheEntry(PassRefPtrWillBeRawPtr<DeleteEntryCallback> callback) |
| 340 : m_callback(callback) | 340 : m_callback(callback) |
| 341 { | 341 { |
| 342 } | 342 } |
| 343 ~DeleteCacheEntry() override { } | 343 ~DeleteCacheEntry() override { } |
| 344 | 344 |
| 345 void onSuccess() | 345 void onSuccess() |
| 346 { | 346 { |
| 347 m_callback->sendSuccess(); | 347 m_callback->sendSuccess(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void onError(WebPassOwnPtr<WebServiceWorkerCacheError> e) | 350 void onError(WebServiceWorkerCacheError error) |
| 351 { | 351 { |
| 352 OwnPtr<WebServiceWorkerCacheError> error = e.release(); | 352 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); |
| 353 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error.get()).data())); | |
| 354 } | 353 } |
| 355 | 354 |
| 356 private: | 355 private: |
| 357 RefPtrWillBePersistent<DeleteEntryCallback> m_callback; | 356 RefPtrWillBePersistent<DeleteEntryCallback> m_callback; |
| 358 }; | 357 }; |
| 359 | 358 |
| 360 class GetCacheForDeleteEntry | 359 class GetCacheForDeleteEntry |
| 361 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { | 360 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { |
| 362 WTF_MAKE_NONCOPYABLE(GetCacheForDeleteEntry); | 361 WTF_MAKE_NONCOPYABLE(GetCacheForDeleteEntry); |
| 363 | 362 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 376 BatchOperation deleteOperation; | 375 BatchOperation deleteOperation; |
| 377 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDele
te; | 376 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDele
te; |
| 378 deleteOperation.request.setURL(KURL(ParsedURLString, m_requestSpec)); | 377 deleteOperation.request.setURL(KURL(ParsedURLString, m_requestSpec)); |
| 379 Vector<BatchOperation> operations; | 378 Vector<BatchOperation> operations; |
| 380 operations.append(deleteOperation); | 379 operations.append(deleteOperation); |
| 381 cache->dispatchBatch(deleteRequest, WebVector<BatchOperation>(operations
)); | 380 cache->dispatchBatch(deleteRequest, WebVector<BatchOperation>(operations
)); |
| 382 } | 381 } |
| 383 | 382 |
| 384 void onError(WebServiceWorkerCacheError* error) | 383 void onError(WebServiceWorkerCacheError* error) |
| 385 { | 384 { |
| 386 m_callback->sendFailure(String::format("Error requesting cache %s: %s",
m_cacheName.utf8().data(), serviceWorkerCacheErrorString(error).data())); | 385 m_callback->sendFailure(String::format("Error requesting cache %s: %s",
m_cacheName.utf8().data(), serviceWorkerCacheErrorString(*error).data())); |
| 387 } | 386 } |
| 388 | 387 |
| 389 private: | 388 private: |
| 390 String m_requestSpec; | 389 String m_requestSpec; |
| 391 String m_cacheName; | 390 String m_cacheName; |
| 392 RefPtrWillBePersistent<DeleteEntryCallback> m_callback; | 391 RefPtrWillBePersistent<DeleteEntryCallback> m_callback; |
| 393 }; | 392 }; |
| 394 | 393 |
| 395 } // namespace | 394 } // namespace |
| 396 | 395 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId(
errorString, cacheId, &cacheName); | 447 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId(
errorString, cacheId, &cacheName); |
| 449 if (!cache) { | 448 if (!cache) { |
| 450 callback->sendFailure(*errorString); | 449 callback->sendFailure(*errorString); |
| 451 return; | 450 return; |
| 452 } | 451 } |
| 453 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback)
, WebString(cacheName)); | 452 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback)
, WebString(cacheName)); |
| 454 } | 453 } |
| 455 | 454 |
| 456 | 455 |
| 457 } // namespace blink | 456 } // namespace blink |
| OLD | NEW |