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

Side by Side Diff: chrome/nacl/nacl_ipc_adapter.cc

Issue 10069051: RefCounted types should not have public destructors, chrome/nacl edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implementation ordering Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/nacl/nacl_ipc_adapter.h ('k') | chrome/nacl/nacl_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/nacl/nacl_ipc_adapter.h" 5 #include "chrome/nacl/nacl_ipc_adapter.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 RewrittenMessage(); 50 RewrittenMessage();
51 51
52 bool is_consumed() const { return data_read_cursor_ == data_len_; } 52 bool is_consumed() const { return data_read_cursor_ == data_len_; }
53 53
54 void SetData(const NaClIPCAdapter::NaClMessageHeader& header, 54 void SetData(const NaClIPCAdapter::NaClMessageHeader& header,
55 const void* payload, size_t payload_length); 55 const void* payload, size_t payload_length);
56 56
57 int Read(char* dest_buffer, int dest_buffer_size); 57 int Read(char* dest_buffer, int dest_buffer_size);
58 58
59 private: 59 private:
60 friend class base::RefCounted<RewrittenMessage>;
61 ~RewrittenMessage() {}
62
60 scoped_array<char> data_; 63 scoped_array<char> data_;
61 int data_len_; 64 int data_len_;
62 65
63 // Offset into data where the next read will happen. This will be equal to 66 // Offset into data where the next read will happen. This will be equal to
64 // data_len_ when all data has been consumed. 67 // data_len_ when all data has been consumed.
65 int data_read_cursor_; 68 int data_read_cursor_;
66 }; 69 };
67 70
68 NaClIPCAdapter::RewrittenMessage::RewrittenMessage() 71 NaClIPCAdapter::RewrittenMessage::RewrittenMessage()
69 : data_len_(0), 72 : data_len_(0),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 122
120 NaClIPCAdapter::NaClIPCAdapter(scoped_ptr<IPC::Channel> channel, 123 NaClIPCAdapter::NaClIPCAdapter(scoped_ptr<IPC::Channel> channel,
121 base::TaskRunner* runner) 124 base::TaskRunner* runner)
122 : lock_(), 125 : lock_(),
123 cond_var_(&lock_), 126 cond_var_(&lock_),
124 task_runner_(runner), 127 task_runner_(runner),
125 locked_data_() { 128 locked_data_() {
126 io_thread_data_.channel_ = channel.Pass(); 129 io_thread_data_.channel_ = channel.Pass();
127 } 130 }
128 131
129 NaClIPCAdapter::~NaClIPCAdapter() {
130 }
131
132 // Note that this message is controlled by the untrusted code. So we should be 132 // Note that this message is controlled by the untrusted code. So we should be
133 // skeptical of anything it contains and quick to give up if anything is fishy. 133 // skeptical of anything it contains and quick to give up if anything is fishy.
134 int NaClIPCAdapter::Send(const char* input_data, size_t input_data_len) { 134 int NaClIPCAdapter::Send(const char* input_data, size_t input_data_len) {
135 base::AutoLock lock(lock_); 135 base::AutoLock lock(lock_);
136 136
137 if (input_data_len > IPC::Channel::kMaximumMessageSize) { 137 if (input_data_len > IPC::Channel::kMaximumMessageSize) {
138 ClearToBeSent(); 138 ClearToBeSent();
139 return -1; 139 return -1;
140 } 140 }
141 141
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return true; 248 return true;
249 } 249 }
250 250
251 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) { 251 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) {
252 } 252 }
253 253
254 void NaClIPCAdapter::OnChannelError() { 254 void NaClIPCAdapter::OnChannelError() {
255 CloseChannel(); 255 CloseChannel();
256 } 256 }
257 257
258 NaClIPCAdapter::~NaClIPCAdapter() {
259 }
260
258 int NaClIPCAdapter::LockedReceive(char* output_buffer, int output_buffer_size) { 261 int NaClIPCAdapter::LockedReceive(char* output_buffer, int output_buffer_size) {
259 lock_.AssertAcquired(); 262 lock_.AssertAcquired();
260 263
261 if (locked_data_.to_be_received_.empty()) 264 if (locked_data_.to_be_received_.empty())
262 return 0; 265 return 0;
263 scoped_refptr<RewrittenMessage> current = 266 scoped_refptr<RewrittenMessage> current =
264 locked_data_.to_be_received_.front(); 267 locked_data_.to_be_received_.front();
265 268
266 int retval = current->Read(output_buffer, output_buffer_size); 269 int retval = current->Read(output_buffer, output_buffer_size);
267 270
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 if (locked_data_.channel_closed_) 312 if (locked_data_.channel_closed_)
310 return false; // TODO(brettw) clean up handles here when we add support! 313 return false; // TODO(brettw) clean up handles here when we add support!
311 314
312 // Actual send must be done on the I/O thread. 315 // Actual send must be done on the I/O thread.
313 task_runner_->PostTask(FROM_HERE, 316 task_runner_->PostTask(FROM_HERE,
314 base::Bind(&NaClIPCAdapter::SendMessageOnIOThread, this, 317 base::Bind(&NaClIPCAdapter::SendMessageOnIOThread, this,
315 base::Passed(&msg))); 318 base::Passed(&msg)));
316 return true; 319 return true;
317 } 320 }
318 321
319 void NaClIPCAdapter::CloseChannelOnIOThread() {
320 io_thread_data_.channel_->Close();
321 }
322
323 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) {
324 io_thread_data_.channel_->Send(message.release());
325 }
326
327 void NaClIPCAdapter::ClearToBeSent() { 322 void NaClIPCAdapter::ClearToBeSent() {
328 lock_.AssertAcquired(); 323 lock_.AssertAcquired();
329 324
330 // Don't let the string keep its buffer behind our back. 325 // Don't let the string keep its buffer behind our back.
331 std::string empty; 326 std::string empty;
332 locked_data_.to_be_sent_.swap(empty); 327 locked_data_.to_be_sent_.swap(empty);
333 } 328 }
329
330 void NaClIPCAdapter::CloseChannelOnIOThread() {
331 io_thread_data_.channel_->Close();
332 }
333
334 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) {
335 io_thread_data_.channel_->Send(message.release());
336 }
OLDNEW
« no previous file with comments | « chrome/nacl/nacl_ipc_adapter.h ('k') | chrome/nacl/nacl_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698