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

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

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

Powered by Google App Engine
This is Rietveld 408576698