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

Side by Side 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 6 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/shared_impl/io_stream_shared.h"
6
7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h"
9
10 namespace ppapi {
11
12 IOStreamShared::IOStreamShared(bool is_input)
13 : is_input_(is_input) {
14 }
15
16 IOStreamShared::~IOStreamShared() {
17 }
18
19 int32_t IOStreamShared::SetBuffer(scoped_ptr<base::SharedMemory> shm,
20 uint32_t size) {
21 if (!size)
yzshen1 2014/01/03 21:51:41 nit: For numeric comparison, please use size == 0.
22 return PP_ERROR_BADARGUMENT;
23
24 if (!(shm && shm->Map(size)))
25 return PP_ERROR_NOMEMORY;
26
27 shm_new_ = shm.Pass();
28 circular_buffer_new_.reset(new CircularBuffer(shm_new_->memory(), size));
29 if (!is_input_)
30 circular_buffer_new_->MoveLimit(size);
31
32 // If the |circular_buffer_| is locked, wait until next |Unlock()|.
33 if ((!circular_buffer_) ||
34 (!circular_buffer_->IsLocked())) {
35 shm_ = shm_new_.Pass();
36 circular_buffer_ = circular_buffer_new_.Pass();
37 }
38 return PP_OK;
39 }
40
41 int32_t IOStreamShared::Write(const void* buffer, uint32_t size) {
42 CHECK(!is_input_);
yzshen1 2014/01/03 21:51:41 Please see my comment about parameter validation i
43 CHECK(buffer);
44 CHECK(size);
45
46 int32_t result = circular_buffer_->Write(buffer, size);
47 if (result > 0)
48 MovePeerLimit(size);
49 return result;
50 }
51
52 int32_t IOStreamShared::WriteAll(const void* buffer, uint32_t size) {
53 CHECK(!is_input_);
54 CHECK(buffer);
55 CHECK(size);
56
57 int32_t result = circular_buffer_->WriteAll(buffer, size);
58 if (result > 0)
59 MovePeerLimit(result);
60 return result;
61 }
62
63 int32_t IOStreamShared::Read(void* buffer, uint32_t size) {
64 CHECK(is_input_);
65 CHECK(buffer);
66 CHECK(size);
67
68 int32_t result = circular_buffer_->Read(buffer, size);
69 if (result > 0)
70 MovePeerLimit(size);
71 return result;
72 }
73
74 int32_t IOStreamShared::ReadAll(void* buffer, uint32_t size) {
75 CHECK(is_input_);
76 CHECK(buffer);
77 CHECK(size);
78
79 int32_t result = circular_buffer_->ReadAll(buffer, size);
80 if (result > 0)
81 MovePeerLimit(result);
82 return result;
83 }
84
85 int32_t IOStreamShared::Lock(void** buffer, uint32_t size) {
86 CHECK(buffer);
87 CHECK(size);
88 return circular_buffer_->Lock(buffer, size);
89 }
90
91 int32_t IOStreamShared::Relock(void* buffer, uint32_t size) {
92 CHECK(buffer);
93 CHECK(size);
94 return circular_buffer_->Relock(buffer, size);
95 }
96
97 int32_t IOStreamShared::Unlock(void* buffer) {
98 int32_t result = circular_buffer_->Unlock(buffer);
99 if (result <= 0)
100 return result;
101
102 if (!shm_new_) {
103 MovePeerLimit(result);
104 } else {
105 // Now that|circular_buffer_| is unlocked, swap in the new buffer.
106 shm_ = shm_new_.Pass();
107 circular_buffer_ = circular_buffer_new_.Pass();
108 if (is_input_ && circular_buffer_->remaining())
109 OnMoreBufferAvailable();
110 }
111 return PP_OK;
112 }
113
114 uint32_t IOStreamShared::remaining() const {
115 if (!circular_buffer_)
116 return 0;
117 return circular_buffer_->remaining();
dmichael (off chromium) 2014/01/03 18:05:29 This isn't right if there's a "new" CircularBuffer
118 }
119
120 void IOStreamShared::MoveLimit(uint32_t offset) {
121 if (circular_buffer_new_) {
122 circular_buffer_new_->MoveLimit(offset);
123 } else {
124 circular_buffer_->MoveLimit(offset);
125 OnMoreBufferAvailable();
126 }
127 }
128
129 void IOStreamShared::OnMoreBufferAvailable() {
130 }
131
132 } // namespace ppapi
OLDNEW
« 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