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

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

Issue 585833002: Revert of Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « content/browser/gpu/shader_disk_cache.cc ('k') | net/disk_cache/backend_unittest.cc » ('j') | 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 590
591 } // namespace 591 } // namespace
592 592
593 // The state needed to pass between ServiceWorkerCache::Keys callbacks. 593 // The state needed to pass between ServiceWorkerCache::Keys callbacks.
594 struct ServiceWorkerCache::KeysContext { 594 struct ServiceWorkerCache::KeysContext {
595 KeysContext(const ServiceWorkerCache::RequestsCallback& callback, 595 KeysContext(const ServiceWorkerCache::RequestsCallback& callback,
596 base::WeakPtr<ServiceWorkerCache> cache) 596 base::WeakPtr<ServiceWorkerCache> cache)
597 : original_callback(callback), 597 : original_callback(callback),
598 cache(cache), 598 cache(cache),
599 out_keys(new ServiceWorkerCache::Requests()), 599 out_keys(new ServiceWorkerCache::Requests()),
600 backend_iterator(NULL),
600 enumerated_entry(NULL) {} 601 enumerated_entry(NULL) {}
601 602
602 ~KeysContext() { 603 ~KeysContext() {
603 for (size_t i = 0, max = entries.size(); i < max; ++i) 604 for (size_t i = 0, max = entries.size(); i < max; ++i)
604 entries[i]->Close(); 605 entries[i]->Close();
605 if (enumerated_entry) 606 if (enumerated_entry)
606 enumerated_entry->Close(); 607 enumerated_entry->Close();
608 if (cache && backend_iterator && cache->backend_)
609 cache->backend_->EndEnumeration(&backend_iterator);
607 } 610 }
608 611
609 // The callback passed to the Keys() function. 612 // The callback passed to the Keys() function.
610 ServiceWorkerCache::RequestsCallback original_callback; 613 ServiceWorkerCache::RequestsCallback original_callback;
611 614
612 // The ServiceWorkerCache that Keys was called on. 615 // The ServiceWorkerCache that Keys was called on.
613 base::WeakPtr<ServiceWorkerCache> cache; 616 base::WeakPtr<ServiceWorkerCache> cache;
614 617
615 // The vector of open entries in the backend. 618 // The vector of open entries in the backend.
616 Entries entries; 619 Entries entries;
617 620
618 // The output of the Keys function. 621 // The output of the Keys function.
619 scoped_ptr<ServiceWorkerCache::Requests> out_keys; 622 scoped_ptr<ServiceWorkerCache::Requests> out_keys;
620 623
621 // Used for enumerating cache entries. 624 // Used for enumerating cache entries.
622 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; 625 void* backend_iterator;
623 disk_cache::Entry* enumerated_entry; 626 disk_cache::Entry* enumerated_entry;
624 }; 627 };
625 628
626 // static 629 // static
627 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache( 630 scoped_refptr<ServiceWorkerCache> ServiceWorkerCache::CreateMemoryCache(
628 net::URLRequestContext* request_context, 631 net::URLRequestContext* request_context,
629 base::WeakPtr<storage::BlobStorageContext> blob_context) { 632 base::WeakPtr<storage::BlobStorageContext> blob_context) {
630 return make_scoped_refptr( 633 return make_scoped_refptr(
631 new ServiceWorkerCache(base::FilePath(), request_context, blob_context)); 634 new ServiceWorkerCache(base::FilePath(), request_context, blob_context));
632 } 635 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key"). 767 // 2.2. Copy the protobuf into a ServiceWorkerFetchRequest (a "key").
765 // 2.3. Push the response into a vector of requests to be returned. 768 // 2.3. Push the response into a vector of requests to be returned.
766 // 3. Return the vector of requests (keys). 769 // 3. Return the vector of requests (keys).
767 770
768 // The entries have to be loaded into a vector first because enumeration loops 771 // The entries have to be loaded into a vector first because enumeration loops
769 // forever if you read data from a cache entry while enumerating. 772 // forever if you read data from a cache entry while enumerating.
770 773
771 scoped_ptr<KeysContext> keys_context( 774 scoped_ptr<KeysContext> keys_context(
772 new KeysContext(callback, weak_ptr_factory_.GetWeakPtr())); 775 new KeysContext(callback, weak_ptr_factory_.GetWeakPtr()));
773 776
774 keys_context->backend_iterator = backend_->CreateIterator(); 777 void** backend_iterator = &keys_context->backend_iterator;
775 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator;
776 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; 778 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry;
777 779
778 net::CompletionCallback open_entry_callback = 780 net::CompletionCallback open_entry_callback =
779 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); 781 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass()));
780 782
781 int rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); 783 int rv = backend_->OpenNextEntry(
784 backend_iterator, enumerated_entry, open_entry_callback);
782 785
783 if (rv != net::ERR_IO_PENDING) 786 if (rv != net::ERR_IO_PENDING)
784 open_entry_callback.Run(rv); 787 open_entry_callback.Run(rv);
785 } 788 }
786 789
787 void ServiceWorkerCache::Close() { 790 void ServiceWorkerCache::Close() {
788 backend_.reset(); 791 backend_.reset();
789 } 792 }
790 793
791 ServiceWorkerCache::ServiceWorkerCache( 794 ServiceWorkerCache::ServiceWorkerCache(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 keys_context->original_callback.Run(ErrorTypeNotFound, 857 keys_context->original_callback.Run(ErrorTypeNotFound,
855 scoped_ptr<Requests>()); 858 scoped_ptr<Requests>());
856 return; 859 return;
857 } 860 }
858 861
859 // Store the entry. 862 // Store the entry.
860 keys_context->entries.push_back(keys_context->enumerated_entry); 863 keys_context->entries.push_back(keys_context->enumerated_entry);
861 keys_context->enumerated_entry = NULL; 864 keys_context->enumerated_entry = NULL;
862 865
863 // Enumerate the next entry. 866 // Enumerate the next entry.
864 disk_cache::Backend::Iterator& iterator = *keys_context->backend_iterator; 867 void** backend_iterator = &keys_context->backend_iterator;
865 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry; 868 disk_cache::Entry** enumerated_entry = &keys_context->enumerated_entry;
869
866 net::CompletionCallback open_entry_callback = 870 net::CompletionCallback open_entry_callback =
867 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass())); 871 base::Bind(KeysDidOpenNextEntry, base::Passed(keys_context.Pass()));
868 872
869 rv = iterator.OpenNextEntry(enumerated_entry, open_entry_callback); 873 rv = cache->backend_->OpenNextEntry(
874 backend_iterator, enumerated_entry, open_entry_callback);
870 875
871 if (rv != net::ERR_IO_PENDING) 876 if (rv != net::ERR_IO_PENDING)
872 open_entry_callback.Run(rv); 877 open_entry_callback.Run(rv);
873 } 878 }
874 879
875 // static 880 // static
876 void ServiceWorkerCache::KeysProcessNextEntry( 881 void ServiceWorkerCache::KeysProcessNextEntry(
877 scoped_ptr<KeysContext> keys_context, 882 scoped_ptr<KeysContext> keys_context,
878 const Entries::iterator& iter) { 883 const Entries::iterator& iter) {
879 if (iter == keys_context->entries.end()) { 884 if (iter == keys_context->entries.end()) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 initialized_ = true; 973 initialized_ = true;
969 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); 974 for (std::vector<base::Closure>::iterator it = init_callbacks_.begin();
970 it != init_callbacks_.end(); 975 it != init_callbacks_.end();
971 ++it) { 976 ++it) {
972 it->Run(); 977 it->Run();
973 } 978 }
974 init_callbacks_.clear(); 979 init_callbacks_.clear();
975 } 980 }
976 981
977 } // namespace content 982 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/shader_disk_cache.cc ('k') | net/disk_cache/backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698