From 80f8f849be55037a30f8535c323650e49785907e Mon Sep 17 00:00:00 2001 From: "bbudge@chromium.org" Date: Wed, 18 Dec 2013 22:47:57 +0000 Subject: [PATCH] Pepper: add quota_amount and max_written_offset fields to SerializedHandle. This field will be non-zero if the file is contained in a file system that requires quota checks. This will be used by the NaCl PPAPI proxy to verify that file writes respect quota. The NaClQuotaAmount class is defined which is thread safe ref-counted, so multiple file descriptors can modify quota amounts. BUG=194304 Review URL: https://codereview.chromium.org/60733002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241691 0039d316-1c4b-4281-b951-d872f2087c98 --- components/nacl/loader/nacl_ipc_adapter.cc | 2 +- .../renderer_host/pepper/pepper_file_io_host.cc | 2 +- ppapi/proxy/ppapi_param_traits.cc | 2 +- ppapi/proxy/serialized_handle.cc | 28 +++++++++----- ppapi/proxy/serialized_handle.h | 44 ++++++++++++++++------ 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/components/nacl/loader/nacl_ipc_adapter.cc b/components/nacl/loader/nacl_ipc_adapter.cc index 57e7ef047fcc..c6aaf61ce008 100644 --- a/components/nacl/loader/nacl_ipc_adapter.cc +++ b/components/nacl/loader/nacl_ipc_adapter.cc @@ -445,7 +445,7 @@ bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) { #else iter->descriptor().fd, #endif - TranslatePepperFileReadWriteOpenFlags(iter->open_flag())))); + TranslatePepperFileReadWriteOpenFlags(iter->open_flags())))); break; case ppapi::proxy::SerializedHandle::INVALID: { // Nothing to do. TODO(dmichael): Should we log this? Or is it diff --git a/content/browser/renderer_host/pepper/pepper_file_io_host.cc b/content/browser/renderer_host/pepper/pepper_file_io_host.cc index 29df53270c05..7a27e272dcb9 100644 --- a/content/browser/renderer_host/pepper/pepper_file_io_host.cc +++ b/content/browser/renderer_host/pepper/pepper_file_io_host.cc @@ -601,7 +601,7 @@ bool PepperFileIOHost::AddFileToReplyContext( if (transit_file == IPC::InvalidPlatformFileForTransit()) return false; ppapi::proxy::SerializedHandle file_handle; - file_handle.set_file_handle(transit_file, open_flags); + file_handle.set_file_handle(transit_file, open_flags, 0 /* file_io */); reply_context->params.AppendHandle(file_handle); return true; } diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc index 5ee0a34397a3..e04203ee461f 100644 --- a/ppapi/proxy/ppapi_param_traits.cc +++ b/ppapi/proxy/ppapi_param_traits.cc @@ -280,7 +280,7 @@ bool ParamTraits::Read(const Message* m, case ppapi::proxy::SerializedHandle::FILE: { IPC::PlatformFileForTransit desc; if (ParamTraits::Read(m, iter, &desc)) { - r->set_file_handle(desc, header.open_flag); + r->set_file_handle(desc, header.open_flags, header.file_io); return true; } break; diff --git a/ppapi/proxy/serialized_handle.cc b/ppapi/proxy/serialized_handle.cc index c9ce13b41a9e..fb3404e74646 100644 --- a/ppapi/proxy/serialized_handle.cc +++ b/ppapi/proxy/serialized_handle.cc @@ -21,14 +21,18 @@ SerializedHandle::SerializedHandle() : type_(INVALID), shm_handle_(base::SharedMemory::NULLHandle()), size_(0), - descriptor_(IPC::InvalidPlatformFileForTransit()) { + descriptor_(IPC::InvalidPlatformFileForTransit()), + open_flags_(0), + file_io_(0) { } SerializedHandle::SerializedHandle(Type type_param) : type_(type_param), shm_handle_(base::SharedMemory::NULLHandle()), size_(0), - descriptor_(IPC::InvalidPlatformFileForTransit()) { + descriptor_(IPC::InvalidPlatformFileForTransit()), + open_flags_(0), + file_io_(0) { } SerializedHandle::SerializedHandle(const base::SharedMemoryHandle& handle, @@ -36,7 +40,9 @@ SerializedHandle::SerializedHandle(const base::SharedMemoryHandle& handle, : type_(SHARED_MEMORY), shm_handle_(handle), size_(size), - descriptor_(IPC::InvalidPlatformFileForTransit()) { + descriptor_(IPC::InvalidPlatformFileForTransit()), + open_flags_(0), + file_io_(0) { } SerializedHandle::SerializedHandle( @@ -45,7 +51,9 @@ SerializedHandle::SerializedHandle( : type_(type), shm_handle_(base::SharedMemory::NULLHandle()), size_(0), - descriptor_(socket_descriptor) { + descriptor_(socket_descriptor), + open_flags_(0), + file_io_(0) { } bool SerializedHandle::IsHandleValid() const { @@ -98,7 +106,7 @@ bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) { return false; } if (hdr.type == FILE) { - if (!pickle->WriteInt(hdr.open_flag)) + if (!pickle->WriteInt(hdr.open_flags) || !pickle->WriteInt(hdr.file_io)) return false; } return true; @@ -106,7 +114,7 @@ bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) { // static bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) { - *hdr = Header(INVALID, 0, 0); + *hdr = Header(INVALID, 0, 0, 0); int type = 0; if (!iter->ReadInt(&type)) return false; @@ -121,10 +129,12 @@ bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) { break; } case FILE: { - int open_flag = 0; - if (!iter->ReadInt(&open_flag)) + int open_flags = 0; + PP_Resource file_io = 0; + if (!iter->ReadInt(&open_flags) || !iter->ReadInt(&file_io)) return false; - hdr->open_flag = open_flag; + hdr->open_flags = open_flags; + hdr->file_io = file_io; valid_type = true; } case SOCKET: diff --git a/ppapi/proxy/serialized_handle.h b/ppapi/proxy/serialized_handle.h index 91efa075b5de..a662b757fc3b 100644 --- a/ppapi/proxy/serialized_handle.h +++ b/ppapi/proxy/serialized_handle.h @@ -8,11 +8,14 @@ #include #include +#include "base/atomicops.h" #include "base/basictypes.h" #include "base/logging.h" +#include "base/memory/ref_counted.h" #include "base/memory/shared_memory.h" #include "build/build_config.h" #include "ipc/ipc_platform_file.h" +#include "ppapi/c/pp_resource.h" #include "ppapi/proxy/ppapi_proxy_export.h" class Pickle; @@ -27,14 +30,24 @@ namespace proxy { class PPAPI_PROXY_EXPORT SerializedHandle { public: enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE, FILE }; + // Header contains the fields that we send in IPC messages, apart from the + // actual handle. See comments on the SerializedHandle fields below. struct Header { - Header() : type(INVALID), size(0), open_flag(0) {} - Header(Type type_arg, uint32 size_arg, int32 open_flag_arg) - : type(type_arg), size(size_arg), open_flag(open_flag_arg) { + Header() : type(INVALID), size(0), open_flags(0) {} + Header(Type type_arg, + uint32 size_arg, + int32 open_flags_arg, + PP_Resource file_io_arg) + : type(type_arg), + size(size_arg), + open_flags(open_flags_arg), + file_io(file_io_arg) { } + Type type; uint32 size; - int32 open_flag; + int32 open_flags; + PP_Resource file_io; }; SerializedHandle(); @@ -65,8 +78,11 @@ class PPAPI_PROXY_EXPORT SerializedHandle { DCHECK(is_socket() || is_channel_handle() || is_file()); return descriptor_; } - int32 open_flag() const { - return open_flag_; + int32 open_flags() const { + return open_flags_; + } + PP_Resource file_io() const { + return file_io_; } void set_shmem(const base::SharedMemoryHandle& handle, uint32 size) { type_ = SHARED_MEMORY; @@ -90,13 +106,15 @@ class PPAPI_PROXY_EXPORT SerializedHandle { size_ = 0; } void set_file_handle(const IPC::PlatformFileForTransit& descriptor, - int32 open_flag) { + int32 open_flags, + PP_Resource file_io) { type_ = FILE; descriptor_ = descriptor; shm_handle_ = base::SharedMemory::NULLHandle(); size_ = 0; - open_flag_ = open_flag; + open_flags_ = open_flags; + file_io_ = file_io; } void set_null_shmem() { set_shmem(base::SharedMemory::NULLHandle(), 0); @@ -108,12 +126,12 @@ class PPAPI_PROXY_EXPORT SerializedHandle { set_channel_handle(IPC::InvalidPlatformFileForTransit()); } void set_null_file_handle() { - set_file_handle(IPC::InvalidPlatformFileForTransit(), 0); + set_file_handle(IPC::InvalidPlatformFileForTransit(), 0, 0); } bool IsHandleValid() const; Header header() const { - return Header(type_, size_, open_flag_); + return Header(type_, size_, open_flags_, file_io_); } // Closes the handle and sets it to invalid. @@ -140,8 +158,10 @@ class PPAPI_PROXY_EXPORT SerializedHandle { // This is valid if type == SOCKET || type == CHANNEL_HANDLE || type == FILE. IPC::PlatformFileForTransit descriptor_; - // This is valid if type == FILE. - int32 open_flag_; + // The following fields are valid if type == FILE. + int32 open_flags_; + // This is non-zero if file writes require quota checking. + PP_Resource file_io_; }; } // namespace proxy -- 2.11.4.GIT