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

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

Issue 597413002: Mojo: NULL -> nullptr in mojo/system and mojo/embedder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EXPECT_TRUE Created 6 years, 2 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
« no previous file with comments | « mojo/system/raw_channel_unittest.cc ('k') | mojo/system/remote_message_pipe_unittest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <windows.h> 7 #include <windows.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 typedef BOOL(WINAPI* CancelIoExFunc)(HANDLE, LPOVERLAPPED); 43 typedef BOOL(WINAPI* CancelIoExFunc)(HANDLE, LPOVERLAPPED);
44 44
45 bool is_vista_or_higher_; 45 bool is_vista_or_higher_;
46 SetFileCompletionNotificationModesFunc 46 SetFileCompletionNotificationModesFunc
47 set_file_completion_notification_modes_; 47 set_file_completion_notification_modes_;
48 CancelIoExFunc cancel_io_ex_; 48 CancelIoExFunc cancel_io_ex_;
49 }; 49 };
50 50
51 VistaOrHigherFunctions::VistaOrHigherFunctions() 51 VistaOrHigherFunctions::VistaOrHigherFunctions()
52 : is_vista_or_higher_(base::win::GetVersion() >= base::win::VERSION_VISTA), 52 : is_vista_or_higher_(base::win::GetVersion() >= base::win::VERSION_VISTA),
53 set_file_completion_notification_modes_(NULL), 53 set_file_completion_notification_modes_(nullptr),
54 cancel_io_ex_(NULL) { 54 cancel_io_ex_(nullptr) {
55 if (!is_vista_or_higher_) 55 if (!is_vista_or_higher_)
56 return; 56 return;
57 57
58 HMODULE module = GetModuleHandleW(L"kernel32.dll"); 58 HMODULE module = GetModuleHandleW(L"kernel32.dll");
59 set_file_completion_notification_modes_ = 59 set_file_completion_notification_modes_ =
60 reinterpret_cast<SetFileCompletionNotificationModesFunc>( 60 reinterpret_cast<SetFileCompletionNotificationModesFunc>(
61 GetProcAddress(module, "SetFileCompletionNotificationModes")); 61 GetProcAddress(module, "SetFileCompletionNotificationModes"));
62 DCHECK(set_file_completion_notification_modes_); 62 DCHECK(set_file_completion_notification_modes_);
63 63
64 cancel_io_ex_ = 64 cancel_io_ex_ =
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 DCHECK(owner_); 272 DCHECK(owner_);
273 DCHECK_EQ(base::MessageLoop::current(), owner_->message_loop_for_io()); 273 DCHECK_EQ(base::MessageLoop::current(), owner_->message_loop_for_io());
274 owner_->write_lock().AssertAcquired(); 274 owner_->write_lock().AssertAcquired();
275 275
276 // If read/write is pending, we have to retain the corresponding buffer. 276 // If read/write is pending, we have to retain the corresponding buffer.
277 if (pending_read_) 277 if (pending_read_)
278 preserved_read_buffer_after_detach_ = read_buffer.Pass(); 278 preserved_read_buffer_after_detach_ = read_buffer.Pass();
279 if (pending_write_) 279 if (pending_write_)
280 preserved_write_buffer_after_detach_ = write_buffer.Pass(); 280 preserved_write_buffer_after_detach_ = write_buffer.Pass();
281 281
282 owner_ = NULL; 282 owner_ = nullptr;
283 if (ShouldSelfDestruct()) 283 if (ShouldSelfDestruct())
284 delete this; 284 delete this;
285 } 285 }
286 286
287 bool RawChannelWin::RawChannelIOHandler::ShouldSelfDestruct() const { 287 bool RawChannelWin::RawChannelIOHandler::ShouldSelfDestruct() const {
288 if (owner_ || suppress_self_destruct_) 288 if (owner_ || suppress_self_destruct_)
289 return false; 289 return false;
290 290
291 // Note: Detached, hence no lock needed for |pending_write_|. 291 // Note: Detached, hence no lock needed for |pending_write_|.
292 return !pending_read_ && !pending_write_; 292 return !pending_read_ && !pending_write_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } else if (error == ERROR_BROKEN_PIPE) { 340 } else if (error == ERROR_BROKEN_PIPE) {
341 owner_->OnWriteCompleted(IO_FAILED_SHUTDOWN, 0, 0); 341 owner_->OnWriteCompleted(IO_FAILED_SHUTDOWN, 0, 0);
342 } else { 342 } else {
343 LOG(WARNING) << "WriteFile: " << logging::SystemErrorCodeToString(error); 343 LOG(WARNING) << "WriteFile: " << logging::SystemErrorCodeToString(error);
344 owner_->OnWriteCompleted(IO_FAILED_UNKNOWN, 0, 0); 344 owner_->OnWriteCompleted(IO_FAILED_UNKNOWN, 0, 0);
345 } 345 }
346 } 346 }
347 347
348 RawChannelWin::RawChannelWin(embedder::ScopedPlatformHandle handle) 348 RawChannelWin::RawChannelWin(embedder::ScopedPlatformHandle handle)
349 : handle_(handle.Pass()), 349 : handle_(handle.Pass()),
350 io_handler_(NULL), 350 io_handler_(nullptr),
351 skip_completion_port_on_success_( 351 skip_completion_port_on_success_(
352 g_vista_or_higher_functions.Get().is_vista_or_higher()) { 352 g_vista_or_higher_functions.Get().is_vista_or_higher()) {
353 DCHECK(handle_.is_valid()); 353 DCHECK(handle_.is_valid());
354 } 354 }
355 355
356 RawChannelWin::~RawChannelWin() { 356 RawChannelWin::~RawChannelWin() {
357 DCHECK(!io_handler_); 357 DCHECK(!io_handler_);
358 } 358 }
359 359
360 size_t RawChannelWin::GetSerializedPlatformHandleSize() const { 360 size_t RawChannelWin::GetSerializedPlatformHandleSize() const {
361 // TODO(vtl): Implement. 361 // TODO(vtl): Implement.
362 return 0; 362 return 0;
363 } 363 }
364 364
365 RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) { 365 RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) {
366 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); 366 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io());
367 DCHECK(io_handler_); 367 DCHECK(io_handler_);
368 DCHECK(!io_handler_->pending_read()); 368 DCHECK(!io_handler_->pending_read());
369 369
370 char* buffer = NULL; 370 char* buffer = nullptr;
371 size_t bytes_to_read = 0; 371 size_t bytes_to_read = 0;
372 read_buffer()->GetBuffer(&buffer, &bytes_to_read); 372 read_buffer()->GetBuffer(&buffer, &bytes_to_read);
373 373
374 DWORD bytes_read_dword = 0; 374 DWORD bytes_read_dword = 0;
375 BOOL result = ReadFile(io_handler_->handle(), 375 BOOL result = ReadFile(io_handler_->handle(),
376 buffer, 376 buffer,
377 static_cast<DWORD>(bytes_to_read), 377 static_cast<DWORD>(bytes_to_read),
378 &bytes_read_dword, 378 &bytes_read_dword,
379 &io_handler_->read_context()->overlapped); 379 &io_handler_->read_context()->overlapped);
380 if (!result) { 380 if (!result) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 DCHECK(io_handler_); 546 DCHECK(io_handler_);
547 547
548 write_lock().AssertAcquired(); 548 write_lock().AssertAcquired();
549 549
550 if (io_handler_->pending_read() || io_handler_->pending_write_no_lock()) { 550 if (io_handler_->pending_read() || io_handler_->pending_write_no_lock()) {
551 // |io_handler_| will be alive until pending read/write (if any) completes. 551 // |io_handler_| will be alive until pending read/write (if any) completes.
552 // Call |CancelIoEx()| or |CancelIo()| so that resources can be freed up as 552 // Call |CancelIoEx()| or |CancelIo()| so that resources can be freed up as
553 // soon as possible. 553 // soon as possible.
554 // Note: |CancelIo()| only cancels read/write requests started from this 554 // Note: |CancelIo()| only cancels read/write requests started from this
555 // thread. 555 // thread.
556 if (g_vista_or_higher_functions.Get().is_vista_or_higher()) 556 if (g_vista_or_higher_functions.Get().is_vista_or_higher()) {
557 g_vista_or_higher_functions.Get().CancelIoEx(io_handler_->handle(), NULL); 557 g_vista_or_higher_functions.Get().CancelIoEx(io_handler_->handle(),
558 else 558 nullptr);
559 } else {
559 CancelIo(io_handler_->handle()); 560 CancelIo(io_handler_->handle());
561 }
560 } 562 }
561 563
562 io_handler_->DetachFromOwnerNoLock(read_buffer.Pass(), write_buffer.Pass()); 564 io_handler_->DetachFromOwnerNoLock(read_buffer.Pass(), write_buffer.Pass());
563 io_handler_ = NULL; 565 io_handler_ = nullptr;
564 } 566 }
565 567
566 } // namespace 568 } // namespace
567 569
568 // ----------------------------------------------------------------------------- 570 // -----------------------------------------------------------------------------
569 571
570 // Static factory method declared in raw_channel.h. 572 // Static factory method declared in raw_channel.h.
571 // static 573 // static
572 scoped_ptr<RawChannel> RawChannel::Create( 574 scoped_ptr<RawChannel> RawChannel::Create(
573 embedder::ScopedPlatformHandle handle) { 575 embedder::ScopedPlatformHandle handle) {
574 return scoped_ptr<RawChannel>(new RawChannelWin(handle.Pass())); 576 return scoped_ptr<RawChannel>(new RawChannelWin(handle.Pass()));
575 } 577 }
576 578
577 } // namespace system 579 } // namespace system
578 } // namespace mojo 580 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/raw_channel_unittest.cc ('k') | mojo/system/remote_message_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698