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

Side by Side Diff: shell/android/main.cc

Issue 1061413002: Shell: Make a separate binary for child processes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 8 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/android/main.h" 5 #include "shell/android/main.h"
6 6
7 #include "base/android/fifo_utils.h" 7 #include "base/android/fifo_utils.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_array.h" 9 #include "base/android/jni_array.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 28 matching lines...) Expand all
39 namespace { 39 namespace {
40 40
41 // Tag for logging. 41 // Tag for logging.
42 const char kLogTag[] = "chromium"; 42 const char kLogTag[] = "chromium";
43 43
44 // Command line argument for the communication fifo. 44 // Command line argument for the communication fifo.
45 const char kFifoPath[] = "fifo-path"; 45 const char kFifoPath[] = "fifo-path";
46 46
47 class MojoShellRunner : public base::DelegateSimpleThread::Delegate { 47 class MojoShellRunner : public base::DelegateSimpleThread::Delegate {
48 public: 48 public:
49 MojoShellRunner(const std::vector<std::string>& parameters) 49 MojoShellRunner(const base::FilePath& mojo_shell_path,
50 : parameters_(parameters) {} 50 const base::FilePath& mojo_shell_child_path,
51 const std::vector<std::string>& parameters)
52 : mojo_shell_path_(mojo_shell_path),
53 mojo_shell_child_path_(mojo_shell_child_path),
54 parameters_(parameters) {}
51 ~MojoShellRunner() override {} 55 ~MojoShellRunner() override {}
52 56
53 private: 57 private:
54 void Run() override; 58 void Run() override;
55 59
56 std::vector<std::string> parameters_; 60 const base::FilePath mojo_shell_path_;
61 const base::FilePath mojo_shell_child_path_;
62 const std::vector<std::string> parameters_;
57 63
58 DISALLOW_COPY_AND_ASSIGN(MojoShellRunner); 64 DISALLOW_COPY_AND_ASSIGN(MojoShellRunner);
59 }; 65 };
60 66
61 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop = 67 LazyInstance<scoped_ptr<base::MessageLoop>> g_java_message_loop =
62 LAZY_INSTANCE_INITIALIZER; 68 LAZY_INSTANCE_INITIALIZER;
63 69
64 LazyInstance<scoped_ptr<Context>> g_context = LAZY_INSTANCE_INITIALIZER; 70 LazyInstance<scoped_ptr<Context>> g_context = LAZY_INSTANCE_INITIALIZER;
65 71
66 LazyInstance<scoped_ptr<MojoShellRunner>> g_shell_runner = 72 LazyInstance<scoped_ptr<MojoShellRunner>> g_shell_runner =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 g_shell_thread.Pointer()->reset(); 104 g_shell_thread.Pointer()->reset();
99 Java_ShellMain_finishActivity(base::android::AttachCurrentThread(), 105 Java_ShellMain_finishActivity(base::android::AttachCurrentThread(),
100 g_main_activiy.Get().obj()); 106 g_main_activiy.Get().obj());
101 exit(0); 107 exit(0);
102 } 108 }
103 109
104 void MojoShellRunner::Run() { 110 void MojoShellRunner::Run() {
105 base::MessageLoop loop(common::MessagePumpMojo::Create()); 111 base::MessageLoop loop(common::MessagePumpMojo::Create());
106 Context* context = g_context.Pointer()->get(); 112 Context* context = g_context.Pointer()->get();
107 ConfigureAndroidServices(context); 113 ConfigureAndroidServices(context);
108 context->Init(); 114 context->InitWithPaths(mojo_shell_path_, mojo_shell_child_path_);
109 115
110 for (auto& args : parameters_) 116 for (const auto& args : parameters_)
111 ApplyApplicationArgs(context, args); 117 ApplyApplicationArgs(context, args);
112 118
113 RunCommandLineApps(context); 119 RunCommandLineApps(context);
114 loop.Run(); 120 loop.Run();
115 121
116 g_java_message_loop.Pointer()->get()->PostTask(FROM_HERE, 122 g_java_message_loop.Pointer()->get()->PostTask(FROM_HERE,
117 base::Bind(&QuitShellThread)); 123 base::Bind(&QuitShellThread));
118 } 124 }
119 125
120 // Initialize stdout redirection if the command line switch is present. 126 // Initialize stdout redirection if the command line switch is present.
(...skipping 14 matching lines...) Expand all
135 CHECK(dup2(STDOUT_FILENO, STDERR_FILENO) != -1) 141 CHECK(dup2(STDOUT_FILENO, STDERR_FILENO) != -1)
136 << "Unable to redirect stderr to stdout."; 142 << "Unable to redirect stderr to stdout.";
137 } 143 }
138 144
139 } // namespace 145 } // namespace
140 146
141 static void Init(JNIEnv* env, 147 static void Init(JNIEnv* env,
142 jclass clazz, 148 jclass clazz,
143 jobject activity, 149 jobject activity,
144 jstring mojo_shell_path, 150 jstring mojo_shell_path,
151 jstring mojo_shell_child_path,
145 jobjectArray jparameters, 152 jobjectArray jparameters,
146 jstring j_local_apps_directory, 153 jstring j_local_apps_directory,
147 jstring j_tmp_dir) { 154 jstring j_tmp_dir) {
148 g_main_activiy.Get().Reset(env, activity); 155 g_main_activiy.Get().Reset(env, activity);
149 156
150 // Setting the TMPDIR environment variable so that applications can use it. 157 // Setting the TMPDIR environment variable so that applications can use it.
151 // TODO(qsr) We will need our subprocesses to inherit this. 158 // TODO(qsr) We will need our subprocesses to inherit this.
152 int return_value = 159 int return_value =
153 setenv("TMPDIR", 160 setenv("TMPDIR",
154 base::android::ConvertJavaStringToUTF8(env, j_tmp_dir).c_str(), 1); 161 base::android::ConvertJavaStringToUTF8(env, j_tmp_dir).c_str(), 1);
155 DCHECK_EQ(return_value, 0); 162 DCHECK_EQ(return_value, 0);
156 163
157 base::android::ScopedJavaLocalRef<jobject> scoped_activity(env, activity); 164 base::android::ScopedJavaLocalRef<jobject> scoped_activity(env, activity);
158 base::android::InitApplicationContext(env, scoped_activity); 165 base::android::InitApplicationContext(env, scoped_activity);
159 166
160 std::vector<std::string> parameters; 167 std::vector<std::string> parameters;
161 parameters.push_back( 168 parameters.push_back(
162 base::android::ConvertJavaStringToUTF8(env, mojo_shell_path)); 169 base::android::ConvertJavaStringToUTF8(env, mojo_shell_path));
163 base::android::AppendJavaStringArrayToStringVector(env, jparameters, 170 base::android::AppendJavaStringArrayToStringVector(env, jparameters,
164 &parameters); 171 &parameters);
165 base::CommandLine::Init(0, nullptr); 172 base::CommandLine::Init(0, nullptr);
166 base::CommandLine::ForCurrentProcess()->InitFromArgv(parameters); 173 base::CommandLine::ForCurrentProcess()->InitFromArgv(parameters);
167 g_shell_runner.Get().reset(new MojoShellRunner(parameters)); 174 g_shell_runner.Get().reset(new MojoShellRunner(
175 base::FilePath(
176 base::android::ConvertJavaStringToUTF8(env, mojo_shell_path)),
177 base::FilePath(
178 base::android::ConvertJavaStringToUTF8(env, mojo_shell_child_path)),
179 parameters));
168 180
169 InitializeLogging(); 181 InitializeLogging();
170 182
171 InitializeRedirection(); 183 InitializeRedirection();
172 184
173 // We want ~MessageLoop to happen prior to ~Context. Initializing 185 // We want ~MessageLoop to happen prior to ~Context. Initializing
174 // LazyInstances is akin to stack-allocating objects; their destructors 186 // LazyInstances is akin to stack-allocating objects; their destructors
175 // will be invoked first-in-last-out. 187 // will be invoked first-in-last-out.
176 Context* shell_context = new Context(); 188 Context* shell_context = new Context();
177 shell_context->SetShellFileRoot(base::FilePath( 189 shell_context->SetShellFileRoot(base::FilePath(
(...skipping 29 matching lines...) Expand all
207 base::CommandLine::ForCurrentProcess()->AppendArg( 219 base::CommandLine::ForCurrentProcess()->AppendArg(
208 base::android::ConvertJavaStringToUTF8(env, jurl)); 220 base::android::ConvertJavaStringToUTF8(env, jurl));
209 } 221 }
210 222
211 bool RegisterShellMain(JNIEnv* env) { 223 bool RegisterShellMain(JNIEnv* env) {
212 return RegisterNativesImpl(env); 224 return RegisterNativesImpl(env);
213 } 225 }
214 226
215 } // namespace shell 227 } // namespace shell
216 } // namespace mojo 228 } // namespace mojo
229
230 // TODO(vtl): We need a main(), even though it should never be called.
231 int main(int argc, char** argv) {
232 NOTREACHED();
233 return 1;
234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698