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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/http/mock_http_cache.h" 5 #include "net/http/mock_http_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "net/base/completion_callback.h" 9 #include "net/base/completion_callback.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 //----------------------------------------------------------------------------- 45 //-----------------------------------------------------------------------------
46 46
47 struct MockDiskEntry::CallbackInfo { 47 struct MockDiskEntry::CallbackInfo {
48 scoped_refptr<MockDiskEntry> entry; 48 scoped_refptr<MockDiskEntry> entry;
49 net::CompletionCallback callback; 49 net::CompletionCallback callback;
50 int result; 50 int result;
51 }; 51 };
52 52
53 MockDiskEntry::MockDiskEntry(const std::string& key) 53 MockDiskEntry::MockDiskEntry(const std::string& key)
54 : key_(key), doomed_(false), sparse_(false), 54 : key_(key),
55 fail_requests_(false), fail_sparse_requests_(false), busy_(false), 55 doomed_(false),
56 sparse_(false),
57 fail_requests_(false),
58 fail_sparse_requests_(false),
59 busy_(false),
56 delayed_(false) { 60 delayed_(false) {
57 test_mode_ = GetTestModeForEntry(key); 61 test_mode_ = GetTestModeForEntry(key);
58 } 62 }
59 63
60 void MockDiskEntry::Doom() { 64 void MockDiskEntry::Doom() {
61 doomed_ = true; 65 doomed_ = true;
62 } 66 }
63 67
64 void MockDiskEntry::Close() { 68 void MockDiskEntry::Close() {
65 Release(); 69 Release();
66 } 70 }
67 71
68 std::string MockDiskEntry::GetKey() const { 72 std::string MockDiskEntry::GetKey() const {
69 return key_; 73 return key_;
70 } 74 }
71 75
72 base::Time MockDiskEntry::GetLastUsed() const { 76 base::Time MockDiskEntry::GetLastUsed() const {
73 return base::Time::FromInternalValue(0); 77 return base::Time::FromInternalValue(0);
74 } 78 }
75 79
76 base::Time MockDiskEntry::GetLastModified() const { 80 base::Time MockDiskEntry::GetLastModified() const {
77 return base::Time::FromInternalValue(0); 81 return base::Time::FromInternalValue(0);
78 } 82 }
79 83
80 int32 MockDiskEntry::GetDataSize(int index) const { 84 int32 MockDiskEntry::GetDataSize(int index) const {
81 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); 85 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
82 return static_cast<int32>(data_[index].size()); 86 return static_cast<int32>(data_[index].size());
83 } 87 }
84 88
85 int MockDiskEntry::ReadData( 89 int MockDiskEntry::ReadData(int index,
86 int index, int offset, net::IOBuffer* buf, int buf_len, 90 int offset,
87 const net::CompletionCallback& callback) { 91 net::IOBuffer* buf,
92 int buf_len,
93 const net::CompletionCallback& callback) {
88 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); 94 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
89 DCHECK(!callback.is_null()); 95 DCHECK(!callback.is_null());
90 96
91 if (fail_requests_) 97 if (fail_requests_)
92 return net::ERR_CACHE_READ_FAILURE; 98 return net::ERR_CACHE_READ_FAILURE;
93 99
94 if (offset < 0 || offset > static_cast<int>(data_[index].size())) 100 if (offset < 0 || offset > static_cast<int>(data_[index].size()))
95 return net::ERR_FAILED; 101 return net::ERR_FAILED;
96 if (static_cast<size_t>(offset) == data_[index].size()) 102 if (static_cast<size_t>(offset) == data_[index].size())
97 return 0; 103 return 0;
98 104
99 int num = std::min(buf_len, static_cast<int>(data_[index].size()) - offset); 105 int num = std::min(buf_len, static_cast<int>(data_[index].size()) - offset);
100 memcpy(buf->data(), &data_[index][offset], num); 106 memcpy(buf->data(), &data_[index][offset], num);
101 107
102 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ) 108 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ)
103 return num; 109 return num;
104 110
105 CallbackLater(callback, num); 111 CallbackLater(callback, num);
106 return net::ERR_IO_PENDING; 112 return net::ERR_IO_PENDING;
107 } 113 }
108 114
109 int MockDiskEntry::WriteData( 115 int MockDiskEntry::WriteData(int index,
110 int index, int offset, net::IOBuffer* buf, int buf_len, 116 int offset,
111 const net::CompletionCallback& callback, bool truncate) { 117 net::IOBuffer* buf,
118 int buf_len,
119 const net::CompletionCallback& callback,
120 bool truncate) {
112 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); 121 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
113 DCHECK(!callback.is_null()); 122 DCHECK(!callback.is_null());
114 DCHECK(truncate); 123 DCHECK(truncate);
115 124
116 if (fail_requests_) { 125 if (fail_requests_) {
117 CallbackLater(callback, net::ERR_CACHE_READ_FAILURE); 126 CallbackLater(callback, net::ERR_CACHE_READ_FAILURE);
118 return net::ERR_IO_PENDING; 127 return net::ERR_IO_PENDING;
119 } 128 }
120 129
121 if (offset < 0 || offset > static_cast<int>(data_[index].size())) 130 if (offset < 0 || offset > static_cast<int>(data_[index].size()))
122 return net::ERR_FAILED; 131 return net::ERR_FAILED;
123 132
124 data_[index].resize(offset + buf_len); 133 data_[index].resize(offset + buf_len);
125 if (buf_len) 134 if (buf_len)
126 memcpy(&data_[index][offset], buf->data(), buf_len); 135 memcpy(&data_[index][offset], buf->data(), buf_len);
127 136
128 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE) 137 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE)
129 return buf_len; 138 return buf_len;
130 139
131 CallbackLater(callback, buf_len); 140 CallbackLater(callback, buf_len);
132 return net::ERR_IO_PENDING; 141 return net::ERR_IO_PENDING;
133 } 142 }
134 143
135 int MockDiskEntry::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 144 int MockDiskEntry::ReadSparseData(int64 offset,
145 net::IOBuffer* buf,
146 int buf_len,
136 const net::CompletionCallback& callback) { 147 const net::CompletionCallback& callback) {
137 DCHECK(!callback.is_null()); 148 DCHECK(!callback.is_null());
138 if (fail_sparse_requests_) 149 if (fail_sparse_requests_)
139 return net::ERR_NOT_IMPLEMENTED; 150 return net::ERR_NOT_IMPLEMENTED;
140 if (!sparse_ || busy_) 151 if (!sparse_ || busy_)
141 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; 152 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
142 if (offset < 0) 153 if (offset < 0)
143 return net::ERR_FAILED; 154 return net::ERR_FAILED;
144 155
145 if (fail_requests_) 156 if (fail_requests_)
146 return net::ERR_CACHE_READ_FAILURE; 157 return net::ERR_CACHE_READ_FAILURE;
147 158
148 DCHECK(offset < kint32max); 159 DCHECK(offset < kint32max);
149 int real_offset = static_cast<int>(offset); 160 int real_offset = static_cast<int>(offset);
150 if (!buf_len) 161 if (!buf_len)
151 return 0; 162 return 0;
152 163
153 int num = std::min(static_cast<int>(data_[1].size()) - real_offset, 164 int num = std::min(static_cast<int>(data_[1].size()) - real_offset, buf_len);
154 buf_len);
155 memcpy(buf->data(), &data_[1][real_offset], num); 165 memcpy(buf->data(), &data_[1][real_offset], num);
156 166
157 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ) 167 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ)
158 return num; 168 return num;
159 169
160 CallbackLater(callback, num); 170 CallbackLater(callback, num);
161 busy_ = true; 171 busy_ = true;
162 delayed_ = false; 172 delayed_ = false;
163 return net::ERR_IO_PENDING; 173 return net::ERR_IO_PENDING;
164 } 174 }
165 175
166 int MockDiskEntry::WriteSparseData(int64 offset, net::IOBuffer* buf, 176 int MockDiskEntry::WriteSparseData(int64 offset,
177 net::IOBuffer* buf,
167 int buf_len, 178 int buf_len,
168 const net::CompletionCallback& callback) { 179 const net::CompletionCallback& callback) {
169 DCHECK(!callback.is_null()); 180 DCHECK(!callback.is_null());
170 if (fail_sparse_requests_) 181 if (fail_sparse_requests_)
171 return net::ERR_NOT_IMPLEMENTED; 182 return net::ERR_NOT_IMPLEMENTED;
172 if (busy_) 183 if (busy_)
173 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; 184 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
174 if (!sparse_) { 185 if (!sparse_) {
175 if (data_[1].size()) 186 if (data_[1].size())
176 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; 187 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
(...skipping 14 matching lines...) Expand all
191 data_[1].resize(real_offset + buf_len); 202 data_[1].resize(real_offset + buf_len);
192 203
193 memcpy(&data_[1][real_offset], buf->data(), buf_len); 204 memcpy(&data_[1][real_offset], buf->data(), buf_len);
194 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE) 205 if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE)
195 return buf_len; 206 return buf_len;
196 207
197 CallbackLater(callback, buf_len); 208 CallbackLater(callback, buf_len);
198 return net::ERR_IO_PENDING; 209 return net::ERR_IO_PENDING;
199 } 210 }
200 211
201 int MockDiskEntry::GetAvailableRange(int64 offset, int len, int64* start, 212 int MockDiskEntry::GetAvailableRange(int64 offset,
213 int len,
214 int64* start,
202 const net::CompletionCallback& callback) { 215 const net::CompletionCallback& callback) {
203 DCHECK(!callback.is_null()); 216 DCHECK(!callback.is_null());
204 if (!sparse_ || busy_) 217 if (!sparse_ || busy_)
205 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; 218 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED;
206 if (offset < 0) 219 if (offset < 0)
207 return net::ERR_FAILED; 220 return net::ERR_FAILED;
208 221
209 if (fail_requests_) 222 if (fail_requests_)
210 return net::ERR_CACHE_READ_FAILURE; 223 return net::ERR_CACHE_READ_FAILURE;
211 224
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // leveraging the fact that this class is reference counted. 296 // leveraging the fact that this class is reference counted.
284 void MockDiskEntry::CallbackLater(const net::CompletionCallback& callback, 297 void MockDiskEntry::CallbackLater(const net::CompletionCallback& callback,
285 int result) { 298 int result) {
286 if (ignore_callbacks_) 299 if (ignore_callbacks_)
287 return StoreAndDeliverCallbacks(true, this, callback, result); 300 return StoreAndDeliverCallbacks(true, this, callback, result);
288 base::MessageLoop::current()->PostTask( 301 base::MessageLoop::current()->PostTask(
289 FROM_HERE, 302 FROM_HERE,
290 base::Bind(&MockDiskEntry::RunCallback, this, callback, result)); 303 base::Bind(&MockDiskEntry::RunCallback, this, callback, result));
291 } 304 }
292 305
293 void MockDiskEntry::RunCallback( 306 void MockDiskEntry::RunCallback(const net::CompletionCallback& callback,
294 const net::CompletionCallback& callback, int result) { 307 int result) {
295 if (busy_) { 308 if (busy_) {
296 // This is kind of hacky, but controlling the behavior of just this entry 309 // This is kind of hacky, but controlling the behavior of just this entry
297 // from a test is sort of complicated. What we really want to do is 310 // from a test is sort of complicated. What we really want to do is
298 // delay the delivery of a sparse IO operation a little more so that the 311 // delay the delivery of a sparse IO operation a little more so that the
299 // request start operation (async) will finish without seeing the end of 312 // request start operation (async) will finish without seeing the end of
300 // this operation (already posted to the message loop)... and without 313 // this operation (already posted to the message loop)... and without
301 // just delaying for n mS (which may cause trouble with slow bots). So 314 // just delaying for n mS (which may cause trouble with slow bots). So
302 // we re-post this operation (all async sparse IO operations will take two 315 // we re-post this operation (all async sparse IO operations will take two
303 // trips through the message loop instead of one). 316 // trips through the message loop instead of one).
304 if (!delayed_) { 317 if (!delayed_) {
305 delayed_ = true; 318 delayed_ = true;
306 return CallbackLater(callback, result); 319 return CallbackLater(callback, result);
307 } 320 }
308 } 321 }
309 busy_ = false; 322 busy_ = false;
310 callback.Run(result); 323 callback.Run(result);
311 } 324 }
312 325
313 // When |store| is true, stores the callback to be delivered later; otherwise 326 // When |store| is true, stores the callback to be delivered later; otherwise
314 // delivers any callback previously stored. 327 // delivers any callback previously stored.
315 // Static. 328 // Static.
316 void MockDiskEntry::StoreAndDeliverCallbacks( 329 void MockDiskEntry::StoreAndDeliverCallbacks(
317 bool store, MockDiskEntry* entry, const net::CompletionCallback& callback, 330 bool store,
331 MockDiskEntry* entry,
332 const net::CompletionCallback& callback,
318 int result) { 333 int result) {
319 static std::vector<CallbackInfo> callback_list; 334 static std::vector<CallbackInfo> callback_list;
320 if (store) { 335 if (store) {
321 CallbackInfo c = {entry, callback, result}; 336 CallbackInfo c = {entry, callback, result};
322 callback_list.push_back(c); 337 callback_list.push_back(c);
323 } else { 338 } else {
324 for (size_t i = 0; i < callback_list.size(); i++) { 339 for (size_t i = 0; i < callback_list.size(); i++) {
325 CallbackInfo& c = callback_list[i]; 340 CallbackInfo& c = callback_list[i];
326 c.entry->CallbackLater(c.callback, c.result); 341 c.entry->CallbackLater(c.callback, c.result);
327 } 342 }
328 callback_list.clear(); 343 callback_list.clear();
329 } 344 }
330 } 345 }
331 346
332 // Statics. 347 // Statics.
333 bool MockDiskEntry::cancel_ = false; 348 bool MockDiskEntry::cancel_ = false;
334 bool MockDiskEntry::ignore_callbacks_ = false; 349 bool MockDiskEntry::ignore_callbacks_ = false;
335 350
336 //----------------------------------------------------------------------------- 351 //-----------------------------------------------------------------------------
337 352
338 MockDiskCache::MockDiskCache() 353 MockDiskCache::MockDiskCache()
339 : open_count_(0), create_count_(0), fail_requests_(false), 354 : open_count_(0),
340 soft_failures_(false), double_create_check_(true), 355 create_count_(0),
356 fail_requests_(false),
357 soft_failures_(false),
358 double_create_check_(true),
341 fail_sparse_requests_(false) { 359 fail_sparse_requests_(false) {
342 } 360 }
343 361
344 MockDiskCache::~MockDiskCache() { 362 MockDiskCache::~MockDiskCache() {
345 ReleaseAll(); 363 ReleaseAll();
346 } 364 }
347 365
348 net::CacheType MockDiskCache::GetCacheType() const { 366 net::CacheType MockDiskCache::GetCacheType() const {
349 return net::DISK_CACHE; 367 return net::DISK_CACHE;
350 } 368 }
351 369
352 int32 MockDiskCache::GetEntryCount() const { 370 int32 MockDiskCache::GetEntryCount() const {
353 return static_cast<int32>(entries_.size()); 371 return static_cast<int32>(entries_.size());
354 } 372 }
355 373
356 int MockDiskCache::OpenEntry(const std::string& key, disk_cache::Entry** entry, 374 int MockDiskCache::OpenEntry(const std::string& key,
375 disk_cache::Entry** entry,
357 const net::CompletionCallback& callback) { 376 const net::CompletionCallback& callback) {
358 DCHECK(!callback.is_null()); 377 DCHECK(!callback.is_null());
359 if (fail_requests_) 378 if (fail_requests_)
360 return net::ERR_CACHE_OPEN_FAILURE; 379 return net::ERR_CACHE_OPEN_FAILURE;
361 380
362 EntryMap::iterator it = entries_.find(key); 381 EntryMap::iterator it = entries_.find(key);
363 if (it == entries_.end()) 382 if (it == entries_.end())
364 return net::ERR_CACHE_OPEN_FAILURE; 383 return net::ERR_CACHE_OPEN_FAILURE;
365 384
366 if (it->second->is_doomed()) { 385 if (it->second->is_doomed()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 const base::Time end_time, 469 const base::Time end_time,
451 const net::CompletionCallback& callback) { 470 const net::CompletionCallback& callback) {
452 return net::ERR_NOT_IMPLEMENTED; 471 return net::ERR_NOT_IMPLEMENTED;
453 } 472 }
454 473
455 int MockDiskCache::DoomEntriesSince(const base::Time initial_time, 474 int MockDiskCache::DoomEntriesSince(const base::Time initial_time,
456 const net::CompletionCallback& callback) { 475 const net::CompletionCallback& callback) {
457 return net::ERR_NOT_IMPLEMENTED; 476 return net::ERR_NOT_IMPLEMENTED;
458 } 477 }
459 478
460 int MockDiskCache::OpenNextEntry(void** iter, disk_cache::Entry** next_entry, 479 int MockDiskCache::OpenNextEntry(void** iter,
480 disk_cache::Entry** next_entry,
461 const net::CompletionCallback& callback) { 481 const net::CompletionCallback& callback) {
462 return net::ERR_NOT_IMPLEMENTED; 482 return net::ERR_NOT_IMPLEMENTED;
463 } 483 }
464 484
465 void MockDiskCache::EndEnumeration(void** iter) { 485 void MockDiskCache::EndEnumeration(void** iter) {
466 } 486 }
467 487
468 void MockDiskCache::GetStats( 488 void MockDiskCache::GetStats(
469 std::vector<std::pair<std::string, std::string> >* stats) { 489 std::vector<std::pair<std::string, std::string> >* stats) {
470 } 490 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 net::HttpResponseInfo* response_info, 540 net::HttpResponseInfo* response_info,
521 bool* response_truncated) { 541 bool* response_truncated) {
522 int size = disk_entry->GetDataSize(0); 542 int size = disk_entry->GetDataSize(0);
523 543
524 net::TestCompletionCallback cb; 544 net::TestCompletionCallback cb;
525 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(size)); 545 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(size));
526 int rv = disk_entry->ReadData(0, 0, buffer.get(), size, cb.callback()); 546 int rv = disk_entry->ReadData(0, 0, buffer.get(), size, cb.callback());
527 rv = cb.GetResult(rv); 547 rv = cb.GetResult(rv);
528 EXPECT_EQ(size, rv); 548 EXPECT_EQ(size, rv);
529 549
530 return net::HttpCache::ParseResponseInfo(buffer->data(), size, 550 return net::HttpCache::ParseResponseInfo(
531 response_info, 551 buffer->data(), size, response_info, response_truncated);
532 response_truncated);
533 } 552 }
534 553
535 bool MockHttpCache::WriteResponseInfo( 554 bool MockHttpCache::WriteResponseInfo(
536 disk_cache::Entry* disk_entry, const net::HttpResponseInfo* response_info, 555 disk_cache::Entry* disk_entry,
537 bool skip_transient_headers, bool response_truncated) { 556 const net::HttpResponseInfo* response_info,
557 bool skip_transient_headers,
558 bool response_truncated) {
538 Pickle pickle; 559 Pickle pickle;
539 response_info->Persist( 560 response_info->Persist(&pickle, skip_transient_headers, response_truncated);
540 &pickle, skip_transient_headers, response_truncated);
541 561
542 net::TestCompletionCallback cb; 562 net::TestCompletionCallback cb;
543 scoped_refptr<net::WrappedIOBuffer> data(new net::WrappedIOBuffer( 563 scoped_refptr<net::WrappedIOBuffer> data(
544 reinterpret_cast<const char*>(pickle.data()))); 564 new net::WrappedIOBuffer(reinterpret_cast<const char*>(pickle.data())));
545 int len = static_cast<int>(pickle.size()); 565 int len = static_cast<int>(pickle.size());
546 566
547 int rv = disk_entry->WriteData(0, 0, data.get(), len, cb.callback(), true); 567 int rv = disk_entry->WriteData(0, 0, data.get(), len, cb.callback(), true);
548 rv = cb.GetResult(rv); 568 rv = cb.GetResult(rv);
549 return (rv == len); 569 return (rv == len);
550 } 570 }
551 571
552 bool MockHttpCache::OpenBackendEntry(const std::string& key, 572 bool MockHttpCache::OpenBackendEntry(const std::string& key,
553 disk_cache::Entry** entry) { 573 disk_cache::Entry** entry) {
554 net::TestCompletionCallback cb; 574 net::TestCompletionCallback cb;
(...skipping 26 matching lines...) Expand all
581 601
582 int MockDiskCacheNoCB::CreateEntry(const std::string& key, 602 int MockDiskCacheNoCB::CreateEntry(const std::string& key,
583 disk_cache::Entry** entry, 603 disk_cache::Entry** entry,
584 const net::CompletionCallback& callback) { 604 const net::CompletionCallback& callback) {
585 return net::ERR_IO_PENDING; 605 return net::ERR_IO_PENDING;
586 } 606 }
587 607
588 //----------------------------------------------------------------------------- 608 //-----------------------------------------------------------------------------
589 609
590 int MockBackendNoCbFactory::CreateBackend( 610 int MockBackendNoCbFactory::CreateBackend(
591 net::NetLog* net_log, scoped_ptr<disk_cache::Backend>* backend, 611 net::NetLog* net_log,
612 scoped_ptr<disk_cache::Backend>* backend,
592 const net::CompletionCallback& callback) { 613 const net::CompletionCallback& callback) {
593 backend->reset(new MockDiskCacheNoCB()); 614 backend->reset(new MockDiskCacheNoCB());
594 return net::OK; 615 return net::OK;
595 } 616 }
596 617
597 //----------------------------------------------------------------------------- 618 //-----------------------------------------------------------------------------
598 619
599 MockBlockingBackendFactory::MockBlockingBackendFactory() 620 MockBlockingBackendFactory::MockBlockingBackendFactory()
600 : backend_(NULL), 621 : backend_(NULL), block_(true), fail_(false) {
601 block_(true),
602 fail_(false) {
603 } 622 }
604 623
605 MockBlockingBackendFactory::~MockBlockingBackendFactory() { 624 MockBlockingBackendFactory::~MockBlockingBackendFactory() {
606 } 625 }
607 626
608 int MockBlockingBackendFactory::CreateBackend( 627 int MockBlockingBackendFactory::CreateBackend(
609 net::NetLog* net_log, scoped_ptr<disk_cache::Backend>* backend, 628 net::NetLog* net_log,
629 scoped_ptr<disk_cache::Backend>* backend,
610 const net::CompletionCallback& callback) { 630 const net::CompletionCallback& callback) {
611 if (!block_) { 631 if (!block_) {
612 if (!fail_) 632 if (!fail_)
613 backend->reset(new MockDiskCache()); 633 backend->reset(new MockDiskCache());
614 return Result(); 634 return Result();
615 } 635 }
616 636
617 backend_ = backend; 637 backend_ = backend;
618 callback_ = callback; 638 callback_ = callback;
619 return net::ERR_IO_PENDING; 639 return net::ERR_IO_PENDING;
620 } 640 }
621 641
622 void MockBlockingBackendFactory::FinishCreation() { 642 void MockBlockingBackendFactory::FinishCreation() {
623 block_ = false; 643 block_ = false;
624 if (!callback_.is_null()) { 644 if (!callback_.is_null()) {
625 if (!fail_) 645 if (!fail_)
626 backend_->reset(new MockDiskCache()); 646 backend_->reset(new MockDiskCache());
627 net::CompletionCallback cb = callback_; 647 net::CompletionCallback cb = callback_;
628 callback_.Reset(); 648 callback_.Reset();
629 cb.Run(Result()); // This object can be deleted here. 649 cb.Run(Result()); // This object can be deleted here.
630 } 650 }
631 } 651 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698