Avoid sending notifications when the bitmap data in the history backend is replaced with bitmap data which is byte for byte equal.
Bug=168223
Test=HistoryBackendTest.*
Manual: see comment #7 in bug
Review URL: https://chromiumcodereview.appspot.com/11830007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176691 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 5565316246b58c1168fb10e9439fc903ebb8faa6
diff --git a/base/memory/ref_counted_memory.cc b/base/memory/ref_counted_memory.cc
index 9bcde32..b048a6e 100644
--- a/base/memory/ref_counted_memory.cc
+++ b/base/memory/ref_counted_memory.cc
@@ -8,6 +8,13 @@
namespace base {
+bool RefCountedMemory::Equals(
+ const scoped_refptr<RefCountedMemory>& other) const {
+ return other.get() &&
+ size() == other->size() &&
+ (memcmp(front(), other->front(), size()) == 0);
+}
+
RefCountedMemory::RefCountedMemory() {}
RefCountedMemory::~RefCountedMemory() {}
diff --git a/base/memory/ref_counted_memory.h b/base/memory/ref_counted_memory.h
index 9edcd6f..b99871b 100644
--- a/base/memory/ref_counted_memory.h
+++ b/base/memory/ref_counted_memory.h
@@ -27,6 +27,9 @@
// Size of the memory pointed to.
virtual size_t size() const = 0;
+ // Returns true if |other| is byte for byte equal.
+ bool Equals(const scoped_refptr<RefCountedMemory>& other) const;
+
protected:
friend class base::RefCountedThreadSafe<RefCountedMemory>;
RefCountedMemory();
diff --git a/base/memory/ref_counted_memory_unittest.cc b/base/memory/ref_counted_memory_unittest.cc
index 1936040..c6f2b9c 100644
--- a/base/memory/ref_counted_memory_unittest.cc
+++ b/base/memory/ref_counted_memory_unittest.cc
@@ -42,4 +42,30 @@
EXPECT_EQ('e', mem->front()[1]);
}
+TEST(RefCountedMemoryUnitTest, Equals) {
+ std::string s1("same");
+ scoped_refptr<RefCountedMemory> mem1 = RefCountedString::TakeString(&s1);
+
+ std::vector<unsigned char> d2;
+ d2.push_back('s');
+ d2.push_back('a');
+ d2.push_back('m');
+ d2.push_back('e');
+ scoped_refptr<RefCountedMemory> mem2 = RefCountedBytes::TakeVector(&d2);
+
+ EXPECT_TRUE(mem1->Equals(mem2));
+
+ std::string s3("diff");
+ scoped_refptr<RefCountedMemory> mem3 = RefCountedString::TakeString(&s3);
+
+ EXPECT_FALSE(mem1->Equals(mem3));
+ EXPECT_FALSE(mem2->Equals(mem3));
+}
+
+TEST(RefCountedMemoryUnitTest, EqualsNull) {
+ std::string s("str");
+ scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s);
+ EXPECT_FALSE(mem->Equals(NULL));
+}
+
} // namespace base