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) {
}
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)
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(5);
#else
if (jurl)
app_url = base::android::ConvertJavaStringToUTF8(env, jurl);
app_urls.push_back(GURL(base::android::ConvertJavaStringToUTF8(env, jurl)));
#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);
......@@ -83,7 +77,7 @@ static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) {
shell_context->set_activity(activity.obj());
g_context.Get().reset(shell_context);
shell::Run(shell_context);
shell::Run(shell_context, app_urls);
}
bool RegisterMojoMain(JNIEnv* env) {
......
......@@ -5,6 +5,8 @@
#ifndef MOJO_SHELL_CONTEXT_H_
#define MOJO_SHELL_CONTEXT_H_
#include <string>
#include "mojo/service_manager/service_manager.h"
#include "mojo/shell/keep_alive.h"
#include "mojo/shell/loader.h"
......@@ -29,6 +31,11 @@ class 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_; }
Storage* storage() { return &storage_; }
Loader* loader() { return &loader_; }
......@@ -42,6 +49,9 @@ class Context {
private:
class NativeViewportServiceLoader;
std::string mojo_origin_;
TaskRunners task_runners_;
Storage storage_;
Loader loader_;
......
......@@ -14,6 +14,7 @@
#include "mojo/shell/context.h"
#include "mojo/shell/init.h"
#include "mojo/shell/run.h"
#include "mojo/shell/switches.h"
#include "ui/gl/gl_surface.h"
namespace {
......@@ -67,8 +68,26 @@ int main(int argc, char** argv) {
gfx::GLSurface::InitializeOneOff();
base::MessageLoop message_loop;
mojo::shell::Context context;
message_loop.PostTask(FROM_HERE, base::Bind(mojo::shell::Run, &context));
mojo::shell::Context shell_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();
}
......
......@@ -4,11 +4,9 @@
#include "mojo/shell/dynamic_service_loader.h"
#include "base/command_line.h"
#include "base/location.h"
#include "mojo/shell/context.h"
#include "mojo/shell/keep_alive.h"
#include "mojo/shell/switches.h"
namespace mojo {
namespace shell {
......@@ -44,11 +42,8 @@ class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate {
GURL url_to_load;
if (url.SchemeIs("mojo")) {
std::string origin =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kOrigin);
std::string lib = MakeSharedLibraryName(url.ExtractFileName());
url_to_load = GURL(origin + "/" + lib);
url_to_load = GURL(loader->context_->mojo_origin() + "/" + lib);
} else {
url_to_load = url;
}
......
......@@ -4,40 +4,32 @@
#include "mojo/shell/run.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "mojo/service_manager/service_manager.h"
#include "mojo/shell/context.h"
#include "mojo/shell/keep_alive.h"
#include "mojo/shell/switches.h"
#include "url/gurl.h"
namespace mojo {
namespace shell {
void Run(Context* context) {
void Run(Context* context, const std::vector<GURL>& app_urls) {
KeepAlive keep_alive(context);
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
base::CommandLine::StringVector args = command_line.GetArgs();
if (args.empty()) {
LOG(ERROR) << "No app path specified.";
if (app_urls.empty()) {
LOG(ERROR) << "No app path specified";
return;
}
for (base::CommandLine::StringVector::const_iterator it = args.begin();
it != args.end(); ++it) {
GURL url(*it);
if (url.scheme() == "mojo" && !command_line.HasSwitch(switches::kOrigin)) {
LOG(ERROR) << "mojo: url passed with no --origin specified.";
for (std::vector<GURL>::const_iterator it = app_urls.begin();
it != app_urls.end();
++it) {
if (it->scheme() == "mojo" && context->mojo_origin().empty()) {
LOG(ERROR) << "mojo: URL passed with no origin specified";
return;
}
ScopedMessagePipeHandle no_handle;
context->service_manager()->ConnectToService(
GURL(*it), std::string(), no_handle.Pass());
*it, std::string(), no_handle.Pass());
}
}
......
......@@ -5,12 +5,16 @@
#ifndef MOJO_SHELL_RUN_H_
#define MOJO_SHELL_RUN_H_
#include <vector>
#include "url/gurl.h"
namespace mojo {
namespace shell {
class Context;
void Run(Context* context);
void Run(Context* context, const std::vector<GURL>& app_urls);
} // namespace shell
} // 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