Mojo: (Mostly) factor out command-line switches from the shell's load code path.

(Still to do: switches::kDisableCache.)

This is to make the shell more testable.

R=sky@chromium.org

Review URL: https://codereview.chromium.org/305013015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274373 0039d316-1c4b-4281-b951-d872f2087c98
parent 9352cb77
...@@ -58,21 +58,15 @@ static void Init(JNIEnv* env, jclass clazz, jobject context) { ...@@ -58,21 +58,15 @@ static void Init(JNIEnv* env, jclass clazz, jobject context) {
} }
static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) { static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) {
std::string app_url; std::vector<GURL> app_urls;
#if defined(MOJO_SHELL_DEBUG_URL) #if defined(MOJO_SHELL_DEBUG_URL)
app_url = MOJO_SHELL_DEBUG_URL; app_urls.push_back(GURL(MOJO_SHELL_DEBUG_URL));
// Sleep for 5 seconds to give the debugger a chance to attach. // Sleep for 5 seconds to give the debugger a chance to attach.
sleep(5); sleep(5);
#else #else
if (jurl) if (jurl)
app_url = base::android::ConvertJavaStringToUTF8(env, jurl); app_urls.push_back(GURL(base::android::ConvertJavaStringToUTF8(env, jurl)));
#endif #endif
if (!app_url.empty()) {
std::vector<std::string> argv;
argv.push_back("mojo_shell");
argv.push_back(app_url);
base::CommandLine::ForCurrentProcess()->InitFromArgv(argv);
}
g_env.Get().reset(new Environment); g_env.Get().reset(new Environment);
...@@ -83,7 +77,7 @@ static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) { ...@@ -83,7 +77,7 @@ static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) {
shell_context->set_activity(activity.obj()); shell_context->set_activity(activity.obj());
g_context.Get().reset(shell_context); g_context.Get().reset(shell_context);
shell::Run(shell_context); shell::Run(shell_context, app_urls);
} }
bool RegisterMojoMain(JNIEnv* env) { bool RegisterMojoMain(JNIEnv* env) {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef MOJO_SHELL_CONTEXT_H_ #ifndef MOJO_SHELL_CONTEXT_H_
#define MOJO_SHELL_CONTEXT_H_ #define MOJO_SHELL_CONTEXT_H_
#include <string>
#include "mojo/service_manager/service_manager.h" #include "mojo/service_manager/service_manager.h"
#include "mojo/shell/keep_alive.h" #include "mojo/shell/keep_alive.h"
#include "mojo/shell/loader.h" #include "mojo/shell/loader.h"
...@@ -29,6 +31,11 @@ class Context { ...@@ -29,6 +31,11 @@ class Context {
Context(); Context();
~Context(); ~Context();
const std::string& mojo_origin() const { return mojo_origin_; }
void set_mojo_origin(const std::string& mojo_origin) {
mojo_origin_ = mojo_origin;
}
TaskRunners* task_runners() { return &task_runners_; } TaskRunners* task_runners() { return &task_runners_; }
Storage* storage() { return &storage_; } Storage* storage() { return &storage_; }
Loader* loader() { return &loader_; } Loader* loader() { return &loader_; }
...@@ -42,6 +49,9 @@ class Context { ...@@ -42,6 +49,9 @@ class Context {
private: private:
class NativeViewportServiceLoader; class NativeViewportServiceLoader;
std::string mojo_origin_;
TaskRunners task_runners_; TaskRunners task_runners_;
Storage storage_; Storage storage_;
Loader loader_; Loader loader_;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "mojo/shell/context.h" #include "mojo/shell/context.h"
#include "mojo/shell/init.h" #include "mojo/shell/init.h"
#include "mojo/shell/run.h" #include "mojo/shell/run.h"
#include "mojo/shell/switches.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
namespace { namespace {
...@@ -67,8 +68,26 @@ int main(int argc, char** argv) { ...@@ -67,8 +68,26 @@ int main(int argc, char** argv) {
gfx::GLSurface::InitializeOneOff(); gfx::GLSurface::InitializeOneOff();
base::MessageLoop message_loop; base::MessageLoop message_loop;
mojo::shell::Context context; mojo::shell::Context shell_context;
message_loop.PostTask(FROM_HERE, base::Bind(mojo::shell::Run, &context));
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kOrigin)) {
shell_context.set_mojo_origin(
command_line.GetSwitchValueASCII(switches::kOrigin));
}
std::vector<GURL> app_urls;
base::CommandLine::StringVector args = command_line.GetArgs();
for (base::CommandLine::StringVector::const_iterator it = args.begin();
it != args.end();
++it)
app_urls.push_back(GURL(*it));
message_loop.PostTask(FROM_HERE,
base::Bind(mojo::shell::Run,
&shell_context,
app_urls));
message_loop.Run(); message_loop.Run();
} }
......
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
#include "mojo/shell/dynamic_service_loader.h" #include "mojo/shell/dynamic_service_loader.h"
#include "base/command_line.h"
#include "base/location.h" #include "base/location.h"
#include "mojo/shell/context.h" #include "mojo/shell/context.h"
#include "mojo/shell/keep_alive.h" #include "mojo/shell/keep_alive.h"
#include "mojo/shell/switches.h"
namespace mojo { namespace mojo {
namespace shell { namespace shell {
...@@ -44,11 +42,8 @@ class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate { ...@@ -44,11 +42,8 @@ class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate {
GURL url_to_load; GURL url_to_load;
if (url.SchemeIs("mojo")) { if (url.SchemeIs("mojo")) {
std::string origin =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kOrigin);
std::string lib = MakeSharedLibraryName(url.ExtractFileName()); std::string lib = MakeSharedLibraryName(url.ExtractFileName());
url_to_load = GURL(origin + "/" + lib); url_to_load = GURL(loader->context_->mojo_origin() + "/" + lib);
} else { } else {
url_to_load = url; url_to_load = url;
} }
......
...@@ -4,40 +4,32 @@ ...@@ -4,40 +4,32 @@
#include "mojo/shell/run.h" #include "mojo/shell/run.h"
#include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "mojo/service_manager/service_manager.h" #include "mojo/service_manager/service_manager.h"
#include "mojo/shell/context.h" #include "mojo/shell/context.h"
#include "mojo/shell/keep_alive.h" #include "mojo/shell/keep_alive.h"
#include "mojo/shell/switches.h"
#include "url/gurl.h"
namespace mojo { namespace mojo {
namespace shell { namespace shell {
void Run(Context* context) { void Run(Context* context, const std::vector<GURL>& app_urls) {
KeepAlive keep_alive(context); KeepAlive keep_alive(context);
const base::CommandLine& command_line = if (app_urls.empty()) {
*base::CommandLine::ForCurrentProcess(); LOG(ERROR) << "No app path specified";
base::CommandLine::StringVector args = command_line.GetArgs();
if (args.empty()) {
LOG(ERROR) << "No app path specified.";
return; return;
} }
for (base::CommandLine::StringVector::const_iterator it = args.begin(); for (std::vector<GURL>::const_iterator it = app_urls.begin();
it != args.end(); ++it) { it != app_urls.end();
GURL url(*it); ++it) {
if (url.scheme() == "mojo" && !command_line.HasSwitch(switches::kOrigin)) { if (it->scheme() == "mojo" && context->mojo_origin().empty()) {
LOG(ERROR) << "mojo: url passed with no --origin specified."; LOG(ERROR) << "mojo: URL passed with no origin specified";
return; return;
} }
ScopedMessagePipeHandle no_handle; ScopedMessagePipeHandle no_handle;
context->service_manager()->ConnectToService( context->service_manager()->ConnectToService(
GURL(*it), std::string(), no_handle.Pass()); *it, std::string(), no_handle.Pass());
} }
} }
......
...@@ -5,12 +5,16 @@ ...@@ -5,12 +5,16 @@
#ifndef MOJO_SHELL_RUN_H_ #ifndef MOJO_SHELL_RUN_H_
#define MOJO_SHELL_RUN_H_ #define MOJO_SHELL_RUN_H_
#include <vector>
#include "url/gurl.h"
namespace mojo { namespace mojo {
namespace shell { namespace shell {
class Context; class Context;
void Run(Context* context); void Run(Context* context, const std::vector<GURL>& app_urls);
} // namespace shell } // namespace shell
} // namespace mojo } // namespace mojo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment