Commit 20430a88 authored by tzik's avatar tzik Committed by Commit Bot

Remove WTF::RefCountedBase::RefCount()

This CL removes the getter of the ref count value from
WTF::RefCountedBase, which is missing on base::RefCounted and will be
unavailable after these unification. And this also removes all usage of
the getter.

Bug: 763844
Change-Id: I3b91d16213a160c9c6a2bf1e4cea16598043c00e
Reviewed-on: https://chromium-review.googlesource.com/680618Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504364}
parent 3ac0e5b0
...@@ -148,45 +148,25 @@ TEST(CSSCalculationValue, AccumulatePixelsAndPercent) { ...@@ -148,45 +148,25 @@ TEST(CSSCalculationValue, AccumulatePixelsAndPercent) {
TEST(CSSCalculationValue, RefCount) { TEST(CSSCalculationValue, RefCount) {
RefPtr<CalculationValue> calc = RefPtr<CalculationValue> calc =
CalculationValue::Create(PixelsAndPercent(1, 2), kValueRangeAll); CalculationValue::Create(PixelsAndPercent(1, 2), kValueRangeAll);
Length length_a(calc);
EXPECT_EQ(calc->RefCount(), 2);
Length length_b; // FIXME: Test the Length construction without using the ref count value.
length_b = length_a;
EXPECT_EQ(calc->RefCount(), 3);
Length length_c(calc); EXPECT_TRUE(calc->HasOneRef());
length_c = length_a; {
EXPECT_EQ(calc->RefCount(), 4); Length length_a(calc);
EXPECT_FALSE(calc->HasOneRef());
Length length_d( Length length_b;
CalculationValue::Create(PixelsAndPercent(1, 2), kValueRangeAll));
length_d = length_a;
EXPECT_EQ(calc->RefCount(), 5);
}
TEST(CSSCalculationValue, RefCountLeak) {
RefPtr<CalculationValue> calc =
CalculationValue::Create(PixelsAndPercent(1, 2), kValueRangeAll);
Length length_a(calc);
Length length_b = length_a;
for (int i = 0; i < 100; ++i)
length_b = length_a; length_b = length_a;
EXPECT_EQ(calc->RefCount(), 3);
Length length_c(length_a); Length length_c(calc);
for (int i = 0; i < 100; ++i)
length_c = length_a; length_c = length_a;
EXPECT_EQ(calc->RefCount(), 4);
Length length_d(calc); Length length_d(
for (int i = 0; i < 100; ++i) CalculationValue::Create(PixelsAndPercent(1, 2), kValueRangeAll));
length_d = length_a; length_d = length_a;
EXPECT_EQ(calc->RefCount(), 5); }
EXPECT_TRUE(calc->HasOneRef());
length_d = Length();
EXPECT_EQ(calc->RefCount(), 4);
} }
TEST(CSSCalculationValue, AddToLengthUnitValues) { TEST(CSSCalculationValue, AddToLengthUnitValues) {
......
...@@ -1528,7 +1528,6 @@ inline void BreakingContext::CommitAndUpdateLineBreakIfNeeded() { ...@@ -1528,7 +1528,6 @@ inline void BreakingContext::CommitAndUpdateLineBreakIfNeeded() {
} }
} }
SECURITY_DCHECK(current_style_->RefCount() > 0);
if (check_for_break && !width_.FitsOnLine()) { if (check_for_break && !width_.FitsOnLine()) {
// if we have floats, try to get below them. // if we have floats, try to get below them.
if (current_character_is_space_ && !ignoring_spaces_ && if (current_character_is_space_ && !ignoring_spaces_ &&
......
...@@ -90,9 +90,9 @@ HarfBuzzFace::~HarfBuzzFace() { ...@@ -90,9 +90,9 @@ HarfBuzzFace::~HarfBuzzFace() {
HarfBuzzFontCache::iterator result = HarfBuzzFontCache::iterator result =
FontGlobalContext::GetHarfBuzzFontCache().find(unique_id_); FontGlobalContext::GetHarfBuzzFontCache().find(unique_id_);
SECURITY_DCHECK(result != FontGlobalContext::GetHarfBuzzFontCache().end()); SECURITY_DCHECK(result != FontGlobalContext::GetHarfBuzzFontCache().end());
DCHECK_GT(result.Get()->value->RefCount(), 1); DCHECK(!result.Get()->value->HasOneRef());
result.Get()->value->Deref(); result.Get()->value->Deref();
if (result.Get()->value->RefCount() == 1) if (result.Get()->value->HasOneRef())
FontGlobalContext::GetHarfBuzzFontCache().erase(unique_id_); FontGlobalContext::GetHarfBuzzFontCache().erase(unique_id_);
} }
......
...@@ -46,18 +46,17 @@ static inline ShapeResultTestInfo* TestInfo(RefPtr<ShapeResult>& result) { ...@@ -46,18 +46,17 @@ static inline ShapeResultTestInfo* TestInfo(RefPtr<ShapeResult>& result) {
TEST_F(HarfBuzzShaperTest, MutableUnique) { TEST_F(HarfBuzzShaperTest, MutableUnique) {
RefPtr<ShapeResult> result = RefPtr<ShapeResult> result =
ShapeResult::Create(&font, 0, TextDirection::kLtr); ShapeResult::Create(&font, 0, TextDirection::kLtr);
EXPECT_EQ(1, result->RefCount()); EXPECT_TRUE(result->HasOneRef());
// At this point, |result| has only one ref count. // At this point, |result| has only one ref count.
RefPtr<ShapeResult> result2 = result->MutableUnique(); RefPtr<ShapeResult> result2 = result->MutableUnique();
EXPECT_EQ(result.Get(), result2.Get()); EXPECT_EQ(result.Get(), result2.Get());
EXPECT_EQ(2, result2->RefCount()); EXPECT_FALSE(result2->HasOneRef());
// Since |result| has 2 ref counts, it should return a clone. // Since |result| has 2 ref counts, it should return a clone.
RefPtr<ShapeResult> result3 = result->MutableUnique(); RefPtr<ShapeResult> result3 = result->MutableUnique();
EXPECT_NE(result.Get(), result3.Get()); EXPECT_NE(result.Get(), result3.Get());
EXPECT_EQ(1, result3->RefCount()); EXPECT_TRUE(result3->HasOneRef());
EXPECT_EQ(2, result->RefCount());
} }
TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) { TEST_F(HarfBuzzShaperTest, ResolveCandidateRunsLatin) {
......
...@@ -316,7 +316,7 @@ TEST(FunctionalTest, MemberFunctionBindByPassedUniquePtr) { ...@@ -316,7 +316,7 @@ TEST(FunctionalTest, MemberFunctionBindByPassedUniquePtr) {
EXPECT_EQ(10, function1()); EXPECT_EQ(10, function1());
} }
class Number : public RefCounted<Number> { class Number {
public: public:
static RefPtr<Number> Create(int value) { static RefPtr<Number> Create(int value) {
return WTF::AdoptRef(new Number(value)); return WTF::AdoptRef(new Number(value));
...@@ -325,11 +325,20 @@ class Number : public RefCounted<Number> { ...@@ -325,11 +325,20 @@ class Number : public RefCounted<Number> {
~Number() { value_ = 0; } ~Number() { value_ = 0; }
int Value() const { return value_; } int Value() const { return value_; }
int RefCount() const { return ref_count_; }
bool HasOneRef() const { return ref_count_ == 1; }
void Ref() const { ++ref_count_; }
void Deref() const {
if (--ref_count_ == 0)
delete this;
}
private: private:
explicit Number(int value) : value_(value) {} explicit Number(int value) : value_(value) {}
int value_; int value_;
mutable int ref_count_ = 1;
}; };
int MultiplyNumberByTwo(Number* number) { int MultiplyNumberByTwo(Number* number) {
...@@ -338,7 +347,7 @@ int MultiplyNumberByTwo(Number* number) { ...@@ -338,7 +347,7 @@ int MultiplyNumberByTwo(Number* number) {
TEST(FunctionalTest, RefCountedStorage) { TEST(FunctionalTest, RefCountedStorage) {
RefPtr<Number> five = Number::Create(5); RefPtr<Number> five = Number::Create(5);
EXPECT_EQ(1, five->RefCount()); EXPECT_TRUE(five->HasOneRef());
Function<int()> multiply_five_by_two_function = Function<int()> multiply_five_by_two_function =
WTF::Bind(MultiplyNumberByTwo, five); WTF::Bind(MultiplyNumberByTwo, five);
EXPECT_EQ(2, five->RefCount()); EXPECT_EQ(2, five->RefCount());
......
...@@ -57,13 +57,6 @@ class WTF_EXPORT RefCountedBase { ...@@ -57,13 +57,6 @@ class WTF_EXPORT RefCountedBase {
return ref_count_ == 1; return ref_count_ == 1;
} }
int RefCount() const {
#if CHECK_REF_COUNTED_LIFECYCLE
SECURITY_DCHECK(verifier_.IsSafeToUse());
#endif
return ref_count_;
}
protected: protected:
RefCountedBase() RefCountedBase()
: ref_count_(1) : ref_count_(1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment