Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "shell/out_of_process_native_runner.h" | 5 #include "shell/out_of_process_native_runner.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_util.h" | |
| 14 #include "elf.h" | |
|
Mark Seaborn
2015/09/15 19:42:58
Should be <elf.h> since this is a system header
Sean Klein
2015/09/15 21:35:40
Done.
| |
| 11 #include "shell/child_controller.mojom.h" | 15 #include "shell/child_controller.mojom.h" |
| 12 #include "shell/child_process_host.h" | 16 #include "shell/child_process_host.h" |
| 13 #include "shell/in_process_native_runner.h" | 17 #include "shell/in_process_native_runner.h" |
| 14 | 18 |
| 15 namespace shell { | 19 namespace shell { |
| 16 | 20 |
| 17 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context) | 21 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context) |
| 18 : context_(context) { | 22 : context_(context) { |
| 19 } | 23 } |
| 20 | 24 |
| 21 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { | 25 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { |
| 22 if (child_process_host_) { | 26 if (child_process_host_) { |
| 23 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been | 27 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been |
| 24 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may | 28 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may |
| 25 // not have a child process to wait on.) Probably we should fix |Join()|. | 29 // not have a child process to wait on.) Probably we should fix |Join()|. |
| 26 child_process_host_->Join(); | 30 child_process_host_->Join(); |
| 27 } | 31 } |
| 28 } | 32 } |
| 29 | 33 |
| 30 void OutOfProcessNativeRunner::Start( | 34 void OutOfProcessNativeRunner::Start( |
| 31 const base::FilePath& app_path, | 35 const base::FilePath& app_path, |
| 32 mojo::InterfaceRequest<mojo::Application> application_request, | 36 mojo::InterfaceRequest<mojo::Application> application_request, |
| 33 const base::Closure& app_completed_callback) { | 37 const base::Closure& app_completed_callback) { |
| 34 app_path_ = app_path; | 38 app_path_ = app_path; |
| 35 | 39 |
| 36 DCHECK(app_completed_callback_.is_null()); | 40 DCHECK(app_completed_callback_.is_null()); |
| 37 app_completed_callback_ = app_completed_callback; | 41 app_completed_callback_ = app_completed_callback; |
| 38 | 42 |
| 39 child_process_host_.reset(new ChildProcessHost(context_)); | 43 child_process_host_.reset(new ChildProcessHost(context_)); |
| 40 child_process_host_->Start(); | 44 |
| 45 bool require_32_bit = false; | |
| 46 char data[EI_NIDENT]; | |
|
Mark Seaborn
2015/09/15 19:42:58
This new code could also be conditionalised on "#i
Sean Klein
2015/09/15 21:35:40
It seems a bit misleading to use a conditional her
| |
| 47 if (EI_NIDENT != ReadFile(app_path, data, EI_NIDENT)) | |
|
Mark Seaborn
2015/09/15 19:42:58
How about ReadFile(app_path, data, sizeof(data)),
Sean Klein
2015/09/15 21:35:40
Done.
| |
| 48 assert(false); | |
|
Mark Seaborn
2015/09/15 19:42:58
Chromium style is to avoid assert() and use CHECK(
Sean Klein
2015/09/15 21:35:40
This seems misleading to me (I am not a fan of sil
Mark Seaborn
2015/09/15 22:25:43
Maybe:
size_t bytes_read = ReadFile(...);
DCHECK_
| |
| 49 if (data[EI_CLASS] == ELFCLASS32) | |
| 50 require_32_bit = true; | |
|
Mark Seaborn
2015/09/15 19:42:58
How about splitting this new code into a Require32
Sean Klein
2015/09/15 21:35:40
Done.
| |
| 51 child_process_host_->Start(require_32_bit); | |
| 41 | 52 |
| 42 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. | 53 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. |
| 43 child_process_host_->StartApp( | 54 child_process_host_->StartApp( |
| 44 app_path.AsUTF8Unsafe(), application_request.Pass(), | 55 app_path.AsUTF8Unsafe(), application_request.Pass(), |
| 45 base::Bind(&OutOfProcessNativeRunner::AppCompleted, | 56 base::Bind(&OutOfProcessNativeRunner::AppCompleted, |
| 46 base::Unretained(this))); | 57 base::Unretained(this))); |
| 47 } | 58 } |
| 48 | 59 |
| 49 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { | 60 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { |
| 50 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; | 61 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 61 | 72 |
| 62 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( | 73 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( |
| 63 const Options& options) { | 74 const Options& options) { |
| 64 if (options.force_in_process) | 75 if (options.force_in_process) |
| 65 return make_scoped_ptr(new InProcessNativeRunner(context_)); | 76 return make_scoped_ptr(new InProcessNativeRunner(context_)); |
| 66 | 77 |
| 67 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); | 78 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); |
| 68 } | 79 } |
| 69 | 80 |
| 70 } // namespace shell | 81 } // namespace shell |
| OLD | NEW |