Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1581)

Side by Side Diff: Source/modules/serviceworkers/InspectorServiceWorkerCacheAgent.cpp

Issue 1044203004: [Storage] Cache storage inspection on all the frames! (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorSt ring, 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(iden tifier);
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 adoptPtr(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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 GetCacheKeysForRequestData(const DataRequestParams& params, PassOwnPtr<WebSe rviceWorkerCache> cache, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback ) 207 GetCacheKeysForRequestData(const DataRequestParams& params, PassOwnPtr<WebSe rviceWorkerCache> cache, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback )
210 : m_params(params) 208 : m_params(params)
211 , m_cache(cache) 209 , m_cache(cache)
212 , m_callback(callback) 210 , m_callback(callback)
213 { 211 {
214 } 212 }
215 virtual ~GetCacheKeysForRequestData() { } 213 virtual ~GetCacheKeysForRequestData() { }
216 214
217 void onSuccess(WebVector<WebServiceWorkerRequest>* requests) 215 void onSuccess(WebVector<WebServiceWorkerRequest>* requests)
218 { 216 {
217 if (requests->isEmpty()) {
218 RefPtr<TypeBuilder::Array<DataEntry>> array = TypeBuilder::Array<Dat aEntry>::create();
219 m_callback->sendSuccess(array, false);
220 return;
221 }
219 RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumul ator(requests->size(), m_params, m_callback)); 222 RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumul ator(requests->size(), m_params, m_callback));
220 223
221 for (size_t i = 0; i < requests->size(); i++) { 224 for (size_t i = 0; i < requests->size(); i++) {
222 const auto& request = (*requests)[i]; 225 const auto& request = (*requests)[i];
223 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r equest, accumulator, m_callback); 226 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r equest, accumulator, m_callback);
224 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache: :QueryParams()); 227 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache: :QueryParams());
225 } 228 }
226 } 229 }
227 230
228 void onError(WebServiceWorkerCacheError* error) 231 void onError(WebServiceWorkerCacheError* error)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 { 286 {
284 m_callback->sendFailure(String::format("Error requesting cache names: %s ", serviceWorkerCacheErrorString(error).data())); 287 m_callback->sendFailure(String::format("Error requesting cache names: %s ", serviceWorkerCacheErrorString(error).data()));
285 } 288 }
286 289
287 private: 290 private:
288 RefPtrWillBePersistent<DeleteCacheCallback> m_callback; 291 RefPtrWillBePersistent<DeleteCacheCallback> m_callback;
289 }; 292 };
290 293
291 } // namespace 294 } // namespace
292 295
293 InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(ServiceWorker GlobalScope* scope) 296 InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent()
294 : InspectorBaseAgent<blink::InspectorServiceWorkerCacheAgent, InspectorFront end::ServiceWorkerCache>("ServiceWorkerCache") 297 : InspectorBaseAgent<InspectorServiceWorkerCacheAgent, InspectorFrontend::Ca cheStorage>("CacheStorage")
295 , m_globalScope(scope)
296 { 298 {
297 } 299 }
298 300
299 InspectorServiceWorkerCacheAgent::~InspectorServiceWorkerCacheAgent() { } 301 InspectorServiceWorkerCacheAgent::~InspectorServiceWorkerCacheAgent() { }
300 302
301 DEFINE_TRACE(InspectorServiceWorkerCacheAgent) 303 DEFINE_TRACE(InspectorServiceWorkerCacheAgent)
302 { 304 {
303 InspectorBaseAgent::trace(visitor); 305 InspectorBaseAgent::trace(visitor);
304 } 306 }
305 307
306 void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorStrin g, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) 308 void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorStrin g, const String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallbac k> callback)
307 { 309 {
308 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); 310 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin);
309 if (!cache) { 311 if (!cache) {
310 callback->sendFailure(*errorString); 312 callback->sendFailure(*errorString);
311 return; 313 return;
312 } 314 }
313 cache->dispatchKeys(new RequestCacheNames(callback)); 315 cache->dispatchKeys(new RequestCacheNames(callback));
314 } 316 }
315 317
316 318 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 { 319 {
319 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); 320 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin);
320 if (!cache) { 321 if (!cache) {
321 callback->sendFailure(*errorString); 322 callback->sendFailure(*errorString);
322 return; 323 return;
323 } 324 }
324 DataRequestParams params; 325 DataRequestParams params;
325 params.cacheName = cacheName; 326 params.cacheName = cacheName;
326 params.pageSize = pageSize; 327 params.pageSize = pageSize;
327 params.skipCount = skipCount; 328 params.skipCount = skipCount;
328 cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString( cacheName)); 329 cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString( cacheName));
329 } 330 }
330 331
331 void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, con st String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) 332 void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, con st String& securityOrigin, const String& cacheName, PassRefPtrWillBeRawPtr<Delet eCacheCallback> callback)
332 { 333 {
333 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); 334 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin);
334 if (!cache) { 335 if (!cache) {
335 callback->sendFailure(*errorString); 336 callback->sendFailure(*errorString);
336 return; 337 return;
337 } 338 }
338 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); 339 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName));
339 } 340 }
340 341
341 } // namespace blink 342 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698