diff options
author | rvargas <rvargas@chromium.org> | 2014-09-23 15:03:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-23 22:03:36 +0000 |
commit | ecaef8a307d1bc5e48adbdc9234c92c902b8843b (patch) | |
tree | 96a3f45f6d05e9e35e9ed361f02e2cb2a794bb1d /base | |
parent | c0eeabce5a81bd4a011f27b082f970abb55568d8 (diff) | |
download | chromium_src-ecaef8a307d1bc5e48adbdc9234c92c902b8843b.zip chromium_src-ecaef8a307d1bc5e48adbdc9234c92c902b8843b.tar.gz chromium_src-ecaef8a307d1bc5e48adbdc9234c92c902b8843b.tar.bz2 |
Remove implicit HANDLE conversions from base.
BUG=416722
R=brettw@chromium.org
Review URL: https://codereview.chromium.org/593113004
Cr-Commit-Position: refs/heads/master@{#296276}
Diffstat (limited to 'base')
-rw-r--r-- | base/debug/gdi_debug_util_win.cc | 2 | ||||
-rw-r--r-- | base/files/file_util_unittest.cc | 4 | ||||
-rw-r--r-- | base/files/file_util_win.cc | 16 | ||||
-rw-r--r-- | base/files/file_win.cc | 31 | ||||
-rw-r--r-- | base/message_loop/message_loop_unittest.cc | 24 | ||||
-rw-r--r-- | base/message_loop/message_pump_win.cc | 6 | ||||
-rw-r--r-- | base/sync_socket_win.cc | 2 | ||||
-rw-r--r-- | base/test/test_file_util_win.cc | 18 | ||||
-rw-r--r-- | base/win/event_trace_consumer_unittest.cc | 20 |
9 files changed, 63 insertions, 60 deletions
diff --git a/base/debug/gdi_debug_util_win.cc b/base/debug/gdi_debug_util_win.cc index 4bac759..ddd4106 100644 --- a/base/debug/gdi_debug_util_win.cc +++ b/base/debug/gdi_debug_util_win.cc @@ -41,7 +41,7 @@ void CollectChildGDIUsageAndDie(DWORD parent_pid) { ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, proc_entry.th32ParentProcessID)); - if (!process) + if (!process.IsValid()) continue; int num_gdi_handles = ::GetGuiResources(process.Get(), GR_GDIOBJECTS); diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc index e085aef..47dec30 100644 --- a/base/files/file_util_unittest.cc +++ b/base/files/file_util_unittest.cc @@ -139,12 +139,12 @@ class ReparsePoint { OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. NULL)); - created_ = dir_.IsValid() && SetReparsePoint(dir_, target); + created_ = dir_.IsValid() && SetReparsePoint(dir_.Get(), target); } ~ReparsePoint() { if (created_) - DeleteReparsePoint(dir_); + DeleteReparsePoint(dir_.Get()); } bool IsValid() { return created_; } diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc index 82b53c5..b586191 100644 --- a/base/files/file_util_win.cc +++ b/base/files/file_util_win.cc @@ -504,7 +504,7 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); - if (!file_handle) + if (!file_handle.IsValid()) return false; // Create a file mapping object. Can't easily use MemoryMappedFile, because @@ -517,7 +517,7 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) { 0, 1, // Just one byte. No need to look at the data. NULL)); - if (!file_map_handle) + if (!file_map_handle.IsValid()) return false; // Use a view of the file to get the path to the file. @@ -602,11 +602,11 @@ int ReadFile(const FilePath& filename, char* data, int max_size) { OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL)); - if (!file) + if (!file.IsValid()) return -1; DWORD read; - if (::ReadFile(file, data, max_size, &read, NULL)) + if (::ReadFile(file.Get(), data, max_size, &read, NULL)) return read; return -1; @@ -621,14 +621,14 @@ int WriteFile(const FilePath& filename, const char* data, int size) { CREATE_ALWAYS, 0, NULL)); - if (!file) { + if (!file.IsValid()) { DPLOG(WARNING) << "CreateFile failed for path " << UTF16ToUTF8(filename.value()); return -1; } DWORD written; - BOOL result = ::WriteFile(file, data, size, &written, NULL); + BOOL result = ::WriteFile(file.Get(), data, size, &written, NULL); if (result && static_cast<int>(written) == size) return written; @@ -653,14 +653,14 @@ int AppendToFile(const FilePath& filename, const char* data, int size) { OPEN_EXISTING, 0, NULL)); - if (!file) { + if (!file.IsValid()) { DPLOG(WARNING) << "CreateFile failed for path " << UTF16ToUTF8(filename.value()); return -1; } DWORD written; - BOOL result = ::WriteFile(file, data, size, &written, NULL); + BOOL result = ::WriteFile(file.Get(), data, size, &written, NULL); if (result && static_cast<int>(written) == size) return written; diff --git a/base/files/file_win.cc b/base/files/file_win.cc index e9a7b4c..727b5ce 100644 --- a/base/files/file_win.cc +++ b/base/files/file_win.cc @@ -107,7 +107,7 @@ bool File::IsValid() const { } PlatformFile File::GetPlatformFile() const { - return file_; + return file_.Get(); } PlatformFile File::TakePlatformFile() { @@ -128,7 +128,7 @@ int64 File::Seek(Whence whence, int64 offset) { LARGE_INTEGER distance, res; distance.QuadPart = offset; DWORD move_method = static_cast<DWORD>(whence); - if (!SetFilePointerEx(file_, distance, &res, move_method)) + if (!SetFilePointerEx(file_.Get(), distance, &res, move_method)) return -1; return res.QuadPart; } @@ -148,7 +148,7 @@ int File::Read(int64 offset, char* data, int size) { overlapped.OffsetHigh = offset_li.HighPart; DWORD bytes_read; - if (::ReadFile(file_, data, size, &bytes_read, &overlapped)) + if (::ReadFile(file_.Get(), data, size, &bytes_read, &overlapped)) return bytes_read; if (ERROR_HANDLE_EOF == GetLastError()) return 0; @@ -164,7 +164,7 @@ int File::ReadAtCurrentPos(char* data, int size) { return -1; DWORD bytes_read; - if (::ReadFile(file_, data, size, &bytes_read, NULL)) + if (::ReadFile(file_.Get(), data, size, &bytes_read, NULL)) return bytes_read; if (ERROR_HANDLE_EOF == GetLastError()) return 0; @@ -193,7 +193,7 @@ int File::Write(int64 offset, const char* data, int size) { overlapped.OffsetHigh = offset_li.HighPart; DWORD bytes_written; - if (::WriteFile(file_, data, size, &bytes_written, &overlapped)) + if (::WriteFile(file_.Get(), data, size, &bytes_written, &overlapped)) return bytes_written; return -1; @@ -207,7 +207,7 @@ int File::WriteAtCurrentPos(const char* data, int size) { return -1; DWORD bytes_written; - if (::WriteFile(file_, data, size, &bytes_written, NULL)) + if (::WriteFile(file_.Get(), data, size, &bytes_written, NULL)) return bytes_written; return -1; @@ -235,14 +235,14 @@ bool File::SetLength(int64 length) { LARGE_INTEGER file_pointer; LARGE_INTEGER zero; zero.QuadPart = 0; - if (!::SetFilePointerEx(file_, zero, &file_pointer, FILE_CURRENT)) + if (!::SetFilePointerEx(file_.Get(), zero, &file_pointer, FILE_CURRENT)) return false; LARGE_INTEGER length_li; length_li.QuadPart = length; // If length > file size, SetFilePointerEx() should extend the file // with zeroes on all Windows standard file systems (NTFS, FATxx). - if (!::SetFilePointerEx(file_, length_li, NULL, FILE_BEGIN)) + if (!::SetFilePointerEx(file_.Get(), length_li, NULL, FILE_BEGIN)) return false; // Set the new file length and move the file pointer to its old position. @@ -251,14 +251,15 @@ bool File::SetLength(int64 length) { // TODO(rvargas): Emulating ftruncate details seem suspicious and it is not // promised by the interface (nor was promised by PlatformFile). See if this // implementation detail can be removed. - return ((::SetEndOfFile(file_) != FALSE) && - (::SetFilePointerEx(file_, file_pointer, NULL, FILE_BEGIN) != FALSE)); + return ((::SetEndOfFile(file_.Get()) != FALSE) && + (::SetFilePointerEx(file_.Get(), file_pointer, NULL, FILE_BEGIN) != + FALSE)); } bool File::Flush() { base::ThreadRestrictions::AssertIOAllowed(); DCHECK(IsValid()); - return ::FlushFileBuffers(file_) != FALSE; + return ::FlushFileBuffers(file_.Get()) != FALSE; } bool File::SetTimes(Time last_access_time, Time last_modified_time) { @@ -267,7 +268,7 @@ bool File::SetTimes(Time last_access_time, Time last_modified_time) { FILETIME last_access_filetime = last_access_time.ToFileTime(); FILETIME last_modified_filetime = last_modified_time.ToFileTime(); - return (::SetFileTime(file_, NULL, &last_access_filetime, + return (::SetFileTime(file_.Get(), NULL, &last_access_filetime, &last_modified_filetime) != FALSE); } @@ -276,7 +277,7 @@ bool File::GetInfo(Info* info) { DCHECK(IsValid()); BY_HANDLE_FILE_INFORMATION file_info; - if (!GetFileInformationByHandle(file_, &file_info)) + if (!GetFileInformationByHandle(file_.Get(), &file_info)) return false; LARGE_INTEGER size; @@ -294,7 +295,7 @@ bool File::GetInfo(Info* info) { File::Error base::File::Lock() { DCHECK(IsValid()); - BOOL result = LockFile(file_, 0, 0, MAXDWORD, MAXDWORD); + BOOL result = LockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); if (!result) return OSErrorToFileError(GetLastError()); return FILE_OK; @@ -302,7 +303,7 @@ File::Error base::File::Lock() { File::Error File::Unlock() { DCHECK(IsValid()); - BOOL result = UnlockFile(file_, 0, 0, MAXDWORD, MAXDWORD); + BOOL result = UnlockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); if (!result) return OSErrorToFileError(GetLastError()); return FILE_OK; diff --git a/base/message_loop/message_loop_unittest.cc b/base/message_loop/message_loop_unittest.cc index 0a6e817..b07ba0e0 100644 --- a/base/message_loop/message_loop_unittest.cc +++ b/base/message_loop/message_loop_unittest.cc @@ -333,7 +333,7 @@ void RunTest_RecursiveDenial2(MessageLoop::Type message_loop_type) { &order, false)); // Let the other thread execute. - WaitForSingleObject(event, INFINITE); + WaitForSingleObject(event.Get(), INFINITE); MessageLoop::current()->Run(); ASSERT_EQ(order.Size(), 17); @@ -377,7 +377,7 @@ void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) { &order, true)); // Let the other thread execute. - WaitForSingleObject(event, INFINITE); + WaitForSingleObject(event.Get(), INFINITE); MessageLoop::current()->Run(); ASSERT_EQ(order.Size(), 18); @@ -517,10 +517,10 @@ TestIOHandler::TestIOHandler(const wchar_t* name, HANDLE signal, bool wait) } void TestIOHandler::Init() { - MessageLoopForIO::current()->RegisterIOHandler(file_, this); + MessageLoopForIO::current()->RegisterIOHandler(file_.Get(), this); DWORD read; - EXPECT_FALSE(ReadFile(file_, buffer_, size(), &read, context())); + EXPECT_FALSE(ReadFile(file_.Get(), buffer_, size(), &read, context())); EXPECT_EQ(ERROR_IO_PENDING, GetLastError()); if (wait_) WaitForIO(); @@ -554,7 +554,7 @@ void RunTest_IOHandler() { MessageLoop* thread_loop = thread.message_loop(); ASSERT_TRUE(NULL != thread_loop); - TestIOHandler handler(kPipeName, callback_called, false); + TestIOHandler handler(kPipeName, callback_called.Get(), false); thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler))); // Make sure the thread runs and sleeps for lack of work. @@ -562,9 +562,9 @@ void RunTest_IOHandler() { const char buffer[] = "Hello there!"; DWORD written; - EXPECT_TRUE(WriteFile(server, buffer, sizeof(buffer), &written, NULL)); + EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL)); - DWORD result = WaitForSingleObject(callback_called, 1000); + DWORD result = WaitForSingleObject(callback_called.Get(), 1000); EXPECT_EQ(WAIT_OBJECT_0, result); thread.Stop(); @@ -595,8 +595,8 @@ void RunTest_WaitForIO() { MessageLoop* thread_loop = thread.message_loop(); ASSERT_TRUE(NULL != thread_loop); - TestIOHandler handler1(kPipeName1, callback1_called, false); - TestIOHandler handler2(kPipeName2, callback2_called, true); + TestIOHandler handler1(kPipeName1, callback1_called.Get(), false); + TestIOHandler handler2(kPipeName2, callback2_called.Get(), true); thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler1))); // TODO(ajwong): Do we really need such long Sleeps in ths function? @@ -612,12 +612,12 @@ void RunTest_WaitForIO() { const char buffer[] = "Hello there!"; DWORD written; - EXPECT_TRUE(WriteFile(server1, buffer, sizeof(buffer), &written, NULL)); + EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); PlatformThread::Sleep(2 * delay); - EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called, 0)) << + EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called.Get(), 0)) << "handler1 has not been called"; - EXPECT_TRUE(WriteFile(server2, buffer, sizeof(buffer), &written, NULL)); + EXPECT_TRUE(WriteFile(server2.Get(), buffer, sizeof(buffer), &written, NULL)); HANDLE objects[2] = { callback1_called.Get(), callback2_called.Get() }; DWORD result = WaitForMultipleObjects(2, objects, TRUE, 1000); diff --git a/base/message_loop/message_pump_win.cc b/base/message_loop/message_pump_win.cc index ad42226..ad89b7f 100644 --- a/base/message_loop/message_pump_win.cc +++ b/base/message_loop/message_pump_win.cc @@ -421,7 +421,7 @@ void MessagePumpForIO::ScheduleWork() { return; // Someone else continued the pumping. // Make sure the MessagePump does some work for us. - BOOL ret = PostQueuedCompletionStatus(port_, 0, + BOOL ret = PostQueuedCompletionStatus(port_.Get(), 0, reinterpret_cast<ULONG_PTR>(this), reinterpret_cast<OVERLAPPED*>(this)); if (ret) @@ -443,7 +443,7 @@ void MessagePumpForIO::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { void MessagePumpForIO::RegisterIOHandler(HANDLE file_handle, IOHandler* handler) { ULONG_PTR key = HandlerToKey(handler, true); - HANDLE port = CreateIoCompletionPort(file_handle, port_, key, 1); + HANDLE port = CreateIoCompletionPort(file_handle, port_.Get(), key, 1); DPCHECK(port); } @@ -455,7 +455,7 @@ bool MessagePumpForIO::RegisterJobObject(HANDLE job_handle, ULONG_PTR key = HandlerToKey(handler, false); JOBOBJECT_ASSOCIATE_COMPLETION_PORT info; info.CompletionKey = reinterpret_cast<void*>(key); - info.CompletionPort = port_; + info.CompletionPort = port_.Get(); return SetInformationJobObject(job_handle, JobObjectAssociateCompletionPortInformation, &info, diff --git a/base/sync_socket_win.cc b/base/sync_socket_win.cc index 6b2575c..c07e62a 100644 --- a/base/sync_socket_win.cc +++ b/base/sync_socket_win.cc @@ -85,7 +85,7 @@ bool CreatePairImpl(HANDLE* socket_a, HANDLE* socket_b, bool overlapped) { return false; } - if (!ConnectNamedPipe(handle_a, NULL)) { + if (!ConnectNamedPipe(handle_a.Get(), NULL)) { DWORD error = GetLastError(); if (error != ERROR_PIPE_CONNECTED) { DPLOG(ERROR) << "ConnectNamedPipe failed"; diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc index 94eb3ef..fd22a63 100644 --- a/base/test/test_file_util_win.cc +++ b/base/test/test_file_util_win.cc @@ -136,12 +136,12 @@ bool EvictFileFromSystemCache(const FilePath& file) { base::win::ScopedHandle file_handle( CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); - if (!file_handle) + if (!file_handle.IsValid()) return false; // Get some attributes to restore later. BY_HANDLE_FILE_INFORMATION bhi = {0}; - CHECK(::GetFileInformationByHandle(file_handle, &bhi)); + CHECK(::GetFileInformationByHandle(file_handle.Get(), &bhi)); // Execute in chunks. It could be optimized. We want to do few of these since // these operations will be slow without the cache. @@ -159,7 +159,7 @@ bool EvictFileFromSystemCache(const FilePath& file) { DWORD bytes_read, bytes_written; for (;;) { bytes_read = 0; - ::ReadFile(file_handle, buffer, kOneMB, &bytes_read, NULL); + ::ReadFile(file_handle.Get(), buffer, kOneMB, &bytes_read, NULL); if (bytes_read == 0) break; @@ -176,8 +176,8 @@ bool EvictFileFromSystemCache(const FilePath& file) { // Note that SetFilePointer will also fail if total_bytes isn't sector // aligned, but that shouldn't happen here. DCHECK((total_bytes % kOneMB) == 0); - SetFilePointer(file_handle, total_bytes, NULL, FILE_BEGIN); - if (!::WriteFile(file_handle, buffer, kOneMB, &bytes_written, NULL) || + SetFilePointer(file_handle.Get(), total_bytes, NULL, FILE_BEGIN); + if (!::WriteFile(file_handle.Get(), buffer, kOneMB, &bytes_written, NULL) || bytes_written != kOneMB) { BOOL freed = VirtualFree(buffer, 0, MEM_RELEASE); DCHECK(freed); @@ -202,14 +202,14 @@ bool EvictFileFromSystemCache(const FilePath& file) { file_handle.Set(NULL); file_handle.Set(CreateFile(file.value().c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)); - CHECK_NE(SetFilePointer(file_handle, total_bytes, NULL, FILE_BEGIN), + CHECK_NE(SetFilePointer(file_handle.Get(), total_bytes, NULL, FILE_BEGIN), INVALID_SET_FILE_POINTER); - CHECK(::SetEndOfFile(file_handle)); + CHECK(::SetEndOfFile(file_handle.Get())); } // Restore the file attributes. - CHECK(::SetFileTime(file_handle, &bhi.ftCreationTime, &bhi.ftLastAccessTime, - &bhi.ftLastWriteTime)); + CHECK(::SetFileTime(file_handle.Get(), &bhi.ftCreationTime, + &bhi.ftLastAccessTime, &bhi.ftLastWriteTime)); return true; } diff --git a/base/win/event_trace_consumer_unittest.cc b/base/win/event_trace_consumer_unittest.cc index 3231240..92e91b9 100644 --- a/base/win/event_trace_consumer_unittest.cc +++ b/base/win/event_trace_consumer_unittest.cc @@ -149,13 +149,13 @@ class EtwTraceConsumerRealtimeTest: public EtwTraceConsumerBaseTest { HRESULT StartConsumerThread() { consumer_ready_.Set(::CreateEvent(NULL, TRUE, FALSE, NULL)); - EXPECT_TRUE(consumer_ready_ != NULL); + EXPECT_TRUE(consumer_ready_.IsValid()); consumer_thread_.Set(::CreateThread(NULL, 0, ConsumerThreadMainProc, this, 0, NULL)); if (consumer_thread_.Get() == NULL) return HRESULT_FROM_WIN32(::GetLastError()); - HANDLE events[] = { consumer_ready_, consumer_thread_ }; + HANDLE events[] = { consumer_ready_.Get(), consumer_thread_.Get() }; DWORD result = ::WaitForMultipleObjects(arraysize(events), events, FALSE, INFINITE); switch (result) { @@ -165,10 +165,10 @@ class EtwTraceConsumerRealtimeTest: public EtwTraceConsumerBaseTest { case WAIT_OBJECT_0 + 1: { // The thread finished. This may race with the event, so check // explicitly for the event here, before concluding there's trouble. - if (::WaitForSingleObject(consumer_ready_, 0) == WAIT_OBJECT_0) + if (::WaitForSingleObject(consumer_ready_.Get(), 0) == WAIT_OBJECT_0) return S_OK; DWORD exit_code = 0; - if (::GetExitCodeThread(consumer_thread_, &exit_code)) + if (::GetExitCodeThread(consumer_thread_.Get(), &exit_code)) return exit_code; return HRESULT_FROM_WIN32(::GetLastError()); } @@ -179,11 +179,13 @@ class EtwTraceConsumerRealtimeTest: public EtwTraceConsumerBaseTest { // Waits for consumer_ thread to exit, and returns its exit code. HRESULT JoinConsumerThread() { - if (::WaitForSingleObject(consumer_thread_, INFINITE) != WAIT_OBJECT_0) + if (::WaitForSingleObject(consumer_thread_.Get(), INFINITE) != + WAIT_OBJECT_0) { return HRESULT_FROM_WIN32(::GetLastError()); + } DWORD exit_code = 0; - if (::GetExitCodeThread(consumer_thread_, &exit_code)) + if (::GetExitCodeThread(consumer_thread_.Get(), &exit_code)) return exit_code; return HRESULT_FROM_WIN32(::GetLastError()); @@ -208,7 +210,7 @@ TEST_F(EtwTraceConsumerRealtimeTest, ConsumerReturnsWhenSessionClosed) { ASSERT_HRESULT_SUCCEEDED(StartConsumerThread()); // Wait around for the consumer_ thread a bit. - ASSERT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(consumer_thread_, 50)); + ASSERT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(consumer_thread_.Get(), 50)); ASSERT_HRESULT_SUCCEEDED(controller.Stop(NULL)); // The consumer_ returns success on session stop. @@ -244,8 +246,8 @@ TEST_F(EtwTraceConsumerRealtimeTest, ConsumeEvent) { EtwMofEvent<1> event(kTestEventType, 1, TRACE_LEVEL_ERROR); EXPECT_EQ(ERROR_SUCCESS, provider.Log(&event.header)); - EXPECT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(TestConsumer::sank_event_, - INFINITE)); + EXPECT_EQ(WAIT_OBJECT_0, + ::WaitForSingleObject(TestConsumer::sank_event_.Get(), INFINITE)); ASSERT_HRESULT_SUCCEEDED(controller.Stop(NULL)); ASSERT_HRESULT_SUCCEEDED(JoinConsumerThread()); ASSERT_NE(0u, TestConsumer::events_.size()); |