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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host.cc

Issue 780653003: Revert of Upgrade the windows specific version of LaunchProcess to avoid raw handles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
(...skipping 29 matching lines...) Expand all
40 40
41 NativeMessageProcessHost::NativeMessageProcessHost( 41 NativeMessageProcessHost::NativeMessageProcessHost(
42 const std::string& source_extension_id, 42 const std::string& source_extension_id,
43 const std::string& native_host_name, 43 const std::string& native_host_name,
44 scoped_ptr<NativeProcessLauncher> launcher) 44 scoped_ptr<NativeProcessLauncher> launcher)
45 : client_(NULL), 45 : client_(NULL),
46 source_extension_id_(source_extension_id), 46 source_extension_id_(source_extension_id),
47 native_host_name_(native_host_name), 47 native_host_name_(native_host_name),
48 launcher_(launcher.Pass()), 48 launcher_(launcher.Pass()),
49 closed_(false), 49 closed_(false),
50 process_handle_(base::kNullProcessHandle),
50 #if defined(OS_POSIX) 51 #if defined(OS_POSIX)
51 read_file_(-1), 52 read_file_(-1),
52 #endif 53 #endif
53 read_pending_(false), 54 read_pending_(false),
54 write_pending_(false), 55 write_pending_(false),
55 weak_factory_(this) { 56 weak_factory_(this) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 58
58 task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( 59 task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
59 content::BrowserThread::IO); 60 content::BrowserThread::IO);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 DCHECK(task_runner_->BelongsToCurrentThread()); 96 DCHECK(task_runner_->BelongsToCurrentThread());
96 97
97 GURL origin(std::string(kExtensionScheme) + "://" + source_extension_id_); 98 GURL origin(std::string(kExtensionScheme) + "://" + source_extension_id_);
98 launcher_->Launch(origin, native_host_name_, 99 launcher_->Launch(origin, native_host_name_,
99 base::Bind(&NativeMessageProcessHost::OnHostProcessLaunched, 100 base::Bind(&NativeMessageProcessHost::OnHostProcessLaunched,
100 weak_factory_.GetWeakPtr())); 101 weak_factory_.GetWeakPtr()));
101 } 102 }
102 103
103 void NativeMessageProcessHost::OnHostProcessLaunched( 104 void NativeMessageProcessHost::OnHostProcessLaunched(
104 NativeProcessLauncher::LaunchResult result, 105 NativeProcessLauncher::LaunchResult result,
105 base::Process process, 106 base::ProcessHandle process_handle,
106 base::File read_file, 107 base::File read_file,
107 base::File write_file) { 108 base::File write_file) {
108 DCHECK(task_runner_->BelongsToCurrentThread()); 109 DCHECK(task_runner_->BelongsToCurrentThread());
109 110
110 switch (result) { 111 switch (result) {
111 case NativeProcessLauncher::RESULT_INVALID_NAME: 112 case NativeProcessLauncher::RESULT_INVALID_NAME:
112 Close(kInvalidNameError); 113 Close(kInvalidNameError);
113 return; 114 return;
114 case NativeProcessLauncher::RESULT_NOT_FOUND: 115 case NativeProcessLauncher::RESULT_NOT_FOUND:
115 Close(kNotFoundError); 116 Close(kNotFoundError);
116 return; 117 return;
117 case NativeProcessLauncher::RESULT_FORBIDDEN: 118 case NativeProcessLauncher::RESULT_FORBIDDEN:
118 Close(kForbiddenError); 119 Close(kForbiddenError);
119 return; 120 return;
120 case NativeProcessLauncher::RESULT_FAILED_TO_START: 121 case NativeProcessLauncher::RESULT_FAILED_TO_START:
121 Close(kFailedToStartError); 122 Close(kFailedToStartError);
122 return; 123 return;
123 case NativeProcessLauncher::RESULT_SUCCESS: 124 case NativeProcessLauncher::RESULT_SUCCESS:
124 break; 125 break;
125 } 126 }
126 127
127 process_ = process.Pass(); 128 process_handle_ = process_handle;
128 #if defined(OS_POSIX) 129 #if defined(OS_POSIX)
129 // This object is not the owner of the file so it should not keep an fd. 130 // This object is not the owner of the file so it should not keep an fd.
130 read_file_ = read_file.GetPlatformFile(); 131 read_file_ = read_file.GetPlatformFile();
131 #endif 132 #endif
132 133
133 scoped_refptr<base::TaskRunner> task_runner( 134 scoped_refptr<base::TaskRunner> task_runner(
134 content::BrowserThread::GetBlockingPool()-> 135 content::BrowserThread::GetBlockingPool()->
135 GetTaskRunnerWithShutdownBehavior( 136 GetTaskRunnerWithShutdownBehavior(
136 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 137 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
137 138
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 void NativeMessageProcessHost::Close(const std::string& error_message) { 342 void NativeMessageProcessHost::Close(const std::string& error_message) {
342 DCHECK(task_runner_->BelongsToCurrentThread()); 343 DCHECK(task_runner_->BelongsToCurrentThread());
343 344
344 if (!closed_) { 345 if (!closed_) {
345 closed_ = true; 346 closed_ = true;
346 read_stream_.reset(); 347 read_stream_.reset();
347 write_stream_.reset(); 348 write_stream_.reset();
348 client_->CloseChannel(error_message); 349 client_->CloseChannel(error_message);
349 } 350 }
350 351
351 if (process_.IsValid()) { 352 if (process_handle_ != base::kNullProcessHandle) {
352 // Kill the host process if necessary to make sure we don't leave zombies. 353 // Kill the host process if necessary to make sure we don't leave zombies.
353 // On OSX base::EnsureProcessTerminated() may block, so we have to post a 354 // On OSX base::EnsureProcessTerminated() may block, so we have to post a
354 // task on the blocking pool. 355 // task on the blocking pool.
355 #if defined(OS_MACOSX) 356 #if defined(OS_MACOSX)
356 content::BrowserThread::PostBlockingPoolTask( 357 content::BrowserThread::PostBlockingPoolTask(
357 FROM_HERE, 358 FROM_HERE, base::Bind(&base::EnsureProcessTerminated, process_handle_));
358 base::Bind(&base::EnsureProcessTerminated, Passed(&process_)));
359 #else 359 #else
360 base::EnsureProcessTerminated(process_.Pass()); 360 base::EnsureProcessTerminated(process_handle_);
361 #endif 361 #endif
362 process_handle_ = base::kNullProcessHandle;
362 } 363 }
363 } 364 }
364 365
365 } // namespace extensions 366 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698