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

Side by Side Diff: Source/modules/cachestorage/InspectorCacheStorageAgent.cpp

Issue 1111563006: [CacheStorage] Entry deletion and cache refresh in Inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Test and comments Created 5 years, 7 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
« no previous file with comments | « Source/modules/cachestorage/InspectorCacheStorageAgent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
11 #include "platform/heap/Handle.h" 11 #include "platform/heap/Handle.h"
12 #include "platform/weborigin/DatabaseIdentifier.h" 12 #include "platform/weborigin/DatabaseIdentifier.h"
13 #include "platform/weborigin/KURL.h"
13 #include "platform/weborigin/SecurityOrigin.h" 14 #include "platform/weborigin/SecurityOrigin.h"
14 #include "public/platform/Platform.h" 15 #include "public/platform/Platform.h"
15 #include "public/platform/WebServiceWorkerCache.h" 16 #include "public/platform/WebServiceWorkerCache.h"
16 #include "public/platform/WebServiceWorkerCacheError.h" 17 #include "public/platform/WebServiceWorkerCacheError.h"
17 #include "public/platform/WebServiceWorkerCacheStorage.h" 18 #include "public/platform/WebServiceWorkerCacheStorage.h"
18 #include "public/platform/WebServiceWorkerRequest.h" 19 #include "public/platform/WebServiceWorkerRequest.h"
19 #include "public/platform/WebServiceWorkerResponse.h" 20 #include "public/platform/WebServiceWorkerResponse.h"
20 #include "public/platform/WebString.h" 21 #include "public/platform/WebString.h"
21 #include "public/platform/WebURL.h" 22 #include "public/platform/WebURL.h"
22 #include "public/platform/WebVector.h" 23 #include "public/platform/WebVector.h"
23 #include "wtf/Noncopyable.h" 24 #include "wtf/Noncopyable.h"
24 #include "wtf/OwnPtr.h" 25 #include "wtf/OwnPtr.h"
25 #include "wtf/PassRefPtr.h" 26 #include "wtf/PassRefPtr.h"
26 #include "wtf/RefCounted.h" 27 #include "wtf/RefCounted.h"
27 #include "wtf/RefPtr.h" 28 #include "wtf/RefPtr.h"
28 #include "wtf/Vector.h" 29 #include "wtf/Vector.h"
29 #include "wtf/text/StringBuilder.h" 30 #include "wtf/text/StringBuilder.h"
30 31
31 #include <algorithm> 32 #include <algorithm>
32 33
33 using blink::TypeBuilder::Array; 34 using blink::TypeBuilder::Array;
34 using blink::TypeBuilder::CacheStorage::Cache; 35 using blink::TypeBuilder::CacheStorage::Cache;
35 using blink::TypeBuilder::CacheStorage::DataEntry; 36 using blink::TypeBuilder::CacheStorage::DataEntry;
36 37
37 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::DeleteCac heCallback DeleteCacheCallback; 38 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::DeleteCac heCallback DeleteCacheCallback;
39 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::DeleteEnt ryCallback DeleteEntryCallback;
38 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestCa cheNamesCallback RequestCacheNamesCallback; 40 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestCa cheNamesCallback RequestCacheNamesCallback;
39 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestEn triesCallback RequestEntriesCallback; 41 typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestEn triesCallback RequestEntriesCallback;
40 typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback; 42 typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback;
43 typedef blink::WebServiceWorkerCache::BatchOperation BatchOperation;
41 44
42 namespace blink { 45 namespace blink {
43 46
44 namespace { 47 namespace {
45 48
46 String buildCacheId(const String& securityOrigin, const String& cacheName) 49 String buildCacheId(const String& securityOrigin, const String& cacheName)
47 { 50 {
48 String id(securityOrigin); 51 String id(securityOrigin);
49 id.append("|"); 52 id.append("|");
50 id.append(cacheName); 53 id.append(cacheName);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (m_params.skipCount > 0) 187 if (m_params.skipCount > 0)
185 m_responses.remove(0, m_params.skipCount); 188 m_responses.remove(0, m_params.skipCount);
186 bool hasMore = false; 189 bool hasMore = false;
187 if (static_cast<size_t>(m_params.pageSize) < m_responses.size()) { 190 if (static_cast<size_t>(m_params.pageSize) < m_responses.size()) {
188 m_responses.remove(m_params.pageSize, m_responses.size() - m_params. pageSize); 191 m_responses.remove(m_params.pageSize, m_responses.size() - m_params. pageSize);
189 hasMore = true; 192 hasMore = true;
190 } 193 }
191 RefPtr<Array<DataEntry>> array = Array<DataEntry>::create(); 194 RefPtr<Array<DataEntry>> array = Array<DataEntry>::create();
192 for (const auto& requestResponse : m_responses) { 195 for (const auto& requestResponse : m_responses) {
193 RefPtr<DataEntry> entry = DataEntry::create() 196 RefPtr<DataEntry> entry = DataEntry::create()
194 .setRequest(JSONString::create(requestResponse.request)->toJSONS tring()) 197 .setRequest(requestResponse.request)
195 .setResponse(JSONString::create(requestResponse.response)->toJSO NString()); 198 .setResponse(requestResponse.response);
196 array->addItem(entry); 199 array->addItem(entry);
197 } 200 }
198 m_callback->sendSuccess(array, hasMore); 201 m_callback->sendSuccess(array, hasMore);
199 } 202 }
200 203
201 private: 204 private:
202 DataRequestParams m_params; 205 DataRequestParams m_params;
203 int m_numResponsesLeft; 206 int m_numResponsesLeft;
204 Vector<RequestResponse> m_responses; 207 Vector<RequestResponse> m_responses;
205 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; 208 RefPtrWillBePersistent<RequestEntriesCallback> m_callback;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 324
322 void onError(WebServiceWorkerCacheError* error) 325 void onError(WebServiceWorkerCacheError* error)
323 { 326 {
324 m_callback->sendFailure(String::format("Error requesting cache names: %s ", serviceWorkerCacheErrorString(error).data())); 327 m_callback->sendFailure(String::format("Error requesting cache names: %s ", serviceWorkerCacheErrorString(error).data()));
325 } 328 }
326 329
327 private: 330 private:
328 RefPtrWillBePersistent<DeleteCacheCallback> m_callback; 331 RefPtrWillBePersistent<DeleteCacheCallback> m_callback;
329 }; 332 };
330 333
334 class DeleteCacheEntry
335 : public WebServiceWorkerCache::CacheWithResponsesCallbacks {
336 WTF_MAKE_NONCOPYABLE(DeleteCacheEntry);
337 public:
338
339 DeleteCacheEntry(PassRefPtrWillBeRawPtr<DeleteEntryCallback> callback)
340 : m_callback(callback)
341 {
342 }
343 virtual ~DeleteCacheEntry() { }
344
345 void onSuccess(WebVector<WebServiceWorkerResponse>* requests)
346 {
347 m_callback->sendSuccess();
348 }
349
350 void onError(WebServiceWorkerCacheError* error)
351 {
352 m_callback->sendFailure(String::format("Error requesting cache names: %s ", serviceWorkerCacheErrorString(error).data()));
353 }
354
355 private:
356 RefPtrWillBePersistent<DeleteEntryCallback> m_callback;
357 };
358
359 class GetCacheForDeleteEntry
360 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks {
361 WTF_MAKE_NONCOPYABLE(GetCacheForDeleteEntry);
362
363 public:
364 GetCacheForDeleteEntry(const String& requestSpec, const String& cacheName, P assRefPtrWillBeRawPtr<DeleteEntryCallback> callback)
365 : m_requestSpec(requestSpec)
366 , m_cacheName(cacheName)
367 , m_callback(callback)
368 {
369 }
370 virtual ~GetCacheForDeleteEntry() { }
371
372 void onSuccess(WebServiceWorkerCache* cache)
373 {
374 auto* deleteRequest = new DeleteCacheEntry( m_callback);
375 BatchOperation deleteOperation;
376 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDele te;
377 deleteOperation.request.setURL(KURL(ParsedURLString, m_requestSpec));
378 Vector<BatchOperation> operations;
379 operations.append(deleteOperation);
380 cache->dispatchBatch(deleteRequest, WebVector<BatchOperation>(operations ));
381 }
382
383 void onError(WebServiceWorkerCacheError* error)
384 {
385 m_callback->sendFailure(String::format("Error requesting cache %s: %s", m_cacheName.utf8().data(), serviceWorkerCacheErrorString(error).data()));
386 }
387
388 private:
389 String m_requestSpec;
390 String m_cacheName;
391 RefPtrWillBePersistent<DeleteEntryCallback> m_callback;
392 };
393
331 } // namespace 394 } // namespace
332 395
333 InspectorCacheStorageAgent::InspectorCacheStorageAgent() 396 InspectorCacheStorageAgent::InspectorCacheStorageAgent()
334 : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheSto rage>("CacheStorage") 397 : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheSto rage>("CacheStorage")
335 { 398 {
336 } 399 }
337 400
338 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { } 401 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { }
339 402
340 DEFINE_TRACE(InspectorCacheStorageAgent) 403 DEFINE_TRACE(InspectorCacheStorageAgent)
(...skipping 30 matching lines...) Expand all
371 { 434 {
372 String cacheName; 435 String cacheName;
373 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId( errorString, cacheId, &cacheName); 436 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId( errorString, cacheId, &cacheName);
374 if (!cache) { 437 if (!cache) {
375 callback->sendFailure(*errorString); 438 callback->sendFailure(*errorString);
376 return; 439 return;
377 } 440 }
378 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); 441 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName));
379 } 442 }
380 443
444 void InspectorCacheStorageAgent::deleteEntry(ErrorString* errorString, const Str ing& cacheId, const String& request, PassRefPtrWillBeRawPtr<DeleteEntryCallback> callback)
445 {
446 String cacheName;
447 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId( errorString, cacheId, &cacheName);
448 if (!cache) {
449 callback->sendFailure(*errorString);
450 return;
451 }
452 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback) , WebString(cacheName));
453 }
454
455
381 } // namespace blink 456 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/cachestorage/InspectorCacheStorageAgent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698