| 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 cache(cache), | 598 cache(cache), |
| 599 out_keys(new ServiceWorkerCache::Requests()), | 599 out_keys(new ServiceWorkerCache::Requests()), |
| 600 backend_iterator(NULL), | 600 backend_iterator(NULL), |
| 601 enumerated_entry(NULL) {} | 601 enumerated_entry(NULL) {} |
| 602 | 602 |
| 603 ~KeysContext() { | 603 ~KeysContext() { |
| 604 for (size_t i = 0, max = entries.size(); i < max; ++i) | 604 for (size_t i = 0, max = entries.size(); i < max; ++i) |
| 605 entries[i]->Close(); | 605 entries[i]->Close(); |
| 606 if (enumerated_entry) | 606 if (enumerated_entry) |
| 607 enumerated_entry->Close(); | 607 enumerated_entry->Close(); |
| 608 if (cache && backend_iterator) | 608 if (cache && backend_iterator && cache->backend_) |
| 609 cache->backend_->EndEnumeration(&backend_iterator); | 609 cache->backend_->EndEnumeration(&backend_iterator); |
| 610 } | 610 } |
| 611 | 611 |
| 612 // The callback passed to the Keys() function. | 612 // The callback passed to the Keys() function. |
| 613 ServiceWorkerCache::RequestsCallback original_callback; | 613 ServiceWorkerCache::RequestsCallback original_callback; |
| 614 | 614 |
| 615 // The ServiceWorkerCache that Keys was called on. | 615 // The ServiceWorkerCache that Keys was called on. |
| 616 base::WeakPtr<ServiceWorkerCache> cache; | 616 base::WeakPtr<ServiceWorkerCache> cache; |
| 617 | 617 |
| 618 // The vector of open entries in the backend. | 618 // The vector of open entries in the backend. |
| 619 Entries entries; | 619 Entries entries; |
| 620 | 620 |
| 621 // The output of the Keys function. | 621 // The output of the Keys function. |
| 622 scoped_ptr<ServiceWorkerCache::Requests> out_keys; | 622 scoped_ptr<ServiceWorkerCache::Requests> out_keys; |
| 623 | 623 |
| 624 // Used for enumerating cache entries. | 624 // Used for enumerating cache entries. |
| 625 void* backend_iterator; | 625 void* backend_iterator; |
| 626 disk_cache::Entry* enumerated_entry; | 626 disk_cache::Entry* enumerated_entry; |
| 627 }; | 627 }; |
| 628 | 628 |
| 629 // static | 629 // static |
| 630 scoped_ptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache( | 630 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache( |
| 631 net::URLRequestContext* request_context, | 631 net::URLRequestContext* request_context, |
| 632 base::WeakPtr<storage::BlobStorageContext> blob_context) { | 632 base::WeakPtr<storage::BlobStorageContext> blob_context) { |
| 633 return make_scoped_ptr( | 633 return make_scoped_refptr( |
| 634 new ServiceWorkerCache(base::FilePath(), request_context, blob_context)); | 634 new ServiceWorkerCache(base::FilePath(), request_context, blob_context)); |
| 635 } | 635 } |
| 636 | 636 |
| 637 // static | 637 // static |
| 638 scoped_ptr<ServiceWorkerCache> ServiceWorkerCache::CreatePersistentCache( | 638 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreatePersistentCache( |
| 639 const base::FilePath& path, | 639 const base::FilePath& path, |
| 640 net::URLRequestContext* request_context, | 640 net::URLRequestContext* request_context, |
| 641 base::WeakPtr<storage::BlobStorageContext> blob_context) { | 641 base::WeakPtr<storage::BlobStorageContext> blob_context) { |
| 642 return make_scoped_ptr( | 642 return make_scoped_refptr( |
| 643 new ServiceWorkerCache(path, request_context, blob_context)); | 643 new ServiceWorkerCache(path, request_context, blob_context)); |
| 644 } | 644 } |
| 645 | 645 |
| 646 ServiceWorkerCache::~ServiceWorkerCache() { | 646 ServiceWorkerCache::~ServiceWorkerCache() { |
| 647 } | 647 } |
| 648 | 648 |
| 649 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() { | 649 base::WeakPtr<ServiceWorkerCache> ServiceWorkerCache::AsWeakPtr() { |
| 650 return weak_ptr_factory_.GetWeakPtr(); | 650 return weak_ptr_factory_.GetWeakPtr(); |
| 651 } | 651 } |
| 652 | 652 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 net::CompletionCallback open_entry_callback = | 800 net::CompletionCallback open_entry_callback = |
| 801 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); | 801 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); |
| 802 | 802 |
| 803 int rv = backend_->OpenNextEntry( | 803 int rv = backend_->OpenNextEntry( |
| 804 backend_iterator, enumerated_entry, open_entry_callback); | 804 backend_iterator, enumerated_entry, open_entry_callback); |
| 805 | 805 |
| 806 if (rv != net::ERR_IO_PENDING) | 806 if (rv != net::ERR_IO_PENDING) |
| 807 open_entry_callback.Run(rv); | 807 open_entry_callback.Run(rv); |
| 808 } | 808 } |
| 809 | 809 |
| 810 void ServiceWorkerCache::Close() { |
| 811 backend_.reset(); |
| 812 } |
| 813 |
| 810 ServiceWorkerCache::ServiceWorkerCache( | 814 ServiceWorkerCache::ServiceWorkerCache( |
| 811 const base::FilePath& path, | 815 const base::FilePath& path, |
| 812 net::URLRequestContext* request_context, | 816 net::URLRequestContext* request_context, |
| 813 base::WeakPtr<storage::BlobStorageContext> blob_context) | 817 base::WeakPtr<storage::BlobStorageContext> blob_context) |
| 814 : path_(path), | 818 : path_(path), |
| 815 request_context_(request_context), | 819 request_context_(request_context), |
| 816 blob_storage_context_(blob_context), | 820 blob_storage_context_(blob_context), |
| 817 initialized_(false), | 821 initialized_(false), |
| 818 weak_ptr_factory_(this) { | 822 weak_ptr_factory_(this) { |
| 819 } | 823 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 830 return; | 834 return; |
| 831 } | 835 } |
| 832 | 836 |
| 833 base::WeakPtr<ServiceWorkerCache> cache = keys_context->cache; | 837 base::WeakPtr<ServiceWorkerCache> cache = keys_context->cache; |
| 834 if (rv < 0 || !cache) { | 838 if (rv < 0 || !cache) { |
| 835 keys_context->original_callback.Run(ErrorTypeStorage, | 839 keys_context->original_callback.Run(ErrorTypeStorage, |
| 836 scoped_ptr<Requests>()); | 840 scoped_ptr<Requests>()); |
| 837 return; | 841 return; |
| 838 } | 842 } |
| 839 | 843 |
| 844 if (!cache->backend_) { |
| 845 keys_context->original_callback.Run(ErrorTypeNotFound, |
| 846 scoped_ptr<Requests>()); |
| 847 return; |
| 848 } |
| 849 |
| 840 // Store the entry. | 850 // Store the entry. |
| 841 keys_context->entries.push_back(keys_context->enumerated_entry); | 851 keys_context->entries.push_back(keys_context->enumerated_entry); |
| 842 keys_context->enumerated_entry = NULL; | 852 keys_context->enumerated_entry = NULL; |
| 843 | 853 |
| 844 // Enumerate the next entry. | 854 // Enumerate the next entry. |
| 845 void** backend_iterator = &keys_context->backend_iterator; | 855 void** backend_iterator = &keys_context->backend_iterator; |
| 846 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; | 856 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; |
| 847 | 857 |
| 848 net::CompletionCallback open_entry_callback = | 858 net::CompletionCallback open_entry_callback = |
| 849 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); | 859 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 initialized_ = true; | 961 initialized_ = true; |
| 952 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); | 962 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); |
| 953 it != init_callbacks_.end(); | 963 it != init_callbacks_.end(); |
| 954 ++it) { | 964 ++it) { |
| 955 it->Run(); | 965 it->Run(); |
| 956 } | 966 } |
| 957 init_callbacks_.clear(); | 967 init_callbacks_.clear(); |
| 958 } | 968 } |
| 959 | 969 |
| 960 } // namespace content | 970 } // namespace content |
| OLD | NEW |