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 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 NativeMessageProcessHost::~NativeMessageProcessHost() { | 65 NativeMessageProcessHost::~NativeMessageProcessHost() { |
66 DCHECK(task_runner_->BelongsToCurrentThread()); | 66 DCHECK(task_runner_->BelongsToCurrentThread()); |
67 | 67 |
68 if (process_.IsValid()) { | 68 if (process_.IsValid()) { |
69 // 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. |
70 // 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 |
71 // task on the blocking pool. | 71 // task on the blocking pool. |
72 #if defined(OS_MACOSX) | 72 #if defined(OS_MACOSX) |
73 base::PostTaskWithTraits( | 73 base::PostTaskWithTraits( |
74 FROM_HERE, | 74 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
75 base::TaskTraits().MayBlock().WithPriority( | |
76 base::TaskPriority::BACKGROUND), | |
77 base::BindOnce(&base::EnsureProcessTerminated, Passed(&process_))); | 75 base::BindOnce(&base::EnsureProcessTerminated, Passed(&process_))); |
78 #else | 76 #else |
79 base::EnsureProcessTerminated(std::move(process_)); | 77 base::EnsureProcessTerminated(std::move(process_)); |
80 #endif | 78 #endif |
81 } | 79 } |
82 } | 80 } |
83 | 81 |
84 // static | 82 // static |
85 std::unique_ptr<NativeMessageHost> NativeMessageHost::Create( | 83 std::unique_ptr<NativeMessageHost> NativeMessageHost::Create( |
86 gfx::NativeView native_view, | 84 gfx::NativeView native_view, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 break; | 138 break; |
141 } | 139 } |
142 | 140 |
143 process_ = std::move(process); | 141 process_ = std::move(process); |
144 #if defined(OS_POSIX) | 142 #if defined(OS_POSIX) |
145 // This object is not the owner of the file so it should not keep an fd. | 143 // This object is not the owner of the file so it should not keep an fd. |
146 read_file_ = read_file.GetPlatformFile(); | 144 read_file_ = read_file.GetPlatformFile(); |
147 #endif | 145 #endif |
148 | 146 |
149 scoped_refptr<base::TaskRunner> task_runner(base::CreateTaskRunnerWithTraits( | 147 scoped_refptr<base::TaskRunner> task_runner(base::CreateTaskRunnerWithTraits( |
150 base::TaskTraits() | 148 {base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
151 .MayBlock() | 149 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})); |
152 .WithPriority(base::TaskPriority::USER_VISIBLE) | |
153 .WithShutdownBehavior(base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN))); | |
154 | 150 |
155 read_stream_.reset(new net::FileStream(std::move(read_file), task_runner)); | 151 read_stream_.reset(new net::FileStream(std::move(read_file), task_runner)); |
156 write_stream_.reset(new net::FileStream(std::move(write_file), task_runner)); | 152 write_stream_.reset(new net::FileStream(std::move(write_file), task_runner)); |
157 | 153 |
158 WaitRead(); | 154 WaitRead(); |
159 DoWrite(); | 155 DoWrite(); |
160 } | 156 } |
161 | 157 |
162 void NativeMessageProcessHost::OnMessage(const std::string& json) { | 158 void NativeMessageProcessHost::OnMessage(const std::string& json) { |
163 DCHECK(task_runner_->BelongsToCurrentThread()); | 159 DCHECK(task_runner_->BelongsToCurrentThread()); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 349 |
354 if (!closed_) { | 350 if (!closed_) { |
355 closed_ = true; | 351 closed_ = true; |
356 read_stream_.reset(); | 352 read_stream_.reset(); |
357 write_stream_.reset(); | 353 write_stream_.reset(); |
358 client_->CloseChannel(error_message); | 354 client_->CloseChannel(error_message); |
359 } | 355 } |
360 } | 356 } |
361 | 357 |
362 } // namespace extensions | 358 } // namespace extensions |
OLD | NEW |