Skip to content

Commit

Permalink
Make SharedMemory use uint32 instead of size_t. This removes the rema…
Browse files Browse the repository at this point in the history
…ining size_t's from the IPC code.

Review URL: http://codereview.chromium.org/581001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39164 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jam@chromium.org committed Feb 16, 2010
1 parent 77bd2ce commit b5ab398
Show file tree
Hide file tree
Showing 41 changed files with 108 additions and 106 deletions.
8 changes: 4 additions & 4 deletions app/clipboard/clipboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace {
// the bitmap data or -1 if the data is invalid.
// returns: true if the bitmap size is valid, false otherwise.
bool IsBitmapSafe(const Clipboard::ObjectMapParams& params,
size_t* bitmap_bytes) {
uint32* bitmap_bytes) {
*bitmap_bytes = -1;
if (params[1].size() != sizeof(gfx::Size))
return false;
const gfx::Size* size =
reinterpret_cast<const gfx::Size*>(&(params[1].front()));
size_t total_size = size->width();
uint32 total_size = size->width();
// Using INT_MAX not SIZE_T_MAX to put a reasonable bound on things.
if (INT_MAX / size->width() <= size->height())
return false;
Expand All @@ -42,7 +42,7 @@ bool IsBitmapSafe(const Clipboard::ObjectMapParams& params,
// Returns true if the clipboard data makes sense and it's safe to access the
// bitmap.
bool ValidatePlainBitmap(const Clipboard::ObjectMapParams& params) {
size_t bitmap_bytes = -1;
uint32 bitmap_bytes = -1;
if (!IsBitmapSafe(params, &bitmap_bytes))
return false;
if (bitmap_bytes != params[0].size())
Expand All @@ -56,7 +56,7 @@ bool ValidatePlainBitmap(const Clipboard::ObjectMapParams& params) {
bool ValidateAndMapSharedBitmap(const Clipboard::ObjectMapParams& params,
base::SharedMemory* bitmap_data) {
using base::SharedMemory;
size_t bitmap_bytes = -1;
uint32 bitmap_bytes = -1;
if (!IsBitmapSafe(params, &bitmap_bytes))
return false;

Expand Down
2 changes: 1 addition & 1 deletion app/clipboard/clipboard_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ TEST_F(ClipboardTest, SharedBitmapTest) {
0x91E9F63A, 0xC31EA14F, 0x69AB32DF, 0x643A3FD1,
};
gfx::Size fake_bitmap_size(3, 4);
size_t bytes = sizeof(fake_bitmap);
uint32 bytes = sizeof(fake_bitmap);

// Create shared memory region.
base::SharedMemory shared_buf;
Expand Down
10 changes: 5 additions & 5 deletions base/shared_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SharedMemory {
// If name is the empty string, use a unique name.
// Returns true on success, false on failure.
bool Create(const std::wstring& name, bool read_only, bool open_existing,
size_t size);
uint32 size);

// Deletes resources associated with a shared memory segment based on name.
// Not all platforms require this call.
Expand All @@ -88,7 +88,7 @@ class SharedMemory {
// Maps the shared memory into the caller's address space.
// Returns true on success, false otherwise. The memory address
// is accessed via the memory() accessor.
bool Map(size_t bytes);
bool Map(uint32 bytes);

// Unmaps the shared memory from the caller's address space.
// Returns true if successful; returns false on error or if the
Expand All @@ -100,7 +100,7 @@ class SharedMemory {
// shared memory, and not to those that opened shared memory
// created externally.
// Returns 0 if not opened or unknown.
size_t max_size() const { return max_size_; }
uint32 max_size() const { return max_size_; }

// Gets a pointer to the opened memory space if it has been
// Mapped via Map(). Returns NULL if it is not mapped.
Expand Down Expand Up @@ -161,7 +161,7 @@ class SharedMemory {

private:
#if defined(OS_POSIX)
bool CreateOrOpen(const std::wstring &name, int posix_flags, size_t size);
bool CreateOrOpen(const std::wstring &name, int posix_flags, uint32 size);
bool FilePathForMemoryName(const std::wstring& memname, FilePath* path);
void LockOrUnlockCommon(int function);

Expand All @@ -179,7 +179,7 @@ class SharedMemory {
#endif
void* memory_;
bool read_only_;
size_t max_size_;
uint32 max_size_;
#if !defined(OS_POSIX)
SharedMemoryLock lock_;
#endif
Expand Down
8 changes: 4 additions & 4 deletions base/shared_memory_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) {
}

bool SharedMemory::Create(const std::wstring &name, bool read_only,
bool open_existing, size_t size) {
bool open_existing, uint32 size) {
read_only_ = read_only;

int posix_flags = 0;
Expand Down Expand Up @@ -144,7 +144,7 @@ bool SharedMemory::FilePathForMemoryName(const std::wstring& memname,
// In case we want to delete it later, it may be useful to save the value
// of mem_filename after FilePathForMemoryName().
bool SharedMemory::CreateOrOpen(const std::wstring &name,
int posix_flags, size_t size) {
int posix_flags, uint32 size) {
DCHECK(mapped_file_ == -1);

file_util::ScopedFILE file_closer;
Expand Down Expand Up @@ -206,7 +206,7 @@ bool SharedMemory::CreateOrOpen(const std::wstring &name,
struct stat stat;
if (fstat(fileno(fp), &stat) != 0)
return false;
const size_t current_size = stat.st_size;
const uint32 current_size = stat.st_size;
if (current_size != size) {
if (ftruncate(fileno(fp), size) != 0)
return false;
Expand All @@ -233,7 +233,7 @@ bool SharedMemory::CreateOrOpen(const std::wstring &name,
return true;
}

bool SharedMemory::Map(size_t bytes) {
bool SharedMemory::Map(uint32 bytes) {
if (mapped_file_ == -1)
return false;

Expand Down
10 changes: 5 additions & 5 deletions base/shared_memory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MultipleThreadMain : public PlatformThread::Delegate {
// PlatformThread::Delegate interface.
void ThreadMain() {
ScopedNSAutoreleasePool pool; // noop if not OSX
const int kDataSize = 1024;
const uint32 kDataSize = 1024;
SharedMemory memory;
bool rv = memory.Create(s_test_name_, false, true, kDataSize);
EXPECT_TRUE(rv);
Expand Down Expand Up @@ -77,7 +77,7 @@ class MultipleLockThread : public PlatformThread::Delegate {

// PlatformThread::Delegate interface.
void ThreadMain() {
const int kDataSize = sizeof(int);
const uint32 kDataSize = sizeof(int);
SharedMemoryHandle handle = NULL;
{
SharedMemory memory1;
Expand Down Expand Up @@ -115,7 +115,7 @@ class MultipleLockThread : public PlatformThread::Delegate {
} // namespace

TEST(SharedMemoryTest, OpenClose) {
const int kDataSize = 1024;
const uint32 kDataSize = 1024;
std::wstring test_name = L"SharedMemoryOpenCloseTest";

// Open two handles to a memory segment, confirm that they are mapped
Expand Down Expand Up @@ -234,7 +234,7 @@ TEST(SharedMemoryTest, AnonymousPrivate) {
int i, j;
int count = 4;
bool rv;
const int kDataSize = 8192;
const uint32 kDataSize = 8192;

scoped_array<SharedMemory> memories(new SharedMemory[count]);
scoped_array<int*> pointers(new int*[count]);
Expand Down Expand Up @@ -288,7 +288,7 @@ class SharedMemoryProcessTest : public MultiProcessTest {
static int TaskTestMain() {
int errors = 0;
ScopedNSAutoreleasePool pool; // noop if not OSX
const int kDataSize = 1024;
const uint32 kDataSize = 1024;
SharedMemory memory;
bool rv = memory.Create(s_test_name_, false, true, kDataSize);
EXPECT_TRUE(rv);
Expand Down
4 changes: 2 additions & 2 deletions base/shared_memory_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) {
}

bool SharedMemory::Create(const std::wstring &name, bool read_only,
bool open_existing, size_t size) {
bool open_existing, uint32 size) {
DCHECK(mapped_file_ == NULL);

name_ = name;
Expand Down Expand Up @@ -102,7 +102,7 @@ bool SharedMemory::Open(const std::wstring &name, bool read_only) {
return false;
}

bool SharedMemory::Map(size_t bytes) {
bool SharedMemory::Map(uint32 bytes) {
if (mapped_file_ == NULL)
return false;

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/renderer_host/audio_renderer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ uint32 AudioRendererHost::IPCAudioSource::OnMoreData(AudioOutputStream* stream,
SubmitPacketRequest(&auto_lock);
} else {
// Low latency mode.
size = std::min(static_cast<uint32>(shared_memory_.max_size()), max_size);
size = std::min(shared_memory_.max_size(), max_size);
memcpy(dest, shared_memory_.memory(), size);
memset(shared_memory_.memory(), 0, shared_memory_.max_size());
shared_socket_->Send(&pending_bytes, sizeof(pending_bytes));
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/renderer_host/resource_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ void ResourceMessageFilter::OnDuplicateSection(

#if defined(OS_MACOSX)
void ResourceMessageFilter::OnAllocateSharedMemoryBuffer(
size_t buffer_size,
uint32 buffer_size,
base::SharedMemoryHandle* handle) {
base::SharedMemory shared_buf;
shared_buf.Create(L"", false, false, buffer_size);
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/renderer_host/resource_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// Used to ask the browser to allocate a block of shared memory for the
// renderer to send back data in, since shared memory can't be created
// in the renderer on OS X due to the sandbox.
void OnAllocateSharedMemoryBuffer(size_t buffer_size,
base::SharedMemoryHandle* handle);
void OnAllocateSharedMemoryBuffer(uint32 buffer_size,
base::SharedMemoryHandle* handle);
#endif

void OnResourceTypeStats(const WebKit::WebCache::ResourceTypeStats& stats);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/visitedlink_master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ bool VisitedLinkMaster::GetDatabaseFileName(FilePath* filename) {
// in so that it can be written to the shared memory
bool VisitedLinkMaster::CreateURLTable(int32 num_entries, bool init_to_empty) {
// The table is the size of the table followed by the entries.
int32 alloc_size = num_entries * sizeof(Fingerprint) + sizeof(SharedHeader);
uint32 alloc_size = num_entries * sizeof(Fingerprint) + sizeof(SharedHeader);

// Create the shared memory object.
shared_memory_ = new base::SharedMemory();
Expand Down
2 changes: 1 addition & 1 deletion chrome/common/command_buffer_messages_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ IPC_BEGIN_MESSAGES(CommandBuffer)
IPC_SYNC_MESSAGE_ROUTED1_2(CommandBufferMsg_GetTransferBuffer,
int32 /* id */,
base::SharedMemoryHandle /* transfer_buffer */,
size_t /* size */)
uint32 /* size */)

#if defined(OS_MACOSX)
// On Mac OS X the GPU plugin must be offscreen, because there is no
Expand Down
2 changes: 1 addition & 1 deletion chrome/common/plugin_messages_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ IPC_BEGIN_MESSAGES(Plugin)

IPC_SYNC_MESSAGE_ROUTED0_2(PluginMsg_Print,
base::SharedMemoryHandle /* shared_memory*/,
size_t /* size */)
uint32 /* size */)

IPC_SYNC_MESSAGE_ROUTED0_1(PluginMsg_GetPluginScriptableObject,
int /* route_id */)
Expand Down
2 changes: 1 addition & 1 deletion chrome/common/render_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ struct ViewHostMsg_DidPrintPage_Params {
base::SharedMemoryHandle metafile_data_handle;

// Size of the metafile data.
unsigned data_size;
uint32 data_size;

// Cookie for the document to ensure correctness.
int document_cookie;
Expand Down
4 changes: 2 additions & 2 deletions chrome/common/render_messages_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1636,12 +1636,12 @@ IPC_BEGIN_MESSAGES(ViewHost)
// Asks the browser to create a block of shared memory for the renderer to pass
// NativeMetafile data to the browser.
IPC_SYNC_MESSAGE_ROUTED1_1(ViewHostMsg_AllocatePDFTransport,
size_t /* buffer size */,
uint32 /* buffer size */,
base::SharedMemoryHandle /* browser handle */)
// Asks the browser to create a block of shared memory for the renderer to
// fill in and pass back to the browser.
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_AllocateSharedMemoryBuffer,
size_t /* buffer size */,
uint32 /* buffer size */,
base::SharedMemoryHandle /* browser handle */)
#endif

Expand Down
2 changes: 1 addition & 1 deletion chrome/common/resource_dispatcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static const char test_page_mime_type[] = "text/html";
static const char test_page_charset[] = "";
static const char test_page_contents[] =
"<html><head><title>Google</title></head><body><h1>Google</h1></body></html>";
static const int test_page_contents_len = arraysize(test_page_contents) - 1;
static const uint32 test_page_contents_len = arraysize(test_page_contents) - 1;

// Listens for request response data and stores it so that it can be compared
// to the reference data.
Expand Down
2 changes: 1 addition & 1 deletion chrome/plugin/command_buffer_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void CommandBufferStub::OnDestroyTransferBuffer(int32 id) {
void CommandBufferStub::OnGetTransferBuffer(
int32 id,
base::SharedMemoryHandle* transfer_buffer,
size_t* size) {
uint32* size) {
*transfer_buffer = base::SharedMemoryHandle();
*size = 0;

Expand Down
2 changes: 1 addition & 1 deletion chrome/plugin/command_buffer_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CommandBufferStub : public IPC::Channel::Listener,
void OnDestroyTransferBuffer(int32 id);
void OnGetTransferBuffer(int32 id,
base::SharedMemoryHandle* transfer_buffer,
size_t* size);
uint32* size);
#if defined(OS_MACOSX)
void OnSetWindowSize(int32 width, int32 height);
void SwapBuffersCallback();
Expand Down
4 changes: 2 additions & 2 deletions chrome/plugin/webplugin_delegate_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void WebPluginDelegateStub::OnDidPaint() {
}

void WebPluginDelegateStub::OnPrint(base::SharedMemoryHandle* shared_memory,
size_t* size) {
uint32* size) {
#if defined(OS_WIN)
printing::NativeMetafile metafile;
if (!metafile.CreateDc(NULL, NULL)) {
Expand Down Expand Up @@ -407,7 +407,7 @@ void WebPluginDelegateStub::OnCreateCommandBuffer(int* route_id) {
}

void WebPluginDelegateStub::CreateSharedBuffer(
size_t size,
uint32 size,
base::SharedMemory* shared_buf,
base::SharedMemoryHandle* remote_handle) {
if (!shared_buf->Create(std::wstring(), false, false, size)) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/plugin/webplugin_delegate_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WebPluginDelegateStub : public IPC::Channel::Listener,
bool* handled, WebCursor* cursor);
void OnPaint(const gfx::Rect& damaged_rect);
void OnDidPaint();
void OnPrint(base::SharedMemoryHandle* shared_memory, size_t* size);
void OnPrint(base::SharedMemoryHandle* shared_memory, uint32* size);
void OnUpdateGeometry(const PluginMsg_UpdateGeometry_Param& param);
void OnGetPluginScriptableObject(int* route_id);
void OnSendJavaScriptStream(const GURL& url,
Expand Down Expand Up @@ -98,7 +98,7 @@ class WebPluginDelegateStub : public IPC::Channel::Listener,
int notify_id);
void OnHTTPRangeRequestReply(unsigned long resource_id, int range_request_id);
void OnCreateCommandBuffer(int* route_id);
void CreateSharedBuffer(size_t size,
void CreateSharedBuffer(uint32 size,
base::SharedMemory* shared_buf,
base::SharedMemoryHandle* remote_handle);

Expand Down
2 changes: 1 addition & 1 deletion chrome/renderer/command_buffer_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Buffer CommandBufferProxy::GetTransferBuffer(int32 id) {
// Assuming we are in the renderer process, the service is responsible for
// duplicating the handle. This might not be true for NaCl.
base::SharedMemoryHandle handle;
size_t size;
uint32 size;
if (!Send(new CommandBufferMsg_GetTransferBuffer(route_id_,
id,
&handle,
Expand Down
17 changes: 10 additions & 7 deletions chrome/renderer/mock_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,43 +145,46 @@ int MockPrinter::GetPrintedPages() const {
return page_number_;
}

const MockPrinterPage* MockPrinter::GetPrintedPage(size_t pageno) const {
const MockPrinterPage* MockPrinter::GetPrintedPage(unsigned int pageno) const {
if (pages_.size() > pageno)
return pages_[pageno];
else
return NULL;
}

int MockPrinter::GetWidth(size_t page) const {
int MockPrinter::GetWidth(unsigned int page) const {
if (printer_status_ != PRINTER_READY || page >= pages_.size())
return -1;
return pages_[page]->width();
}

int MockPrinter::GetHeight(size_t page) const {
int MockPrinter::GetHeight(unsigned int page) const {
if (printer_status_ != PRINTER_READY || page >= pages_.size())
return -1;
return pages_[page]->height();
}

bool MockPrinter::GetBitmapChecksum(size_t page, std::string* checksum) const {
bool MockPrinter::GetBitmapChecksum(
unsigned int page, std::string* checksum) const {
if (printer_status_ != PRINTER_READY || page >= pages_.size())
return false;
*checksum = pages_[page]->image().checksum();
return true;
}

bool MockPrinter::SaveSource(size_t page, const FilePath& filepath) const {
bool MockPrinter::SaveSource(
unsigned int page, const FilePath& filepath) const {
if (printer_status_ != PRINTER_READY || page >= pages_.size())
return false;
const uint8* source_data = pages_[page]->source_data();
size_t source_size = pages_[page]->source_size();
uint32 source_size = pages_[page]->source_size();
file_util::WriteFile(filepath, reinterpret_cast<const char*>(source_data),
source_size);
return true;
}

bool MockPrinter::SaveBitmap(size_t page, const FilePath& filepath) const {
bool MockPrinter::SaveBitmap(
unsigned int page, const FilePath& filepath) const {
if (printer_status_ != PRINTER_READY || page >= pages_.size())
return false;

Expand Down
Loading

0 comments on commit b5ab398

Please sign in to comment.