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

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) 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.
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 input)
13 : input_(input) {
14 }
15
16 IOStreamShared::~IOStreamShared() {
17 }
18
19 int32_t IOStreamShared::SetBuffer(scoped_ptr<base::SharedMemory> shm,
20 uint32_t size) {
bbudge 2013/12/31 00:51:53 indent
Peng 2013/12/31 23:33:54 Done.
21 CHECK(size);
22 CHECK(shm);
23 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
24
25 shm_new_ = shm.Pass();
26 circular_buffer_new_.reset(new CircularBuffer(shm_new_->memory(), size));
27 if (!input_)
28 circular_buffer_new_->MoveLimit(size);
29
30 // If the |circular_buffer_| is locked , we can not replace it right now.
31 // 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.
32 if ((!circular_buffer_) ||
33 (!circular_buffer_->IsLocked())) {
34 shm_ = shm_new_.Pass();
35 circular_buffer_ = circular_buffer_new_.Pass();
36 }
37 return PP_OK;
38 }
39
40 int32_t IOStreamShared::Write(const void* buffer, uint32_t size) {
41 CHECK(!input_);
42 CHECK(buffer);
43 CHECK(size);
44
45 int32_t result = circular_buffer_->Write(buffer, size);
46 if (result > 0)
47 MovePeerLimit(size);
48 return result;
49 }
50
51 int32_t IOStreamShared::WriteAll(const void* buffer, uint32_t size) {
52 CHECK(!input_);
53 CHECK(buffer);
54 CHECK(size);
55
56 int32_t result = circular_buffer_->WriteAll(buffer, size);
57 if (result > 0)
58 MovePeerLimit(result);
59 return result;
60 }
61
62 int32_t IOStreamShared::Read(void* buffer, uint32_t size) {
63 CHECK(input_);
64 CHECK(buffer);
65 CHECK(size);
66
67 int32_t result = circular_buffer_->Read(buffer, size);
68 if (result > 0)
69 MovePeerLimit(size);
70 return result;
71 }
72
73 int32_t IOStreamShared::ReadAll(void* buffer, uint32_t size) {
74 CHECK(input_);
75 CHECK(buffer);
76 CHECK(size);
77
78 int32_t result = circular_buffer_->ReadAll(buffer, size);
79 if (result > 0)
80 MovePeerLimit(result);
81 return result;
82 }
83
84 int32_t IOStreamShared::Lock(void** buffer, uint32_t size) {
85 CHECK(buffer);
86 CHECK(size);
87
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 // |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.
106 shm_ = shm_new_.Pass();
107 circular_buffer_ = circular_buffer_new_.Pass();
108 if (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();
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