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

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

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

Powered by Google App Engine
This is Rietveld 408576698