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 "modules/cachestorage/InspectorCacheStorageAgent.h" | 5 #include "modules/cachestorage/InspectorCacheStorageAgent.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "public/platform/WebString.h" | 23 #include "public/platform/WebString.h" |
24 #include "public/platform/WebURL.h" | 24 #include "public/platform/WebURL.h" |
25 #include "public/platform/WebVector.h" | 25 #include "public/platform/WebVector.h" |
26 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h" | 26 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h" |
27 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheError.h" | 27 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheError.h" |
28 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheStorage.h" | 28 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheStorage.h" |
29 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" | 29 #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" |
30 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" | 30 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" |
31 | 31 |
32 using blink::protocol::Array; | 32 using blink::protocol::Array; |
33 using blink::protocol::CacheStorage::Cache; | 33 // Renaming Cache since there is another blink::Cache. |
| 34 using ProtocolCache = blink::protocol::CacheStorage::Cache; |
34 using blink::protocol::CacheStorage::DataEntry; | 35 using blink::protocol::CacheStorage::DataEntry; |
35 using blink::protocol::Response; | 36 // Renaming Response since there is another blink::Response. |
| 37 using ProtocolResponse = blink::protocol::Response; |
36 | 38 |
37 typedef blink::protocol::CacheStorage::Backend::DeleteCacheCallback | 39 typedef blink::protocol::CacheStorage::Backend::DeleteCacheCallback |
38 DeleteCacheCallback; | 40 DeleteCacheCallback; |
39 typedef blink::protocol::CacheStorage::Backend::DeleteEntryCallback | 41 typedef blink::protocol::CacheStorage::Backend::DeleteEntryCallback |
40 DeleteEntryCallback; | 42 DeleteEntryCallback; |
41 typedef blink::protocol::CacheStorage::Backend::RequestCacheNamesCallback | 43 typedef blink::protocol::CacheStorage::Backend::RequestCacheNamesCallback |
42 RequestCacheNamesCallback; | 44 RequestCacheNamesCallback; |
43 typedef blink::protocol::CacheStorage::Backend::RequestEntriesCallback | 45 typedef blink::protocol::CacheStorage::Backend::RequestEntriesCallback |
44 RequestEntriesCallback; | 46 RequestEntriesCallback; |
45 typedef blink::WebServiceWorkerCache::BatchOperation BatchOperation; | 47 typedef blink::WebServiceWorkerCache::BatchOperation BatchOperation; |
46 | 48 |
47 namespace blink { | 49 namespace blink { |
48 | 50 |
49 namespace { | 51 namespace { |
50 | 52 |
51 String BuildCacheId(const String& security_origin, const String& cache_name) { | 53 String BuildCacheId(const String& security_origin, const String& cache_name) { |
52 String id(security_origin); | 54 String id(security_origin); |
53 id.append('|'); | 55 id.append('|'); |
54 id.append(cache_name); | 56 id.append(cache_name); |
55 return id; | 57 return id; |
56 } | 58 } |
57 | 59 |
58 Response ParseCacheId(const String& id, | 60 ProtocolResponse ParseCacheId(const String& id, |
59 String* security_origin, | 61 String* security_origin, |
60 String* cache_name) { | 62 String* cache_name) { |
61 size_t pipe = id.find('|'); | 63 size_t pipe = id.find('|'); |
62 if (pipe == WTF::kNotFound) | 64 if (pipe == WTF::kNotFound) |
63 return Response::Error("Invalid cache id."); | 65 return ProtocolResponse::Error("Invalid cache id."); |
64 *security_origin = id.Substring(0, pipe); | 66 *security_origin = id.Substring(0, pipe); |
65 *cache_name = id.Substring(pipe + 1); | 67 *cache_name = id.Substring(pipe + 1); |
66 return Response::OK(); | 68 return ProtocolResponse::OK(); |
67 } | 69 } |
68 | 70 |
69 Response AssertCacheStorage( | 71 ProtocolResponse AssertCacheStorage( |
70 const String& security_origin, | 72 const String& security_origin, |
71 std::unique_ptr<WebServiceWorkerCacheStorage>& result) { | 73 std::unique_ptr<WebServiceWorkerCacheStorage>& result) { |
72 RefPtr<SecurityOrigin> sec_origin = | 74 RefPtr<SecurityOrigin> sec_origin = |
73 SecurityOrigin::CreateFromString(security_origin); | 75 SecurityOrigin::CreateFromString(security_origin); |
74 | 76 |
75 // Cache Storage API is restricted to trustworthy origins. | 77 // Cache Storage API is restricted to trustworthy origins. |
76 if (!sec_origin->IsPotentiallyTrustworthy()) | 78 if (!sec_origin->IsPotentiallyTrustworthy()) { |
77 return Response::Error(sec_origin->IsPotentiallyTrustworthyErrorMessage()); | 79 return ProtocolResponse::Error( |
| 80 sec_origin->IsPotentiallyTrustworthyErrorMessage()); |
| 81 } |
78 | 82 |
79 std::unique_ptr<WebServiceWorkerCacheStorage> cache = | 83 std::unique_ptr<WebServiceWorkerCacheStorage> cache = |
80 Platform::Current()->CreateCacheStorage(WebSecurityOrigin(sec_origin)); | 84 Platform::Current()->CreateCacheStorage(WebSecurityOrigin(sec_origin)); |
81 if (!cache) | 85 if (!cache) |
82 return Response::Error("Could not find cache storage."); | 86 return ProtocolResponse::Error("Could not find cache storage."); |
83 result = std::move(cache); | 87 result = std::move(cache); |
84 return Response::OK(); | 88 return ProtocolResponse::OK(); |
85 } | 89 } |
86 | 90 |
87 Response AssertCacheStorageAndNameForId( | 91 ProtocolResponse AssertCacheStorageAndNameForId( |
88 const String& cache_id, | 92 const String& cache_id, |
89 String* cache_name, | 93 String* cache_name, |
90 std::unique_ptr<WebServiceWorkerCacheStorage>& result) { | 94 std::unique_ptr<WebServiceWorkerCacheStorage>& result) { |
91 String security_origin; | 95 String security_origin; |
92 Response response = ParseCacheId(cache_id, &security_origin, cache_name); | 96 ProtocolResponse response = |
| 97 ParseCacheId(cache_id, &security_origin, cache_name); |
93 if (!response.isSuccess()) | 98 if (!response.isSuccess()) |
94 return response; | 99 return response; |
95 return AssertCacheStorage(security_origin, result); | 100 return AssertCacheStorage(security_origin, result); |
96 } | 101 } |
97 | 102 |
98 CString ServiceWorkerCacheErrorString(WebServiceWorkerCacheError error) { | 103 CString ServiceWorkerCacheErrorString(WebServiceWorkerCacheError error) { |
99 switch (error) { | 104 switch (error) { |
100 case kWebServiceWorkerCacheErrorNotImplemented: | 105 case kWebServiceWorkerCacheErrorNotImplemented: |
101 return CString("not implemented."); | 106 return CString("not implemented."); |
102 break; | 107 break; |
(...skipping 19 matching lines...) Expand all Loading... |
122 WTF_MAKE_NONCOPYABLE(RequestCacheNames); | 127 WTF_MAKE_NONCOPYABLE(RequestCacheNames); |
123 | 128 |
124 public: | 129 public: |
125 RequestCacheNames(const String& security_origin, | 130 RequestCacheNames(const String& security_origin, |
126 std::unique_ptr<RequestCacheNamesCallback> callback) | 131 std::unique_ptr<RequestCacheNamesCallback> callback) |
127 : security_origin_(security_origin), callback_(std::move(callback)) {} | 132 : security_origin_(security_origin), callback_(std::move(callback)) {} |
128 | 133 |
129 ~RequestCacheNames() override {} | 134 ~RequestCacheNames() override {} |
130 | 135 |
131 void OnSuccess(const WebVector<WebString>& caches) override { | 136 void OnSuccess(const WebVector<WebString>& caches) override { |
132 std::unique_ptr<Array<Cache>> array = Array<Cache>::create(); | 137 std::unique_ptr<Array<ProtocolCache>> array = |
| 138 Array<ProtocolCache>::create(); |
133 for (size_t i = 0; i < caches.size(); i++) { | 139 for (size_t i = 0; i < caches.size(); i++) { |
134 String name = String(caches[i]); | 140 String name = String(caches[i]); |
135 std::unique_ptr<Cache> entry = | 141 std::unique_ptr<ProtocolCache> entry = |
136 Cache::create() | 142 ProtocolCache::create() |
137 .setSecurityOrigin(security_origin_) | 143 .setSecurityOrigin(security_origin_) |
138 .setCacheName(name) | 144 .setCacheName(name) |
139 .setCacheId(BuildCacheId(security_origin_, name)) | 145 .setCacheId(BuildCacheId(security_origin_, name)) |
140 .build(); | 146 .build(); |
141 array->addItem(std::move(entry)); | 147 array->addItem(std::move(entry)); |
142 } | 148 } |
143 callback_->sendSuccess(std::move(array)); | 149 callback_->sendSuccess(std::move(array)); |
144 } | 150 } |
145 | 151 |
146 void OnError(WebServiceWorkerCacheError error) override { | 152 void OnError(WebServiceWorkerCacheError error) override { |
147 callback_->sendFailure(Response::Error( | 153 callback_->sendFailure(ProtocolResponse::Error( |
148 String::Format("Error requesting cache names: %s", | 154 String::Format("Error requesting cache names: %s", |
149 ServiceWorkerCacheErrorString(error).data()))); | 155 ServiceWorkerCacheErrorString(error).data()))); |
150 } | 156 } |
151 | 157 |
152 private: | 158 private: |
153 String security_origin_; | 159 String security_origin_; |
154 std::unique_ptr<RequestCacheNamesCallback> callback_; | 160 std::unique_ptr<RequestCacheNamesCallback> callback_; |
155 }; | 161 }; |
156 | 162 |
157 struct DataRequestParams { | 163 struct DataRequestParams { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 DataEntry::create() | 217 DataEntry::create() |
212 .setRequest(request_response.request) | 218 .setRequest(request_response.request) |
213 .setResponse(request_response.response) | 219 .setResponse(request_response.response) |
214 .setResponseTime(request_response.response_time) | 220 .setResponseTime(request_response.response_time) |
215 .build(); | 221 .build(); |
216 array->addItem(std::move(entry)); | 222 array->addItem(std::move(entry)); |
217 } | 223 } |
218 callback_->sendSuccess(std::move(array), has_more); | 224 callback_->sendSuccess(std::move(array), has_more); |
219 } | 225 } |
220 | 226 |
221 void SendFailure(const Response& error) { callback_->sendFailure(error); } | 227 void SendFailure(const ProtocolResponse& error) { |
| 228 callback_->sendFailure(error); |
| 229 } |
222 | 230 |
223 private: | 231 private: |
224 DataRequestParams params_; | 232 DataRequestParams params_; |
225 int num_responses_left_; | 233 int num_responses_left_; |
226 Vector<RequestResponse> responses_; | 234 Vector<RequestResponse> responses_; |
227 std::unique_ptr<RequestEntriesCallback> callback_; | 235 std::unique_ptr<RequestEntriesCallback> callback_; |
228 }; | 236 }; |
229 | 237 |
230 class GetCacheResponsesForRequestData | 238 class GetCacheResponsesForRequestData |
231 : public WebServiceWorkerCache::CacheMatchCallbacks { | 239 : public WebServiceWorkerCache::CacheMatchCallbacks { |
232 WTF_MAKE_NONCOPYABLE(GetCacheResponsesForRequestData); | 240 WTF_MAKE_NONCOPYABLE(GetCacheResponsesForRequestData); |
233 | 241 |
234 public: | 242 public: |
235 GetCacheResponsesForRequestData(const DataRequestParams& params, | 243 GetCacheResponsesForRequestData(const DataRequestParams& params, |
236 const WebServiceWorkerRequest& request, | 244 const WebServiceWorkerRequest& request, |
237 PassRefPtr<ResponsesAccumulator> accum) | 245 PassRefPtr<ResponsesAccumulator> accum) |
238 : params_(params), request_(request), accumulator_(std::move(accum)) {} | 246 : params_(params), request_(request), accumulator_(std::move(accum)) {} |
239 ~GetCacheResponsesForRequestData() override {} | 247 ~GetCacheResponsesForRequestData() override {} |
240 | 248 |
241 void OnSuccess(const WebServiceWorkerResponse& response) override { | 249 void OnSuccess(const WebServiceWorkerResponse& response) override { |
242 accumulator_->AddRequestResponsePair(request_, response); | 250 accumulator_->AddRequestResponsePair(request_, response); |
243 } | 251 } |
244 | 252 |
245 void OnError(WebServiceWorkerCacheError error) override { | 253 void OnError(WebServiceWorkerCacheError error) override { |
246 accumulator_->SendFailure(Response::Error( | 254 accumulator_->SendFailure(ProtocolResponse::Error( |
247 String::Format("Error requesting responses for cache %s: %s", | 255 String::Format("Error requesting responses for cache %s: %s", |
248 params_.cache_name.Utf8().data(), | 256 params_.cache_name.Utf8().data(), |
249 ServiceWorkerCacheErrorString(error).data()))); | 257 ServiceWorkerCacheErrorString(error).data()))); |
250 } | 258 } |
251 | 259 |
252 private: | 260 private: |
253 DataRequestParams params_; | 261 DataRequestParams params_; |
254 WebServiceWorkerRequest request_; | 262 WebServiceWorkerRequest request_; |
255 RefPtr<ResponsesAccumulator> accumulator_; | 263 RefPtr<ResponsesAccumulator> accumulator_; |
256 }; | 264 }; |
(...skipping 25 matching lines...) Expand all Loading... |
282 for (size_t i = 0; i < requests.size(); i++) { | 290 for (size_t i = 0; i < requests.size(); i++) { |
283 const auto& request = requests[i]; | 291 const auto& request = requests[i]; |
284 auto cache_request = WTF::MakeUnique<GetCacheResponsesForRequestData>( | 292 auto cache_request = WTF::MakeUnique<GetCacheResponsesForRequestData>( |
285 params_, request, accumulator); | 293 params_, request, accumulator); |
286 cache_->DispatchMatch(std::move(cache_request), request, | 294 cache_->DispatchMatch(std::move(cache_request), request, |
287 WebServiceWorkerCache::QueryParams()); | 295 WebServiceWorkerCache::QueryParams()); |
288 } | 296 } |
289 } | 297 } |
290 | 298 |
291 void OnError(WebServiceWorkerCacheError error) override { | 299 void OnError(WebServiceWorkerCacheError error) override { |
292 callback_->sendFailure(Response::Error( | 300 callback_->sendFailure(ProtocolResponse::Error( |
293 String::Format("Error requesting requests for cache %s: %s", | 301 String::Format("Error requesting requests for cache %s: %s", |
294 params_.cache_name.Utf8().data(), | 302 params_.cache_name.Utf8().data(), |
295 ServiceWorkerCacheErrorString(error).data()))); | 303 ServiceWorkerCacheErrorString(error).data()))); |
296 } | 304 } |
297 | 305 |
298 private: | 306 private: |
299 DataRequestParams params_; | 307 DataRequestParams params_; |
300 std::unique_ptr<WebServiceWorkerCache> cache_; | 308 std::unique_ptr<WebServiceWorkerCache> cache_; |
301 std::unique_ptr<RequestEntriesCallback> callback_; | 309 std::unique_ptr<RequestEntriesCallback> callback_; |
302 }; | 310 }; |
(...skipping 10 matching lines...) Expand all Loading... |
313 | 321 |
314 void OnSuccess(std::unique_ptr<WebServiceWorkerCache> cache) override { | 322 void OnSuccess(std::unique_ptr<WebServiceWorkerCache> cache) override { |
315 auto cache_request = WTF::MakeUnique<GetCacheKeysForRequestData>( | 323 auto cache_request = WTF::MakeUnique<GetCacheKeysForRequestData>( |
316 params_, std::move(cache), std::move(callback_)); | 324 params_, std::move(cache), std::move(callback_)); |
317 cache_request->Cache()->DispatchKeys(std::move(cache_request), | 325 cache_request->Cache()->DispatchKeys(std::move(cache_request), |
318 WebServiceWorkerRequest(), | 326 WebServiceWorkerRequest(), |
319 WebServiceWorkerCache::QueryParams()); | 327 WebServiceWorkerCache::QueryParams()); |
320 } | 328 } |
321 | 329 |
322 void OnError(WebServiceWorkerCacheError error) override { | 330 void OnError(WebServiceWorkerCacheError error) override { |
323 callback_->sendFailure(Response::Error(String::Format( | 331 callback_->sendFailure(ProtocolResponse::Error(String::Format( |
324 "Error requesting cache %s: %s", params_.cache_name.Utf8().data(), | 332 "Error requesting cache %s: %s", params_.cache_name.Utf8().data(), |
325 ServiceWorkerCacheErrorString(error).data()))); | 333 ServiceWorkerCacheErrorString(error).data()))); |
326 } | 334 } |
327 | 335 |
328 private: | 336 private: |
329 DataRequestParams params_; | 337 DataRequestParams params_; |
330 std::unique_ptr<RequestEntriesCallback> callback_; | 338 std::unique_ptr<RequestEntriesCallback> callback_; |
331 }; | 339 }; |
332 | 340 |
333 class DeleteCache : public WebServiceWorkerCacheStorage::CacheStorageCallbacks { | 341 class DeleteCache : public WebServiceWorkerCacheStorage::CacheStorageCallbacks { |
334 WTF_MAKE_NONCOPYABLE(DeleteCache); | 342 WTF_MAKE_NONCOPYABLE(DeleteCache); |
335 | 343 |
336 public: | 344 public: |
337 DeleteCache(std::unique_ptr<DeleteCacheCallback> callback) | 345 DeleteCache(std::unique_ptr<DeleteCacheCallback> callback) |
338 : callback_(std::move(callback)) {} | 346 : callback_(std::move(callback)) {} |
339 ~DeleteCache() override {} | 347 ~DeleteCache() override {} |
340 | 348 |
341 void OnSuccess() override { callback_->sendSuccess(); } | 349 void OnSuccess() override { callback_->sendSuccess(); } |
342 | 350 |
343 void OnError(WebServiceWorkerCacheError error) override { | 351 void OnError(WebServiceWorkerCacheError error) override { |
344 callback_->sendFailure(Response::Error( | 352 callback_->sendFailure(ProtocolResponse::Error( |
345 String::Format("Error requesting cache names: %s", | 353 String::Format("Error requesting cache names: %s", |
346 ServiceWorkerCacheErrorString(error).data()))); | 354 ServiceWorkerCacheErrorString(error).data()))); |
347 } | 355 } |
348 | 356 |
349 private: | 357 private: |
350 std::unique_ptr<DeleteCacheCallback> callback_; | 358 std::unique_ptr<DeleteCacheCallback> callback_; |
351 }; | 359 }; |
352 | 360 |
353 class DeleteCacheEntry : public WebServiceWorkerCache::CacheBatchCallbacks { | 361 class DeleteCacheEntry : public WebServiceWorkerCache::CacheBatchCallbacks { |
354 WTF_MAKE_NONCOPYABLE(DeleteCacheEntry); | 362 WTF_MAKE_NONCOPYABLE(DeleteCacheEntry); |
355 | 363 |
356 public: | 364 public: |
357 DeleteCacheEntry(std::unique_ptr<DeleteEntryCallback> callback) | 365 DeleteCacheEntry(std::unique_ptr<DeleteEntryCallback> callback) |
358 : callback_(std::move(callback)) {} | 366 : callback_(std::move(callback)) {} |
359 ~DeleteCacheEntry() override {} | 367 ~DeleteCacheEntry() override {} |
360 | 368 |
361 void OnSuccess() override { callback_->sendSuccess(); } | 369 void OnSuccess() override { callback_->sendSuccess(); } |
362 | 370 |
363 void OnError(WebServiceWorkerCacheError error) override { | 371 void OnError(WebServiceWorkerCacheError error) override { |
364 callback_->sendFailure(Response::Error( | 372 callback_->sendFailure(ProtocolResponse::Error( |
365 String::Format("Error requesting cache names: %s", | 373 String::Format("Error requesting cache names: %s", |
366 ServiceWorkerCacheErrorString(error).data()))); | 374 ServiceWorkerCacheErrorString(error).data()))); |
367 } | 375 } |
368 | 376 |
369 private: | 377 private: |
370 std::unique_ptr<DeleteEntryCallback> callback_; | 378 std::unique_ptr<DeleteEntryCallback> callback_; |
371 }; | 379 }; |
372 | 380 |
373 class GetCacheForDeleteEntry | 381 class GetCacheForDeleteEntry |
374 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { | 382 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { |
(...skipping 15 matching lines...) Expand all Loading... |
390 delete_operation.operation_type = | 398 delete_operation.operation_type = |
391 WebServiceWorkerCache::kOperationTypeDelete; | 399 WebServiceWorkerCache::kOperationTypeDelete; |
392 delete_operation.request.SetURL(KURL(kParsedURLString, request_spec_)); | 400 delete_operation.request.SetURL(KURL(kParsedURLString, request_spec_)); |
393 Vector<BatchOperation> operations; | 401 Vector<BatchOperation> operations; |
394 operations.push_back(delete_operation); | 402 operations.push_back(delete_operation); |
395 cache.release()->DispatchBatch(std::move(delete_request), | 403 cache.release()->DispatchBatch(std::move(delete_request), |
396 WebVector<BatchOperation>(operations)); | 404 WebVector<BatchOperation>(operations)); |
397 } | 405 } |
398 | 406 |
399 void OnError(WebServiceWorkerCacheError error) override { | 407 void OnError(WebServiceWorkerCacheError error) override { |
400 callback_->sendFailure(Response::Error(String::Format( | 408 callback_->sendFailure(ProtocolResponse::Error(String::Format( |
401 "Error requesting cache %s: %s", cache_name_.Utf8().data(), | 409 "Error requesting cache %s: %s", cache_name_.Utf8().data(), |
402 ServiceWorkerCacheErrorString(error).data()))); | 410 ServiceWorkerCacheErrorString(error).data()))); |
403 } | 411 } |
404 | 412 |
405 private: | 413 private: |
406 String request_spec_; | 414 String request_spec_; |
407 String cache_name_; | 415 String cache_name_; |
408 std::unique_ptr<DeleteEntryCallback> callback_; | 416 std::unique_ptr<DeleteEntryCallback> callback_; |
409 }; | 417 }; |
410 | 418 |
(...skipping 10 matching lines...) Expand all Loading... |
421 void InspectorCacheStorageAgent::requestCacheNames( | 429 void InspectorCacheStorageAgent::requestCacheNames( |
422 const String& security_origin, | 430 const String& security_origin, |
423 std::unique_ptr<RequestCacheNamesCallback> callback) { | 431 std::unique_ptr<RequestCacheNamesCallback> callback) { |
424 RefPtr<SecurityOrigin> sec_origin = | 432 RefPtr<SecurityOrigin> sec_origin = |
425 SecurityOrigin::CreateFromString(security_origin); | 433 SecurityOrigin::CreateFromString(security_origin); |
426 | 434 |
427 // Cache Storage API is restricted to trustworthy origins. | 435 // Cache Storage API is restricted to trustworthy origins. |
428 if (!sec_origin->IsPotentiallyTrustworthy()) { | 436 if (!sec_origin->IsPotentiallyTrustworthy()) { |
429 // Don't treat this as an error, just don't attempt to open and enumerate | 437 // Don't treat this as an error, just don't attempt to open and enumerate |
430 // the caches. | 438 // the caches. |
431 callback->sendSuccess(Array<protocol::CacheStorage::Cache>::create()); | 439 callback->sendSuccess(Array<ProtocolCache>::create()); |
432 return; | 440 return; |
433 } | 441 } |
434 | 442 |
435 std::unique_ptr<WebServiceWorkerCacheStorage> cache; | 443 std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
436 Response response = AssertCacheStorage(security_origin, cache); | 444 ProtocolResponse response = AssertCacheStorage(security_origin, cache); |
437 if (!response.isSuccess()) { | 445 if (!response.isSuccess()) { |
438 callback->sendFailure(response); | 446 callback->sendFailure(response); |
439 return; | 447 return; |
440 } | 448 } |
441 cache->DispatchKeys( | 449 cache->DispatchKeys( |
442 WTF::MakeUnique<RequestCacheNames>(security_origin, std::move(callback))); | 450 WTF::MakeUnique<RequestCacheNames>(security_origin, std::move(callback))); |
443 } | 451 } |
444 | 452 |
445 void InspectorCacheStorageAgent::requestEntries( | 453 void InspectorCacheStorageAgent::requestEntries( |
446 const String& cache_id, | 454 const String& cache_id, |
447 int skip_count, | 455 int skip_count, |
448 int page_size, | 456 int page_size, |
449 std::unique_ptr<RequestEntriesCallback> callback) { | 457 std::unique_ptr<RequestEntriesCallback> callback) { |
450 String cache_name; | 458 String cache_name; |
451 std::unique_ptr<WebServiceWorkerCacheStorage> cache; | 459 std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
452 Response response = | 460 ProtocolResponse response = |
453 AssertCacheStorageAndNameForId(cache_id, &cache_name, cache); | 461 AssertCacheStorageAndNameForId(cache_id, &cache_name, cache); |
454 if (!response.isSuccess()) { | 462 if (!response.isSuccess()) { |
455 callback->sendFailure(response); | 463 callback->sendFailure(response); |
456 return; | 464 return; |
457 } | 465 } |
458 DataRequestParams params; | 466 DataRequestParams params; |
459 params.cache_name = cache_name; | 467 params.cache_name = cache_name; |
460 params.page_size = page_size; | 468 params.page_size = page_size; |
461 params.skip_count = skip_count; | 469 params.skip_count = skip_count; |
462 cache->DispatchOpen( | 470 cache->DispatchOpen( |
463 WTF::MakeUnique<GetCacheForRequestData>(params, std::move(callback)), | 471 WTF::MakeUnique<GetCacheForRequestData>(params, std::move(callback)), |
464 WebString(cache_name)); | 472 WebString(cache_name)); |
465 } | 473 } |
466 | 474 |
467 void InspectorCacheStorageAgent::deleteCache( | 475 void InspectorCacheStorageAgent::deleteCache( |
468 const String& cache_id, | 476 const String& cache_id, |
469 std::unique_ptr<DeleteCacheCallback> callback) { | 477 std::unique_ptr<DeleteCacheCallback> callback) { |
470 String cache_name; | 478 String cache_name; |
471 std::unique_ptr<WebServiceWorkerCacheStorage> cache; | 479 std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
472 Response response = | 480 ProtocolResponse response = |
473 AssertCacheStorageAndNameForId(cache_id, &cache_name, cache); | 481 AssertCacheStorageAndNameForId(cache_id, &cache_name, cache); |
474 if (!response.isSuccess()) { | 482 if (!response.isSuccess()) { |
475 callback->sendFailure(response); | 483 callback->sendFailure(response); |
476 return; | 484 return; |
477 } | 485 } |
478 cache->DispatchDelete(WTF::MakeUnique<DeleteCache>(std::move(callback)), | 486 cache->DispatchDelete(WTF::MakeUnique<DeleteCache>(std::move(callback)), |
479 WebString(cache_name)); | 487 WebString(cache_name)); |
480 } | 488 } |
481 | 489 |
482 void InspectorCacheStorageAgent::deleteEntry( | 490 void InspectorCacheStorageAgent::deleteEntry( |
483 const String& cache_id, | 491 const String& cache_id, |
484 const String& request, | 492 const String& request, |
485 std::unique_ptr<DeleteEntryCallback> callback) { | 493 std::unique_ptr<DeleteEntryCallback> callback) { |
486 String cache_name; | 494 String cache_name; |
487 std::unique_ptr<WebServiceWorkerCacheStorage> cache; | 495 std::unique_ptr<WebServiceWorkerCacheStorage> cache; |
488 Response response = | 496 ProtocolResponse response = |
489 AssertCacheStorageAndNameForId(cache_id, &cache_name, cache); | 497 AssertCacheStorageAndNameForId(cache_id, &cache_name, cache); |
490 if (!response.isSuccess()) { | 498 if (!response.isSuccess()) { |
491 callback->sendFailure(response); | 499 callback->sendFailure(response); |
492 return; | 500 return; |
493 } | 501 } |
494 cache->DispatchOpen(WTF::MakeUnique<GetCacheForDeleteEntry>( | 502 cache->DispatchOpen(WTF::MakeUnique<GetCacheForDeleteEntry>( |
495 request, cache_name, std::move(callback)), | 503 request, cache_name, std::move(callback)), |
496 WebString(cache_name)); | 504 WebString(cache_name)); |
497 } | 505 } |
498 | 506 |
499 } // namespace blink | 507 } // namespace blink |
OLD | NEW |