| OLD | NEW |
| 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 <utility> |
| 6 |
| 5 #include "base/bind.h" | 7 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 7 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 13 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 14 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| (...skipping 2162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2177 DoomSparseEntry(); | 2179 DoomSparseEntry(); |
| 2178 } | 2180 } |
| 2179 | 2181 |
| 2180 // A CompletionCallback wrapper that deletes the cache from within the callback. | 2182 // A CompletionCallback wrapper that deletes the cache from within the callback. |
| 2181 // The way a CompletionCallback works means that all tasks (even new ones) | 2183 // The way a CompletionCallback works means that all tasks (even new ones) |
| 2182 // are executed by the message loop before returning to the caller so the only | 2184 // are executed by the message loop before returning to the caller so the only |
| 2183 // way to simulate a race is to execute what we want on the callback. | 2185 // way to simulate a race is to execute what we want on the callback. |
| 2184 class SparseTestCompletionCallback: public net::TestCompletionCallback { | 2186 class SparseTestCompletionCallback: public net::TestCompletionCallback { |
| 2185 public: | 2187 public: |
| 2186 explicit SparseTestCompletionCallback(scoped_ptr<disk_cache::Backend> cache) | 2188 explicit SparseTestCompletionCallback(scoped_ptr<disk_cache::Backend> cache) |
| 2187 : cache_(cache.Pass()) { | 2189 : cache_(std::move(cache)) {} |
| 2188 } | |
| 2189 | 2190 |
| 2190 private: | 2191 private: |
| 2191 void SetResult(int result) override { | 2192 void SetResult(int result) override { |
| 2192 cache_.reset(); | 2193 cache_.reset(); |
| 2193 TestCompletionCallback::SetResult(result); | 2194 TestCompletionCallback::SetResult(result); |
| 2194 } | 2195 } |
| 2195 | 2196 |
| 2196 scoped_ptr<disk_cache::Backend> cache_; | 2197 scoped_ptr<disk_cache::Backend> cache_; |
| 2197 DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback); | 2198 DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback); |
| 2198 }; | 2199 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2215 for (int i = 0; i < 12; i++) { | 2216 for (int i = 0; i < 12; i++) { |
| 2216 EXPECT_EQ(kSize, | 2217 EXPECT_EQ(kSize, |
| 2217 entry->WriteSparseData( | 2218 entry->WriteSparseData( |
| 2218 offset, buf.get(), kSize, net::CompletionCallback())); | 2219 offset, buf.get(), kSize, net::CompletionCallback())); |
| 2219 offset *= 4; | 2220 offset *= 4; |
| 2220 } | 2221 } |
| 2221 EXPECT_EQ(9, cache_->GetEntryCount()); | 2222 EXPECT_EQ(9, cache_->GetEntryCount()); |
| 2222 | 2223 |
| 2223 entry->Close(); | 2224 entry->Close(); |
| 2224 disk_cache::Backend* cache = cache_.get(); | 2225 disk_cache::Backend* cache = cache_.get(); |
| 2225 SparseTestCompletionCallback cb(cache_.Pass()); | 2226 SparseTestCompletionCallback cb(std::move(cache_)); |
| 2226 int rv = cache->DoomEntry(key, cb.callback()); | 2227 int rv = cache->DoomEntry(key, cb.callback()); |
| 2227 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 2228 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 2228 EXPECT_EQ(net::OK, cb.WaitForResult()); | 2229 EXPECT_EQ(net::OK, cb.WaitForResult()); |
| 2229 } | 2230 } |
| 2230 | 2231 |
| 2231 void DiskCacheEntryTest::PartialSparseEntry() { | 2232 void DiskCacheEntryTest::PartialSparseEntry() { |
| 2232 std::string key("the first key"); | 2233 std::string key("the first key"); |
| 2233 disk_cache::Entry* entry; | 2234 disk_cache::Entry* entry; |
| 2234 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 2235 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 2235 | 2236 |
| (...skipping 1920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4156 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 4157 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
| 4157 | 4158 |
| 4158 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback()); | 4159 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback()); |
| 4159 EXPECT_EQ(0, callback.GetResult(ret)); | 4160 EXPECT_EQ(0, callback.GetResult(ret)); |
| 4160 | 4161 |
| 4161 ret = entry->ReadSparseData(kSize, buffer.get(), kSize, callback.callback()); | 4162 ret = entry->ReadSparseData(kSize, buffer.get(), kSize, callback.callback()); |
| 4162 EXPECT_EQ(kSize, callback.GetResult(ret)); | 4163 EXPECT_EQ(kSize, callback.GetResult(ret)); |
| 4163 | 4164 |
| 4164 entry->Close(); | 4165 entry->Close(); |
| 4165 } | 4166 } |
| OLD | NEW |