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

Side by Side Diff: content/browser/service_worker/service_worker_cache.cc

Issue 606843002: Make a context struct for ServiceWorkerCache::Put callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « no previous file | 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 "content/browser/service_worker/service_worker_cache.h" 5 #include "content/browser/service_worker/service_worker_cache.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 scoped_refptr<net::IOBufferWithSize> buffer; 48 scoped_refptr<net::IOBufferWithSize> buffer;
49 scoped_refptr<storage::BlobData> blob_data; 49 scoped_refptr<storage::BlobData> blob_data;
50 int total_bytes_read; 50 int total_bytes_read;
51 51
52 DISALLOW_COPY_AND_ASSIGN(ResponseReadContext); 52 DISALLOW_COPY_AND_ASSIGN(ResponseReadContext);
53 }; 53 };
54 54
55 // Streams data from a blob and writes it to a given disk_cache::Entry. 55 // Streams data from a blob and writes it to a given disk_cache::Entry.
56 class BlobReader : public net::URLRequest::Delegate { 56 class BlobReader : public net::URLRequest::Delegate {
57 public: 57 public:
58 typedef base::Callback<void(disk_cache::ScopedEntryPtr, bool)> 58 typedef base::Callback<void(bool)> BoolCallback;
59 EntryBoolCallback;
60 59
61 BlobReader(disk_cache::ScopedEntryPtr entry) 60 BlobReader(disk_cache::ScopedEntryPtr entry)
62 : cache_entry_offset_(0), 61 : cache_entry_offset_(0),
63 buffer_(new net::IOBufferWithSize(kBufferSize)), 62 buffer_(new net::IOBufferWithSize(kBufferSize)),
64 weak_ptr_factory_(this) { 63 weak_ptr_factory_(this) {
65 DCHECK(entry); 64 DCHECK(entry);
66 entry_ = entry.Pass(); 65 entry_ = entry.Pass();
67 } 66 }
68 67
69 void StreamBlobToCache(net::URLRequestContext* request_context, 68 void StreamBlobToCache(net::URLRequestContext* request_context,
70 scoped_ptr<storage::BlobDataHandle> blob_data_handle, 69 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
71 const EntryBoolCallback& callback) { 70 const BoolCallback& callback) {
72 callback_ = callback; 71 callback_ = callback;
73 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( 72 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest(
74 blob_data_handle.Pass(), request_context, this); 73 blob_data_handle.Pass(), request_context, this);
75 blob_request_->Start(); 74 blob_request_->Start();
76 } 75 }
77 76
78 // net::URLRequest::Delegate overrides for reading blobs. 77 // net::URLRequest::Delegate overrides for reading blobs.
79 virtual void OnReceivedRedirect(net::URLRequest* request, 78 virtual void OnReceivedRedirect(net::URLRequest* request,
80 const net::RedirectInfo& redirect_info, 79 const net::RedirectInfo& redirect_info,
81 bool* defer_redirect) OVERRIDE { 80 bool* defer_redirect) OVERRIDE {
(...skipping 13 matching lines...) Expand all
95 bool fatal) OVERRIDE { 94 bool fatal) OVERRIDE {
96 NOTREACHED(); 95 NOTREACHED();
97 } 96 }
98 virtual void OnBeforeNetworkStart(net::URLRequest* request, 97 virtual void OnBeforeNetworkStart(net::URLRequest* request,
99 bool* defer) OVERRIDE { 98 bool* defer) OVERRIDE {
100 NOTREACHED(); 99 NOTREACHED();
101 } 100 }
102 101
103 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE { 102 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {
104 if (!request->status().is_success()) { 103 if (!request->status().is_success()) {
105 callback_.Run(entry_.Pass(), false); 104 callback_.Run(false);
106 return; 105 return;
107 } 106 }
108 ReadFromBlob(); 107 ReadFromBlob();
109 } 108 }
110 109
111 virtual void ReadFromBlob() { 110 virtual void ReadFromBlob() {
112 int bytes_read = 0; 111 int bytes_read = 0;
113 bool done = 112 bool done =
114 blob_request_->Read(buffer_.get(), buffer_->size(), &bytes_read); 113 blob_request_->Read(buffer_.get(), buffer_->size(), &bytes_read);
115 if (done) 114 if (done)
116 OnReadCompleted(blob_request_.get(), bytes_read); 115 OnReadCompleted(blob_request_.get(), bytes_read);
117 } 116 }
118 117
119 virtual void OnReadCompleted(net::URLRequest* request, 118 virtual void OnReadCompleted(net::URLRequest* request,
120 int bytes_read) OVERRIDE { 119 int bytes_read) OVERRIDE {
121 if (!request->status().is_success()) { 120 if (!request->status().is_success()) {
122 callback_.Run(entry_.Pass(), false); 121 callback_.Run(false);
123 return; 122 return;
124 } 123 }
125 124
126 if (bytes_read == 0) { 125 if (bytes_read == 0) {
127 callback_.Run(entry_.Pass(), true); 126 callback_.Run(true);
128 return; 127 return;
129 } 128 }
130 129
131 net::CompletionCallback cache_write_callback = 130 net::CompletionCallback cache_write_callback =
132 base::Bind(&BlobReader::DidWriteDataToEntry, 131 base::Bind(&BlobReader::DidWriteDataToEntry,
133 weak_ptr_factory_.GetWeakPtr(), 132 weak_ptr_factory_.GetWeakPtr(),
134 bytes_read); 133 bytes_read);
135 134
136 int rv = entry_->WriteData(INDEX_RESPONSE_BODY, 135 int rv = entry_->WriteData(INDEX_RESPONSE_BODY,
137 cache_entry_offset_, 136 cache_entry_offset_,
138 buffer_.get(), 137 buffer_.get(),
139 bytes_read, 138 bytes_read,
140 cache_write_callback, 139 cache_write_callback,
141 true /* truncate */); 140 true /* truncate */);
142 if (rv != net::ERR_IO_PENDING) 141 if (rv != net::ERR_IO_PENDING)
143 cache_write_callback.Run(rv); 142 cache_write_callback.Run(rv);
144 } 143 }
145 144
146 void DidWriteDataToEntry(int expected_bytes, int rv) { 145 void DidWriteDataToEntry(int expected_bytes, int rv) {
147 if (rv != expected_bytes) { 146 if (rv != expected_bytes) {
148 callback_.Run(entry_.Pass(), false); 147 callback_.Run(false);
149 return; 148 return;
150 } 149 }
151 150
152 cache_entry_offset_ += rv; 151 cache_entry_offset_ += rv;
153 ReadFromBlob(); 152 ReadFromBlob();
154 } 153 }
155 154
156 private: 155 private:
157 int cache_entry_offset_; 156 int cache_entry_offset_;
158 disk_cache::ScopedEntryPtr entry_; 157 disk_cache::ScopedEntryPtr entry_;
159 scoped_ptr<net::URLRequest> blob_request_; 158 scoped_ptr<net::URLRequest> blob_request_;
160 EntryBoolCallback callback_; 159 BoolCallback callback_;
161 scoped_refptr<net::IOBufferWithSize> buffer_; 160 scoped_refptr<net::IOBufferWithSize> buffer_;
162 base::WeakPtrFactory<BlobReader> weak_ptr_factory_; 161 base::WeakPtrFactory<BlobReader> weak_ptr_factory_;
163 }; 162 };
164 163
164 // The state needed to pass between ServiceWorkerCache::Put callbacks.
165 struct PutContext {
166 PutContext(scoped_ptr<ServiceWorkerFetchRequest> request,
167 scoped_ptr<ServiceWorkerResponse> response,
168 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
169 const ServiceWorkerCache::ErrorCallback& callback,
170 net::URLRequestContext* request_context)
171 : request(request.Pass()),
172 response(response.Pass()),
173 blob_data_handle(blob_data_handle.Pass()),
174 callback(callback),
175 request_context(request_context),
176 cache_entry(NULL) {}
177 ~PutContext() {
178 if (cache_entry)
179 cache_entry->Close();
180 }
181
182 // Input parameters to the Put function.
183 scoped_ptr<ServiceWorkerFetchRequest> request;
184 scoped_ptr<ServiceWorkerResponse> response;
185 scoped_ptr<storage::BlobDataHandle> blob_data_handle;
186 ServiceWorkerCache::ErrorCallback callback;
187
188 net::URLRequestContext* request_context;
189 disk_cache::Entry* cache_entry;
horo 2014/09/26 02:15:02 Why don't you use ScopedEntryPtr?
jkarlin 2014/09/26 11:15:02 Because the asynchronous disk_cache API wants an E
horo 2014/09/29 03:13:24 Ah, I got it.
190
191 DISALLOW_COPY_AND_ASSIGN(PutContext);
192 };
193
165 // Put callbacks 194 // Put callbacks
166 void PutDidCreateEntry(scoped_ptr<ServiceWorkerFetchRequest> request, 195 void PutDidCreateEntry(scoped_ptr<PutContext> put_context, int rv);
167 scoped_ptr<ServiceWorkerResponse> response, 196 void PutDidWriteHeaders(scoped_ptr<PutContext> put_context,
168 const ServiceWorkerCache::ErrorCallback& callback,
169 scoped_ptr<disk_cache::Entry*> entryptr,
170 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
171 net::URLRequestContext* request_context,
172 int rv);
173 void PutDidWriteHeaders(scoped_ptr<ServiceWorkerResponse> response,
174 const ServiceWorkerCache::ErrorCallback& callback,
175 disk_cache::ScopedEntryPtr entry,
176 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
177 net::URLRequestContext* request_context,
178 int expected_bytes, 197 int expected_bytes,
179 int rv); 198 int rv);
180 void PutDidWriteBlobToCache(const ServiceWorkerCache::ErrorCallback& callback, 199 void PutDidWriteBlobToCache(scoped_ptr<PutContext> put_context,
181 scoped_ptr<BlobReader> blob_reader, 200 scoped_ptr<BlobReader> blob_reader,
182 disk_cache::ScopedEntryPtr entry,
183 bool success); 201 bool success);
184 202
185 // Match callbacks 203 // Match callbacks
186 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, 204 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request,
187 const ServiceWorkerCache::ResponseCallback& callback, 205 const ServiceWorkerCache::ResponseCallback& callback,
188 base::WeakPtr<storage::BlobStorageContext> blob_storage, 206 base::WeakPtr<storage::BlobStorageContext> blob_storage,
189 scoped_ptr<disk_cache::Entry*> entryptr, 207 scoped_ptr<disk_cache::Entry*> entryptr,
190 int rv); 208 int rv);
191 void MatchDidReadHeaderData( 209 void MatchDidReadHeaderData(
192 scoped_ptr<ServiceWorkerFetchRequest> request, 210 scoped_ptr<ServiceWorkerFetchRequest> request,
(...skipping 29 matching lines...) Expand all
222 const HeadersCallback& callback, 240 const HeadersCallback& callback,
223 const scoped_refptr<net::IOBufferWithSize>& buffer, 241 const scoped_refptr<net::IOBufferWithSize>& buffer,
224 int rv); 242 int rv);
225 243
226 // CreateBackend callbacks 244 // CreateBackend callbacks
227 void CreateBackendDidCreate(const ServiceWorkerCache::ErrorCallback& callback, 245 void CreateBackendDidCreate(const ServiceWorkerCache::ErrorCallback& callback,
228 scoped_ptr<ScopedBackendPtr> backend_ptr, 246 scoped_ptr<ScopedBackendPtr> backend_ptr,
229 base::WeakPtr<ServiceWorkerCache> cache, 247 base::WeakPtr<ServiceWorkerCache> cache,
230 int rv); 248 int rv);
231 249
232 void PutDidCreateEntry(scoped_ptr<ServiceWorkerFetchRequest> request, 250 void PutDidCreateEntry(scoped_ptr<PutContext> put_context, int rv) {
233 scoped_ptr<ServiceWorkerResponse> response,
234 const ServiceWorkerCache::ErrorCallback& callback,
235 scoped_ptr<disk_cache::Entry*> entryptr,
236 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
237 net::URLRequestContext* request_context,
238 int rv) {
239 if (rv != net::OK) { 251 if (rv != net::OK) {
240 callback.Run(ServiceWorkerCache::ErrorTypeExists); 252 put_context->callback.Run(ServiceWorkerCache::ErrorTypeExists);
241 return; 253 return;
242 } 254 }
243 255
244 DCHECK(entryptr); 256 DCHECK(put_context->cache_entry);
245 disk_cache::ScopedEntryPtr entry(*entryptr);
246 257
247 ServiceWorkerRequestResponseHeaders headers; 258 ServiceWorkerRequestResponseHeaders headers;
248 headers.set_method(request->method); 259 headers.set_method(put_context->request->method);
249 260
250 headers.set_status_code(response->status_code); 261 headers.set_status_code(put_context->response->status_code);
251 headers.set_status_text(response->status_text); 262 headers.set_status_text(put_context->response->status_text);
252 for (ServiceWorkerHeaderMap::const_iterator it = request->headers.begin(); 263 for (ServiceWorkerHeaderMap::const_iterator it =
253 it != request->headers.end(); 264 put_context->request->headers.begin();
265 it != put_context->request->headers.end();
254 ++it) { 266 ++it) {
255 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map = 267 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map =
256 headers.add_request_headers(); 268 headers.add_request_headers();
257 header_map->set_name(it->first); 269 header_map->set_name(it->first);
258 header_map->set_value(it->second); 270 header_map->set_value(it->second);
259 } 271 }
260 272
261 for (ServiceWorkerHeaderMap::const_iterator it = response->headers.begin(); 273 for (ServiceWorkerHeaderMap::const_iterator it =
262 it != response->headers.end(); 274 put_context->response->headers.begin();
275 it != put_context->response->headers.end();
263 ++it) { 276 ++it) {
264 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map = 277 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map =
265 headers.add_response_headers(); 278 headers.add_response_headers();
266 header_map->set_name(it->first); 279 header_map->set_name(it->first);
267 header_map->set_value(it->second); 280 header_map->set_value(it->second);
268 } 281 }
269 282
270 scoped_ptr<std::string> serialized(new std::string()); 283 scoped_ptr<std::string> serialized(new std::string());
271 if (!headers.SerializeToString(serialized.get())) { 284 if (!headers.SerializeToString(serialized.get())) {
272 callback.Run(ServiceWorkerCache::ErrorTypeStorage); 285 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage);
273 return; 286 return;
274 } 287 }
275 288
276 scoped_refptr<net::StringIOBuffer> buffer( 289 scoped_refptr<net::StringIOBuffer> buffer(
277 new net::StringIOBuffer(serialized.Pass())); 290 new net::StringIOBuffer(serialized.Pass()));
278 291
279 // Get a temporary copy of the entry pointer before passing it in base::Bind. 292 // Get a temporary copy of the entry pointer before passing it in base::Bind.
280 disk_cache::Entry* tmp_entry_ptr = entry.get(); 293 disk_cache::Entry* tmp_entry_ptr = put_context->cache_entry;
281 294
282 net::CompletionCallback write_headers_callback = 295 net::CompletionCallback write_headers_callback = base::Bind(
283 base::Bind(PutDidWriteHeaders, 296 PutDidWriteHeaders, base::Passed(put_context.Pass()), buffer->size());
284 base::Passed(response.Pass()),
285 callback,
286 base::Passed(entry.Pass()),
287 base::Passed(blob_data_handle.Pass()),
288 request_context,
289 buffer->size());
290 297
291 rv = tmp_entry_ptr->WriteData(INDEX_HEADERS, 298 rv = tmp_entry_ptr->WriteData(INDEX_HEADERS,
292 0 /* offset */, 299 0 /* offset */,
293 buffer.get(), 300 buffer.get(),
294 buffer->size(), 301 buffer->size(),
295 write_headers_callback, 302 write_headers_callback,
296 true /* truncate */); 303 true /* truncate */);
297 304
298 if (rv != net::ERR_IO_PENDING) 305 if (rv != net::ERR_IO_PENDING)
299 write_headers_callback.Run(rv); 306 write_headers_callback.Run(rv);
300 } 307 }
301 308
302 void PutDidWriteHeaders(scoped_ptr<ServiceWorkerResponse> response, 309 void PutDidWriteHeaders(scoped_ptr<PutContext> put_context,
303 const ServiceWorkerCache::ErrorCallback& callback,
304 disk_cache::ScopedEntryPtr entry,
305 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
306 net::URLRequestContext* request_context,
307 int expected_bytes, 310 int expected_bytes,
308 int rv) { 311 int rv) {
309 if (rv != expected_bytes) { 312 if (rv != expected_bytes) {
310 entry->Doom(); 313 put_context->cache_entry->Doom();
311 callback.Run(ServiceWorkerCache::ErrorTypeStorage); 314 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage);
312 return; 315 return;
313 } 316 }
314 317
315 // The metadata is written, now for the response content. The data is streamed 318 // The metadata is written, now for the response content. The data is streamed
316 // from the blob into the cache entry. 319 // from the blob into the cache entry.
317 320
318 if (response->blob_uuid.empty()) { 321 if (put_context->response->blob_uuid.empty()) {
319 callback.Run(ServiceWorkerCache::ErrorTypeOK); 322 put_context->callback.Run(ServiceWorkerCache::ErrorTypeOK);
320 return; 323 return;
321 } 324 }
322 325
323 DCHECK(blob_data_handle); 326 DCHECK(put_context->blob_data_handle);
324 327
328 disk_cache::ScopedEntryPtr entry(put_context->cache_entry);
329 put_context->cache_entry = NULL;
325 scoped_ptr<BlobReader> reader(new BlobReader(entry.Pass())); 330 scoped_ptr<BlobReader> reader(new BlobReader(entry.Pass()));
331
326 BlobReader* reader_ptr = reader.get(); 332 BlobReader* reader_ptr = reader.get();
327 333
328 reader_ptr->StreamBlobToCache( 334 // Grab some pointers before passing put_context in Bind.
329 request_context, 335 net::URLRequestContext* request_context = put_context->request_context;
330 blob_data_handle.Pass(), 336 scoped_ptr<storage::BlobDataHandle> blob_data_handle =
331 base::Bind( 337 put_context->blob_data_handle.Pass();
332 PutDidWriteBlobToCache, callback, base::Passed(reader.Pass()))); 338
339 reader_ptr->StreamBlobToCache(request_context,
340 blob_data_handle.Pass(),
341 base::Bind(PutDidWriteBlobToCache,
342 base::Passed(put_context.Pass()),
343 base::Passed(reader.Pass())));
333 } 344 }
334 345
335 void PutDidWriteBlobToCache(const ServiceWorkerCache::ErrorCallback& callback, 346 void PutDidWriteBlobToCache(scoped_ptr<PutContext> put_context,
336 scoped_ptr<BlobReader> blob_reader, 347 scoped_ptr<BlobReader> blob_reader,
337 disk_cache::ScopedEntryPtr entry,
338 bool success) { 348 bool success) {
339 if (!success) { 349 if (!success) {
340 entry->Doom(); 350 put_context->cache_entry->Doom();
341 callback.Run(ServiceWorkerCache::ErrorTypeStorage); 351 put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage);
342 return; 352 return;
343 } 353 }
344 354
345 callback.Run(ServiceWorkerCache::ErrorTypeOK); 355 put_context->callback.Run(ServiceWorkerCache::ErrorTypeOK);
346 } 356 }
347 357
348 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, 358 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request,
349 const ServiceWorkerCache::ResponseCallback& callback, 359 const ServiceWorkerCache::ResponseCallback& callback,
350 base::WeakPtr<storage::BlobStorageContext> blob_storage, 360 base::WeakPtr<storage::BlobStorageContext> blob_storage,
351 scoped_ptr<disk_cache::Entry*> entryptr, 361 scoped_ptr<disk_cache::Entry*> entryptr,
352 int rv) { 362 int rv) {
353 if (rv != net::OK) { 363 if (rv != net::OK) {
354 callback.Run(ServiceWorkerCache::ErrorTypeNotFound, 364 callback.Run(ServiceWorkerCache::ErrorTypeNotFound,
355 scoped_ptr<ServiceWorkerResponse>(), 365 scoped_ptr<ServiceWorkerResponse>(),
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 672
663 // The vector of open entries in the backend. 673 // The vector of open entries in the backend.
664 Entries entries; 674 Entries entries;
665 675
666 // The output of the Keys function. 676 // The output of the Keys function.
667 scoped_ptr<ServiceWorkerCache::Requests> out_keys; 677 scoped_ptr<ServiceWorkerCache::Requests> out_keys;
668 678
669 // Used for enumerating cache entries. 679 // Used for enumerating cache entries.
670 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; 680 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator;
671 disk_cache::Entry* enumerated_entry; 681 disk_cache::Entry* enumerated_entry;
682
683 DISALLOW_COPY_AND_ASSIGN(KeysContext);
672 }; 684 };
673 685
674 // static 686 // static
675 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache( 687 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache(
676 net::URLRequestContext* request_context, 688 net::URLRequestContext* request_context,
677 base::WeakPtr<storage::BlobStorageContext> blob_context) { 689 base::WeakPtr<storage::BlobStorageContext> blob_context) {
678 return make_scoped_refptr( 690 return make_scoped_refptr(
679 new ServiceWorkerCache(base::FilePath(), request_context, blob_context)); 691 new ServiceWorkerCache(base::FilePath(), request_context, blob_context));
680 } 692 }
681 693
(...skipping 10 matching lines...) Expand all
692 } 704 }
693 705
694 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() { 706 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() {
695 return weak_ptr_factory_.GetWeakPtr(); 707 return weak_ptr_factory_.GetWeakPtr();
696 } 708 }
697 709
698 void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request, 710 void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request,
699 scoped_ptr<ServiceWorkerResponse> response, 711 scoped_ptr<ServiceWorkerResponse> response,
700 const ErrorCallback& callback) { 712 const ErrorCallback& callback) {
701 scoped_ptr<storage::BlobDataHandle> blob_data_handle; 713 scoped_ptr<storage::BlobDataHandle> blob_data_handle;
702
703 if (!response->blob_uuid.empty()) { 714 if (!response->blob_uuid.empty()) {
704 if (!blob_storage_context_) { 715 if (!blob_storage_context_) {
705 callback.Run(ErrorTypeStorage); 716 callback.Run(ErrorTypeStorage);
706 return; 717 return;
707 } 718 }
708 blob_data_handle = 719 blob_data_handle =
709 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); 720 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid);
710 if (!blob_data_handle) { 721 if (!blob_data_handle) {
711 callback.Run(ErrorTypeStorage); 722 callback.Run(ErrorTypeStorage);
712 return; 723 return;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 void ServiceWorkerCache::PutImpl( 861 void ServiceWorkerCache::PutImpl(
851 scoped_ptr<ServiceWorkerFetchRequest> request, 862 scoped_ptr<ServiceWorkerFetchRequest> request,
852 scoped_ptr<ServiceWorkerResponse> response, 863 scoped_ptr<ServiceWorkerResponse> response,
853 scoped_ptr<storage::BlobDataHandle> blob_data_handle, 864 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
854 const ErrorCallback& callback) { 865 const ErrorCallback& callback) {
855 if (!backend_) { 866 if (!backend_) {
856 callback.Run(ErrorTypeStorage); 867 callback.Run(ErrorTypeStorage);
857 return; 868 return;
858 } 869 }
859 870
860 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); 871 scoped_ptr<PutContext> put_context(new PutContext(request.Pass(),
872 response.Pass(),
873 blob_data_handle.Pass(),
874 callback,
875 request_context_));
861 876
862 disk_cache::Entry** entry_ptr = entry.get(); 877 disk_cache::Entry** entry_ptr = &put_context->cache_entry;
863 878 ServiceWorkerFetchRequest* request_ptr = put_context->request.get();
864 ServiceWorkerFetchRequest* request_ptr = request.get();
865 879
866 net::CompletionCallback create_entry_callback = 880 net::CompletionCallback create_entry_callback =
867 base::Bind(PutDidCreateEntry, 881 base::Bind(PutDidCreateEntry, base::Passed(put_context.Pass()));
868 base::Passed(request.Pass()),
869 base::Passed(response.Pass()),
870 callback,
871 base::Passed(entry.Pass()),
872 base::Passed(blob_data_handle.Pass()),
873 request_context_);
874 882
875 int rv = backend_->CreateEntry( 883 int rv = backend_->CreateEntry(
876 request_ptr->url.spec(), entry_ptr, create_entry_callback); 884 request_ptr->url.spec(), entry_ptr, create_entry_callback);
877 885
878 if (rv != net::ERR_IO_PENDING) 886 if (rv != net::ERR_IO_PENDING)
879 create_entry_callback.Run(rv); 887 create_entry_callback.Run(rv);
880 } 888 }
881 889
882 // static 890 // static
883 void ServiceWorkerCache::KeysDidOpenNextEntry( 891 void ServiceWorkerCache::KeysDidOpenNextEntry(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 initialized_ = true; 1024 initialized_ = true;
1017 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); 1025 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin();
1018 it != init_callbacks_.end(); 1026 it != init_callbacks_.end();
1019 ++it) { 1027 ++it) {
1020 it->Run(); 1028 it->Run();
1021 } 1029 }
1022 init_callbacks_.clear(); 1030 init_callbacks_.clear();
1023 } 1031 }
1024 1032
1025 } // namespace content 1033 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698