1 // Copyright 2019 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_DISK_CACHE_SIMPLE_POST_OPERATION_WAITER_H_ 6 #define NET_DISK_CACHE_SIMPLE_POST_OPERATION_WAITER_H_ 7 8 #include <stdint.h> 9 10 #include <unordered_map> 11 #include <vector> 12 13 #include "base/functional/callback.h" 14 #include "base/memory/ref_counted.h" 15 #include "net/base/cache_type.h" 16 17 namespace disk_cache { 18 19 // See |SimpleBackendImpl::post_doom_waiting_| for the description. This is 20 // refcounted since sometimes this needs to survive backend destruction to 21 // complete some per-entry operations. 22 class SimplePostOperationWaiterTable 23 : public base::RefCounted<SimplePostOperationWaiterTable> { 24 friend class base::RefCounted<SimplePostOperationWaiterTable>; 25 26 public: 27 SimplePostOperationWaiterTable(); 28 29 SimplePostOperationWaiterTable(const SimplePostOperationWaiterTable&) = 30 delete; 31 SimplePostOperationWaiterTable& operator=( 32 const SimplePostOperationWaiterTable&) = delete; 33 34 // The entry for |entry_hash| is performing an operation like doom or opening 35 // by hash; the backend will not attempt to run new operations for this 36 // |entry_hash| until it is is completed. 37 void OnOperationStart(uint64_t entry_hash); 38 39 // The entry for |entry_hash| has been successfully doomed or had its key 40 // figured out, we can now allow operations on this entry, and we can run any 41 // operations enqueued while the operation was taking place. This will happen 42 // synchronously. 43 void OnOperationComplete(uint64_t entry_hash); 44 45 // Returns nullptr if not found. 46 std::vector<base::OnceClosure>* Find(uint64_t entry_hash); 47 Has(uint64_t entry_hash)48 bool Has(uint64_t entry_hash) { 49 return entries_pending_operation_.contains(entry_hash); 50 } 51 52 private: 53 ~SimplePostOperationWaiterTable(); 54 55 std::unordered_map<uint64_t, std::vector<base::OnceClosure>> 56 entries_pending_operation_; 57 }; 58 59 } // namespace disk_cache 60 61 #endif // NET_DISK_CACHE_SIMPLE_POST_OPERATION_WAITER_H_ 62