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

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

Issue 2958033002: Interface for associating in-memory hint bytes with disk cache entries. (Closed)
Patch Set: Rebase Created 3 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 | « net/disk_cache/disk_cache.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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 int buf_len, 63 int buf_len,
64 const CompletionCallback& callback) override; 64 const CompletionCallback& callback) override;
65 int GetAvailableRange(int64_t offset, 65 int GetAvailableRange(int64_t offset,
66 int len, 66 int len,
67 int64_t* start, 67 int64_t* start,
68 const CompletionCallback& callback) override; 68 const CompletionCallback& callback) override;
69 bool CouldBeSparse() const override; 69 bool CouldBeSparse() const override;
70 void CancelSparseIO() override; 70 void CancelSparseIO() override;
71 int ReadyForSparseIO(const CompletionCallback& completion_callback) override; 71 int ReadyForSparseIO(const CompletionCallback& completion_callback) override;
72 72
73 uint8_t in_memory_data() const { return in_memory_data_; }
74 void set_in_memory_data(uint8_t val) { in_memory_data_ = val; }
75
73 // Fail most subsequent requests. 76 // Fail most subsequent requests.
74 void set_fail_requests() { fail_requests_ = true; } 77 void set_fail_requests() { fail_requests_ = true; }
75 78
76 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } 79 void set_fail_sparse_requests() { fail_sparse_requests_ = true; }
77 80
78 // If |value| is true, don't deliver any completion callbacks until called 81 // If |value| is true, don't deliver any completion callbacks until called
79 // again with |value| set to false. Caution: remember to enable callbacks 82 // again with |value| set to false. Caution: remember to enable callbacks
80 // again or all subsequent tests will fail. 83 // again or all subsequent tests will fail.
81 static void IgnoreCallbacks(bool value); 84 static void IgnoreCallbacks(bool value);
82 85
(...skipping 22 matching lines...) Expand all
105 // delivers any callback previously stored. 108 // delivers any callback previously stored.
106 static void StoreAndDeliverCallbacks(bool store, 109 static void StoreAndDeliverCallbacks(bool store,
107 MockDiskEntry* entry, 110 MockDiskEntry* entry,
108 const CompletionCallback& callback, 111 const CompletionCallback& callback,
109 int result); 112 int result);
110 113
111 static const int kNumCacheEntryDataIndices = 3; 114 static const int kNumCacheEntryDataIndices = 3;
112 115
113 std::string key_; 116 std::string key_;
114 std::vector<char> data_[kNumCacheEntryDataIndices]; 117 std::vector<char> data_[kNumCacheEntryDataIndices];
118 uint8_t in_memory_data_;
115 int test_mode_; 119 int test_mode_;
116 bool doomed_; 120 bool doomed_;
117 bool sparse_; 121 bool sparse_;
118 bool fail_requests_; 122 bool fail_requests_;
119 bool fail_sparse_requests_; 123 bool fail_sparse_requests_;
120 bool busy_; 124 bool busy_;
121 bool delayed_; 125 bool delayed_;
122 bool cancel_; 126 bool cancel_;
123 127
124 // Used for pause and restart. 128 // Used for pause and restart.
(...skipping 25 matching lines...) Expand all
150 const CompletionCallback& callback) override; 154 const CompletionCallback& callback) override;
151 int DoomEntriesSince(base::Time initial_time, 155 int DoomEntriesSince(base::Time initial_time,
152 const CompletionCallback& callback) override; 156 const CompletionCallback& callback) override;
153 int CalculateSizeOfAllEntries(const CompletionCallback& callback) override; 157 int CalculateSizeOfAllEntries(const CompletionCallback& callback) override;
154 std::unique_ptr<Iterator> CreateIterator() override; 158 std::unique_ptr<Iterator> CreateIterator() override;
155 void GetStats(base::StringPairs* stats) override; 159 void GetStats(base::StringPairs* stats) override;
156 void OnExternalCacheHit(const std::string& key) override; 160 void OnExternalCacheHit(const std::string& key) override;
157 size_t DumpMemoryStats( 161 size_t DumpMemoryStats(
158 base::trace_event::ProcessMemoryDump* pmd, 162 base::trace_event::ProcessMemoryDump* pmd,
159 const std::string& parent_absolute_name) const override; 163 const std::string& parent_absolute_name) const override;
164 uint8_t GetEntryInMemoryData(const std::string& key) override;
165 void SetEntryInMemoryData(const std::string& key, uint8_t data) override;
160 166
161 // Returns number of times a cache entry was successfully opened. 167 // Returns number of times a cache entry was successfully opened.
162 int open_count() const { return open_count_; } 168 int open_count() const { return open_count_; }
163 169
164 // Returns number of times a cache entry was successfully created. 170 // Returns number of times a cache entry was successfully created.
165 int create_count() const { return create_count_; } 171 int create_count() const { return create_count_; }
166 172
167 // Returns number of doomed entries. 173 // Returns number of doomed entries.
168 int doomed_count() const { return doomed_count_; } 174 int doomed_count() const { return doomed_count_; }
169 175
170 // Fail any subsequent CreateEntry and OpenEntry. 176 // Fail any subsequent CreateEntry and OpenEntry.
171 void set_fail_requests() { fail_requests_ = true; } 177 void set_fail_requests() { fail_requests_ = true; }
172 178
173 // Return entries that fail some of their requests. 179 // Return entries that fail some of their requests.
174 void set_soft_failures(bool value) { soft_failures_ = value; } 180 void set_soft_failures(bool value) { soft_failures_ = value; }
175 181
176 // Makes sure that CreateEntry is not called twice for a given key. 182 // Makes sure that CreateEntry is not called twice for a given key.
177 void set_double_create_check(bool value) { double_create_check_ = value; } 183 void set_double_create_check(bool value) { double_create_check_ = value; }
178 184
185 // Determines whether to provide the GetEntryInMemoryData/SetEntryInMemoryData
186 // interface. Default is true.
187 void set_support_in_memory_entry_data(bool value) {
188 support_in_memory_entry_data_ = value;
189 }
190
179 // Makes all requests for data ranges to fail as not implemented. 191 // Makes all requests for data ranges to fail as not implemented.
180 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } 192 void set_fail_sparse_requests() { fail_sparse_requests_ = true; }
181 193
182 void ReleaseAll(); 194 void ReleaseAll();
183 195
184 // Returns true if a doomed entry exists with this key. 196 // Returns true if a doomed entry exists with this key.
185 bool IsDiskEntryDoomed(const std::string& key); 197 bool IsDiskEntryDoomed(const std::string& key);
186 198
187 // Defers invoking the callback for the given operation. Calling code should 199 // Defers invoking the callback for the given operation. Calling code should
188 // invoke ResumeCacheOperation to resume. 200 // invoke ResumeCacheOperation to resume.
(...skipping 13 matching lines...) Expand all
202 void CallbackLater(const CompletionCallback& callback, int result); 214 void CallbackLater(const CompletionCallback& callback, int result);
203 215
204 EntryMap entries_; 216 EntryMap entries_;
205 int open_count_; 217 int open_count_;
206 int create_count_; 218 int create_count_;
207 int doomed_count_; 219 int doomed_count_;
208 bool fail_requests_; 220 bool fail_requests_;
209 bool soft_failures_; 221 bool soft_failures_;
210 bool double_create_check_; 222 bool double_create_check_;
211 bool fail_sparse_requests_; 223 bool fail_sparse_requests_;
224 bool support_in_memory_entry_data_;
212 225
213 // Used for pause and restart. 226 // Used for pause and restart.
214 MockDiskEntry::DeferOp defer_op_; 227 MockDiskEntry::DeferOp defer_op_;
215 CompletionCallback resume_callback_; 228 CompletionCallback resume_callback_;
216 int resume_return_code_; 229 int resume_return_code_;
217 }; 230 };
218 231
219 class MockBackendFactory : public HttpCache::BackendFactory { 232 class MockBackendFactory : public HttpCache::BackendFactory {
220 public: 233 public:
221 int CreateBackend(NetLog* net_log, 234 int CreateBackend(NetLog* net_log,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 342
330 std::unique_ptr<disk_cache::Backend>* backend_; 343 std::unique_ptr<disk_cache::Backend>* backend_;
331 CompletionCallback callback_; 344 CompletionCallback callback_;
332 bool block_; 345 bool block_;
333 bool fail_; 346 bool fail_;
334 }; 347 };
335 348
336 } // namespace net 349 } // namespace net
337 350
338 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ 351 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache.cc ('k') | net/http/mock_http_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698