OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 CallbackLater(callback, num); | 130 CallbackLater(callback, num); |
131 return net::ERR_IO_PENDING; | 131 return net::ERR_IO_PENDING; |
132 } | 132 } |
133 | 133 |
134 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | 134 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
135 net::CompletionCallback* callback, bool truncate) { | 135 net::CompletionCallback* callback, bool truncate) { |
136 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); | 136 DCHECK(index >= 0 && index < kNumCacheEntryDataIndices); |
137 DCHECK(callback); | 137 DCHECK(callback); |
138 DCHECK(truncate); | 138 DCHECK(truncate); |
139 | 139 |
140 if (fail_requests_) | 140 if (fail_requests_) { |
141 return net::ERR_CACHE_READ_FAILURE; | 141 CallbackLater(callback, net::ERR_CACHE_READ_FAILURE); |
| 142 return net::ERR_IO_PENDING; |
| 143 } |
142 | 144 |
143 if (offset < 0 || offset > static_cast<int>(data_[index].size())) | 145 if (offset < 0 || offset > static_cast<int>(data_[index].size())) |
144 return net::ERR_FAILED; | 146 return net::ERR_FAILED; |
145 | 147 |
146 data_[index].resize(offset + buf_len); | 148 data_[index].resize(offset + buf_len); |
147 if (buf_len) | 149 if (buf_len) |
148 memcpy(&data_[index][offset], buf->data(), buf_len); | 150 memcpy(&data_[index][offset], buf->data(), buf_len); |
149 | 151 |
150 if (GetEffectiveTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE) | 152 if (GetEffectiveTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_WRITE) |
151 return buf_len; | 153 return buf_len; |
(...skipping 4572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4724 // Now return 200 when validating the entry so the metadata will be lost. | 4726 // Now return 200 when validating the entry so the metadata will be lost. |
4725 MockTransaction trans2(kTypicalGET_Transaction); | 4727 MockTransaction trans2(kTypicalGET_Transaction); |
4726 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4728 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
4727 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4729 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
4728 EXPECT_TRUE(response.metadata.get() == NULL); | 4730 EXPECT_TRUE(response.metadata.get() == NULL); |
4729 | 4731 |
4730 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4732 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
4731 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4733 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
4732 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4734 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4733 } | 4735 } |
OLD | NEW |