summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 19:01:21 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-04 19:01:21 +0000
commit4d7e62f808fb995d3240542a18b75bba55aaede8 (patch)
treee348b9964b8aad4395607b030195c59693b6e9e4 /content
parent47577b044cedf34c6e480a1c79f875d48e2dc28b (diff)
downloadchromium_src-4d7e62f808fb995d3240542a18b75bba55aaede8.zip
chromium_src-4d7e62f808fb995d3240542a18b75bba55aaede8.tar.gz
chromium_src-4d7e62f808fb995d3240542a18b75bba55aaede8.tar.bz2
cc: Remove all usage of GetArea() from production code in cc
Consolidate the calls to turn gfx::Size into a number of bytes onto the cc::SharedBitmap class. The class offers the following methods: 1. Get a size_t bytes and bool saying if you overflowed or not. 2. Get a size_t bytes and crash if you overflow. 3. Get a size_t bytes and don't check for overflow. 4. Tell me if the gfx::Size would overflow to create the size_t bytes. These were the use cases I found in the existing code, plus the addition of case 2. A few places that were finding the size_t bytes without looking for overflow (case 3), from a previously-unchecked gfx::Size, were changed to crash on overflow instead (case 2). R=jbauman@chromium.org, piman@chromium.org BUG=348332 Review URL: https://codereview.chromium.org/221523003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261817 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/software_frame_manager.cc9
-rw-r--r--content/child/child_shared_bitmap_manager.cc2
-rw-r--r--content/common/cc_messages.cc5
-rw-r--r--content/common/host_shared_bitmap_manager.cc2
-rw-r--r--content/common/host_shared_bitmap_manager_unittest.cc8
5 files changed, 15 insertions, 11 deletions
diff --git a/content/browser/renderer_host/software_frame_manager.cc b/content/browser/renderer_host/software_frame_manager.cc
index 3630e59..d4fc273 100644
--- a/content/browser/renderer_host/software_frame_manager.cc
+++ b/content/browser/renderer_host/software_frame_manager.cc
@@ -8,6 +8,7 @@
#include "base/callback_helpers.h"
#include "base/debug/alias.h"
#include "base/numerics/safe_math.h"
+#include "cc/resources/shared_bitmap.h"
#include "content/browser/renderer_host/dip_util.h"
#include "content/public/browser/user_metrics.h"
@@ -97,9 +98,11 @@ bool SoftwareFrameManager::SwapToNewFrame(
// The NULL handle is used in testing.
if (base::SharedMemory::IsHandleValid(shared_memory->handle())) {
- DCHECK(frame_data->CheckedSizeInBytes().IsValid())
- << "Integer overflow when computing bytes to map.";
- size_t size_in_bytes = frame_data->SizeInBytes();
+ DCHECK(cc::SharedBitmap::VerifySizeInBytes(frame_data->size));
+ // UncheckedSizeInBytes is okay because the frame_data size was verified
+ // when frame_data was received over IPC.
+ size_t size_in_bytes =
+ cc::SharedBitmap::UncheckedSizeInBytes(frame_data->size);
#ifdef OS_WIN
if (!shared_memory->Map(0)) {
DLOG(ERROR) << "Unable to map renderer memory.";
diff --git a/content/child/child_shared_bitmap_manager.cc b/content/child/child_shared_bitmap_manager.cc
index 7325789..3b1800d 100644
--- a/content/child/child_shared_bitmap_manager.cc
+++ b/content/child/child_shared_bitmap_manager.cc
@@ -25,7 +25,7 @@ scoped_ptr<cc::SharedBitmap> ChildSharedBitmapManager::AllocateSharedBitmap(
"height",
size.height());
size_t memory_size;
- if (!cc::SharedBitmap::GetSizeInBytes(size, &memory_size))
+ if (!cc::SharedBitmap::SizeInBytes(size, &memory_size))
return scoped_ptr<cc::SharedBitmap>();
cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
scoped_ptr<base::SharedMemory> memory;
diff --git a/content/common/cc_messages.cc b/content/common/cc_messages.cc
index 40e2441..5279d4c 100644
--- a/content/common/cc_messages.cc
+++ b/content/common/cc_messages.cc
@@ -755,7 +755,7 @@ void ParamTraits<cc::DelegatedFrameData>::Log(const param_type& p,
void ParamTraits<cc::SoftwareFrameData>::Write(Message* m,
const param_type& p) {
- DCHECK(p.CheckedSizeInBytes().IsValid());
+ DCHECK(cc::SharedBitmap::VerifySizeInBytes(p.size));
m->Reserve(sizeof(cc::SoftwareFrameData));
WriteParam(m, p.id);
@@ -769,7 +769,8 @@ bool ParamTraits<cc::SoftwareFrameData>::Read(const Message* m,
param_type* p) {
if (!ReadParam(m, iter, &p->id))
return false;
- if (!ReadParam(m, iter, &p->size) || !p->CheckedSizeInBytes().IsValid())
+ if (!ReadParam(m, iter, &p->size) ||
+ !cc::SharedBitmap::VerifySizeInBytes(p->size))
return false;
if (!ReadParam(m, iter, &p->damage_rect))
return false;
diff --git a/content/common/host_shared_bitmap_manager.cc b/content/common/host_shared_bitmap_manager.cc
index aa0cd81..88d9f65 100644
--- a/content/common/host_shared_bitmap_manager.cc
+++ b/content/common/host_shared_bitmap_manager.cc
@@ -62,7 +62,7 @@ scoped_ptr<cc::SharedBitmap> HostSharedBitmapManager::GetSharedBitmapFromId(
BitmapData* data = it->second.get();
size_t bitmap_size;
- if (!cc::SharedBitmap::GetSizeInBytes(size, &bitmap_size) ||
+ if (!cc::SharedBitmap::SizeInBytes(size, &bitmap_size) ||
bitmap_size > data->buffer_size)
return scoped_ptr<cc::SharedBitmap>();
diff --git a/content/common/host_shared_bitmap_manager_unittest.cc b/content/common/host_shared_bitmap_manager_unittest.cc
index 1f7d8dd..ed0ddba 100644
--- a/content/common/host_shared_bitmap_manager_unittest.cc
+++ b/content/common/host_shared_bitmap_manager_unittest.cc
@@ -17,7 +17,7 @@ class HostSharedBitmapManagerTest : public testing::Test {
TEST_F(HostSharedBitmapManagerTest, TestCreate) {
gfx::Size bitmap_size(1, 1);
size_t size_in_bytes;
- EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
+ EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
bitmap->CreateAndMapAnonymous(size_in_bytes);
memset(bitmap->memory(), 0xff, size_in_bytes);
@@ -76,7 +76,7 @@ TEST_F(HostSharedBitmapManagerTest, TestCreate) {
TEST_F(HostSharedBitmapManagerTest, TestCreateForChild) {
gfx::Size bitmap_size(1, 1);
size_t size_in_bytes;
- EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
+ EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
base::SharedMemoryHandle handle;
manager_->AllocateSharedBitmapForChild(
@@ -97,7 +97,7 @@ TEST_F(HostSharedBitmapManagerTest, TestCreateForChild) {
TEST_F(HostSharedBitmapManagerTest, RemoveProcess) {
gfx::Size bitmap_size(1, 1);
size_t size_in_bytes;
- EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
+ EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
bitmap->CreateAndMapAnonymous(size_in_bytes);
memset(bitmap->memory(), 0xff, size_in_bytes);
@@ -131,7 +131,7 @@ TEST_F(HostSharedBitmapManagerTest, RemoveProcess) {
TEST_F(HostSharedBitmapManagerTest, AddDuplicate) {
gfx::Size bitmap_size(1, 1);
size_t size_in_bytes;
- EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
+ EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
bitmap->CreateAndMapAnonymous(size_in_bytes);
memset(bitmap->memory(), 0xff, size_in_bytes);