| 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 "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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 private: | 155 private: |
| 156 int cache_entry_offset_; | 156 int cache_entry_offset_; |
| 157 disk_cache::ScopedEntryPtr entry_; | 157 disk_cache::ScopedEntryPtr entry_; |
| 158 scoped_ptr<net::URLRequest> blob_request_; | 158 scoped_ptr<net::URLRequest> blob_request_; |
| 159 EntryBoolCallback callback_; | 159 EntryBoolCallback callback_; |
| 160 scoped_refptr<net::IOBufferWithSize> buffer_; | 160 scoped_refptr<net::IOBufferWithSize> buffer_; |
| 161 base::WeakPtrFactory<BlobReader> weak_ptr_factory_; | 161 base::WeakPtrFactory<BlobReader> weak_ptr_factory_; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 // Put callbacks | 164 // Put callbacks |
| 165 void PutDidCreateEntry(ServiceWorkerFetchRequest* request, | 165 void PutDidCreateEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 166 ServiceWorkerResponse* response, | 166 scoped_ptr<ServiceWorkerResponse> response, |
| 167 const ServiceWorkerCache::ErrorCallback& callback, | 167 const ServiceWorkerCache::ErrorCallback& callback, |
| 168 scoped_ptr<disk_cache::Entry*> entryptr, | 168 scoped_ptr<disk_cache::Entry*> entryptr, |
| 169 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 169 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
| 170 net::URLRequestContext* request_context, | 170 net::URLRequestContext* request_context, |
| 171 int rv); | 171 int rv); |
| 172 void PutDidWriteHeaders(ServiceWorkerResponse* response, | 172 void PutDidWriteHeaders(scoped_ptr<ServiceWorkerResponse> response, |
| 173 const ServiceWorkerCache::ErrorCallback& callback, | 173 const ServiceWorkerCache::ErrorCallback& callback, |
| 174 disk_cache::ScopedEntryPtr entry, | 174 disk_cache::ScopedEntryPtr entry, |
| 175 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 175 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
| 176 net::URLRequestContext* request_context, | 176 net::URLRequestContext* request_context, |
| 177 int expected_bytes, | 177 int expected_bytes, |
| 178 int rv); | 178 int rv); |
| 179 void PutDidWriteBlobToCache(const ServiceWorkerCache::ErrorCallback& callback, | 179 void PutDidWriteBlobToCache(const ServiceWorkerCache::ErrorCallback& callback, |
| 180 scoped_ptr<BlobReader> blob_reader, | 180 scoped_ptr<BlobReader> blob_reader, |
| 181 disk_cache::ScopedEntryPtr entry, | 181 disk_cache::ScopedEntryPtr entry, |
| 182 bool success); | 182 bool success); |
| 183 | 183 |
| 184 // Match callbacks | 184 // Match callbacks |
| 185 void MatchDidOpenEntry(ServiceWorkerFetchRequest* request, | 185 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 186 const ServiceWorkerCache::ResponseCallback& callback, | 186 const ServiceWorkerCache::ResponseCallback& callback, |
| 187 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 187 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 188 scoped_ptr<disk_cache::Entry*> entryptr, | 188 scoped_ptr<disk_cache::Entry*> entryptr, |
| 189 int rv); | 189 int rv); |
| 190 void MatchDidReadHeaderData( | 190 void MatchDidReadHeaderData( |
| 191 ServiceWorkerFetchRequest* request, | 191 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 192 const ServiceWorkerCache::ResponseCallback& callback, | 192 const ServiceWorkerCache::ResponseCallback& callback, |
| 193 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 193 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 194 disk_cache::ScopedEntryPtr entry, | 194 disk_cache::ScopedEntryPtr entry, |
| 195 scoped_ptr<ServiceWorkerRequestResponseHeaders> headers); | 195 scoped_ptr<ServiceWorkerRequestResponseHeaders> headers); |
| 196 void MatchDidReadResponseBodyData( | 196 void MatchDidReadResponseBodyData( |
| 197 ServiceWorkerFetchRequest* request, | 197 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 198 const ServiceWorkerCache::ResponseCallback& callback, | 198 const ServiceWorkerCache::ResponseCallback& callback, |
| 199 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 199 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 200 disk_cache::ScopedEntryPtr entry, | 200 disk_cache::ScopedEntryPtr entry, |
| 201 scoped_ptr<ServiceWorkerResponse> response, | 201 scoped_ptr<ServiceWorkerResponse> response, |
| 202 scoped_ptr<ResponseReadContext> response_context, | 202 scoped_ptr<ResponseReadContext> response_context, |
| 203 int rv); | 203 int rv); |
| 204 void MatchDoneWithBody(ServiceWorkerFetchRequest* request, | 204 void MatchDoneWithBody(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 205 const ServiceWorkerCache::ResponseCallback& callback, | 205 const ServiceWorkerCache::ResponseCallback& callback, |
| 206 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 206 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 207 scoped_ptr<ServiceWorkerResponse> response, | 207 scoped_ptr<ServiceWorkerResponse> response, |
| 208 scoped_ptr<ResponseReadContext> response_context); | 208 scoped_ptr<ResponseReadContext> response_context); |
| 209 | 209 |
| 210 // Delete callbacks | 210 // Delete callbacks |
| 211 void DeleteDidOpenEntry(ServiceWorkerFetchRequest* request, | 211 void DeleteDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 212 const ServiceWorkerCache::ErrorCallback& callback, | 212 const ServiceWorkerCache::ErrorCallback& callback, |
| 213 scoped_ptr<disk_cache::Entry*> entryptr, | 213 scoped_ptr<disk_cache::Entry*> entryptr, |
| 214 int rv); | 214 int rv); |
| 215 | 215 |
| 216 // Copy headers out of a cache entry and into a protobuf. The callback is | 216 // Copy headers out of a cache entry and into a protobuf. The callback is |
| 217 // guaranteed to be run. | 217 // guaranteed to be run. |
| 218 void ReadHeaders(disk_cache::Entry* entry, const HeadersCallback& callback); | 218 void ReadHeaders(disk_cache::Entry* entry, const HeadersCallback& callback); |
| 219 void ReadHeadersDidReadHeaderData( | 219 void ReadHeadersDidReadHeaderData( |
| 220 disk_cache::Entry* entry, | 220 disk_cache::Entry* entry, |
| 221 const HeadersCallback& callback, | 221 const HeadersCallback& callback, |
| 222 const scoped_refptr<net::IOBufferWithSize>& buffer, | 222 const scoped_refptr<net::IOBufferWithSize>& buffer, |
| 223 int rv); | 223 int rv); |
| 224 | 224 |
| 225 // CreateBackend callbacks | 225 // CreateBackend callbacks |
| 226 void CreateBackendDidCreate(const ServiceWorkerCache::ErrorCallback& callback, | 226 void CreateBackendDidCreate(const ServiceWorkerCache::ErrorCallback& callback, |
| 227 scoped_ptr<ScopedBackendPtr> backend_ptr, | 227 scoped_ptr<ScopedBackendPtr> backend_ptr, |
| 228 base::WeakPtr<ServiceWorkerCache> cache, | 228 base::WeakPtr<ServiceWorkerCache> cache, |
| 229 int rv); | 229 int rv); |
| 230 | 230 |
| 231 void PutDidCreateEntry(ServiceWorkerFetchRequest* request, | 231 void PutDidCreateEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 232 ServiceWorkerResponse* response, | 232 scoped_ptr<ServiceWorkerResponse> response, |
| 233 const ServiceWorkerCache::ErrorCallback& callback, | 233 const ServiceWorkerCache::ErrorCallback& callback, |
| 234 scoped_ptr<disk_cache::Entry*> entryptr, | 234 scoped_ptr<disk_cache::Entry*> entryptr, |
| 235 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 235 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
| 236 net::URLRequestContext* request_context, | 236 net::URLRequestContext* request_context, |
| 237 int rv) { | 237 int rv) { |
| 238 if (rv != net::OK) { | 238 if (rv != net::OK) { |
| 239 callback.Run(ServiceWorkerCache::ErrorTypeExists); | 239 callback.Run(ServiceWorkerCache::ErrorTypeExists); |
| 240 return; | 240 return; |
| 241 } | 241 } |
| 242 | 242 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 275 } |
| 276 | 276 |
| 277 scoped_refptr<net::StringIOBuffer> buffer( | 277 scoped_refptr<net::StringIOBuffer> buffer( |
| 278 new net::StringIOBuffer(serialized.Pass())); | 278 new net::StringIOBuffer(serialized.Pass())); |
| 279 | 279 |
| 280 // Get a temporary copy of the entry pointer before passing it in base::Bind. | 280 // Get a temporary copy of the entry pointer before passing it in base::Bind. |
| 281 disk_cache::Entry* tmp_entry_ptr = entry.get(); | 281 disk_cache::Entry* tmp_entry_ptr = entry.get(); |
| 282 | 282 |
| 283 net::CompletionCallback write_headers_callback = | 283 net::CompletionCallback write_headers_callback = |
| 284 base::Bind(PutDidWriteHeaders, | 284 base::Bind(PutDidWriteHeaders, |
| 285 response, | 285 base::Passed(response.Pass()), |
| 286 callback, | 286 callback, |
| 287 base::Passed(entry.Pass()), | 287 base::Passed(entry.Pass()), |
| 288 base::Passed(blob_data_handle.Pass()), | 288 base::Passed(blob_data_handle.Pass()), |
| 289 request_context, | 289 request_context, |
| 290 buffer->size()); | 290 buffer->size()); |
| 291 | 291 |
| 292 rv = tmp_entry_ptr->WriteData(INDEX_HEADERS, | 292 rv = tmp_entry_ptr->WriteData(INDEX_HEADERS, |
| 293 0 /* offset */, | 293 0 /* offset */, |
| 294 buffer.get(), | 294 buffer.get(), |
| 295 buffer->size(), | 295 buffer->size(), |
| 296 write_headers_callback, | 296 write_headers_callback, |
| 297 true /* truncate */); | 297 true /* truncate */); |
| 298 | 298 |
| 299 if (rv != net::ERR_IO_PENDING) | 299 if (rv != net::ERR_IO_PENDING) |
| 300 write_headers_callback.Run(rv); | 300 write_headers_callback.Run(rv); |
| 301 } | 301 } |
| 302 | 302 |
| 303 void PutDidWriteHeaders(ServiceWorkerResponse* response, | 303 void PutDidWriteHeaders(scoped_ptr<ServiceWorkerResponse> response, |
| 304 const ServiceWorkerCache::ErrorCallback& callback, | 304 const ServiceWorkerCache::ErrorCallback& callback, |
| 305 disk_cache::ScopedEntryPtr entry, | 305 disk_cache::ScopedEntryPtr entry, |
| 306 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 306 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
| 307 net::URLRequestContext* request_context, | 307 net::URLRequestContext* request_context, |
| 308 int expected_bytes, | 308 int expected_bytes, |
| 309 int rv) { | 309 int rv) { |
| 310 if (rv != expected_bytes) { | 310 if (rv != expected_bytes) { |
| 311 entry->Doom(); | 311 entry->Doom(); |
| 312 callback.Run(ServiceWorkerCache::ErrorTypeStorage); | 312 callback.Run(ServiceWorkerCache::ErrorTypeStorage); |
| 313 return; | 313 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 339 bool success) { | 339 bool success) { |
| 340 if (!success) { | 340 if (!success) { |
| 341 entry->Doom(); | 341 entry->Doom(); |
| 342 callback.Run(ServiceWorkerCache::ErrorTypeStorage); | 342 callback.Run(ServiceWorkerCache::ErrorTypeStorage); |
| 343 return; | 343 return; |
| 344 } | 344 } |
| 345 | 345 |
| 346 callback.Run(ServiceWorkerCache::ErrorTypeOK); | 346 callback.Run(ServiceWorkerCache::ErrorTypeOK); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void MatchDidOpenEntry(ServiceWorkerFetchRequest* request, | 349 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 350 const ServiceWorkerCache::ResponseCallback& callback, | 350 const ServiceWorkerCache::ResponseCallback& callback, |
| 351 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 351 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 352 scoped_ptr<disk_cache::Entry*> entryptr, | 352 scoped_ptr<disk_cache::Entry*> entryptr, |
| 353 int rv) { | 353 int rv) { |
| 354 if (rv != net::OK) { | 354 if (rv != net::OK) { |
| 355 callback.Run(ServiceWorkerCache::ErrorTypeNotFound, | 355 callback.Run(ServiceWorkerCache::ErrorTypeNotFound, |
| 356 scoped_ptr<ServiceWorkerResponse>(), | 356 scoped_ptr<ServiceWorkerResponse>(), |
| 357 scoped_ptr<storage::BlobDataHandle>()); | 357 scoped_ptr<storage::BlobDataHandle>()); |
| 358 return; | 358 return; |
| 359 } | 359 } |
| 360 | 360 |
| 361 DCHECK(entryptr); | 361 DCHECK(entryptr); |
| 362 disk_cache::ScopedEntryPtr entry(*entryptr); | 362 disk_cache::ScopedEntryPtr entry(*entryptr); |
| 363 | 363 |
| 364 // Copy the entry pointer before passing it in base::Bind. | 364 // Copy the entry pointer before passing it in base::Bind. |
| 365 disk_cache::Entry* tmp_entry_ptr = entry.get(); | 365 disk_cache::Entry* tmp_entry_ptr = entry.get(); |
| 366 | 366 |
| 367 HeadersCallback headers_callback = base::Bind(MatchDidReadHeaderData, | 367 HeadersCallback headers_callback = base::Bind(MatchDidReadHeaderData, |
| 368 request, | 368 base::Passed(request.Pass()), |
| 369 callback, | 369 callback, |
| 370 blob_storage, | 370 blob_storage, |
| 371 base::Passed(entry.Pass())); | 371 base::Passed(entry.Pass())); |
| 372 | 372 |
| 373 ReadHeaders(tmp_entry_ptr, headers_callback); | 373 ReadHeaders(tmp_entry_ptr, headers_callback); |
| 374 } | 374 } |
| 375 | 375 |
| 376 void MatchDidReadHeaderData( | 376 void MatchDidReadHeaderData( |
| 377 ServiceWorkerFetchRequest* request, | 377 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 378 const ServiceWorkerCache::ResponseCallback& callback, | 378 const ServiceWorkerCache::ResponseCallback& callback, |
| 379 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 379 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 380 disk_cache::ScopedEntryPtr entry, | 380 disk_cache::ScopedEntryPtr entry, |
| 381 scoped_ptr<ServiceWorkerRequestResponseHeaders> headers) { | 381 scoped_ptr<ServiceWorkerRequestResponseHeaders> headers) { |
| 382 if (!headers) { | 382 if (!headers) { |
| 383 callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 383 callback.Run(ServiceWorkerCache::ErrorTypeStorage, |
| 384 scoped_ptr<ServiceWorkerResponse>(), | 384 scoped_ptr<ServiceWorkerResponse>(), |
| 385 scoped_ptr<storage::BlobDataHandle>()); | 385 scoped_ptr<storage::BlobDataHandle>()); |
| 386 return; | 386 return; |
| 387 } | 387 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 new net::IOBufferWithSize(kBufferSize)); | 424 new net::IOBufferWithSize(kBufferSize)); |
| 425 | 425 |
| 426 scoped_ptr<ResponseReadContext> read_context( | 426 scoped_ptr<ResponseReadContext> read_context( |
| 427 new ResponseReadContext(response_body_buffer, blob_data)); | 427 new ResponseReadContext(response_body_buffer, blob_data)); |
| 428 | 428 |
| 429 // Copy the entry pointer before passing it in base::Bind. | 429 // Copy the entry pointer before passing it in base::Bind. |
| 430 disk_cache::Entry* tmp_entry_ptr = entry.get(); | 430 disk_cache::Entry* tmp_entry_ptr = entry.get(); |
| 431 | 431 |
| 432 net::CompletionCallback read_callback = | 432 net::CompletionCallback read_callback = |
| 433 base::Bind(MatchDidReadResponseBodyData, | 433 base::Bind(MatchDidReadResponseBodyData, |
| 434 request, | 434 base::Passed(request.Pass()), |
| 435 callback, | 435 callback, |
| 436 blob_storage, | 436 blob_storage, |
| 437 base::Passed(entry.Pass()), | 437 base::Passed(entry.Pass()), |
| 438 base::Passed(response.Pass()), | 438 base::Passed(response.Pass()), |
| 439 base::Passed(read_context.Pass())); | 439 base::Passed(read_context.Pass())); |
| 440 | 440 |
| 441 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY, | 441 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY, |
| 442 0, | 442 0, |
| 443 response_body_buffer.get(), | 443 response_body_buffer.get(), |
| 444 response_body_buffer->size(), | 444 response_body_buffer->size(), |
| 445 read_callback); | 445 read_callback); |
| 446 | 446 |
| 447 if (read_rv != net::ERR_IO_PENDING) | 447 if (read_rv != net::ERR_IO_PENDING) |
| 448 read_callback.Run(read_rv); | 448 read_callback.Run(read_rv); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void MatchDidReadResponseBodyData( | 451 void MatchDidReadResponseBodyData( |
| 452 ServiceWorkerFetchRequest* request, | 452 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 453 const ServiceWorkerCache::ResponseCallback& callback, | 453 const ServiceWorkerCache::ResponseCallback& callback, |
| 454 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 454 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 455 disk_cache::ScopedEntryPtr entry, | 455 disk_cache::ScopedEntryPtr entry, |
| 456 scoped_ptr<ServiceWorkerResponse> response, | 456 scoped_ptr<ServiceWorkerResponse> response, |
| 457 scoped_ptr<ResponseReadContext> response_context, | 457 scoped_ptr<ResponseReadContext> response_context, |
| 458 int rv) { | 458 int rv) { |
| 459 if (rv < 0) { | 459 if (rv < 0) { |
| 460 callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 460 callback.Run(ServiceWorkerCache::ErrorTypeStorage, |
| 461 scoped_ptr<ServiceWorkerResponse>(), | 461 scoped_ptr<ServiceWorkerResponse>(), |
| 462 scoped_ptr<storage::BlobDataHandle>()); | 462 scoped_ptr<storage::BlobDataHandle>()); |
| 463 return; | 463 return; |
| 464 } | 464 } |
| 465 | 465 |
| 466 if (rv == 0) { | 466 if (rv == 0) { |
| 467 MatchDoneWithBody(request, | 467 MatchDoneWithBody(request.Pass(), |
| 468 callback, | 468 callback, |
| 469 blob_storage, | 469 blob_storage, |
| 470 response.Pass(), | 470 response.Pass(), |
| 471 response_context.Pass()); | 471 response_context.Pass()); |
| 472 return; | 472 return; |
| 473 } | 473 } |
| 474 | 474 |
| 475 // TODO(jkarlin): This copying of the the entire cache response into memory is | 475 // TODO(jkarlin): This copying of the the entire cache response into memory is |
| 476 // awful. Create a new interface around SimpleCache that provides access the | 476 // awful. Create a new interface around SimpleCache that provides access the |
| 477 // data directly from the file. See bug http://crbug.com/403493. | 477 // data directly from the file. See bug http://crbug.com/403493. |
| 478 response_context->blob_data->AppendData(response_context->buffer->data(), rv); | 478 response_context->blob_data->AppendData(response_context->buffer->data(), rv); |
| 479 response_context->total_bytes_read += rv; | 479 response_context->total_bytes_read += rv; |
| 480 int total_bytes_read = response_context->total_bytes_read; | 480 int total_bytes_read = response_context->total_bytes_read; |
| 481 | 481 |
| 482 // Grab some pointers before passing them in bind. | 482 // Grab some pointers before passing them in bind. |
| 483 net::IOBufferWithSize* buffer = response_context->buffer.get(); | 483 net::IOBufferWithSize* buffer = response_context->buffer.get(); |
| 484 disk_cache::Entry* tmp_entry_ptr = entry.get(); | 484 disk_cache::Entry* tmp_entry_ptr = entry.get(); |
| 485 | 485 |
| 486 net::CompletionCallback read_callback = | 486 net::CompletionCallback read_callback = |
| 487 base::Bind(MatchDidReadResponseBodyData, | 487 base::Bind(MatchDidReadResponseBodyData, |
| 488 request, | 488 base::Passed(request.Pass()), |
| 489 callback, | 489 callback, |
| 490 blob_storage, | 490 blob_storage, |
| 491 base::Passed(entry.Pass()), | 491 base::Passed(entry.Pass()), |
| 492 base::Passed(response.Pass()), | 492 base::Passed(response.Pass()), |
| 493 base::Passed(response_context.Pass())); | 493 base::Passed(response_context.Pass())); |
| 494 | 494 |
| 495 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY, | 495 int read_rv = tmp_entry_ptr->ReadData(INDEX_RESPONSE_BODY, |
| 496 total_bytes_read, | 496 total_bytes_read, |
| 497 buffer, | 497 buffer, |
| 498 buffer->size(), | 498 buffer->size(), |
| 499 read_callback); | 499 read_callback); |
| 500 | 500 |
| 501 if (read_rv != net::ERR_IO_PENDING) | 501 if (read_rv != net::ERR_IO_PENDING) |
| 502 read_callback.Run(read_rv); | 502 read_callback.Run(read_rv); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void MatchDoneWithBody(ServiceWorkerFetchRequest* request, | 505 void MatchDoneWithBody(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 506 const ServiceWorkerCache::ResponseCallback& callback, | 506 const ServiceWorkerCache::ResponseCallback& callback, |
| 507 base::WeakPtr<storage::BlobStorageContext> blob_storage, | 507 base::WeakPtr<storage::BlobStorageContext> blob_storage, |
| 508 scoped_ptr<ServiceWorkerResponse> response, | 508 scoped_ptr<ServiceWorkerResponse> response, |
| 509 scoped_ptr<ResponseReadContext> response_context) { | 509 scoped_ptr<ResponseReadContext> response_context) { |
| 510 if (!blob_storage) { | 510 if (!blob_storage) { |
| 511 callback.Run(ServiceWorkerCache::ErrorTypeStorage, | 511 callback.Run(ServiceWorkerCache::ErrorTypeStorage, |
| 512 scoped_ptr<ServiceWorkerResponse>(), | 512 scoped_ptr<ServiceWorkerResponse>(), |
| 513 scoped_ptr<storage::BlobDataHandle>()); | 513 scoped_ptr<storage::BlobDataHandle>()); |
| 514 return; | 514 return; |
| 515 } | 515 } |
| 516 | 516 |
| 517 scoped_ptr<storage::BlobDataHandle> blob_data_handle( | 517 scoped_ptr<storage::BlobDataHandle> blob_data_handle( |
| 518 blob_storage->AddFinishedBlob(response_context->blob_data.get())); | 518 blob_storage->AddFinishedBlob(response_context->blob_data.get())); |
| 519 | 519 |
| 520 callback.Run(ServiceWorkerCache::ErrorTypeOK, | 520 callback.Run(ServiceWorkerCache::ErrorTypeOK, |
| 521 response.Pass(), | 521 response.Pass(), |
| 522 blob_data_handle.Pass()); | 522 blob_data_handle.Pass()); |
| 523 } | 523 } |
| 524 | 524 |
| 525 void DeleteDidOpenEntry(ServiceWorkerFetchRequest* request, | 525 void DeleteDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 526 const ServiceWorkerCache::ErrorCallback& callback, | 526 const ServiceWorkerCache::ErrorCallback& callback, |
| 527 scoped_ptr<disk_cache::Entry*> entryptr, | 527 scoped_ptr<disk_cache::Entry*> entryptr, |
| 528 int rv) { | 528 int rv) { |
| 529 if (rv != net::OK) { | 529 if (rv != net::OK) { |
| 530 callback.Run(ServiceWorkerCache::ErrorTypeNotFound); | 530 callback.Run(ServiceWorkerCache::ErrorTypeNotFound); |
| 531 return; | 531 return; |
| 532 } | 532 } |
| 533 | 533 |
| 534 DCHECK(entryptr); | 534 DCHECK(entryptr); |
| 535 disk_cache::ScopedEntryPtr entry(*entryptr); | 535 disk_cache::ScopedEntryPtr entry(*entryptr); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 kMaxCacheBytes, | 679 kMaxCacheBytes, |
| 680 false, /* force */ | 680 false, /* force */ |
| 681 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), | 681 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), |
| 682 NULL, | 682 NULL, |
| 683 backend, | 683 backend, |
| 684 create_cache_callback); | 684 create_cache_callback); |
| 685 if (rv != net::ERR_IO_PENDING) | 685 if (rv != net::ERR_IO_PENDING) |
| 686 create_cache_callback.Run(rv); | 686 create_cache_callback.Run(rv); |
| 687 } | 687 } |
| 688 | 688 |
| 689 void ServiceWorkerCache::Put(ServiceWorkerFetchRequest* request, | 689 void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 690 ServiceWorkerResponse* response, | 690 scoped_ptr<ServiceWorkerResponse> response, |
| 691 const ErrorCallback& callback) { | 691 const ErrorCallback& callback) { |
| 692 DCHECK(backend_); | 692 DCHECK(backend_); |
| 693 | 693 |
| 694 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 694 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
| 695 | 695 |
| 696 disk_cache::Entry** entry_ptr = entry.get(); | 696 disk_cache::Entry** entry_ptr = entry.get(); |
| 697 | 697 |
| 698 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 698 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 699 | 699 |
| 700 if (!response->blob_uuid.empty()) { | 700 if (!response->blob_uuid.empty()) { |
| 701 if (!blob_storage_context_) { | 701 if (!blob_storage_context_) { |
| 702 callback.Run(ErrorTypeStorage); | 702 callback.Run(ErrorTypeStorage); |
| 703 return; | 703 return; |
| 704 } | 704 } |
| 705 blob_data_handle = | 705 blob_data_handle = |
| 706 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); | 706 blob_storage_context_->GetBlobDataFromUUID(response->blob_uuid); |
| 707 if (!blob_data_handle) { | 707 if (!blob_data_handle) { |
| 708 callback.Run(ErrorTypeStorage); | 708 callback.Run(ErrorTypeStorage); |
| 709 return; | 709 return; |
| 710 } | 710 } |
| 711 } | 711 } |
| 712 | 712 |
| 713 ServiceWorkerFetchRequest* request_ptr = request.get(); |
| 714 |
| 713 net::CompletionCallback create_entry_callback = | 715 net::CompletionCallback create_entry_callback = |
| 714 base::Bind(PutDidCreateEntry, | 716 base::Bind(PutDidCreateEntry, |
| 715 request, | 717 base::Passed(request.Pass()), |
| 716 response, | 718 base::Passed(response.Pass()), |
| 717 callback, | 719 callback, |
| 718 base::Passed(entry.Pass()), | 720 base::Passed(entry.Pass()), |
| 719 base::Passed(blob_data_handle.Pass()), | 721 base::Passed(blob_data_handle.Pass()), |
| 720 request_context_); | 722 request_context_); |
| 721 | 723 |
| 722 int rv = backend_->CreateEntry( | 724 int rv = backend_->CreateEntry( |
| 723 request->url.spec(), entry_ptr, create_entry_callback); | 725 request_ptr->url.spec(), entry_ptr, create_entry_callback); |
| 724 | 726 |
| 725 if (rv != net::ERR_IO_PENDING) | 727 if (rv != net::ERR_IO_PENDING) |
| 726 create_entry_callback.Run(rv); | 728 create_entry_callback.Run(rv); |
| 727 } | 729 } |
| 728 | 730 |
| 729 void ServiceWorkerCache::Match(ServiceWorkerFetchRequest* request, | 731 void ServiceWorkerCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 730 const ResponseCallback& callback) { | 732 const ResponseCallback& callback) { |
| 731 DCHECK(backend_); | 733 DCHECK(backend_); |
| 732 | 734 |
| 733 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 735 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
| 734 | 736 |
| 735 disk_cache::Entry** entry_ptr = entry.get(); | 737 disk_cache::Entry** entry_ptr = entry.get(); |
| 736 | 738 |
| 739 ServiceWorkerFetchRequest* request_ptr = request.get(); |
| 740 |
| 737 net::CompletionCallback open_entry_callback = | 741 net::CompletionCallback open_entry_callback = |
| 738 base::Bind(MatchDidOpenEntry, | 742 base::Bind(MatchDidOpenEntry, |
| 739 request, | 743 base::Passed(request.Pass()), |
| 740 callback, | 744 callback, |
| 741 blob_storage_context_, | 745 blob_storage_context_, |
| 742 base::Passed(entry.Pass())); | 746 base::Passed(entry.Pass())); |
| 743 | 747 |
| 744 int rv = | 748 int rv = backend_->OpenEntry( |
| 745 backend_->OpenEntry(request->url.spec(), entry_ptr, open_entry_callback); | 749 request_ptr->url.spec(), entry_ptr, open_entry_callback); |
| 746 if (rv != net::ERR_IO_PENDING) | 750 if (rv != net::ERR_IO_PENDING) |
| 747 open_entry_callback.Run(rv); | 751 open_entry_callback.Run(rv); |
| 748 } | 752 } |
| 749 | 753 |
| 750 void ServiceWorkerCache::Delete(ServiceWorkerFetchRequest* request, | 754 void ServiceWorkerCache::Delete(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 751 const ErrorCallback& callback) { | 755 const ErrorCallback& callback) { |
| 752 DCHECK(backend_); | 756 DCHECK(backend_); |
| 753 | 757 |
| 754 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); | 758 scoped_ptr<disk_cache::Entry*> entry(new disk_cache::Entry*); |
| 755 | 759 |
| 756 disk_cache::Entry** entry_ptr = entry.get(); | 760 disk_cache::Entry** entry_ptr = entry.get(); |
| 757 | 761 |
| 758 net::CompletionCallback open_entry_callback = base::Bind( | 762 ServiceWorkerFetchRequest* request_ptr = request.get(); |
| 759 DeleteDidOpenEntry, request, callback, base::Passed(entry.Pass())); | |
| 760 | 763 |
| 761 int rv = | 764 net::CompletionCallback open_entry_callback = |
| 762 backend_->OpenEntry(request->url.spec(), entry_ptr, open_entry_callback); | 765 base::Bind(DeleteDidOpenEntry, |
| 766 base::Passed(request.Pass()), |
| 767 callback, |
| 768 base::Passed(entry.Pass())); |
| 769 |
| 770 int rv = backend_->OpenEntry( |
| 771 request_ptr->url.spec(), entry_ptr, open_entry_callback); |
| 763 if (rv != net::ERR_IO_PENDING) | 772 if (rv != net::ERR_IO_PENDING) |
| 764 open_entry_callback.Run(rv); | 773 open_entry_callback.Run(rv); |
| 765 } | 774 } |
| 766 | 775 |
| 767 void ServiceWorkerCache::Keys(const RequestsCallback& callback) { | 776 void ServiceWorkerCache::Keys(const RequestsCallback& callback) { |
| 768 DCHECK(backend_); | 777 DCHECK(backend_); |
| 769 | 778 |
| 770 // 1. Iterate through all of the entries, open them, and add them to a vector. | 779 // 1. Iterate through all of the entries, open them, and add them to a vector. |
| 771 // 2. For each open entry: | 780 // 2. For each open entry: |
| 772 // 2.1. Read the headers into a protobuf. | 781 // 2.1. Read the headers into a protobuf. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 req_headers.insert(std::make_pair(header.name(), header.value())); | 893 req_headers.insert(std::make_pair(header.name(), header.value())); |
| 885 } | 894 } |
| 886 } else { | 895 } else { |
| 887 entry->Doom(); | 896 entry->Doom(); |
| 888 } | 897 } |
| 889 | 898 |
| 890 KeysProcessNextEntry(keys_context.Pass(), iter + 1); | 899 KeysProcessNextEntry(keys_context.Pass(), iter + 1); |
| 891 } | 900 } |
| 892 | 901 |
| 893 } // namespace content | 902 } // namespace content |
| OLD | NEW |