summaryrefslogtreecommitdiffstats
path: root/webkit/plugins
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-18 17:00:23 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-18 17:00:23 +0000
commit0dedf72573b37d924b4a29b76cb17550d2cf5f81 (patch)
treebbb5135b127ff199551cb5aba34967dc11249137 /webkit/plugins
parent4af029813d7160506c1ad151a338288681e4294a (diff)
downloadchromium_src-0dedf72573b37d924b4a29b76cb17550d2cf5f81.zip
chromium_src-0dedf72573b37d924b4a29b76cb17550d2cf5f81.tar.gz
chromium_src-0dedf72573b37d924b4a29b76cb17550d2cf5f81.tar.bz2
Convert PPB_Buffer_Impl to use SharedMemory for efficient IPC use.
BUG=none TEST=trybots Review URL: http://codereview.chromium.org/7039022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85773 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc5
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h1
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h4
-rw-r--r--webkit/plugins/ppapi/ppb_buffer_impl.cc23
-rw-r--r--webkit/plugins/ppapi/ppb_buffer_impl.h15
5 files changed, 27 insertions, 21 deletions
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index 8103a09..8405e64 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -243,5 +243,10 @@ std::string MockPluginDelegate::GetFlashCommandLineArgs() {
return std::string();
}
+base::SharedMemory* MockPluginDelegate::CreateAnonymousSharedMemory(
+ uint32_t size) {
+ return NULL;
+}
+
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index ac3664a..0e94e24 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -104,6 +104,7 @@ class MockPluginDelegate : public PluginDelegate {
virtual webkit_glue::P2PTransport* CreateP2PTransport();
virtual double GetLocalTimeZoneOffset(base::Time t);
virtual std::string GetFlashCommandLineArgs();
+ virtual base::SharedMemory* CreateAnonymousSharedMemory(uint32_t size);
};
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index cd714296..d9fd349 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -394,6 +394,10 @@ class PluginDelegate {
// TODO(viettrungluu): Generalize this for use with other plugins if it proves
// necessary.
virtual std::string GetFlashCommandLineArgs() = 0;
+
+ // Create an anonymous shared memory segment of size |size| bytes, and return
+ // a pointer to it, or NULL on error. Caller owns the returned pointer.
+ virtual base::SharedMemory* CreateAnonymousSharedMemory(uint32_t size) = 0;
};
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.cc b/webkit/plugins/ppapi/ppb_buffer_impl.cc
index 4effdf6..8db5d55 100644
--- a/webkit/plugins/ppapi/ppb_buffer_impl.cc
+++ b/webkit/plugins/ppapi/ppb_buffer_impl.cc
@@ -71,8 +71,7 @@ const PPB_Buffer_Dev ppb_buffer = {
} // namespace
PPB_Buffer_Impl::PPB_Buffer_Impl(PluginInstance* instance)
- : Resource(instance),
- size_(0) {
+ : Resource(instance), size_(0) {
}
PPB_Buffer_Impl::~PPB_Buffer_Impl() {
@@ -88,11 +87,11 @@ PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() {
}
bool PPB_Buffer_Impl::Init(uint32_t size) {
- if (size == 0)
+ if (size == 0 || !instance())
return false;
- Unmap();
- size_ = size;
- return true;
+ shared_memory_.reset(
+ instance()->delegate()->CreateAnonymousSharedMemory(size));
+ return shared_memory_.get() != NULL;
}
void PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) const {
@@ -100,20 +99,14 @@ void PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) const {
}
void* PPB_Buffer_Impl::Map() {
- if (size_ == 0)
+ if (!shared_memory_.get() || !shared_memory_->Map(size_))
return NULL;
-
- if (!is_mapped()) {
- mem_buffer_.reset(new unsigned char[size_]);
- memset(mem_buffer_.get(), 0, size_);
- }
- return mem_buffer_.get();
+ return shared_memory_->memory();
}
void PPB_Buffer_Impl::Unmap() {
- mem_buffer_.reset();
+ shared_memory_->Unmap();
}
} // namespace ppapi
} // namespace webkit
-
diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.h b/webkit/plugins/ppapi/ppb_buffer_impl.h
index 7890c3d..e7d83f9 100644
--- a/webkit/plugins/ppapi/ppb_buffer_impl.h
+++ b/webkit/plugins/ppapi/ppb_buffer_impl.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "base/shared_memory.h"
#include "webkit/plugins/ppapi/resource.h"
struct PPB_Buffer_Dev;
@@ -22,28 +23,31 @@ class PPB_Buffer_Impl : public Resource {
virtual ~PPB_Buffer_Impl();
uint32_t size() const { return size_; }
- unsigned char* mapped_buffer() { return mem_buffer_.get(); }
+ unsigned char* mapped_buffer() const {
+ return static_cast<unsigned char*>(shared_memory_->memory());
+ }
+ base::SharedMemoryHandle handle() const { return shared_memory_->handle(); }
// Returns true if this buffer is mapped. False means that the buffer is
// either invalid or not mapped.
- bool is_mapped() const { return !!mem_buffer_.get(); }
+ bool is_mapped() const { return mapped_buffer() != NULL; }
- // Returns a pointer to the interface implementing PPB_PPB_Buffer_Impl that is
+ // Returns a pointer to the interface implementing PPB_Buffer_Impl that is
// exposed to the plugin.
static const PPB_Buffer_Dev* GetInterface();
// Resource overrides.
virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl();
- // PPB_PPB_Buffer_Impl implementation.
+ // PPB_Buffer_Impl implementation.
bool Init(uint32_t size);
void Describe(uint32_t* size_in_bytes) const;
void* Map();
void Unmap();
private:
+ scoped_ptr<base::SharedMemory> shared_memory_;
uint32_t size_;
- scoped_array<unsigned char> mem_buffer_;
DISALLOW_COPY_AND_ASSIGN(PPB_Buffer_Impl);
};
@@ -52,4 +56,3 @@ class PPB_Buffer_Impl : public Resource {
} // namespace webkit
#endif // WEBKIT_PLUGINS_PPAPI_PPB_BUFFER_IMPL_H_
-