summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-02 23:51:55 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-02 23:51:55 +0000
commit33677ce5b0fb289838cfd201a35ce915c12c36cc (patch)
treecced5519e4b91fbaf0f6991f8f97f39e60c54843
parent9352cb772c0a8945b87774c36bbfdb02a227ab49 (diff)
downloadchromium_src-33677ce5b0fb289838cfd201a35ce915c12c36cc.zip
chromium_src-33677ce5b0fb289838cfd201a35ce915c12c36cc.tar.gz
chromium_src-33677ce5b0fb289838cfd201a35ce915c12c36cc.tar.bz2
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
-rw-r--r--mojo/shell/android/mojo_main.cc14
-rw-r--r--mojo/shell/context.h10
-rw-r--r--mojo/shell/desktop/mojo_main.cc23
-rw-r--r--mojo/shell/dynamic_service_loader.cc7
-rw-r--r--mojo/shell/run.cc26
-rw-r--r--mojo/shell/run.h6
6 files changed, 50 insertions, 36 deletions
diff --git a/mojo/shell/android/mojo_main.cc b/mojo/shell/android/mojo_main.cc
index 47f7f52..3faf73f 100644
--- a/mojo/shell/android/mojo_main.cc
+++ b/mojo/shell/android/mojo_main.cc
@@ -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) {
diff --git a/mojo/shell/context.h b/mojo/shell/context.h
index c9acdc4..599a199 100644
--- a/mojo/shell/context.h
+++ b/mojo/shell/context.h
@@ -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_;
diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc
index c1e796a..f2ef50a 100644
--- a/mojo/shell/desktop/mojo_main.cc
+++ b/mojo/shell/desktop/mojo_main.cc
@@ -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();
}
diff --git a/mojo/shell/dynamic_service_loader.cc b/mojo/shell/dynamic_service_loader.cc
index a54edd6..b249c3c 100644
--- a/mojo/shell/dynamic_service_loader.cc
+++ b/mojo/shell/dynamic_service_loader.cc
@@ -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;
}
diff --git a/mojo/shell/run.cc b/mojo/shell/run.cc
index 34cdfc8..6a47e27 100644
--- a/mojo/shell/run.cc
+++ b/mojo/shell/run.cc
@@ -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());
}
}
diff --git a/mojo/shell/run.h b/mojo/shell/run.h
index 0e6ee6e..2b60b4b 100644
--- a/mojo/shell/run.h
+++ b/mojo/shell/run.h
@@ -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