| 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" | 10 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return CString("unknown error."); | 72 return CString("unknown error."); |
| 73 break; | 73 break; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 class RequestCacheNames | 77 class RequestCacheNames |
| 78 : public WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks { | 78 : public WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks { |
| 79 WTF_MAKE_NONCOPYABLE(RequestCacheNames); | 79 WTF_MAKE_NONCOPYABLE(RequestCacheNames); |
| 80 | 80 |
| 81 public: | 81 public: |
| 82 RequestCacheNames(PassRefPtr<RequestCacheNamesCallback> callback) | 82 RequestCacheNames(PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback
) |
| 83 : m_callback(callback) | 83 : m_callback(callback) |
| 84 { | 84 { |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual ~RequestCacheNames() { } | 87 virtual ~RequestCacheNames() { } |
| 88 | 88 |
| 89 void onSuccess(WebVector<WebString>* caches) | 89 void onSuccess(WebVector<WebString>* caches) |
| 90 { | 90 { |
| 91 RefPtr<TypeBuilder::Array<String>> array = TypeBuilder::Array<String>::c
reate(); | 91 RefPtr<TypeBuilder::Array<String>> array = TypeBuilder::Array<String>::c
reate(); |
| 92 for (size_t i = 0; i < caches->size(); i++) { | 92 for (size_t i = 0; i < caches->size(); i++) { |
| 93 array->addItem(String((*caches)[i])); | 93 array->addItem(String((*caches)[i])); |
| 94 } | 94 } |
| 95 m_callback->sendSuccess(array); | 95 m_callback->sendSuccess(array); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void onError(WebServiceWorkerCacheError* error) | 98 void onError(WebServiceWorkerCacheError* error) |
| 99 { | 99 { |
| 100 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); | 100 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); |
| 101 } | 101 } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 RefPtr<RequestCacheNamesCallback> m_callback; | 104 RefPtrWillBePersistent<RequestCacheNamesCallback> m_callback; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 struct DataRequestParams { | 107 struct DataRequestParams { |
| 108 String cacheName; | 108 String cacheName; |
| 109 int skipCount; | 109 int skipCount; |
| 110 int pageSize; | 110 int pageSize; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 struct RequestResponse { | 113 struct RequestResponse { |
| 114 RequestResponse() { } | 114 RequestResponse() { } |
| 115 RequestResponse(const String& request, const String& response) | 115 RequestResponse(const String& request, const String& response) |
| 116 : request(request) | 116 : request(request) |
| 117 , response(response) | 117 , response(response) |
| 118 { | 118 { |
| 119 } | 119 } |
| 120 String request; | 120 String request; |
| 121 String response; | 121 String response; |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 class ResponsesAccumulator : public RefCounted<ResponsesAccumulator> { | 124 class ResponsesAccumulator : public RefCounted<ResponsesAccumulator> { |
| 125 WTF_MAKE_NONCOPYABLE(ResponsesAccumulator); | 125 WTF_MAKE_NONCOPYABLE(ResponsesAccumulator); |
| 126 | 126 |
| 127 public: | 127 public: |
| 128 ResponsesAccumulator(int numResponses, const DataRequestParams& params, Pass
RefPtr<RequestEntriesCallback> callback) | 128 ResponsesAccumulator(int numResponses, const DataRequestParams& params, Pass
RefPtrWillBeRawPtr<RequestEntriesCallback> callback) |
| 129 : m_params(params) | 129 : m_params(params) |
| 130 , m_numResponsesLeft(numResponses) | 130 , m_numResponsesLeft(numResponses) |
| 131 , m_responses(static_cast<size_t>(numResponses)) | 131 , m_responses(static_cast<size_t>(numResponses)) |
| 132 , m_callback(callback) | 132 , m_callback(callback) |
| 133 { | 133 { |
| 134 } | 134 } |
| 135 | 135 |
| 136 void addRequestResponsePair(const WebServiceWorkerRequest& request, const We
bServiceWorkerResponse& response) | 136 void addRequestResponsePair(const WebServiceWorkerRequest& request, const We
bServiceWorkerResponse& response) |
| 137 { | 137 { |
| 138 ASSERT(m_numResponsesLeft > 0); | 138 ASSERT(m_numResponsesLeft > 0); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 162 .setResponse(JSONString::create(requestResponse.response)->toJSO
NString()); | 162 .setResponse(JSONString::create(requestResponse.response)->toJSO
NString()); |
| 163 array->addItem(entry); | 163 array->addItem(entry); |
| 164 } | 164 } |
| 165 m_callback->sendSuccess(array, hasMore); | 165 m_callback->sendSuccess(array, hasMore); |
| 166 } | 166 } |
| 167 | 167 |
| 168 private: | 168 private: |
| 169 DataRequestParams m_params; | 169 DataRequestParams m_params; |
| 170 int m_numResponsesLeft; | 170 int m_numResponsesLeft; |
| 171 Vector<RequestResponse> m_responses; | 171 Vector<RequestResponse> m_responses; |
| 172 RefPtr<RequestEntriesCallback> m_callback; | 172 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 class GetCacheResponsesForRequestData : public WebServiceWorkerCache::CacheMatch
Callbacks { | 175 class GetCacheResponsesForRequestData : public WebServiceWorkerCache::CacheMatch
Callbacks { |
| 176 WTF_MAKE_NONCOPYABLE(GetCacheResponsesForRequestData); | 176 WTF_MAKE_NONCOPYABLE(GetCacheResponsesForRequestData); |
| 177 | 177 |
| 178 public: | 178 public: |
| 179 GetCacheResponsesForRequestData( | 179 GetCacheResponsesForRequestData( |
| 180 const DataRequestParams& params, const WebServiceWorkerRequest& request, | 180 const DataRequestParams& params, const WebServiceWorkerRequest& request, |
| 181 PassRefPtr<ResponsesAccumulator> accum, PassRefPtr<RequestEntriesCallbac
k> callback) | 181 PassRefPtr<ResponsesAccumulator> accum, PassRefPtrWillBeRawPtr<RequestEn
triesCallback> callback) |
| 182 : m_params(params) | 182 : m_params(params) |
| 183 , m_request(request) | 183 , m_request(request) |
| 184 , m_accumulator(accum) | 184 , m_accumulator(accum) |
| 185 , m_callback(callback) | 185 , m_callback(callback) |
| 186 { | 186 { |
| 187 } | 187 } |
| 188 virtual ~GetCacheResponsesForRequestData() { } | 188 virtual ~GetCacheResponsesForRequestData() { } |
| 189 | 189 |
| 190 void onSuccess(WebServiceWorkerResponse* response) | 190 void onSuccess(WebServiceWorkerResponse* response) |
| 191 { | 191 { |
| 192 m_accumulator->addRequestResponsePair(m_request, *response); | 192 m_accumulator->addRequestResponsePair(m_request, *response); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void onError(WebServiceWorkerCacheError* error) | 195 void onError(WebServiceWorkerCacheError* error) |
| 196 { | 196 { |
| 197 m_callback->sendFailure(String::format("Error requesting responses for c
ache %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(e
rror).data())); | 197 m_callback->sendFailure(String::format("Error requesting responses for c
ache %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(e
rror).data())); |
| 198 } | 198 } |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 DataRequestParams m_params; | 201 DataRequestParams m_params; |
| 202 WebServiceWorkerRequest m_request; | 202 WebServiceWorkerRequest m_request; |
| 203 RefPtr<ResponsesAccumulator> m_accumulator; | 203 RefPtr<ResponsesAccumulator> m_accumulator; |
| 204 RefPtr<RequestEntriesCallback> m_callback; | 204 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 class GetCacheKeysForRequestData : public WebServiceWorkerCache::CacheWithReques
tsCallbacks { | 207 class GetCacheKeysForRequestData : public WebServiceWorkerCache::CacheWithReques
tsCallbacks { |
| 208 WTF_MAKE_NONCOPYABLE(GetCacheKeysForRequestData); | 208 WTF_MAKE_NONCOPYABLE(GetCacheKeysForRequestData); |
| 209 | 209 |
| 210 public: | 210 public: |
| 211 GetCacheKeysForRequestData(const DataRequestParams& params, PassOwnPtr<WebSe
rviceWorkerCache> cache, PassRefPtr<RequestEntriesCallback> callback) | 211 GetCacheKeysForRequestData(const DataRequestParams& params, PassOwnPtr<WebSe
rviceWorkerCache> cache, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback
) |
| 212 : m_params(params) | 212 : m_params(params) |
| 213 , m_cache(cache) | 213 , m_cache(cache) |
| 214 , m_callback(callback) | 214 , m_callback(callback) |
| 215 { | 215 { |
| 216 } | 216 } |
| 217 virtual ~GetCacheKeysForRequestData() { } | 217 virtual ~GetCacheKeysForRequestData() { } |
| 218 | 218 |
| 219 void onSuccess(WebVector<WebServiceWorkerRequest>* requests) | 219 void onSuccess(WebVector<WebServiceWorkerRequest>* requests) |
| 220 { | 220 { |
| 221 RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumul
ator(requests->size(), m_params, m_callback)); | 221 RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumul
ator(requests->size(), m_params, m_callback)); |
| 222 | 222 |
| 223 for (size_t i = 0; i < requests->size(); i++) { | 223 for (size_t i = 0; i < requests->size(); i++) { |
| 224 const auto& request = (*requests)[i]; | 224 const auto& request = (*requests)[i]; |
| 225 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r
equest, accumulator, m_callback); | 225 auto* cacheRequest = new GetCacheResponsesForRequestData(m_params, r
equest, accumulator, m_callback); |
| 226 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache:
:QueryParams()); | 226 m_cache->dispatchMatch(cacheRequest, request, WebServiceWorkerCache:
:QueryParams()); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 void onError(WebServiceWorkerCacheError* error) | 230 void onError(WebServiceWorkerCacheError* error) |
| 231 { | 231 { |
| 232 m_callback->sendFailure(String::format("Error requesting requests for ca
che %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(err
or).data())); | 232 m_callback->sendFailure(String::format("Error requesting requests for ca
che %s: %s", m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(err
or).data())); |
| 233 } | 233 } |
| 234 | 234 |
| 235 private: | 235 private: |
| 236 DataRequestParams m_params; | 236 DataRequestParams m_params; |
| 237 OwnPtr<WebServiceWorkerCache> m_cache; | 237 OwnPtr<WebServiceWorkerCache> m_cache; |
| 238 RefPtr<RequestEntriesCallback> m_callback; | 238 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 class GetCacheForRequestData | 241 class GetCacheForRequestData |
| 242 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { | 242 : public WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks { |
| 243 WTF_MAKE_NONCOPYABLE(GetCacheForRequestData); | 243 WTF_MAKE_NONCOPYABLE(GetCacheForRequestData); |
| 244 | 244 |
| 245 public: | 245 public: |
| 246 GetCacheForRequestData(const DataRequestParams& params, PassRefPtr<RequestEn
triesCallback> callback) | 246 GetCacheForRequestData(const DataRequestParams& params, PassRefPtrWillBeRawP
tr<RequestEntriesCallback> callback) |
| 247 : m_params(params) | 247 : m_params(params) |
| 248 , m_callback(callback) | 248 , m_callback(callback) |
| 249 { | 249 { |
| 250 } | 250 } |
| 251 virtual ~GetCacheForRequestData() { } | 251 virtual ~GetCacheForRequestData() { } |
| 252 | 252 |
| 253 void onSuccess(WebServiceWorkerCache* cache) | 253 void onSuccess(WebServiceWorkerCache* cache) |
| 254 { | 254 { |
| 255 auto* cacheRequest = new GetCacheKeysForRequestData(m_params, adoptPtr(c
ache), m_callback); | 255 auto* cacheRequest = new GetCacheKeysForRequestData(m_params, adoptPtr(c
ache), m_callback); |
| 256 cache->dispatchKeys(cacheRequest, nullptr, WebServiceWorkerCache::QueryP
arams()); | 256 cache->dispatchKeys(cacheRequest, nullptr, WebServiceWorkerCache::QueryP
arams()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void onError(WebServiceWorkerCacheError* error) | 259 void onError(WebServiceWorkerCacheError* error) |
| 260 { | 260 { |
| 261 m_callback->sendFailure(String::format("Error requesting cache %s: %s",
m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(error).data())); | 261 m_callback->sendFailure(String::format("Error requesting cache %s: %s",
m_params.cacheName.utf8().data(), serviceWorkerCacheErrorString(error).data())); |
| 262 } | 262 } |
| 263 | 263 |
| 264 private: | 264 private: |
| 265 DataRequestParams m_params; | 265 DataRequestParams m_params; |
| 266 RefPtr<RequestEntriesCallback> m_callback; | 266 RefPtrWillBePersistent<RequestEntriesCallback> m_callback; |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 class DeleteCache : public WebServiceWorkerCacheStorage::CacheStorageCallbacks { | 269 class DeleteCache : public WebServiceWorkerCacheStorage::CacheStorageCallbacks { |
| 270 WTF_MAKE_NONCOPYABLE(DeleteCache); | 270 WTF_MAKE_NONCOPYABLE(DeleteCache); |
| 271 | 271 |
| 272 public: | 272 public: |
| 273 DeleteCache(PassRefPtr<DeleteCacheCallback> callback) | 273 DeleteCache(PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) |
| 274 : m_callback(callback) | 274 : m_callback(callback) |
| 275 { | 275 { |
| 276 } | 276 } |
| 277 virtual ~DeleteCache() { } | 277 virtual ~DeleteCache() { } |
| 278 | 278 |
| 279 void onSuccess() | 279 void onSuccess() |
| 280 { | 280 { |
| 281 m_callback->sendSuccess(); | 281 m_callback->sendSuccess(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void onError(WebServiceWorkerCacheError* error) | 284 void onError(WebServiceWorkerCacheError* error) |
| 285 { | 285 { |
| 286 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); | 286 m_callback->sendFailure(String::format("Error requesting cache names: %s
", serviceWorkerCacheErrorString(error).data())); |
| 287 } | 287 } |
| 288 | 288 |
| 289 private: | 289 private: |
| 290 RefPtr<DeleteCacheCallback> m_callback; | 290 RefPtrWillBePersistent<DeleteCacheCallback> m_callback; |
| 291 }; | 291 }; |
| 292 | 292 |
| 293 } // namespace | 293 } // namespace |
| 294 | 294 |
| 295 InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(ServiceWorker
GlobalScope* scope) | 295 InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(ServiceWorker
GlobalScope* scope) |
| 296 : InspectorBaseAgent<blink::InspectorServiceWorkerCacheAgent>("ServiceWorker
Cache") | 296 : InspectorBaseAgent<blink::InspectorServiceWorkerCacheAgent>("ServiceWorker
Cache") |
| 297 , m_globalScope(scope) | 297 , m_globalScope(scope) |
| 298 { | 298 { |
| 299 } | 299 } |
| 300 | 300 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 { | 337 { |
| 338 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, m_glob
alScope); | 338 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, m_glob
alScope); |
| 339 if (!cache) { | 339 if (!cache) { |
| 340 callback->sendFailure(*errorString); | 340 callback->sendFailure(*errorString); |
| 341 return; | 341 return; |
| 342 } | 342 } |
| 343 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); | 343 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 } // namespace blink | 346 } // namespace blink |
| OLD | NEW |