Chromium Code Reviews| 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/serviceworkers/InspectorServiceWorkerCacheAgent.h" | 6 #include "modules/serviceworkers/InspectorServiceWorkerCacheAgent.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 "modules/serviceworkers/ServiceWorkerGlobalScope.h" | |
| 11 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | |
| 12 #include "platform/JSONValues.h" | 10 #include "platform/JSONValues.h" |
| 13 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 14 #include "platform/weborigin/DatabaseIdentifier.h" | 12 #include "platform/weborigin/DatabaseIdentifier.h" |
| 13 #include "platform/weborigin/SecurityOrigin.h" | |
| 15 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
| 16 #include "public/platform/WebServiceWorkerCache.h" | 15 #include "public/platform/WebServiceWorkerCache.h" |
| 17 #include "public/platform/WebServiceWorkerCacheError.h" | 16 #include "public/platform/WebServiceWorkerCacheError.h" |
| 18 #include "public/platform/WebServiceWorkerCacheStorage.h" | 17 #include "public/platform/WebServiceWorkerCacheStorage.h" |
| 19 #include "public/platform/WebServiceWorkerRequest.h" | 18 #include "public/platform/WebServiceWorkerRequest.h" |
| 20 #include "public/platform/WebServiceWorkerResponse.h" | 19 #include "public/platform/WebServiceWorkerResponse.h" |
| 21 #include "public/platform/WebString.h" | 20 #include "public/platform/WebString.h" |
| 22 #include "public/platform/WebURL.h" | 21 #include "public/platform/WebURL.h" |
| 23 #include "public/platform/WebVector.h" | 22 #include "public/platform/WebVector.h" |
| 24 #include "wtf/Noncopyable.h" | 23 #include "wtf/Noncopyable.h" |
| 25 #include "wtf/OwnPtr.h" | 24 #include "wtf/OwnPtr.h" |
| 26 #include "wtf/PassRefPtr.h" | 25 #include "wtf/PassRefPtr.h" |
| 27 #include "wtf/RefCounted.h" | 26 #include "wtf/RefCounted.h" |
| 28 #include "wtf/RefPtr.h" | 27 #include "wtf/RefPtr.h" |
| 29 #include "wtf/Vector.h" | 28 #include "wtf/Vector.h" |
| 30 #include "wtf/text/StringBuilder.h" | 29 #include "wtf/text/StringBuilder.h" |
| 31 | 30 |
| 32 #include <algorithm> | 31 #include <algorithm> |
| 33 | 32 |
| 34 using blink::TypeBuilder::Array; | 33 using blink::TypeBuilder::Array; |
| 35 using blink::TypeBuilder::ServiceWorkerCache::DataEntry; | 34 using blink::TypeBuilder::CacheStorage::DataEntry; |
| 36 | 35 |
| 37 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Del eteCacheCallback DeleteCacheCallback; | 36 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::DeleteCac heCallback DeleteCacheCallback; |
| 38 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Req uestCacheNamesCallback RequestCacheNamesCallback; | 37 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestCa cheNamesCallback RequestCacheNamesCallback; |
| 39 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Req uestEntriesCallback RequestEntriesCallback; | 38 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestEn triesCallback RequestEntriesCallback; |
| 40 typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback; | 39 typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback; |
| 41 | 40 |
| 42 namespace blink { | 41 namespace blink { |
| 43 | 42 |
| 44 namespace { | 43 namespace { |
| 45 | 44 |
| 46 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorSt ring, ServiceWorkerGlobalScope* globalScope) | 45 WebServiceWorkerCacheStorage* assertCacheStorage(ErrorString* errorString, const String& securityOrigin) |
| 47 { | 46 { |
| 48 String identifier = createDatabaseIdentifierFromSecurityOrigin(globalScope-> securityOrigin()); | 47 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin); |
| 49 OwnPtr<WebServiceWorkerCacheStorage> caches = adoptPtr(Platform::current()-> cacheStorage(identifier)); | 48 String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get ()); |
| 50 if (!caches) { | 49 WebServiceWorkerCacheStorage* cache = Platform::current()->cacheStorage(ide ntifier); |
|
horo
2015/04/03 01:23:46
nit: unnecessary apace after =
horo
2015/04/03 01:23:46
Who deletes this |cache|?
https://code.google.com
jsbell
2015/04/03 03:21:08
Agreed - this this should keep the PassOwnPtr<WebS
dmurph
2015/04/08 19:35:35
Done.
| |
| 51 *errorString = "Cache Storage not available in global scope."; | 50 if (!cache) |
| 52 return nullptr; | 51 *errorString = "Could not find cache storage."; |
| 53 } | 52 return cache; |
| 54 return caches.release(); | |
| 55 } | 53 } |
| 56 | 54 |
| 57 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) | 55 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) |
| 58 { | 56 { |
| 59 switch (*error) { | 57 switch (*error) { |
| 60 case WebServiceWorkerCacheErrorNotImplemented: | 58 case WebServiceWorkerCacheErrorNotImplemented: |
| 61 return CString("not implemented."); | 59 return CString("not implemented."); |
| 62 break; | 60 break; |
| 63 case WebServiceWorkerCacheErrorNotFound: | 61 case WebServiceWorkerCacheErrorNotFound: |
| 64 return CString("not found."); | 62 return CString("not found."); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 { | 281 { |
| 284 m_callback->sendFailure(String::format("Error requesting cache names: %s ", serviceWorkerCacheErrorString(error).data())); | 282 m_callback->sendFailure(String::format("Error requesting cache names: %s ", serviceWorkerCacheErrorString(error).data())); |
| 285 } | 283 } |
| 286 | 284 |
| 287 private: | 285 private: |
| 288 RefPtrWillBePersistent<DeleteCacheCallback> m_callback; | 286 RefPtrWillBePersistent<DeleteCacheCallback> m_callback; |
| 289 }; | 287 }; |
| 290 | 288 |
| 291 } // namespace | 289 } // namespace |
| 292 | 290 |
| 293 InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(ServiceWorker GlobalScope* scope) | 291 InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent() |
| 294 : InspectorBaseAgent<blink::InspectorServiceWorkerCacheAgent, InspectorFront end::ServiceWorkerCache>("ServiceWorkerCache") | 292 : InspectorBaseAgent<InspectorServiceWorkerCacheAgent, InspectorFrontend::Ca cheStorage>("CacheStorage") |
| 295 , m_globalScope(scope) | |
| 296 { | 293 { |
| 297 } | 294 } |
| 298 | 295 |
| 299 InspectorServiceWorkerCacheAgent::~InspectorServiceWorkerCacheAgent() { } | 296 InspectorServiceWorkerCacheAgent::~InspectorServiceWorkerCacheAgent() { } |
| 300 | 297 |
| 301 DEFINE_TRACE(InspectorServiceWorkerCacheAgent) | 298 DEFINE_TRACE(InspectorServiceWorkerCacheAgent) |
| 302 { | 299 { |
| 303 InspectorBaseAgent::trace(visitor); | 300 InspectorBaseAgent::trace(visitor); |
| 304 } | 301 } |
| 305 | 302 |
| 306 void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorStrin g, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) | 303 void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorStrin g, const String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallbac k> callback) |
| 307 { | 304 { |
| 308 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); | 305 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, securi tyOrigin); |
| 309 if (!cache) { | 306 if (!cache) { |
| 310 callback->sendFailure(*errorString); | 307 callback->sendFailure(*errorString); |
| 311 return; | 308 return; |
| 312 } | 309 } |
| 313 cache->dispatchKeys(new RequestCacheNames(callback)); | 310 cache->dispatchKeys(new RequestCacheNames(callback)); |
| 314 } | 311 } |
| 315 | 312 |
| 316 | 313 void InspectorServiceWorkerCacheAgent::requestEntries(ErrorString* errorString, const String& securityOrigin, const String& cacheName, int skipCount, int pageSi ze, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback) |
| 317 void InspectorServiceWorkerCacheAgent::requestEntries(ErrorString* errorString, const String& cacheName, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<Req uestEntriesCallback> callback) | |
| 318 { | 314 { |
| 319 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); | 315 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, securi tyOrigin); |
| 320 if (!cache) { | 316 if (!cache) { |
| 321 callback->sendFailure(*errorString); | 317 callback->sendFailure(*errorString); |
| 322 return; | 318 return; |
| 323 } | 319 } |
| 324 DataRequestParams params; | 320 DataRequestParams params; |
| 325 params.cacheName = cacheName; | 321 params.cacheName = cacheName; |
| 326 params.pageSize = pageSize; | 322 params.pageSize = pageSize; |
| 327 params.skipCount = skipCount; | 323 params.skipCount = skipCount; |
| 328 cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString( cacheName)); | 324 cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString( cacheName)); |
| 329 } | 325 } |
| 330 | 326 |
| 331 void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, con st String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) | 327 void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, con st String& securityOrigin, const String& cacheName, PassRefPtrWillBeRawPtr<Delet eCacheCallback> callback) |
| 332 { | 328 { |
| 333 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); | 329 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, securi tyOrigin); |
| 334 if (!cache) { | 330 if (!cache) { |
| 335 callback->sendFailure(*errorString); | 331 callback->sendFailure(*errorString); |
| 336 return; | 332 return; |
| 337 } | 333 } |
| 338 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); | 334 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); |
| 339 } | 335 } |
| 340 | 336 |
| 341 } // namespace blink | 337 } // namespace blink |
| OLD | NEW |