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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host.cc

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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
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/browser/extensions/api/messaging/native_message_process_host.h" 5 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 DoRead(); 208 DoRead();
209 #endif // defined(!OS_POSIX) 209 #endif // defined(!OS_POSIX)
210 } 210 }
211 211
212 void NativeMessageProcessHost::DoRead() { 212 void NativeMessageProcessHost::DoRead() {
213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
214 214
215 while (!closed_ && !read_eof_ && !read_pending_) { 215 while (!closed_ && !read_eof_ && !read_pending_) {
216 read_buffer_ = new net::IOBuffer(kReadBufferSize); 216 read_buffer_ = new net::IOBuffer(kReadBufferSize);
217 int result = read_stream_->Read( 217 int result = read_stream_->Read(
218 read_buffer_, kReadBufferSize, 218 read_buffer_.get(),
219 base::Bind(&NativeMessageProcessHost::OnRead, 219 kReadBufferSize,
220 base::Unretained(this))); 220 base::Bind(&NativeMessageProcessHost::OnRead, base::Unretained(this)));
221 HandleReadResult(result); 221 HandleReadResult(result);
222 } 222 }
223 } 223 }
224 224
225 void NativeMessageProcessHost::OnRead(int result) { 225 void NativeMessageProcessHost::OnRead(int result) {
226 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 226 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
227 DCHECK(read_pending_); 227 DCHECK(read_pending_);
228 read_pending_ = false; 228 read_pending_ = false;
229 229
230 HandleReadResult(result); 230 HandleReadResult(result);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 base::Passed(&message))); 303 base::Passed(&message)));
304 304
305 incoming_data_.erase(0, kMessageHeaderSize + message_size); 305 incoming_data_.erase(0, kMessageHeaderSize + message_size);
306 } 306 }
307 } 307 }
308 308
309 void NativeMessageProcessHost::DoWrite() { 309 void NativeMessageProcessHost::DoWrite() {
310 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 310 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
311 311
312 while (!write_pending_ && !closed_) { 312 while (!write_pending_ && !closed_) {
313 if (!current_write_buffer_ || !current_write_buffer_->BytesRemaining()) { 313 if (!current_write_buffer_.get() ||
314 !current_write_buffer_->BytesRemaining()) {
314 if (write_queue_.empty()) 315 if (write_queue_.empty())
315 return; 316 return;
316 current_write_buffer_ = new net::DrainableIOBuffer( 317 current_write_buffer_ = new net::DrainableIOBuffer(
317 write_queue_.front(), write_queue_.front()->size()); 318 write_queue_.front().get(), write_queue_.front()->size());
318 write_queue_.pop(); 319 write_queue_.pop();
319 } 320 }
320 321
321 int result = write_stream_->Write( 322 int result =
322 current_write_buffer_, current_write_buffer_->BytesRemaining(), 323 write_stream_->Write(current_write_buffer_.get(),
323 base::Bind(&NativeMessageProcessHost::OnWritten, 324 current_write_buffer_->BytesRemaining(),
324 base::Unretained(this))); 325 base::Bind(&NativeMessageProcessHost::OnWritten,
326 base::Unretained(this)));
325 HandleWriteResult(result); 327 HandleWriteResult(result);
326 } 328 }
327 } 329 }
328 330
329 void NativeMessageProcessHost::HandleWriteResult(int result) { 331 void NativeMessageProcessHost::HandleWriteResult(int result) {
330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 332 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
331 333
332 if (result <= 0) { 334 if (result <= 0) {
333 if (result == net::ERR_IO_PENDING) { 335 if (result == net::ERR_IO_PENDING) {
334 write_pending_ = true; 336 write_pending_ = true;
(...skipping 24 matching lines...) Expand all
359 closed_ = true; 361 closed_ = true;
360 read_stream_.reset(); 362 read_stream_.reset();
361 write_stream_.reset(); 363 write_stream_.reset();
362 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 364 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
363 base::Bind(&Client::CloseChannel, weak_client_ui_, 365 base::Bind(&Client::CloseChannel, weak_client_ui_,
364 destination_port_, error_message)); 366 destination_port_, error_message));
365 } 367 }
366 } 368 }
367 369
368 } // namespace extensions 370 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698