Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1101)

Unified Diff: ppapi/shared_impl/io_stream_shared.cc

Issue 119853003: [PPAPI] Implement an IOStreamResource for data transmission between plugin and renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/shared_impl/io_stream_shared.cc
diff --git a/ppapi/shared_impl/io_stream_shared.cc b/ppapi/shared_impl/io_stream_shared.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b754c3601719dd0c3dfe60c9d55c2d6759598727
--- /dev/null
+++ b/ppapi/shared_impl/io_stream_shared.cc
@@ -0,0 +1,132 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
bbudge 2013/12/31 00:51:53 s/2012/2013 or even 2014!
Peng 2013/12/31 23:33:54 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/shared_impl/io_stream_shared.h"
+
+#include "base/logging.h"
+#include "ppapi/c/pp_errors.h"
+
+namespace ppapi {
+
+IOStreamShared::IOStreamShared(bool input)
+ : input_(input) {
+}
+
+IOStreamShared::~IOStreamShared() {
+}
+
+int32_t IOStreamShared::SetBuffer(scoped_ptr<base::SharedMemory> shm,
+ uint32_t size) {
bbudge 2013/12/31 00:51:53 indent
Peng 2013/12/31 23:33:54 Done.
+ CHECK(size);
+ CHECK(shm);
+ CHECK(shm->Map(size));
bbudge 2013/12/31 00:51:53 These will crash the browser if compiled into the
Peng 2013/12/31 23:33:54 Done. Fixed in this function. For other functions
+
+ shm_new_ = shm.Pass();
+ circular_buffer_new_.reset(new CircularBuffer(shm_new_->memory(), size));
+ if (!input_)
+ circular_buffer_new_->MoveLimit(size);
+
+ // If the |circular_buffer_| is locked , we can not replace it right now.
+ // So we have to do it in |Unlock()|.
bbudge 2013/12/31 00:51:53 Maybe this is a little clearer: // If |circular_bu
Peng 2013/12/31 23:33:54 Done.
+ if ((!circular_buffer_) ||
+ (!circular_buffer_->IsLocked())) {
+ shm_ = shm_new_.Pass();
+ circular_buffer_ = circular_buffer_new_.Pass();
+ }
+ return PP_OK;
+}
+
+int32_t IOStreamShared::Write(const void* buffer, uint32_t size) {
+ CHECK(!input_);
+ CHECK(buffer);
+ CHECK(size);
+
+ int32_t result = circular_buffer_->Write(buffer, size);
+ if (result > 0)
+ MovePeerLimit(size);
+ return result;
+}
+
+int32_t IOStreamShared::WriteAll(const void* buffer, uint32_t size) {
+ CHECK(!input_);
+ CHECK(buffer);
+ CHECK(size);
+
+ int32_t result = circular_buffer_->WriteAll(buffer, size);
+ if (result > 0)
+ MovePeerLimit(result);
+ return result;
+}
+
+int32_t IOStreamShared::Read(void* buffer, uint32_t size) {
+ CHECK(input_);
+ CHECK(buffer);
+ CHECK(size);
+
+ int32_t result = circular_buffer_->Read(buffer, size);
+ if (result > 0)
+ MovePeerLimit(size);
+ return result;
+}
+
+int32_t IOStreamShared::ReadAll(void* buffer, uint32_t size) {
+ CHECK(input_);
+ CHECK(buffer);
+ CHECK(size);
+
+ int32_t result = circular_buffer_->ReadAll(buffer, size);
+ if (result > 0)
+ MovePeerLimit(result);
+ return result;
+}
+
+int32_t IOStreamShared::Lock(void** buffer, uint32_t size) {
+ CHECK(buffer);
+ CHECK(size);
+
+ return circular_buffer_->Lock(buffer, size);
+}
+
+int32_t IOStreamShared::Relock(void* buffer, uint32_t size) {
+ CHECK(buffer);
+ CHECK(size);
+ return circular_buffer_->Relock(buffer, size);
+}
+
+int32_t IOStreamShared::Unlock(void* buffer) {
+ int32_t result = circular_buffer_->Unlock(buffer);
+ if (result <= 0)
+ return result;
+
+ if (!shm_new_) {
+ MovePeerLimit(result);
+ } else {
+ // |circular_buffer_| is unlocked. we need replace it now.
bbudge 2013/12/31 00:51:53 How about this? // Now that |circular_buffer_| is
Peng 2013/12/31 23:33:54 Done.
+ shm_ = shm_new_.Pass();
+ circular_buffer_ = circular_buffer_new_.Pass();
+ if (input_ && circular_buffer_->remaining())
+ OnMoreBufferAvailable();
+ }
+ return PP_OK;
+}
+
+uint32_t IOStreamShared::remaining() const {
+ if (!circular_buffer_)
+ return 0;
+ return circular_buffer_->remaining();
+}
+
+void IOStreamShared::MoveLimit(uint32_t offset) {
+ if (circular_buffer_new_) {
+ circular_buffer_new_->MoveLimit(offset);
+ } else {
+ circular_buffer_->MoveLimit(offset);
+ OnMoreBufferAvailable();
+ }
+}
+
+void IOStreamShared::OnMoreBufferAvailable() {
+}
+
+} // namespace ppapi
« ppapi/shared_impl/io_stream_shared.h ('K') | « ppapi/shared_impl/io_stream_shared.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698