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

Side by Side Diff: net/http/mock_http_cache.h

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: omewhat better take at higher-level HC::T impl, a bit lessy hacky, and actually write to cache now. Created 3 years, 6 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 | « net/http/http_cache_unittest.cc ('k') | net/http/mock_http_cache.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This is a mock of the http cache and related testing classes. To be fair, it 5 // This is a mock of the http cache and related testing classes. To be fair, it
6 // is not really a mock http cache given that it uses the real implementation of 6 // is not really a mock http cache given that it uses the real implementation of
7 // the http cache, but it has fake implementations of all required components, 7 // the http cache, but it has fake implementations of all required components,
8 // so it is useful for unit tests at the http layer. 8 // so it is useful for unit tests at the http layer.
9 9
10 #ifndef NET_HTTP_MOCK_HTTP_CACHE_H_ 10 #ifndef NET_HTTP_MOCK_HTTP_CACHE_H_
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 int buf_len, 57 int buf_len,
58 const CompletionCallback& callback) override; 58 const CompletionCallback& callback) override;
59 int GetAvailableRange(int64_t offset, 59 int GetAvailableRange(int64_t offset,
60 int len, 60 int len,
61 int64_t* start, 61 int64_t* start,
62 const CompletionCallback& callback) override; 62 const CompletionCallback& callback) override;
63 bool CouldBeSparse() const override; 63 bool CouldBeSparse() const override;
64 void CancelSparseIO() override; 64 void CancelSparseIO() override;
65 int ReadyForSparseIO(const CompletionCallback& completion_callback) override; 65 int ReadyForSparseIO(const CompletionCallback& completion_callback) override;
66 66
67 uint8_t memory_entry_data() const { return memory_entry_data_; }
gavinp 2017/06/26 20:18:11 Is this implemented here to make sure that http_ca
68 void set_memory_entry_data(uint8_t val) { memory_entry_data_ = val; }
69
67 // Fail most subsequent requests. 70 // Fail most subsequent requests.
68 void set_fail_requests() { fail_requests_ = true; } 71 void set_fail_requests() { fail_requests_ = true; }
69 72
70 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } 73 void set_fail_sparse_requests() { fail_sparse_requests_ = true; }
71 74
72 // If |value| is true, don't deliver any completion callbacks until called 75 // If |value| is true, don't deliver any completion callbacks until called
73 // again with |value| set to false. Caution: remember to enable callbacks 76 // again with |value| set to false. Caution: remember to enable callbacks
74 // again or all subsequent tests will fail. 77 // again or all subsequent tests will fail.
75 static void IgnoreCallbacks(bool value); 78 static void IgnoreCallbacks(bool value);
76 79
(...skipping 14 matching lines...) Expand all
91 // delivers any callback previously stored. 94 // delivers any callback previously stored.
92 static void StoreAndDeliverCallbacks(bool store, 95 static void StoreAndDeliverCallbacks(bool store,
93 MockDiskEntry* entry, 96 MockDiskEntry* entry,
94 const CompletionCallback& callback, 97 const CompletionCallback& callback,
95 int result); 98 int result);
96 99
97 static const int kNumCacheEntryDataIndices = 3; 100 static const int kNumCacheEntryDataIndices = 3;
98 101
99 std::string key_; 102 std::string key_;
100 std::vector<char> data_[kNumCacheEntryDataIndices]; 103 std::vector<char> data_[kNumCacheEntryDataIndices];
104 unsigned char memory_entry_data_;
101 int test_mode_; 105 int test_mode_;
102 bool doomed_; 106 bool doomed_;
103 bool sparse_; 107 bool sparse_;
104 bool fail_requests_; 108 bool fail_requests_;
105 bool fail_sparse_requests_; 109 bool fail_sparse_requests_;
106 bool busy_; 110 bool busy_;
107 bool delayed_; 111 bool delayed_;
108 bool cancel_; 112 bool cancel_;
109 static bool ignore_callbacks_; 113 static bool ignore_callbacks_;
110 }; 114 };
(...skipping 19 matching lines...) Expand all
130 const CompletionCallback& callback) override; 134 const CompletionCallback& callback) override;
131 int DoomEntriesSince(base::Time initial_time, 135 int DoomEntriesSince(base::Time initial_time,
132 const CompletionCallback& callback) override; 136 const CompletionCallback& callback) override;
133 int CalculateSizeOfAllEntries(const CompletionCallback& callback) override; 137 int CalculateSizeOfAllEntries(const CompletionCallback& callback) override;
134 std::unique_ptr<Iterator> CreateIterator() override; 138 std::unique_ptr<Iterator> CreateIterator() override;
135 void GetStats(base::StringPairs* stats) override; 139 void GetStats(base::StringPairs* stats) override;
136 void OnExternalCacheHit(const std::string& key) override; 140 void OnExternalCacheHit(const std::string& key) override;
137 size_t DumpMemoryStats( 141 size_t DumpMemoryStats(
138 base::trace_event::ProcessMemoryDump* pmd, 142 base::trace_event::ProcessMemoryDump* pmd,
139 const std::string& parent_absolute_name) const override; 143 const std::string& parent_absolute_name) const override;
144 uint8_t GetMemoryEntryData(const std::string& key) override;
145 void SetMemoryEntryData(const std::string& key, uint8_t data) override;
140 146
141 // Returns number of times a cache entry was successfully opened. 147 // Returns number of times a cache entry was successfully opened.
142 int open_count() const { return open_count_; } 148 int open_count() const { return open_count_; }
143 149
144 // Returns number of times a cache entry was successfully created. 150 // Returns number of times a cache entry was successfully created.
145 int create_count() const { return create_count_; } 151 int create_count() const { return create_count_; }
146 152
147 // Fail any subsequent CreateEntry and OpenEntry. 153 // Fail any subsequent CreateEntry and OpenEntry.
148 void set_fail_requests() { fail_requests_ = true; } 154 void set_fail_requests() { fail_requests_ = true; }
149 155
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 292
287 std::unique_ptr<disk_cache::Backend>* backend_; 293 std::unique_ptr<disk_cache::Backend>* backend_;
288 CompletionCallback callback_; 294 CompletionCallback callback_;
289 bool block_; 295 bool block_;
290 bool fail_; 296 bool fail_;
291 }; 297 };
292 298
293 } // namespace net 299 } // namespace net
294 300
295 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ 301 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_
OLDNEW
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/mock_http_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698