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

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

Issue 465463002: Initial implementation of ServiceWorkerCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cache2
Patch Set: Nits Created 6 years, 4 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 "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"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "content/browser/service_worker/service_worker_cache.pb.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "net/base/io_buffer.h"
15 #include "net/base/net_errors.h"
16 #include "net/disk_cache/disk_cache.h"
10 #include "net/url_request/url_request_context.h" 17 #include "net/url_request/url_request_context.h"
18 #include "webkit/browser/blob/blob_data_handle.h"
11 #include "webkit/browser/blob/blob_storage_context.h" 19 #include "webkit/browser/blob/blob_storage_context.h"
20 #include "webkit/browser/blob/blob_url_request_job_factory.h"
12 21
13 namespace content { 22 namespace content {
14 23
24 namespace {
25 // The maximum size of an individual cache. Ultimately cache size is controlled
26 // per-origin.
27 const int kMaxCacheBytes = 512 * 1024 * 1024;
28
29 // Buffer size for cache and blob reading/writing.
30 const int kBufferSize = 1024 * 512;
31 }
32
33 struct ServiceWorkerCache::ResponseReadContext {
34 ResponseReadContext(scoped_refptr<net::IOBufferWithSize> buff,
35 scoped_refptr<webkit_blob::BlobData> blob)
36 : buffer(buff), blob_data(blob), total_bytes_read(0) {}
37
38 scoped_refptr<net::IOBufferWithSize> buffer;
39 scoped_refptr<webkit_blob::BlobData> blob_data;
40 int total_bytes_read;
41
42 DISALLOW_COPY_AND_ASSIGN(ResponseReadContext);
43 };
44
45 // Streams data from a blob and writes it to a given disk_cache::Entry.
46 class ServiceWorkerCache::BlobReader : public net::URLRequest::Delegate {
47 public:
48 BlobReader(disk_cache::ScopedEntryPtr entry)
49 : cache_entry_offset_(0),
50 buffer_(new net::IOBufferWithSize(kBufferSize)),
51 weak_ptr_factory_(this) {
52 DCHECK(entry);
53 entry_ = entry.Pass();
54 }
55
56 void StreamBlobToCache(
57 net::URLRequestContext* request_context,
58 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle,
59 const EntryBoolCallback& callback) {
60 callback_ = callback;
61 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest(
62 blob_data_handle.Pass(), request_context, this);
63 blob_request_->Start();
64 }
65
66 // net::URLRequest::Delegate overrides for reading blobs.
67 virtual void OnReceivedRedirect(net::URLRequest* request,
68 const GURL& new_url,
69 bool* defer_redirect) OVERRIDE {
70 NOTREACHED();
71 }
72 virtual void OnAuthRequired(net::URLRequest* request,
73 net::AuthChallengeInfo* auth_info) OVERRIDE {
74 NOTREACHED();
75 }
76 virtual void OnCertificateRequested(
77 net::URLRequest* request,
78 net::SSLCertRequestInfo* cert_request_info) OVERRIDE {
79 NOTREACHED();
80 }
81 virtual void OnSSLCertificateError(net::URLRequest* request,
82 const net::SSLInfo& ssl_info,
83 bool fatal) OVERRIDE {
84 NOTREACHED();
85 }
86 virtual void OnBeforeNetworkStart(net::URLRequest* request,
87 bool* defer) OVERRIDE {
88 NOTREACHED();
89 }
90
91 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {
92 if (!request->status().is_success()) {
93 callback_.Run(entry_.Pass(), false);
94 return;
95 }
96 ReadFromBlob();
97 }
98
99 virtual void ReadFromBlob() {
100 int bytes_read = 0;
101 bool done =
102 blob_request_->Read(buffer_.get(), buffer_->size(), &bytes_read);
103 if (done)
104 OnReadCompleted(blob_request_.get(), bytes_read);
105 }
106
107 virtual void OnReadCompleted(net::URLRequest* request,
108 int bytes_read) OVERRIDE {
109 if (!request->status().is_success()) {
110 callback_.Run(entry_.Pass(), false);
111 return;
112 }
113
114 if (bytes_read == 0) {
115 callback_.Run(entry_.Pass(), true);
116 return;
117 }
118
119 net::CompletionCallback cache_write_callback =
120 base::Bind(&BlobReader::DidWriteDataToEntry,
121 weak_ptr_factory_.GetWeakPtr(),
122 bytes_read);
123
124 int rv = entry_->WriteData(ServiceWorkerCache::INDEX_RESPONSE_BODY,
125 cache_entry_offset_,
126 buffer_,
127 bytes_read,
128 cache_write_callback,
129 true /* truncate */);
130 if (rv != net::ERR_IO_PENDING)
131 cache_write_callback.Run(rv);
132 }
133
134 void DidWriteDataToEntry(int expected_bytes, int rv) {
135 if (rv != expected_bytes) {
136 callback_.Run(entry_.Pass(), false);
137 return;
138 }
139
140 cache_entry_offset_ += rv;
141 ReadFromBlob();
142 }
143
144 private:
145 int cache_entry_offset_;
146 disk_cache::ScopedEntryPtr entry_;
147 scoped_ptr<net::URLRequest> blob_request_;
148 EntryBoolCallback callback_;
149 scoped_refptr<net::IOBufferWithSize> buffer_;
150 base::WeakPtrFactory<ServiceWorkerCache::BlobReader> weak_ptr_factory_;
151 };
152
15 // static 153 // static
16 scoped_ptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache( 154 scoped_ptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache(
17 const std::string& name, 155 const std::string& name,
18 net::URLRequestContext* request_context, 156 net::URLRequestContext* request_context,
19 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context) { 157 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context) {
20 return make_scoped_ptr(new ServiceWorkerCache( 158 return make_scoped_ptr(new ServiceWorkerCache(
21 base::FilePath(), name, request_context, blob_context)); 159 base::FilePath(), name, request_context, blob_context));
22 } 160 }
23 161
24 // static 162 // static
25 scoped_ptr<ServiceWorkerCache> ServiceWorkerCache::CreatePersistentCache( 163 scoped_ptr<ServiceWorkerCache> ServiceWorkerCache::CreatePersistentCache(
26 const base::FilePath& path, 164 const base::FilePath& path,
27 const std::string& name, 165 const std::string& name,
28 net::URLRequestContext* request_context, 166 net::URLRequestContext* request_context,
29 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context) { 167 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context) {
30 return make_scoped_ptr( 168 return make_scoped_ptr(
31 new ServiceWorkerCache(path, name, request_context, blob_context)); 169 new ServiceWorkerCache(path, name, request_context, blob_context));
32 } 170 }
33 171
34 void ServiceWorkerCache::CreateBackend( 172 ServiceWorkerCache::~ServiceWorkerCache() {
35 const base::Callback<void(bool)>& callback) {
36 callback.Run(true);
37 } 173 }
38 174
39 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() { 175 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() {
40 return weak_ptr_factory_.GetWeakPtr(); 176 return weak_ptr_factory_.GetWeakPtr();
41 } 177 }
42 178
179 void ServiceWorkerCache::CreateBackend(const ErrorCallback& callback) {
180 net::CacheType cache_type =
181 path_.empty() ? net::MEMORY_CACHE : net::DISK_CACHE;
182
183 net::CompletionCallback create_cache_callback =
184 base::Bind(&ServiceWorkerCache::CreateBackendDidCreate,
185 weak_ptr_factory_.GetWeakPtr(),
186 callback);
187
188 // TODO(jkarlin): Use the cache MessageLoopProxy that ServiceWorkerCacheCore
189 // has for disk caches.
190 int rv = disk_cache::CreateCacheBackend(
191 cache_type,
192 net::CACHE_BACKEND_SIMPLE,
193 path_,
194 kMaxCacheBytes,
195 true, /* force */
196 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(),
197 NULL,
198 &backend_,
199 create_cache_callback);
200 if (rv != net::ERR_IO_PENDING)
201 create_cache_callback.Run(rv);
202 }
203
204 void ServiceWorkerCache::CreateBackendDidCreate(const ErrorCallback& callback,
205 int rv) {
206 if (rv != net::OK) {
207 callback.Run(ErrorTypeStorage);
208 return;
209 }
210 callback.Run(ErrorTypeOK);
211 }
212
213 void ServiceWorkerCache::Put(ServiceWorkerFetchRequest* request,
214 ServiceWorkerResponse* response,
215 const ErrorCallback& callback) {
216 DCHECK(backend_);
217
218 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*);
219
220 disk_cache::Entry** entry_ptr = entry.get();
221
222 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle;
223
224 if (!response->blob_uuid.empty()) {
225 if (!blob_storage_context_) {
226 callback.Run(ErrorTypeStorage);
227 return;
228 }
229 blob_data_handle =
230 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid);
231 if (!blob_data_handle) {
232 callback.Run(ErrorTypeStorage);
233 return;
234 }
235 }
236
237 net::CompletionCallback create_entry_callback =
238 base::Bind(&ServiceWorkerCache::PutDidCreateEntry,
239 weak_ptr_factory_.GetWeakPtr(),
240 request,
241 response,
242 callback,
243 base::Passed(entry.Pass()),
244 base::Passed(blob_data_handle.Pass()));
245
246 int rv = backend_->CreateEntry(
247 request->url.spec(), entry_ptr, create_entry_callback);
248
249 if (rv != net::ERR_IO_PENDING)
250 create_entry_callback.Run(rv);
251 }
252
253 void ServiceWorkerCache::Match(ServiceWorkerFetchRequest* request,
254 const ResponseCallback& callback) {
255 DCHECK(backend_);
256
257 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*);
258
259 disk_cache::Entry** entry_ptr = entry.get();
260
261 net::CompletionCallback open_entry_callback =
262 base::Bind(&ServiceWorkerCache::MatchDidOpenEntry,
263 weak_ptr_factory_.GetWeakPtr(),
264 request,
265 callback,
266 base::Passed(entry.Pass()));
267
268 int rv =
269 backend_->OpenEntry(request->url.spec(), entry_ptr, open_entry_callback);
270 if (rv != net::ERR_IO_PENDING)
271 open_entry_callback.Run(rv);
272 }
273
274 void ServiceWorkerCache::Delete(ServiceWorkerFetchRequest* request,
275 const ErrorCallback& callback) {
276 DCHECK(backend_);
277
278 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*);
279
280 disk_cache::Entry** entry_ptr = entry.get();
281
282 net::CompletionCallback open_entry_callback =
283 base::Bind(&ServiceWorkerCache::DeleteDidOpenEntry,
284 weak_ptr_factory_.GetWeakPtr(),
285 request,
286 callback,
287 base::Passed(entry.Pass()));
288
289 int rv =
290 backend_->OpenEntry(request->url.spec(), entry_ptr, open_entry_callback);
291 if (rv != net::ERR_IO_PENDING)
292 open_entry_callback.Run(rv);
293 }
294
295 void ServiceWorkerCache::DerefBlob(const std::string& uuid) {
296 DropBlobDataHandle(uuid);
297 }
298
43 ServiceWorkerCache::ServiceWorkerCache( 299 ServiceWorkerCache::ServiceWorkerCache(
44 const base::FilePath& path, 300 const base::FilePath& path,
45 const std::string& name, 301 const std::string& name,
46 net::URLRequestContext* request_context, 302 net::URLRequestContext* request_context,
47 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context) 303 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context)
48 : path_(path), 304 : path_(path),
49 name_(name), 305 name_(name),
50 request_context_(request_context), 306 request_context_(request_context),
51 blob_storage_context_(blob_context), 307 blob_storage_context_(blob_context),
52 id_(0), 308 id_(0),
53 weak_ptr_factory_(this) { 309 weak_ptr_factory_(this) {
54 } 310 }
55 311
56 ServiceWorkerCache::~ServiceWorkerCache() { 312 void ServiceWorkerCache::MatchDidOpenEntry(
313 ServiceWorkerFetchRequest* request,
314 const ResponseCallback& callback,
315 scoped_ptr<disk_cache::Entry*> entryptr,
316 int rv) {
317 if (rv != net::OK) {
318 callback.Run(ErrorTypeNotFound, scoped_ptr<ServiceWorkerResponse>());
319 return;
320 }
321
322 DCHECK(entryptr);
323 disk_cache::ScopedEntryPtr entry(*entryptr);
324
325 scoped_refptr<net::IOBufferWithSize> buffer(
326 new net::IOBufferWithSize(entry->GetDataSize(INDEX_HEADERS)));
327
328 // Copy the entry pointer before passing it in base::Bind.
329 disk_cache::Entry* tmp_entry_ptr = entry.get();
330
331 net::CompletionCallback read_header_callback =
332 base::Bind(&ServiceWorkerCache::MatchDidReadHeaderData,
333 weak_ptr_factory_.GetWeakPtr(),
334 request,
335 callback,
336 base::Passed(entry.Pass()),
337 buffer);
338
339 int read_rv = tmp_entry_ptr->ReadData(
340 INDEX_HEADERS, 0, buffer.get(), buffer->size(), read_header_callback);
341
342 if (read_rv != net::ERR_IO_PENDING)
343 read_header_callback.Run(read_rv);
344 }
345
346 void ServiceWorkerCache::MatchDidReadHeaderData(
347 ServiceWorkerFetchRequest* request,
348 const ResponseCallback& callback,
349 disk_cache::ScopedEntryPtr entry,
350 const scoped_refptr<net::IOBufferWithSize>& buffer,
351 int rv) {
352 if (rv != buffer->size()) {
353 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>());
354
355 return;
356 }
357
358 ServiceWorkerRequestResponseHeaders headers;
359
360 if (!headers.ParseFromArray(buffer->data(), buffer->size())) {
361 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>());
362
363 return;
364 }
365
366 scoped_ptr<ServiceWorkerResponse> response(
367 new ServiceWorkerResponse(request->url,
368 headers.status_code(),
369 headers.status_text(),
370 std::map<std::string, std::string>(),
371 ""));
372
373 for (int i = 0; i < headers.response_headers_size(); ++i) {
374 const ServiceWorkerRequestResponseHeaders::HeaderMap header =
375 headers.response_headers(i);
376 response->headers.insert(std::make_pair(header.name(), header.value()));
377 }
378
379 // TODO(jkarlin): Insert vary validation here.
380
381 if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) {
382 callback.Run(ErrorTypeOK, response.Pass());
383
384 return;
385 }
386
387 // Stream the response body into a blob.
388 if (!blob_storage_context_) {
389 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>());
390
391 return;
392 }
393
394 response->blob_uuid = base::GenerateGUID();
395
396 scoped_refptr<webkit_blob::BlobData> blob_data =
397 new webkit_blob::BlobData(response->blob_uuid);
398 scoped_refptr<net::IOBufferWithSize> response_body_buffer(
399 new net::IOBufferWithSize(kBufferSize));
400
401 scoped_ptr<ResponseReadContext> read_context(
402 new ResponseReadContext(response_body_buffer, blob_data));
403
404 // Copy the entry pointer before passing it in base::Bind.
405 disk_cache::Entry* tmp_entry_ptr = entry.get();
406
407 net::CompletionCallback read_callback =
408 base::Bind(&ServiceWorkerCache::MatchDidReadResponseBodyData,
409 weak_ptr_factory_.GetWeakPtr(),
410 request,
411 callback,
412 base::Passed(entry.Pass()),
413 base::Passed(response.Pass()),
414 base::Passed(read_context.Pass()));
415
416 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY,
417 0,
418 response_body_buffer.get(),
419 response_body_buffer->size(),
420 read_callback);
421
422 if (read_rv != net::ERR_IO_PENDING)
423 read_callback.Run(read_rv);
424 }
425
426 void ServiceWorkerCache::MatchDidReadResponseBodyData(
427 ServiceWorkerFetchRequest* request,
428 const ResponseCallback& callback,
429 disk_cache::ScopedEntryPtr entry,
430 scoped_ptr<ServiceWorkerResponse> response,
431 scoped_ptr<ResponseReadContext> response_context,
432 int rv) {
433 if (rv < 0) {
434 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>());
435 }
436
437 if (rv == 0) {
438 MatchDoneWithBody(
439 request, callback, response.Pass(), response_context.Pass());
440 return;
441 }
442
443 // TODO(jkarlin): This copying of the the entire cache response into memory is
444 // awful. Create a new interface around SimpleCache that provides access the
445 // data directly from the file. See bug http://crbug.com/403493.
446 response_context->blob_data->AppendData(response_context->buffer->data(), rv);
447 response_context->total_bytes_read += rv;
448 int total_bytes_read = response_context->total_bytes_read;
449
450 // Grab some pointers before passing them in bind.
451 net::IOBufferWithSize* buffer = response_context->buffer;
452 disk_cache::Entry* tmp_entry_ptr = entry.get();
453
454 net::CompletionCallback read_callback =
455 base::Bind(&ServiceWorkerCache::MatchDidReadResponseBodyData,
456 weak_ptr_factory_.GetWeakPtr(),
457 request,
458 callback,
459 base::Passed(entry.Pass()),
460 base::Passed(response.Pass()),
461 base::Passed(response_context.Pass()));
462
463 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY,
464 total_bytes_read,
465 buffer,
466 buffer->size(),
467 read_callback);
468
469 if (read_rv != net::ERR_IO_PENDING)
470 read_callback.Run(read_rv);
471 }
472
473 void ServiceWorkerCache::MatchDoneWithBody(
474 ServiceWorkerFetchRequest* request,
475 const ResponseCallback& callback,
476 scoped_ptr<ServiceWorkerResponse> response,
477 scoped_ptr<ResponseReadContext> response_context) {
478 if (!blob_storage_context_) {
479 callback.Run(ErrorTypeStorage, scoped_ptr<ServiceWorkerResponse>());
480 return;
481 }
482
483 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle(
484 blob_storage_context_->AddFinishedBlob(
485 response_context->blob_data.get()));
486
487 HoldBlobDataHandle(response->blob_uuid, blob_data_handle.Pass());
488 callback.Run(ErrorTypeOK, response.Pass());
489 }
490
491 void ServiceWorkerCache::PutDidCreateEntry(
492 ServiceWorkerFetchRequest* request,
493 ServiceWorkerResponse* response,
494 const ErrorCallback& callback,
495 scoped_ptr<disk_cache::Entry*> entryptr,
496 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle,
497 int rv) {
498 if (rv != net::OK) {
499 callback.Run(ErrorTypeExists);
500 return;
501 }
502
503 DCHECK(entryptr);
504 disk_cache::ScopedEntryPtr entry(*entryptr);
505
506 ServiceWorkerRequestResponseHeaders headers;
507 headers.set_method(request->method);
508
509 headers.set_status_code(response->status_code);
510 headers.set_status_text(response->status_text);
511 for (std::map<std::string, std::string>::const_iterator it =
512 request->headers.begin();
513 it != request->headers.end();
514 ++it) {
515 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map =
516 headers.add_request_headers();
517 header_map->set_name(it->first);
518 header_map->set_value(it->second);
519 }
520
521 for (std::map<std::string, std::string>::const_iterator it =
522 response->headers.begin();
523 it != response->headers.end();
524 ++it) {
525 ServiceWorkerRequestResponseHeaders::HeaderMap* header_map =
526 headers.add_response_headers();
527 header_map->set_name(it->first);
528 header_map->set_value(it->second);
529 }
530
531 std::string serialized;
532 if (!headers.SerializeToString(&serialized)) {
533 callback.Run(ErrorTypeStorage);
534 }
535
536 scoped_refptr<net::ZeroCopyStringIOBuffer> buffer(
537 new net::ZeroCopyStringIOBuffer(&serialized));
538
539 // Get a temporary copy of the entry pointer before passing it in base::Bind.
540 disk_cache::Entry* tmp_entry_ptr = entry.get();
541
542 net::CompletionCallback write_headers_callback =
543 base::Bind(&ServiceWorkerCache::PutDidWriteHeaders,
544 weak_ptr_factory_.GetWeakPtr(),
545 response,
546 callback,
547 base::Passed(entry.Pass()),
548 base::Passed(blob_data_handle.Pass()),
549 buffer->string()->size());
550
551 rv = tmp_entry_ptr->WriteData(INDEX_HEADERS,
552 0 /* offset */,
553 buffer,
554 buffer->string()->size(),
555 write_headers_callback,
556 true /* truncate */);
557
558 if (rv != net::ERR_IO_PENDING)
559 write_headers_callback.Run(rv);
560 }
561
562 void ServiceWorkerCache::PutDidWriteHeaders(
563 ServiceWorkerResponse* response,
564 const ErrorCallback& callback,
565 disk_cache::ScopedEntryPtr entry,
566 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle,
567 int expected_bytes,
568 int rv) {
569 if (rv != expected_bytes) {
570 entry->Doom();
571 callback.Run(ErrorTypeStorage);
572 return;
573 }
574
575 // The metadata is written, now for the response content. The data is streamed
576 // from the blob into the cache entry.
577
578 if (response->blob_uuid.empty()) {
579 callback.Run(ErrorTypeOK);
580 return;
581 }
582
583 DCHECK(blob_data_handle);
584
585 scoped_ptr<BlobReader> reader(new BlobReader(entry.Pass()));
586
587 reader->StreamBlobToCache(
588 request_context_,
589 blob_data_handle.Pass(),
590 base::Bind(&ServiceWorkerCache::PutDidWriteBlobToCache,
591 weak_ptr_factory_.GetWeakPtr(),
592 callback,
593 base::Passed(reader.Pass())));
594 }
595
596 void ServiceWorkerCache::PutDidWriteBlobToCache(
597 const ErrorCallback& callback,
598 scoped_ptr<BlobReader> blob_reader,
599 disk_cache::ScopedEntryPtr entry,
600 bool success) {
601 if (!success) {
602 entry->Doom();
603 callback.Run(ErrorTypeStorage);
604 return;
605 }
606
607 callback.Run(ErrorTypeOK);
608 }
609
610 void ServiceWorkerCache::DeleteDidOpenEntry(
611 ServiceWorkerFetchRequest* request,
612 const ErrorCallback& callback,
613 scoped_ptr<disk_cache::Entry*> entryptr,
614 int rv) {
615 if (rv != net::OK) {
616 callback.Run(ErrorTypeNotFound);
617 return;
618 }
619
620 DCHECK(entryptr);
621 disk_cache::ScopedEntryPtr entry(*entryptr);
622
623 entry->Doom();
624 callback.Run(ErrorTypeOK);
625 }
626
627 void ServiceWorkerCache::HoldBlobDataHandle(
628 const std::string& uuid,
629 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle) {
630 DCHECK(!ContainsKey(blob_data_handle_map_, uuid));
631 blob_data_handle_map_[uuid] = blob_data_handle.release();
632 }
633
634 void ServiceWorkerCache::DropBlobDataHandle(const std::string& uuid) {
635 BlobDataHandleMap::iterator iter = blob_data_handle_map_.find(uuid);
636 if (iter != blob_data_handle_map_.end()) {
637 delete iter->second;
638 blob_data_handle_map_.erase(iter);
639 } else {
640 DLOG(FATAL) << "Failed to find blob UUID in map:" << uuid;
641 }
57 } 642 }
58 643
59 } // namespace content 644 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698