Chromium Code Reviews| Index: remoting/host/native_messaging/native_messaging_reader.cc |
| diff --git a/remoting/host/native_messaging/native_messaging_reader.cc b/remoting/host/native_messaging/native_messaging_reader.cc |
| index 23f6eb2f6fab5073d0951343abe170c26371d7ab..f0559ad4a0fb6a7533d99cdbd927e54edb69ba98 100644 |
| --- a/remoting/host/native_messaging/native_messaging_reader.cc |
| +++ b/remoting/host/native_messaging/native_messaging_reader.cc |
| @@ -4,8 +4,7 @@ |
| #include "remoting/host/native_messaging/native_messaging_reader.h" |
| -#include <stdint.h> |
| - |
| +#include <cstdint> |
| #include <string> |
| #include <utility> |
| @@ -17,9 +16,17 @@ |
| #include "base/sequenced_task_runner.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/stl_util.h" |
| -#include "base/threading/sequenced_worker_pool.h" |
| +#include "base/threading/thread.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/values.h" |
| +#include "build/build_config.h" |
| + |
| +#if defined(OS_WIN) |
| +#include <windows.h> |
| + |
| +#include "base/threading/platform_thread.h" |
| +#include "base/win/scoped_handle.h" |
| +#endif // defined(OS_WIN) |
| namespace { |
| @@ -137,7 +144,10 @@ void NativeMessagingReader::Core::NotifyEof() { |
| NativeMessagingReader::NativeMessagingReader(base::File file) |
| : reader_thread_("Reader"), |
| weak_factory_(this) { |
| - reader_thread_.Start(); |
| + base::Thread::Options options; |
|
Sergey Ulanov
2016/08/09 15:39:58
base::Thread::Options thread_options(base::Message
joedow
2016/08/10 02:49:58
Done.
|
| + options.message_loop_type = base::MessageLoop::TYPE_IO; |
| + reader_thread_.StartWithOptions(options); |
| + |
| read_task_runner_ = reader_thread_.task_runner(); |
| core_.reset(new Core(std::move(file), base::ThreadTaskRunnerHandle::Get(), |
| read_task_runner_, weak_factory_.GetWeakPtr())); |
| @@ -145,6 +155,19 @@ NativeMessagingReader::NativeMessagingReader(base::File file) |
| NativeMessagingReader::~NativeMessagingReader() { |
| read_task_runner_->DeleteSoon(FROM_HERE, core_.release()); |
| + |
| +#if defined(OS_WIN) |
| + base::PlatformThreadId thread_id = reader_thread_.GetThreadId(); |
| + base::win::ScopedHandle thread_handle( |
| + OpenThread(THREAD_TERMINATE, /*bInheritHandle=*/false, thread_id)); |
| + if (!CancelSynchronousIo(thread_handle.Get())) { |
| + // ERROR_NOT_FOUND means there were no pending IO requests so don't treat |
| + // that result as an error. |
| + if (GetLastError() != ERROR_NOT_FOUND) { |
| + PLOG(ERROR) << "CancelSynchronousIo() failed"; |
| + } |
| + } |
| +#endif // defined(OS_WIN) |
| } |
| void NativeMessagingReader::Start(MessageCallback message_callback, |