| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/process/kill.h" | 14 #include "base/process/kill.h" |
| 15 #include "base/task_scheduler/post_task.h" | 15 #include "base/task_scheduler/post_task.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | |
| 17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 18 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" | 17 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
.h" |
| 19 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" | 18 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" |
| 20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 21 #include "extensions/common/constants.h" | 20 #include "extensions/common/constants.h" |
| 22 #include "extensions/common/features/feature.h" | 21 #include "extensions/common/features/feature.h" |
| 23 #include "net/base/file_stream.h" | 22 #include "net/base/file_stream.h" |
| 24 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| 25 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 26 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 64 |
| 66 NativeMessageProcessHost::~NativeMessageProcessHost() { | 65 NativeMessageProcessHost::~NativeMessageProcessHost() { |
| 67 DCHECK(task_runner_->BelongsToCurrentThread()); | 66 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 68 | 67 |
| 69 if (process_.IsValid()) { | 68 if (process_.IsValid()) { |
| 70 // Kill the host process if necessary to make sure we don't leave zombies. | 69 // Kill the host process if necessary to make sure we don't leave zombies. |
| 71 // On OSX base::EnsureProcessTerminated() may block, so we have to post a | 70 // On OSX base::EnsureProcessTerminated() may block, so we have to post a |
| 72 // task on the blocking pool. | 71 // task on the blocking pool. |
| 73 #if defined(OS_MACOSX) | 72 #if defined(OS_MACOSX) |
| 74 base::PostTaskWithTraits( | 73 base::PostTaskWithTraits( |
| 75 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 74 FROM_HERE, |
| 76 base::TaskPriority::BACKGROUND), | 75 base::TaskTraits().MayBlock().WithPriority( |
| 77 base::Bind(&base::EnsureProcessTerminated, Passed(&process_))); | 76 base::TaskPriority::BACKGROUND), |
| 77 base::BindOnce(&base::EnsureProcessTerminated, Passed(&process_))); |
| 78 #else | 78 #else |
| 79 base::EnsureProcessTerminated(std::move(process_)); | 79 base::EnsureProcessTerminated(std::move(process_)); |
| 80 #endif | 80 #endif |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 // static | 84 // static |
| 85 std::unique_ptr<NativeMessageHost> NativeMessageHost::Create( | 85 std::unique_ptr<NativeMessageHost> NativeMessageHost::Create( |
| 86 gfx::NativeView native_view, | 86 gfx::NativeView native_view, |
| 87 const std::string& source_extension_id, | 87 const std::string& source_extension_id, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 case NativeProcessLauncher::RESULT_SUCCESS: | 139 case NativeProcessLauncher::RESULT_SUCCESS: |
| 140 break; | 140 break; |
| 141 } | 141 } |
| 142 | 142 |
| 143 process_ = std::move(process); | 143 process_ = std::move(process); |
| 144 #if defined(OS_POSIX) | 144 #if defined(OS_POSIX) |
| 145 // This object is not the owner of the file so it should not keep an fd. | 145 // This object is not the owner of the file so it should not keep an fd. |
| 146 read_file_ = read_file.GetPlatformFile(); | 146 read_file_ = read_file.GetPlatformFile(); |
| 147 #endif | 147 #endif |
| 148 | 148 |
| 149 scoped_refptr<base::TaskRunner> task_runner( | 149 scoped_refptr<base::TaskRunner> task_runner(base::CreateTaskRunnerWithTraits( |
| 150 content::BrowserThread::GetBlockingPool()-> | 150 base::TaskTraits() |
| 151 GetTaskRunnerWithShutdownBehavior( | 151 .MayBlock() |
| 152 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 152 .WithPriority(base::TaskPriority::USER_VISIBLE) |
| 153 .WithShutdownBehavior(base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN))); |
| 153 | 154 |
| 154 read_stream_.reset(new net::FileStream(std::move(read_file), task_runner)); | 155 read_stream_.reset(new net::FileStream(std::move(read_file), task_runner)); |
| 155 write_stream_.reset(new net::FileStream(std::move(write_file), task_runner)); | 156 write_stream_.reset(new net::FileStream(std::move(write_file), task_runner)); |
| 156 | 157 |
| 157 WaitRead(); | 158 WaitRead(); |
| 158 DoWrite(); | 159 DoWrite(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 void NativeMessageProcessHost::OnMessage(const std::string& json) { | 162 void NativeMessageProcessHost::OnMessage(const std::string& json) { |
| 162 DCHECK(task_runner_->BelongsToCurrentThread()); | 163 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 353 |
| 353 if (!closed_) { | 354 if (!closed_) { |
| 354 closed_ = true; | 355 closed_ = true; |
| 355 read_stream_.reset(); | 356 read_stream_.reset(); |
| 356 write_stream_.reset(); | 357 write_stream_.reset(); |
| 357 client_->CloseChannel(error_message); | 358 client_->CloseChannel(error_message); |
| 358 } | 359 } |
| 359 } | 360 } |
| 360 | 361 |
| 361 } // namespace extensions | 362 } // namespace extensions |
| OLD | NEW |