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

Unified Diff: ppapi/shared_impl/circular_buffer.h

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 6 years, 12 months 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/circular_buffer.h
diff --git a/ppapi/shared_impl/circular_buffer.h b/ppapi/shared_impl/circular_buffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..2c306313bac23cf282623e93b1798051bd83693c
--- /dev/null
+++ b/ppapi/shared_impl/circular_buffer.h
@@ -0,0 +1,92 @@
+// Copyright (c) 2014 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 PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_
+#define PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_
+
+#include "base/basictypes.h"
+#include "ppapi/shared_impl/ppapi_shared_export.h"
+
+namespace ppapi {
+
+class PPAPI_SHARED_EXPORT CircularBuffer {
+ public:
+ // Construct a CircularBuffer by given underlying buffer and size.
yzshen1 2014/01/03 21:51:41 Construct*s*
+ CircularBuffer(void* buffer, uint32_t size);
+
+ ~CircularBuffer();
+
+ // Remaining buffer size for reading or writing.
dmichael (off chromium) 2014/01/03 18:05:29 nit: size in bytes? Same above.
+ uint32_t remaining() const {
dmichael (off chromium) 2014/01/03 18:05:29 I'm worried this might get confusing for users of
+ return remaining_;
+ }
+
+ // Moves position forward by given offset.
+ void MovePosition(uint32_t offset);
+
+ // Moves limit forward by given offset.
+ void MoveLimit(uint32_t offset);
dmichael (off chromium) 2014/01/03 18:05:29 Should these be private or protected? Doesn't seem
+
+ // Reads data and move position forward. The actual read size will be
yzshen1 2014/01/03 21:51:41 move*s*
+ // returned.
+ int32_t Read(void* buffer, uint32_t size);
yzshen1 2014/01/03 21:51:41 The uint32_t and int32_t mismatch seems a little w
+
+ // Similar to |Read()|, but it will fail, if the circular buffer does not have
dmichael (off chromium) 2014/01/03 18:05:29 nit: no comma after fail (same for WriteAll)
+ // enough data.
+ int32_t ReadAll(void* buffer, uint32_t size);
+
+ // Writes data and move position forward. The actual write size will be
yzshen1 2014/01/03 21:51:41 move*s*
+ // returned.
+ int32_t Write(const void* buffer, uint32_t size);
+
+ // Similar to |Write()|, but it will fail, if the circular buffer does not
+ // have enough space for the given size of data.
+ int32_t WriteAll(const void* buffer, uint32_t size);
dmichael (off chromium) 2014/01/03 18:05:29 Should WriteAll and ReadAll return bool instead of
+
+ // Locks the given size of underlying buffer for direct accessing.
+ int32_t Lock(void** buffer, uint32_t size);
yzshen1 2014/01/03 21:51:41 What is the meaning of the return value? Do you me
+
+ // Relocks underlying buffer. It is used for adjusting locked block size;
dmichael (off chromium) 2014/01/03 18:05:29 nit: semicolon should be a period. Please also not
+ int32_t Relock(void* buffer, uint32_t size);
+
+ // Unlocks buffer which is locked by previous |Lock()| call. The locked block
yzshen1 2014/01/03 21:51:41 Is it still necessary to return the block size?
+ // size will be returned.
dmichael (off chromium) 2014/01/03 18:05:29 You should also note that the position is moved by
+ int32_t Unlock(const void* buffer);
yzshen1 2014/01/03 21:51:41 Now that it is only allow to lock one block at a t
+
+ // Returns true if the circular buffer is locked.
+ bool IsLocked() const { return locked_buffer_; }
+
+ private:
+ int32_t ReadInternal(void* buffer, uint32_t size);
+
+ int32_t WriteInternal(const void* buffer, uint32_t size);
+
+ // Underlying buffer pointer.
+ uint8_t* buffer_;
dmichael (off chromium) 2014/01/03 18:05:29 You should probably note that this is unowned (it
+
+ // Underlying buffer size.
+ uint32_t buffer_size_;
+
+ // Current position for reading or writing.
+ uint32_t position_;
+
+ // The limit position for reading or writing.
+ uint32_t limit_;
+
+ // Remaining buffer size for reading or writing.
+ uint32_t remaining_;
+
+ // Locked buffer pointer returned by |Lock()|. It will be reset to NULL,
+ // When |Unlock()| is called.
dmichael (off chromium) 2014/01/03 18:05:29 nit: no comma after NULL, "When" should not be cap
+ uint8_t* locked_buffer_;
+
+ // Locked buffer size.
+ uint32_t locked_buffer_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(CircularBuffer);
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_

Powered by Google App Engine
This is Rietveld 408576698