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

Side by Side Diff: net/disk_cache/entry_unittest.cc

Issue 1894733002: Change scoped_ptr to std::unique_ptr in //net/disk_cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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_test_util.cc ('k') | net/disk_cache/memory/mem_backend_impl.h » ('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) 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> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 0, buf.get(), kSize, net::CompletionCallback())); 1618 0, buf.get(), kSize, net::CompletionCallback()));
1619 1619
1620 // This write creates a child entry and writes to it. 1620 // This write creates a child entry and writes to it.
1621 EXPECT_EQ(kSize, 1621 EXPECT_EQ(kSize,
1622 parent_entry->WriteSparseData( 1622 parent_entry->WriteSparseData(
1623 8192, buf.get(), kSize, net::CompletionCallback())); 1623 8192, buf.get(), kSize, net::CompletionCallback()));
1624 1624
1625 parent_entry->Close(); 1625 parent_entry->Close();
1626 1626
1627 // Perform the enumerations. 1627 // Perform the enumerations.
1628 scoped_ptr<TestIterator> iter = CreateIterator(); 1628 std::unique_ptr<TestIterator> iter = CreateIterator();
1629 disk_cache::Entry* entry = NULL; 1629 disk_cache::Entry* entry = NULL;
1630 int count = 0; 1630 int count = 0;
1631 while (iter->OpenNextEntry(&entry) == net::OK) { 1631 while (iter->OpenNextEntry(&entry) == net::OK) {
1632 ASSERT_TRUE(entry != NULL); 1632 ASSERT_TRUE(entry != NULL);
1633 ++count; 1633 ++count;
1634 disk_cache::MemEntryImpl* mem_entry = 1634 disk_cache::MemEntryImpl* mem_entry =
1635 reinterpret_cast<disk_cache::MemEntryImpl*>(entry); 1635 reinterpret_cast<disk_cache::MemEntryImpl*>(entry);
1636 EXPECT_EQ(disk_cache::MemEntryImpl::PARENT_ENTRY, mem_entry->type()); 1636 EXPECT_EQ(disk_cache::MemEntryImpl::PARENT_ENTRY, mem_entry->type());
1637 mem_entry->Close(); 1637 mem_entry->Close();
1638 } 1638 }
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 InitCache(); 2178 InitCache();
2179 DoomSparseEntry(); 2179 DoomSparseEntry();
2180 } 2180 }
2181 2181
2182 // A CompletionCallback wrapper that deletes the cache from within the callback. 2182 // A CompletionCallback wrapper that deletes the cache from within the callback.
2183 // 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)
2184 // 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
2185 // 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.
2186 class SparseTestCompletionCallback: public net::TestCompletionCallback { 2186 class SparseTestCompletionCallback: public net::TestCompletionCallback {
2187 public: 2187 public:
2188 explicit SparseTestCompletionCallback(scoped_ptr<disk_cache::Backend> cache) 2188 explicit SparseTestCompletionCallback(
2189 std::unique_ptr<disk_cache::Backend> cache)
2189 : cache_(std::move(cache)) {} 2190 : cache_(std::move(cache)) {}
2190 2191
2191 private: 2192 private:
2192 void SetResult(int result) override { 2193 void SetResult(int result) override {
2193 cache_.reset(); 2194 cache_.reset();
2194 TestCompletionCallback::SetResult(result); 2195 TestCompletionCallback::SetResult(result);
2195 } 2196 }
2196 2197
2197 scoped_ptr<disk_cache::Backend> cache_; 2198 std::unique_ptr<disk_cache::Backend> cache_;
2198 DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback); 2199 DISALLOW_COPY_AND_ASSIGN(SparseTestCompletionCallback);
2199 }; 2200 };
2200 2201
2201 // Tests that we don't crash when the backend is deleted while we are working 2202 // Tests that we don't crash when the backend is deleted while we are working
2202 // deleting the sub-entries of a sparse entry. 2203 // deleting the sub-entries of a sparse entry.
2203 TEST_F(DiskCacheEntryTest, DoomSparseEntry2) { 2204 TEST_F(DiskCacheEntryTest, DoomSparseEntry2) {
2204 UseCurrentThread(); 2205 UseCurrentThread();
2205 InitCache(); 2206 InitCache();
2206 std::string key("the key"); 2207 std::string key("the key");
2207 disk_cache::Entry* entry; 2208 disk_cache::Entry* entry;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2344 scoped_refptr<net::IOBuffer> buf1(new net::IOBuffer(kSize)); 2345 scoped_refptr<net::IOBuffer> buf1(new net::IOBuffer(kSize));
2345 CacheTestFillBuffer(buf1->data(), kSize, false); 2346 CacheTestFillBuffer(buf1->data(), kSize, false);
2346 2347
2347 const int k1Meg = 1024 * 1024; 2348 const int k1Meg = 1024 * 1024;
2348 EXPECT_EQ(kSize, WriteSparseData(entry, 8192, buf1.get(), kSize)); 2349 EXPECT_EQ(kSize, WriteSparseData(entry, 8192, buf1.get(), kSize));
2349 EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 8192, buf1.get(), kSize)); 2350 EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 8192, buf1.get(), kSize));
2350 EXPECT_EQ(kSize, WriteSparseData(entry, 2 * k1Meg + 8192, buf1.get(), kSize)); 2351 EXPECT_EQ(kSize, WriteSparseData(entry, 2 * k1Meg + 8192, buf1.get(), kSize));
2351 entry->Close(); 2352 entry->Close();
2352 EXPECT_EQ(4, cache_->GetEntryCount()); 2353 EXPECT_EQ(4, cache_->GetEntryCount());
2353 2354
2354 scoped_ptr<TestIterator> iter = CreateIterator(); 2355 std::unique_ptr<TestIterator> iter = CreateIterator();
2355 int count = 0; 2356 int count = 0;
2356 std::string child_key[2]; 2357 std::string child_key[2];
2357 while (iter->OpenNextEntry(&entry) == net::OK) { 2358 while (iter->OpenNextEntry(&entry) == net::OK) {
2358 ASSERT_TRUE(entry != NULL); 2359 ASSERT_TRUE(entry != NULL);
2359 // Writing to an entry will alter the LRU list and invalidate the iterator. 2360 // Writing to an entry will alter the LRU list and invalidate the iterator.
2360 if (entry->GetKey() != key && count < 2) 2361 if (entry->GetKey() != key && count < 2)
2361 child_key[count++] = entry->GetKey(); 2362 child_key[count++] = entry->GetKey();
2362 entry->Close(); 2363 entry->Close();
2363 } 2364 }
2364 for (int i = 0; i < 2; i++) { 2365 for (int i = 0; i < 2; i++) {
(...skipping 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 4158 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
4158 4159
4159 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback()); 4160 ret = entry->ReadSparseData(0, buffer.get(), kSize, callback.callback());
4160 EXPECT_EQ(0, callback.GetResult(ret)); 4161 EXPECT_EQ(0, callback.GetResult(ret));
4161 4162
4162 ret = entry->ReadSparseData(kSize, buffer.get(), kSize, callback.callback()); 4163 ret = entry->ReadSparseData(kSize, buffer.get(), kSize, callback.callback());
4163 EXPECT_EQ(kSize, callback.GetResult(ret)); 4164 EXPECT_EQ(kSize, callback.GetResult(ret));
4164 4165
4165 entry->Close(); 4166 entry->Close();
4166 } 4167 }
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache_test_util.cc ('k') | net/disk_cache/memory/mem_backend_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698