summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authoragayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 07:04:31 +0000
committeragayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 07:04:31 +0000
commit586a0f567e3842f2aac5f3bd61ec3a9a3f7dfb00 (patch)
tree1b05096b82a5e3048165523e3deda0bd9b0e9495 /net/disk_cache
parent5d529b0e998fe75335a886cdfee16f53fbfc2da2 (diff)
downloadchromium_src-586a0f567e3842f2aac5f3bd61ec3a9a3f7dfb00.zip
chromium_src-586a0f567e3842f2aac5f3bd61ec3a9a3f7dfb00.tar.gz
chromium_src-586a0f567e3842f2aac5f3bd61ec3a9a3f7dfb00.tar.bz2
Make Segment refcounted.
BUG=157187 TEST=net_unittests --gtest_filter="FlashCacheTest.*" --gtest_repeat=10 --shuffle Review URL: https://chromiumcodereview.appspot.com/11364079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/flash/segment.h7
-rw-r--r--net/disk_cache/flash/segment_unittest.cc16
2 files changed, 13 insertions, 10 deletions
diff --git a/net/disk_cache/flash/segment.h b/net/disk_cache/flash/segment.h
index 3c1fa67..f4a4762 100644
--- a/net/disk_cache/flash/segment.h
+++ b/net/disk_cache/flash/segment.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
+#include "base/memory/ref_counted.h"
#include "net/base/net_export.h"
namespace disk_cache {
@@ -56,7 +57,7 @@ class Storage;
// ReadData can be called over the range that was previously written with
// WriteData. Reading from area that was not written will fail.
-class NET_EXPORT_PRIVATE Segment {
+class NET_EXPORT_PRIVATE Segment : public base::RefCounted<Segment> {
public:
// |index| is the index of this segment on |storage|. If the storage size is
// X and the segment size is Y, where X >> Y and X % Y == 0, then the valid
@@ -64,7 +65,6 @@ class NET_EXPORT_PRIVATE Segment {
// |index| is given value Z, then it covers bytes on storage starting at the
// offset Z*Y and ending at the offset Z*Y+Y-1.
Segment(int32 index, bool read_only, Storage* storage);
- ~Segment();
std::vector<int32> GetOffsets() const { return offsets_; }
@@ -92,6 +92,9 @@ class NET_EXPORT_PRIVATE Segment {
bool CanHold(int32 size) const;
private:
+ friend class base::RefCounted<Segment>;
+ ~Segment();
+
bool read_only_; // Indicates whether the segment can be written to.
bool init_; // Indicates whether segment was initialized.
Storage* storage_; // Storage on which the segment resides.
diff --git a/net/disk_cache/flash/segment_unittest.cc b/net/disk_cache/flash/segment_unittest.cc
index fb9fb33..b33d000 100644
--- a/net/disk_cache/flash/segment_unittest.cc
+++ b/net/disk_cache/flash/segment_unittest.cc
@@ -38,28 +38,28 @@ const int32 kSegmentFreeSpace = disk_cache::kFlashSegmentSize -
TEST_F(FlashCacheTest, CreateDestroy) {
int32 index = 0;
- scoped_ptr<disk_cache::Segment> segment(
+ scoped_refptr<disk_cache::Segment> segment(
new disk_cache::Segment(index, false, storage_.get()));
EXPECT_TRUE(segment->Init());
EXPECT_TRUE(segment->Close());
index = num_segments_in_storage_ - 1;
- segment.reset(new disk_cache::Segment(index, false, storage_.get()));
+ segment = new disk_cache::Segment(index, false, storage_.get());
EXPECT_TRUE(segment->Init());
EXPECT_TRUE(segment->Close());
int32 invalid_index = num_segments_in_storage_;
- segment.reset(new disk_cache::Segment(invalid_index, false, storage_.get()));
+ segment = new disk_cache::Segment(invalid_index, false, storage_.get());
EXPECT_FALSE(segment->Init());
invalid_index = -1;
- segment.reset(new disk_cache::Segment(invalid_index, false, storage_.get()));
+ segment = new disk_cache::Segment(invalid_index, false, storage_.get());
EXPECT_FALSE(segment->Init());
}
TEST_F(FlashCacheTest, WriteDataReadData) {
int32 index = rand() % num_segments_in_storage_;
- scoped_ptr<disk_cache::Segment> segment(
+ scoped_refptr<disk_cache::Segment> segment(
new disk_cache::Segment(index, false, storage_.get()));
EXPECT_TRUE(segment->Init());
@@ -69,7 +69,7 @@ TEST_F(FlashCacheTest, WriteDataReadData) {
EXPECT_TRUE(segment->WriteData(entry1.data, entry1.size, &offset));
EXPECT_TRUE(segment->Close());
- segment.reset(new disk_cache::Segment(index, true, storage_.get()));
+ segment = new disk_cache::Segment(index, true, storage_.get());
EXPECT_TRUE(segment->Init());
SmallEntry entry2;
EXPECT_TRUE(segment->ReadData(entry2.data, entry2.size, offset));
@@ -79,7 +79,7 @@ TEST_F(FlashCacheTest, WriteDataReadData) {
TEST_F(FlashCacheTest, FillWithSmallEntries) {
int32 index = rand() % num_segments_in_storage_;
- scoped_ptr<disk_cache::Segment> segment(
+ scoped_refptr<disk_cache::Segment> segment(
new disk_cache::Segment(index, false, storage_.get()));
EXPECT_TRUE(segment->Init());
@@ -99,7 +99,7 @@ TEST_F(FlashCacheTest, FillWithSmallEntries) {
TEST_F(FlashCacheTest, FillWithLargeEntries) {
int32 index = rand() % num_segments_in_storage_;
- scoped_ptr<disk_cache::Segment> segment(
+ scoped_refptr<disk_cache::Segment> segment(
new disk_cache::Segment(index, false, storage_.get()));
EXPECT_TRUE(segment->Init());