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

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

Issue 20737002: Change the API of disk_cache::CreateCacheBackend to use scoped_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix new test Created 7 years, 4 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 | Annotate | Revision Log
« 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 int open_count_; 145 int open_count_;
146 int create_count_; 146 int create_count_;
147 bool fail_requests_; 147 bool fail_requests_;
148 bool soft_failures_; 148 bool soft_failures_;
149 bool double_create_check_; 149 bool double_create_check_;
150 }; 150 };
151 151
152 class MockBackendFactory : public net::HttpCache::BackendFactory { 152 class MockBackendFactory : public net::HttpCache::BackendFactory {
153 public: 153 public:
154 virtual int CreateBackend(net::NetLog* net_log, 154 virtual int CreateBackend(net::NetLog* net_log,
155 disk_cache::Backend** backend, 155 scoped_ptr<disk_cache::Backend>* backend,
156 const net::CompletionCallback& callback) OVERRIDE; 156 const net::CompletionCallback& callback) OVERRIDE;
157 }; 157 };
158 158
159 class MockHttpCache { 159 class MockHttpCache {
160 public: 160 public:
161 MockHttpCache(); 161 MockHttpCache();
162 explicit MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory); 162 explicit MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory);
163 163
164 net::HttpCache* http_cache() { return &http_cache_; } 164 net::HttpCache* http_cache() { return &http_cache_; }
165 165
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 // This version of the disk cache doesn't invoke CreateEntry callbacks. 200 // This version of the disk cache doesn't invoke CreateEntry callbacks.
201 class MockDiskCacheNoCB : public MockDiskCache { 201 class MockDiskCacheNoCB : public MockDiskCache {
202 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, 202 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
203 const net::CompletionCallback& callback) OVERRIDE; 203 const net::CompletionCallback& callback) OVERRIDE;
204 }; 204 };
205 205
206 class MockBackendNoCbFactory : public net::HttpCache::BackendFactory { 206 class MockBackendNoCbFactory : public net::HttpCache::BackendFactory {
207 public: 207 public:
208 virtual int CreateBackend(net::NetLog* net_log, 208 virtual int CreateBackend(net::NetLog* net_log,
209 disk_cache::Backend** backend, 209 scoped_ptr<disk_cache::Backend>* backend,
210 const net::CompletionCallback& callback) OVERRIDE; 210 const net::CompletionCallback& callback) OVERRIDE;
211 }; 211 };
212 212
213 // This backend factory allows us to control the backend instantiation. 213 // This backend factory allows us to control the backend instantiation.
214 class MockBlockingBackendFactory : public net::HttpCache::BackendFactory { 214 class MockBlockingBackendFactory : public net::HttpCache::BackendFactory {
215 public: 215 public:
216 MockBlockingBackendFactory(); 216 MockBlockingBackendFactory();
217 virtual ~MockBlockingBackendFactory(); 217 virtual ~MockBlockingBackendFactory();
218 218
219 virtual int CreateBackend(net::NetLog* net_log, 219 virtual int CreateBackend(net::NetLog* net_log,
220 disk_cache::Backend** backend, 220 scoped_ptr<disk_cache::Backend>* backend,
221 const net::CompletionCallback& callback) OVERRIDE; 221 const net::CompletionCallback& callback) OVERRIDE;
222 222
223 // Completes the backend creation. Any blocked call will be notified via the 223 // Completes the backend creation. Any blocked call will be notified via the
224 // provided callback. 224 // provided callback.
225 void FinishCreation(); 225 void FinishCreation();
226 226
227 disk_cache::Backend** backend() { return backend_; } 227 scoped_ptr<disk_cache::Backend>* backend() { return backend_; }
228 void set_fail(bool fail) { fail_ = fail; } 228 void set_fail(bool fail) { fail_ = fail; }
229 229
230 const net::CompletionCallback& callback() { return callback_; } 230 const net::CompletionCallback& callback() { return callback_; }
231 231
232 private: 232 private:
233 int Result() { return fail_ ? net::ERR_FAILED : net::OK; } 233 int Result() { return fail_ ? net::ERR_FAILED : net::OK; }
234 234
235 disk_cache::Backend** backend_; 235 scoped_ptr<disk_cache::Backend>* backend_;
236 net::CompletionCallback callback_; 236 net::CompletionCallback callback_;
237 bool block_; 237 bool block_;
238 bool fail_; 238 bool fail_;
239 }; 239 };
240 240
241 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ 241 #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