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

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

Issue 1702673002: DevTools: migrate remote debugging protocol generators to jinja2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 "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 13 matching lines...) Expand all
24 #include "wtf/Noncopyable.h" 24 #include "wtf/Noncopyable.h"
25 #include "wtf/OwnPtr.h" 25 #include "wtf/OwnPtr.h"
26 #include "wtf/PassRefPtr.h" 26 #include "wtf/PassRefPtr.h"
27 #include "wtf/RefCounted.h" 27 #include "wtf/RefCounted.h"
28 #include "wtf/RefPtr.h" 28 #include "wtf/RefPtr.h"
29 #include "wtf/Vector.h" 29 #include "wtf/Vector.h"
30 #include "wtf/text/StringBuilder.h" 30 #include "wtf/text/StringBuilder.h"
31 31
32 #include <algorithm> 32 #include <algorithm>
33 33
34 using blink::protocol::TypeBuilder::Array; 34 using blink::protocol::Array;
35 using blink::protocol::TypeBuilder::CacheStorage::Cache; 35 using blink::protocol::CacheStorage::Cache;
36 using blink::protocol::TypeBuilder::CacheStorage::DataEntry; 36 using blink::protocol::CacheStorage::DataEntry;
37 37
38 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::DeleteCacheCall back DeleteCacheCallback; 38 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::DeleteCacheCall back DeleteCacheCallback;
39 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::DeleteEntryCall back DeleteEntryCallback; 39 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::DeleteEntryCall back DeleteEntryCallback;
40 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::RequestCacheNam esCallback RequestCacheNamesCallback; 40 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::RequestCacheNam esCallback RequestCacheNamesCallback;
41 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::RequestEntriesC allback RequestEntriesCallback; 41 typedef blink::protocol::Dispatcher::CacheStorageCommandHandler::RequestEntriesC allback RequestEntriesCallback;
42 typedef blink::protocol::Dispatcher::CallbackBase RequestCallback; 42 typedef blink::protocol::Dispatcher::CallbackBase RequestCallback;
43 typedef blink::WebServiceWorkerCache::BatchOperation BatchOperation; 43 typedef blink::WebServiceWorkerCache::BatchOperation BatchOperation;
44 44
45 namespace blink { 45 namespace blink {
46 46
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 InspectorBaseAgent::trace(visitor); 410 InspectorBaseAgent::trace(visitor);
411 } 411 }
412 412
413 void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, con st String& securityOrigin, PassRefPtr<RequestCacheNamesCallback> callback) 413 void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, con st String& securityOrigin, PassRefPtr<RequestCacheNamesCallback> callback)
414 { 414 {
415 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin); 415 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin);
416 416
417 // Cache Storage API is restricted to trustworthy origins. 417 // Cache Storage API is restricted to trustworthy origins.
418 if (!secOrigin->isPotentiallyTrustworthy()) { 418 if (!secOrigin->isPotentiallyTrustworthy()) {
419 // Don't treat this as an error, just don't attempt to open and enumerat e the caches. 419 // Don't treat this as an error, just don't attempt to open and enumerat e the caches.
420 callback->sendSuccess(Array<protocol::TypeBuilder::CacheStorage::Cache>: :create()); 420 callback->sendSuccess(Array<protocol::CacheStorage::Cache>::create());
421 return; 421 return;
422 } 422 }
423 423
424 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); 424 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin);
425 if (!cache) { 425 if (!cache) {
426 callback->sendFailure(*errorString); 426 callback->sendFailure(*errorString);
427 return; 427 return;
428 } 428 }
429 cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback)); 429 cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback));
430 } 430 }
(...skipping 30 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698