diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 18:59:20 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 18:59:20 +0000 |
commit | 5fe733dee6afd3ab897cafbfcdcc1450264409b0 (patch) | |
tree | 64d39f452e1aee1076356da52d836c902e8b92eb | |
parent | 072f6f57560ab3616915b0aa9f61331deb2cf260 (diff) | |
download | chromium_src-5fe733dee6afd3ab897cafbfcdcc1450264409b0.zip chromium_src-5fe733dee6afd3ab897cafbfcdcc1450264409b0.tar.gz chromium_src-5fe733dee6afd3ab897cafbfcdcc1450264409b0.tar.bz2 |
POSIX: Transfer network data using shared memory
This patch adds the long planned support for sharing memory on POSIX
by transporting file descriptors. It largely builds on the shared
memory cleanup work by jrg.
We move FileDescriptor out of chrome/common/file_descriptor_posix.h
and into base/file_descriptor_posix.h. Since all that's left in the
chrome/common verion is the DescriptorSet, those files are renamed to
descriptor_set.[h|cc].
The SharedMemoryHandle on POSIX then becomes a typedef to a
FileDescriptor and thus can be serialised over IPC.
After that, it's mostly a case of cleaning up those snippets of code
which considered SharedMemoryHandles to be scaler values.
Review URL: http://codereview.chromium.org/21208
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9580 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/file_descriptor_posix.h | 32 | ||||
-rw-r--r-- | base/shared_memory.h | 15 | ||||
-rw-r--r-- | base/shared_memory_posix.cc | 26 | ||||
-rw-r--r-- | base/shared_memory_win.cc | 9 | ||||
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.cc | 26 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 8 | ||||
-rw-r--r-- | chrome/common/common.scons | 2 | ||||
-rw-r--r-- | chrome/common/descriptor_set_posix.cc (renamed from chrome/common/file_descriptor_posix.cc) | 28 | ||||
-rw-r--r-- | chrome/common/descriptor_set_posix.h (renamed from chrome/common/file_descriptor_posix.h) | 37 | ||||
-rw-r--r-- | chrome/common/ipc_channel_posix.cc | 2 | ||||
-rw-r--r-- | chrome/common/ipc_channel_posix.h | 2 | ||||
-rw-r--r-- | chrome/common/ipc_message.h | 2 | ||||
-rw-r--r-- | chrome/common/ipc_message_utils.h | 12 | ||||
-rw-r--r-- | chrome/common/ipc_send_fds_test.cc | 9 | ||||
-rw-r--r-- | chrome/common/ipc_tests.cc | 2 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.cc | 3 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/render_thread_unittest.cc | 5 |
18 files changed, 144 insertions, 80 deletions
diff --git a/base/file_descriptor_posix.h b/base/file_descriptor_posix.h new file mode 100644 index 0000000..8ebc5be --- /dev/null +++ b/base/file_descriptor_posix.h @@ -0,0 +1,32 @@ +// Copyright (c) 2006-2009 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. + +#ifndef BASE_FILE_DESCRIPTOR_POSIX_H_ +#define BASE_FILE_DESCRIPTOR_POSIX_H_ + +namespace base { + +// ----------------------------------------------------------------------------- +// We introduct a special structure for file descriptors in order that we are +// able to use template specialisation to special-case their handling. +// ----------------------------------------------------------------------------- +struct FileDescriptor { + FileDescriptor() + : fd(-1), + auto_close(false) { } + + FileDescriptor(int ifd, bool iauto_close) + : fd(ifd), + auto_close(iauto_close) { } + + int fd; + // If true, this file descriptor should be closed after it has been used. For + // example an IPC system might interpret this flag as indicating that the + // file descriptor it has been given should be closed after use. + bool auto_close; +}; + +} // namespace base + +#endif // BASE_FILE_DESCRIPTOR_POSIX_H_ diff --git a/base/shared_memory.h b/base/shared_memory.h index 3bfa003..b44367a 100644 --- a/base/shared_memory.h +++ b/base/shared_memory.h @@ -9,6 +9,7 @@ #if defined(OS_POSIX) #include <semaphore.h> +#include "base/file_descriptor_posix.h" #endif #include <string> @@ -23,7 +24,7 @@ namespace base { typedef HANDLE SharedMemoryHandle; typedef HANDLE SharedMemoryLock; #elif defined(OS_POSIX) -typedef int SharedMemoryHandle; +typedef FileDescriptor SharedMemoryHandle; // On POSIX, the lock is implemented as a lockf() on the mapped file, // so no additional member (or definition of SharedMemoryLock) is // needed. @@ -49,6 +50,10 @@ class SharedMemory { // Destructor. Will close any open files. ~SharedMemory(); + // Return true iff the given handle is valid (i.e. not the distingished + // invalid value; NULL for a HANDLE and -1 for a file descriptor) + static bool IsHandleValid(const SharedMemoryHandle& handle); + // Creates or opens a shared memory segment based on a name. // If read_only is true, opens the memory as read-only. // If open_existing is true, and the shared memory already exists, @@ -92,7 +97,7 @@ class SharedMemory { // Get access to the underlying OS handle for this segment. // Use of this handle for anything other than an opaque // identifier is not portable. - SharedMemoryHandle handle() const { return mapped_file_; } + SharedMemoryHandle handle() const; // Closes the open shared memory segment. // It is safe to call Close repeatedly. @@ -147,7 +152,11 @@ class SharedMemory { bool close_self); std::wstring name_; - SharedMemoryHandle mapped_file_; +#if defined(OS_WIN) + HANDLE mapped_file_; +#elif defined(OS_POSIX) + int mapped_file_; +#endif void* memory_; bool read_only_; size_t max_size_; diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index bd33cda..e6f81c5 100644 --- a/base/shared_memory_posix.cc +++ b/base/shared_memory_posix.cc @@ -29,7 +29,7 @@ SharedMemory::SharedMemory() } SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only) - : mapped_file_(handle), + : mapped_file_(handle.fd), memory_(NULL), read_only_(read_only), max_size_(0) { @@ -37,7 +37,7 @@ SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only) SharedMemory::SharedMemory(SharedMemoryHandle handle, bool read_only, ProcessHandle process) - : mapped_file_(handle), + : mapped_file_(handle.fd), memory_(NULL), read_only_(read_only), max_size_(0) { @@ -50,6 +50,11 @@ SharedMemory::~SharedMemory() { Close(); } +// static +bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { + return handle.fd >= 0; +} + bool SharedMemory::Create(const std::wstring &name, bool read_only, bool open_existing, size_t size) { read_only_ = read_only; @@ -232,10 +237,15 @@ bool SharedMemory::Unmap() { bool SharedMemory::ShareToProcessCommon(ProcessHandle process, SharedMemoryHandle *new_handle, bool close_self) { - *new_handle = 0; - // TODO(awalker): figure out if we need this, and do the appropriate - // VM magic if so. - return false; + const int new_fd = dup(mapped_file_); + DCHECK(new_fd >= -1); + new_handle->fd = new_fd; + new_handle->auto_close = true; + + if (close_self) + Close(); + + return true; } @@ -277,4 +287,8 @@ void SharedMemory::Unlock() { LockOrUnlockCommon(F_ULOCK); } +SharedMemoryHandle SharedMemory::handle() const { + return FileDescriptor(mapped_file_, false); +} + } // namespace base diff --git a/base/shared_memory_win.cc b/base/shared_memory_win.cc index 4ae4752..3822fc9 100644 --- a/base/shared_memory_win.cc +++ b/base/shared_memory_win.cc @@ -45,6 +45,11 @@ SharedMemory::~SharedMemory() { CloseHandle(lock_); } +// static +bool SharedMemory::IsHandleValid(const SharedMemoryHandle& handle) { + return handle != NULL; +} + bool SharedMemory::Create(const std::wstring &name, bool read_only, bool open_existing, size_t size) { DCHECK(mapped_file_ == NULL); @@ -168,4 +173,8 @@ void SharedMemory::Unlock() { ReleaseMutex(lock_); } +SharedMemoryHandle SharedMemory::handle() const { + return mapped_file_; +} + } // namespace base diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 24d5f4d..eabce0e 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -524,18 +524,14 @@ void BrowserRenderProcessHost::InitVisitedLinks() { return; } -#if defined(OS_WIN) - base::SharedMemoryHandle handle_for_process = NULL; - visitedlink_master->ShareToProcess(GetRendererProcessHandle(), - &handle_for_process); - DCHECK(handle_for_process); - if (handle_for_process) { + base::SharedMemoryHandle handle_for_process; + bool r = visitedlink_master->ShareToProcess(GetRendererProcessHandle(), + &handle_for_process); + DCHECK(r); + + if (base::SharedMemory::IsHandleValid(handle_for_process)) { channel_->Send(new ViewMsg_VisitedLink_NewTable(handle_for_process)); } -#else - // TODO(port): ShareToProcess is Windows-specific. - NOTIMPLEMENTED(); -#endif } void BrowserRenderProcessHost::InitUserScripts() { @@ -553,11 +549,11 @@ void BrowserRenderProcessHost::InitUserScripts() { void BrowserRenderProcessHost::SendUserScriptsUpdate( base::SharedMemory *shared_memory) { - base::SharedMemoryHandle handle_for_process = NULL; - shared_memory->ShareToProcess(GetRendererProcessHandle(), - &handle_for_process); - DCHECK(handle_for_process); - if (handle_for_process) { + base::SharedMemoryHandle handle_for_process; + bool r = shared_memory->ShareToProcess(GetRendererProcessHandle(), + &handle_for_process); + DCHECK(r); + if (base::SharedMemory::IsHandleValid(handle_for_process)) { channel_->Send(new ViewMsg_UserScripts_NewScripts(handle_for_process)); } } diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index f74e06c..c6461bf 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -232,7 +232,6 @@ 4DCE9E2D0EF0B8C000682526 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4DCE9E2B0EF0B8C000682526 /* MainMenu.xib */; }; 4DDC644B0EAE390800FB5EBE /* libxml.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D7BFB230E9D4BBF009A6919 /* libxml.a */; }; 4DDC64580EAE394200FB5EBE /* libzlib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DDC64550EAE392400FB5EBE /* libzlib.a */; }; - 50886B71DAE5D39B7B066A3E /* file_descriptor_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4BC2B5751BE559198D20DD1E /* file_descriptor_posix.cc */; }; 534E66C40F311BEC0006B2B2 /* temp_scaffolding_stubs.cc in Sources */ = {isa = PBXBuildFile; fileRef = 534E66C30F311BEC0006B2B2 /* temp_scaffolding_stubs.cc */; }; 544FBC49CB83E458B6B7069D /* test_web_contents.cc in Sources */ = {isa = PBXBuildFile; fileRef = 56E1D7DF17D327BFCB0B895D /* test_web_contents.cc */; }; 671555F7DF06E224B646E5D2 /* backing_store_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = B94B5B0CBF4D7FAC48BB1AE2 /* backing_store_posix.cc */; }; @@ -272,6 +271,7 @@ 844EA08D0F3E0C5000B0EF26 /* debugger_node.cc in Sources */ = {isa = PBXBuildFile; fileRef = 844EA07A0F3E0C1000B0EF26 /* debugger_node.cc */; }; 844EA08E0F3E0C5900B0EF26 /* debugger_wrapper.cc in Sources */ = {isa = PBXBuildFile; fileRef = 844EA0820F3E0C1000B0EF26 /* debugger_wrapper.cc */; }; 8570EB3F140C07ABF1957F12 /* url_pattern_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = A9C335E39D39A7DE087850FC /* url_pattern_unittest.cc */; }; + 884BD6B5D58856CAC05DE5C0 /* descriptor_set_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = FE95CE48F3AD7531827F63CF /* descriptor_set_posix.cc */; }; 8F51B73AAAF1772ECF9BD180 /* url_fetcher.cc in Sources */ = {isa = PBXBuildFile; fileRef = 778D7927798B7E3FAA498D3D /* url_fetcher.cc */; }; 94542322A5E5A8F4FDDAB7F0 /* render_view_host_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = A76E42AD0F28EDB5009A7E88 /* render_view_host_manager.cc */; }; A0EB956531B9DB1E40DAE980 /* user_script_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 37521A11B07C479E93A39D52 /* user_script_unittest.cc */; }; @@ -1774,7 +1774,6 @@ 37521A11B07C479E93A39D52 /* user_script_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = user_script_unittest.cc; path = common/extensions/user_script_unittest.cc; sourceTree = SOURCE_ROOT; }; 3CCF8AA8A56FF8FE59F0C299 /* template_url.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = template_url.cc; sourceTree = "<group>"; }; 433B6EFB7A1D931A13C9556F /* url_fetcher_protect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = url_fetcher_protect.h; sourceTree = "<group>"; }; - 4BC2B5751BE559198D20DD1E /* file_descriptor_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_descriptor_posix.cc; sourceTree = "<group>"; }; 4D1F59EA0F2A6B590040C1E3 /* image_diff */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = image_diff; sourceTree = BUILT_PRODUCTS_DIR; }; 4D1F59FD0F2A6BBB0040C1E3 /* image_diff.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = image_diff.cc; sourceTree = "<group>"; }; 4D1F5AB10F2A6EE90040C1E3 /* libpng.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libpng.xcodeproj; path = third_party/libpng/libpng.xcodeproj; sourceTree = "<group>"; }; @@ -2681,6 +2680,7 @@ E4F324790EE5D17E002533CE /* referrer.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = referrer.cc; sourceTree = "<group>"; }; EA72C084DB3FC0FC595E525E /* template_url_model.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = template_url_model.cc; sourceTree = "<group>"; }; EA72CF50C0AB4492A644C703 /* url_fetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = url_fetcher.h; sourceTree = "<group>"; }; + FE95CE48F3AD7531827F63CF /* descriptor_set_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = descriptor_set_posix.cc; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -3559,11 +3559,11 @@ 4D7BFBA00E9D4C9F009A6919 /* common_resources.h */, 4D7BFBA10E9D4C9F009A6919 /* debug_flags.cc */, 4D7BFBA20E9D4C9F009A6919 /* debug_flags.h */, + FE95CE48F3AD7531827F63CF /* descriptor_set_posix.cc */, 4D7BFBA30E9D4C9F009A6919 /* drag_drop_types.cc */, 4D7BFBA40E9D4C9F009A6919 /* drag_drop_types.h */, 4D7BFBA50E9D4C9F009A6919 /* env_vars.cc */, 4D7BFBA60E9D4C9F009A6919 /* env_vars.h */, - 4BC2B5751BE559198D20DD1E /* file_descriptor_posix.cc */, 4D7BFBA70E9D4C9F009A6919 /* filter_policy.h */, 4D7BFBA80E9D4C9F009A6919 /* gears_api.h */, 4D7BFBAA0E9D4C9F009A6919 /* ipc_channel.h */, @@ -5438,8 +5438,8 @@ B562E2C70F0582F800FB1A4F /* common_glue.cc in Sources */, 4D7BFCCE0E9D4D7A009A6919 /* cookie_monster_sqlite.cc in Sources */, 4D7BFC2E0E9D4CF5009A6919 /* debug_flags.cc in Sources */, + 884BD6B5D58856CAC05DE5C0 /* descriptor_set_posix.cc in Sources */, 4D7BFC330E9D4CF9009A6919 /* env_vars.cc in Sources */, - 50886B71DAE5D39B7B066A3E /* file_descriptor_posix.cc in Sources */, B5FDC0580EE488E500BEC6E6 /* ipc_channel_posix.cc in Sources */, B5DBEA900EFC60E200C95176 /* ipc_channel_proxy.cc in Sources */, 4D7BFC380E9D4CFF009A6919 /* ipc_message.cc in Sources */, diff --git a/chrome/common/common.scons b/chrome/common/common.scons index 7eca809..829da06 100644 --- a/chrome/common/common.scons +++ b/chrome/common/common.scons @@ -219,7 +219,7 @@ if not env.Bit('windows'): # TODO(port): This is temporary so we can link. input_files.Append( 'temp_scaffolding_stubs.cc', - 'file_descriptor_posix.cc', + 'descriptor_set_posix.cc', ) # TODO(port): Port these. diff --git a/chrome/common/file_descriptor_posix.cc b/chrome/common/descriptor_set_posix.cc index 7db9514..82f2899 100644 --- a/chrome/common/file_descriptor_posix.cc +++ b/chrome/common/descriptor_set_posix.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/common/file_descriptor_posix.h" +#include "chrome/common/descriptor_set_posix.h" #include "base/logging.h" @@ -29,20 +29,27 @@ DescriptorSet::~DescriptorSet() { } } -void DescriptorSet::Add(int fd) { - struct FileDescriptor sd; +bool DescriptorSet::Add(int fd) { + if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE) + return false; + + struct base::FileDescriptor sd; sd.fd = fd; sd.auto_close = false; descriptors_.push_back(sd); - DCHECK(descriptors_.size() <= MAX_DESCRIPTORS_PER_MESSAGE); + return true; } -void DescriptorSet::AddAndAutoClose(int fd) { - struct FileDescriptor sd; +bool DescriptorSet::AddAndAutoClose(int fd) { + if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE) + return false; + + struct base::FileDescriptor sd; sd.fd = fd; sd.auto_close = true; descriptors_.push_back(sd); DCHECK(descriptors_.size() <= MAX_DESCRIPTORS_PER_MESSAGE); + return true; } int DescriptorSet::NextDescriptor() { @@ -53,19 +60,22 @@ int DescriptorSet::NextDescriptor() { } void DescriptorSet::GetDescriptors(int* buffer) const { - for (std::vector<FileDescriptor>::const_iterator + DCHECK_EQ(next_descriptor_, 0u); + + for (std::vector<base::FileDescriptor>::const_iterator i = descriptors_.begin(); i != descriptors_.end(); ++i) { *(buffer++) = i->fd; } } void DescriptorSet::CommitAll() { - for (std::vector<FileDescriptor>::iterator + for (std::vector<base::FileDescriptor>::iterator i = descriptors_.begin(); i != descriptors_.end(); ++i) { if (i->auto_close) close(i->fd); } descriptors_.clear(); + next_descriptor_ = 0; } void DescriptorSet::SetDescriptors(const int* buffer, unsigned count) { @@ -74,7 +84,7 @@ void DescriptorSet::SetDescriptors(const int* buffer, unsigned count) { descriptors_.reserve(count); for (unsigned i = 0; i < count; ++i) { - struct FileDescriptor sd; + struct base::FileDescriptor sd; sd.fd = buffer[i]; sd.auto_close = true; descriptors_.push_back(sd); diff --git a/chrome/common/file_descriptor_posix.h b/chrome/common/descriptor_set_posix.h index 43590b0..36a0433 100644 --- a/chrome/common/file_descriptor_posix.h +++ b/chrome/common/descriptor_set_posix.h @@ -2,30 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_COMMON_FILE_DESCRIPTOR_POSIX_H_ -#define CHROME_COMMON_FILE_DESCRIPTOR_POSIX_H_ +#ifndef CHROME_COMMON_DESCRIPTOR_SET_POSIX_H_ +#define CHROME_COMMON_DESCRIPTOR_SET_POSIX_H_ #include <vector> -// ----------------------------------------------------------------------------- -// A FileDescriptor is a structure for use in IPC messages. It allows one to -// send descriptors over an IPC channel. -// -// In the Windows world, processes can peek and poke the HANDLE table of other -// processes. On POSIX, in order to transmit descriptors we need to include -// them in a control-message (a side-channel on the UNIX domain socket). -// Serialising this type adds descriptors to a vector in the IPC Message, from -// which the IPC channel can package them up for the kernel. -// ----------------------------------------------------------------------------- -struct FileDescriptor { - FileDescriptor() - : fd(-1), - auto_close(false) { } - - int fd; - // If true, close this descriptor after it has been sent. - bool auto_close; -}; +#include "base/basictypes.h" +#include "base/file_descriptor_posix.h" // ----------------------------------------------------------------------------- // A DescriptorSet is an ordered set of POSIX file descriptors. These are @@ -52,11 +35,11 @@ class DescriptorSet { // --------------------------------------------------------------------------- // Interfaces for building during message serialisation... - // Add a descriptor to the end of the set - void Add(int fd); + // Add a descriptor to the end of the set. Returns false iff the set is full. + bool Add(int fd); // Add a descriptor to the end of the set and automatically close it after - // transmission. - void AddAndAutoClose(int fd); + // transmission. Returns false iff the set is full. + bool AddAndAutoClose(int fd); // --------------------------------------------------------------------------- @@ -115,10 +98,12 @@ class DescriptorSet { // these descriptors are sent as control data. After sending, any descriptors // with a true flag are closed. If this message has been received, then these // are the descriptors which were received and all close flags are true. - std::vector<FileDescriptor> descriptors_; + std::vector<base::FileDescriptor> descriptors_; // When deserialising the message, the descriptors will be extracted // one-by-one. This contains the index of the next unused descriptor. unsigned next_descriptor_; + + DISALLOW_COPY_AND_ASSIGN(DescriptorSet); }; #endif // CHROME_COMMON_FILE_DESCRIPTOR_POSIX_H_ diff --git a/chrome/common/ipc_channel_posix.cc b/chrome/common/ipc_channel_posix.cc index b688c77..d9f44dd 100644 --- a/chrome/common/ipc_channel_posix.cc +++ b/chrome/common/ipc_channel_posix.cc @@ -28,7 +28,7 @@ #include "base/singleton.h" #include "chrome/common/chrome_counters.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/file_descriptor_posix.h" +#include "chrome/common/descriptor_set_posix.h" #include "chrome/common/ipc_message_utils.h" namespace IPC { diff --git a/chrome/common/ipc_channel_posix.h b/chrome/common/ipc_channel_posix.h index 555d463..d6ed17d 100644 --- a/chrome/common/ipc_channel_posix.h +++ b/chrome/common/ipc_channel_posix.h @@ -14,7 +14,7 @@ #include <vector> #include "base/message_loop.h" -#include "chrome/common/file_descriptor_posix.h" +#include "chrome/common/descriptor_set_posix.h" namespace IPC { diff --git a/chrome/common/ipc_message.h b/chrome/common/ipc_message.h index 0af3b44..8aedbe3 100644 --- a/chrome/common/ipc_message.h +++ b/chrome/common/ipc_message.h @@ -17,7 +17,7 @@ #define IPC_MESSAGE_LOG_ENABLED #endif #elif defined(OS_POSIX) -#include "chrome/common/file_descriptor_posix.h" +#include "chrome/common/descriptor_set_posix.h" #endif namespace IPC { diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index bd38df0..e7dd7e3 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -13,7 +13,7 @@ #include "base/string_util.h" #include "base/tuple.h" #if defined(OS_POSIX) -#include "chrome/common/file_descriptor_posix.h" +#include "chrome/common/descriptor_set_posix.h" #endif #include "chrome/common/ipc_sync_message.h" #include "chrome/common/thumbnail_score.h" @@ -668,13 +668,15 @@ struct ParamTraits<gfx::Size> { #if defined(OS_POSIX) template<> -struct ParamTraits<FileDescriptor> { - typedef FileDescriptor param_type; +struct ParamTraits<base::FileDescriptor> { + typedef base::FileDescriptor param_type; static void Write(Message* m, const param_type& p) { if (p.auto_close) { - m->descriptor_set()->AddAndAutoClose(p.fd); + if (!m->descriptor_set()->AddAndAutoClose(p.fd)) + NOTREACHED(); } else { - m->descriptor_set()->Add(p.fd); + if (!m->descriptor_set()->Add(p.fd)) + NOTREACHED(); } } static bool Read(const Message* m, void** iter, param_type* r) { diff --git a/chrome/common/ipc_send_fds_test.cc b/chrome/common/ipc_send_fds_test.cc index ca22bd5..e7cb207 100644 --- a/chrome/common/ipc_send_fds_test.cc +++ b/chrome/common/ipc_send_fds_test.cc @@ -47,10 +47,11 @@ class MyChannelDescriptorListener : public IPC::Channel::Listener { virtual void OnMessageReceived(const IPC::Message& message) { void* iter = NULL; - FileDescriptor descriptor; + base::FileDescriptor descriptor; ASSERT_TRUE( - IPC::ParamTraits<FileDescriptor>::Read(&message, &iter, &descriptor)); + IPC::ParamTraits<base::FileDescriptor>::Read( + &message, &iter, &descriptor)); VerifyAndCloseDescriptor(descriptor.fd, expected_inode_num_); MessageLoop::current()->Quit(); @@ -67,7 +68,7 @@ void TestDescriptorServer(IPC::Channel &chan, base::ProcessHandle process_handle) { ASSERT_TRUE(process_handle); - FileDescriptor descriptor; + base::FileDescriptor descriptor; const int fd = open(kDevRandomPath, O_RDONLY); ASSERT_GE(fd, 0); descriptor.auto_close = true; @@ -76,7 +77,7 @@ void TestDescriptorServer(IPC::Channel &chan, IPC::Message* message = new IPC::Message(0, // routing_id 3, // message type IPC::Message::PRIORITY_NORMAL); - IPC::ParamTraits<FileDescriptor>::Write(message, descriptor); + IPC::ParamTraits<base::FileDescriptor>::Write(message, descriptor); chan.Send(message); // Run message loop. diff --git a/chrome/common/ipc_tests.cc b/chrome/common/ipc_tests.cc index 2544e43..4b24406 100644 --- a/chrome/common/ipc_tests.cc +++ b/chrome/common/ipc_tests.cc @@ -27,7 +27,7 @@ #include "base/thread.h" #include "chrome/common/chrome_switches.h" #if defined(OS_POSIX) -#include "chrome/common/file_descriptor_posix.h" +#include "chrome/common/descriptor_set_posix.h" #endif #include "chrome/common/ipc_channel.h" #include "chrome/common/ipc_channel_proxy.h" diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc index 7f64d32..e9db613 100644 --- a/chrome/common/resource_dispatcher.cc +++ b/chrome/common/resource_dispatcher.cc @@ -342,7 +342,8 @@ void ResourceDispatcher::OnReceivedData(int request_id, sender->Send( new ViewHostMsg_DataReceived_ACK(MSG_ROUTING_NONE, request_id)); - DCHECK((shm_handle && data_len > 0) || (!shm_handle && !data_len)); + const bool shm_valid = base::SharedMemory::IsHandleValid(shm_handle); + DCHECK((shm_valid && data_len > 0) || (!shm_valid && !data_len)); base::SharedMemory shared_mem(shm_handle, true); // read only PendingRequestList::iterator it = pending_requests_.find(request_id); diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 1655e04..2b411c0 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -164,13 +164,13 @@ void RenderThread::CleanUp() { } void RenderThread::OnUpdateVisitedLinks(base::SharedMemoryHandle table) { - DCHECK(table) << "Bad table handle"; + DCHECK(base::SharedMemory::IsHandleValid(table)) << "Bad table handle"; visited_link_slave_->Init(table); } void RenderThread::OnUpdateUserScripts( base::SharedMemoryHandle scripts) { - DCHECK(scripts) << "Bad scripts handle"; + DCHECK(base::SharedMemory::IsHandleValid(scripts)) << "Bad scripts handle"; user_script_slave_->UpdateScripts(scripts); } diff --git a/chrome/renderer/render_thread_unittest.cc b/chrome/renderer/render_thread_unittest.cc index 4fb7a24..9d13170 100644 --- a/chrome/renderer/render_thread_unittest.cc +++ b/chrome/renderer/render_thread_unittest.cc @@ -45,7 +45,12 @@ TEST_F(RenderThreadTest, TestGlobal) { TEST_F(RenderThreadTest, TestVisitedMsg) { RenderThread thread(ASCIIToWide(kThreadName)); +#if defined(OS_WIN) IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(NULL); +#elif defined(OS_POSIX) + IPC::Message* msg = new ViewMsg_VisitedLink_NewTable( + base::SharedMemoryHandle()); +#endif ASSERT_TRUE(msg); // Message goes nowhere, but this confirms Init() has happened. // Unusually (?), RenderThread() Start()s itself in it's constructor. |