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

Side by Side Diff: mojo/system/raw_channel.cc

Issue 223783006: Mojo: Make Channel take a RawChannel rather than creating it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: spurious space Created 6 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 | « mojo/system/raw_channel.h ('k') | mojo/system/raw_channel_posix.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/system/raw_channel.h" 5 #include "mojo/system/raw_channel.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 size_t RawChannel::WriteBuffer::GetTotalBytesToWrite() const { 85 size_t RawChannel::WriteBuffer::GetTotalBytesToWrite() const {
86 if (message_queue_.empty()) 86 if (message_queue_.empty())
87 return 0; 87 return 0;
88 88
89 MessageInTransit* message = message_queue_.front(); 89 MessageInTransit* message = message_queue_.front();
90 DCHECK_LT(offset_, message->total_size()); 90 DCHECK_LT(offset_, message->total_size());
91 return message->total_size() - offset_; 91 return message->total_size() - offset_;
92 } 92 }
93 93
94 RawChannel::RawChannel(Delegate* delegate, 94 RawChannel::RawChannel()
95 base::MessageLoopForIO* message_loop_for_io) 95 : delegate_(NULL),
96 : delegate_(delegate), 96 message_loop_for_io_(NULL),
97 message_loop_for_io_(message_loop_for_io),
98 read_stopped_(false), 97 read_stopped_(false),
99 write_stopped_(false), 98 write_stopped_(false),
100 weak_ptr_factory_(this) { 99 weak_ptr_factory_(this) {
101 } 100 }
102 101
103 RawChannel::~RawChannel() { 102 RawChannel::~RawChannel() {
104 DCHECK(!read_buffer_); 103 DCHECK(!read_buffer_);
105 DCHECK(!write_buffer_); 104 DCHECK(!write_buffer_);
106 105
107 // No need to take the |write_lock_| here -- if there are still weak pointers 106 // No need to take the |write_lock_| here -- if there are still weak pointers
108 // outstanding, then we're hosed anyway (since we wouldn't be able to 107 // outstanding, then we're hosed anyway (since we wouldn't be able to
109 // invalidate them cleanly, since we might not be on the I/O thread). 108 // invalidate them cleanly, since we might not be on the I/O thread).
110 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); 109 DCHECK(!weak_ptr_factory_.HasWeakPtrs());
111 } 110 }
112 111
113 bool RawChannel::Init() { 112 bool RawChannel::Init(Delegate* delegate) {
114 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io_); 113 DCHECK(delegate);
114
115 DCHECK(!delegate_);
116 delegate_ = delegate;
117
118 CHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_IO);
119 DCHECK(!message_loop_for_io_);
120 message_loop_for_io_ =
121 static_cast<base::MessageLoopForIO*>(base::MessageLoop::current());
115 122
116 // No need to take the lock. No one should be using us yet. 123 // No need to take the lock. No one should be using us yet.
117 DCHECK(!read_buffer_); 124 DCHECK(!read_buffer_);
118 read_buffer_.reset(new ReadBuffer); 125 read_buffer_.reset(new ReadBuffer);
119 DCHECK(!write_buffer_); 126 DCHECK(!write_buffer_);
120 write_buffer_.reset(new WriteBuffer); 127 write_buffer_.reset(new WriteBuffer);
121 128
122 if (!OnInit()) 129 if (!OnInit())
123 return false; 130 return false;
124 131
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 350 }
344 351
345 write_stopped_ = true; 352 write_stopped_ = true;
346 STLDeleteElements(&write_buffer_->message_queue_); 353 STLDeleteElements(&write_buffer_->message_queue_);
347 write_buffer_->offset_ = 0; 354 write_buffer_->offset_ = 0;
348 return false; 355 return false;
349 } 356 }
350 357
351 } // namespace system 358 } // namespace system
352 } // namespace mojo 359 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/raw_channel.h ('k') | mojo/system/raw_channel_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698