summaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 00:50:13 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 00:50:13 +0000
commit05094a3fd1209ad3c5fa5c92c78694da589b9448 (patch)
tree59eab02505b51bcff2c1a48ea097de85befbfaef /ipc
parentd643172a8573e7e75f325bec2125de8071bfd0fc (diff)
downloadchromium_src-05094a3fd1209ad3c5fa5c92c78694da589b9448.zip
chromium_src-05094a3fd1209ad3c5fa5c92c78694da589b9448.tar.gz
chromium_src-05094a3fd1209ad3c5fa5c92c78694da589b9448.tar.bz2
Convert some constants declared as anonymous enums into static consts so they have types. This defines the constants where they're declared to preserve the existing readability as well as allow us to do things like dimension arrays based on the values of the constants.
The drawback to defining constants at their declaration point is that supplying them to a templated function, like what DCHECK_EQ() expands into, triggers an "undefined symbol" error on Mac/Linux (and adding explicit storage for them in the .cc file can cause duplicate symbol errors on Windows). Here I've worked around that by converting DCHECK_EQ(a, b) to DCHECK(b == a). The original motiviation for this change was to find a way to eliminate some cases of passing anonymous-typed values as template arguments (which happens when you use a value from the enum in e.g. EXPECT_EQ()), which is technically illegal in C++03, though we don't warn about it. Simply naming the enum would have done this, but in general naming enums used to declare constants like this is bizarre ("enum Constants { ... }"?). BUG=92247 TEST=Compiles Review URL: http://codereview.chromium.org/7817005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r--ipc/file_descriptor_set_posix.cc10
-rw-r--r--ipc/file_descriptor_set_posix.h4
-rw-r--r--ipc/file_descriptor_set_posix_unittest.cc6
-rw-r--r--ipc/ipc_channel.h12
-rw-r--r--ipc/ipc_channel_posix.cc11
-rw-r--r--ipc/ipc_channel_posix.h13
6 files changed, 24 insertions, 32 deletions
diff --git a/ipc/file_descriptor_set_posix.cc b/ipc/file_descriptor_set_posix.cc
index 7f17322..df2a8e4 100644
--- a/ipc/file_descriptor_set_posix.cc
+++ b/ipc/file_descriptor_set_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,7 +36,7 @@ FileDescriptorSet::~FileDescriptorSet() {
}
bool FileDescriptorSet::Add(int fd) {
- if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE)
+ if (descriptors_.size() == kMaxDescriptorsPerMessage)
return false;
struct base::FileDescriptor sd;
@@ -47,14 +47,14 @@ bool FileDescriptorSet::Add(int fd) {
}
bool FileDescriptorSet::AddAndAutoClose(int fd) {
- if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE)
+ if (descriptors_.size() == kMaxDescriptorsPerMessage)
return false;
struct base::FileDescriptor sd;
sd.fd = fd;
sd.auto_close = true;
descriptors_.push_back(sd);
- DCHECK(descriptors_.size() <= MAX_DESCRIPTORS_PER_MESSAGE);
+ DCHECK(descriptors_.size() <= kMaxDescriptorsPerMessage);
return true;
}
@@ -122,7 +122,7 @@ void FileDescriptorSet::CommitAll() {
}
void FileDescriptorSet::SetDescriptors(const int* buffer, unsigned count) {
- DCHECK_LE(count, MAX_DESCRIPTORS_PER_MESSAGE);
+ DCHECK(count <= kMaxDescriptorsPerMessage);
DCHECK_EQ(descriptors_.size(), 0u);
DCHECK_EQ(consumed_descriptor_highwater_, 0u);
diff --git a/ipc/file_descriptor_set_posix.h b/ipc/file_descriptor_set_posix.h
index 1554c38..f7d4ad0 100644
--- a/ipc/file_descriptor_set_posix.h
+++ b/ipc/file_descriptor_set_posix.h
@@ -31,9 +31,7 @@ class IPC_EXPORT FileDescriptorSet
//
// In debugging mode, it's a fatal error to try and add more than this number
// of descriptors to a FileDescriptorSet.
- enum {
- MAX_DESCRIPTORS_PER_MESSAGE = 5,
- };
+ static const size_t kMaxDescriptorsPerMessage = 5;
// ---------------------------------------------------------------------------
// Interfaces for building during message serialisation...
diff --git a/ipc/file_descriptor_set_posix_unittest.cc b/ipc/file_descriptor_set_posix_unittest.cc
index 5fc8c50..fdb00f51 100644
--- a/ipc/file_descriptor_set_posix_unittest.cc
+++ b/ipc/file_descriptor_set_posix_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -67,10 +67,8 @@ TEST(FileDescriptorSet, BasicAddAndClose) {
TEST(FileDescriptorSet, MaxSize) {
scoped_refptr<FileDescriptorSet> set(new FileDescriptorSet);
- for (unsigned i = 0;
- i < FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE; ++i) {
+ for (size_t i = 0; i < FileDescriptorSet::kMaxDescriptorsPerMessage; ++i)
ASSERT_TRUE(set->Add(kFDBase + 1 + i));
- }
ASSERT_TRUE(!set->Add(kFDBase));
diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h
index 3724e56..8bb35c4 100644
--- a/ipc/ipc_channel.h
+++ b/ipc/ipc_channel.h
@@ -94,14 +94,12 @@ class IPC_EXPORT Channel : public Message::Sender {
#endif
};
- enum {
- // The maximum message size in bytes. Attempting to receive a
- // message of this size or bigger results in a channel error.
- kMaximumMessageSize = 128 * 1024 * 1024,
+ // The maximum message size in bytes. Attempting to receive a message of this
+ // size or bigger results in a channel error.
+ static const size_t kMaximumMessageSize = 128 * 1024 * 1024;
- // Ammount of data to read at once from the pipe.
- kReadBufferSize = 4 * 1024
- };
+ // Ammount of data to read at once from the pipe.
+ static const size_t kReadBufferSize = 4 * 1024;
// Initialize a Channel.
//
diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc
index df927d0..a88506c 100644
--- a/ipc/ipc_channel_posix.cc
+++ b/ipc/ipc_channel_posix.cc
@@ -585,8 +585,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
p = input_buf_;
end = p + bytes_read;
} else {
- if (input_overflow_buf_.size() >
- static_cast<size_t>(kMaximumMessageSize - bytes_read)) {
+ if (input_overflow_buf_.size() > (kMaximumMessageSize - bytes_read)) {
input_overflow_buf_.clear();
LOG(ERROR) << "IPC message is too big";
return false;
@@ -676,7 +675,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() {
}
if (header_fds >
- FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE) {
+ FileDescriptorSet::kMaxDescriptorsPerMessage) {
// There are too many descriptors in this message
error = "Message requires an excessive number of descriptors";
}
@@ -782,7 +781,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
msgh.msg_iov = &iov;
msgh.msg_iovlen = 1;
char buf[CMSG_SPACE(
- sizeof(int[FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE]))];
+ sizeof(int) * FileDescriptorSet::kMaxDescriptorsPerMessage)];
ssize_t bytes_written = 1;
int fd_written = -1;
@@ -793,7 +792,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
struct cmsghdr *cmsg;
const unsigned num_fds = msg->file_descriptor_set()->size();
- DCHECK_LE(num_fds, FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE);
+ DCHECK(num_fds <= FileDescriptorSet::kMaxDescriptorsPerMessage);
if (msg->file_descriptor_set()->ContainsDirectoryDescriptor()) {
LOG(FATAL) << "Panic: attempting to transport directory descriptor over"
" IPC. Aborting to maintain sandbox isolation.";
@@ -815,7 +814,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
msgh.msg_controllen = cmsg->cmsg_len;
// DCHECK_LE above already checks that
- // num_fds < MAX_DESCRIPTORS_PER_MESSAGE so no danger of overflow.
+ // num_fds < kMaxDescriptorsPerMessage so no danger of overflow.
msg->header()->num_fds = static_cast<uint16>(num_fds);
#if defined(IPC_USES_READWRITE)
diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h
index 399d282..06c545c 100644
--- a/ipc/ipc_channel_posix.h
+++ b/ipc/ipc_channel_posix.h
@@ -128,19 +128,18 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
// We read from the pipe into this buffer
char input_buf_[Channel::kReadBufferSize];
- enum {
- // We assume a worst case: kReadBufferSize bytes of messages, where each
- // message has no payload and a full complement of descriptors.
- MAX_READ_FDS = (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) *
- FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE,
- };
+ // We assume a worst case: kReadBufferSize bytes of messages, where each
+ // message has no payload and a full complement of descriptors.
+ static const size_t kMaxReadFDs =
+ (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) *
+ FileDescriptorSet::kMaxDescriptorsPerMessage;
// This is a control message buffer large enough to hold kMaxReadFDs
#if defined(OS_MACOSX)
// TODO(agl): OSX appears to have non-constant CMSG macros!
char input_cmsg_buf_[1024];
#else
- char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)];
+ char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * kMaxReadFDs)];
#endif
// Large messages that span multiple pipe buffers, get built-up using