summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorben <ben@chromium.org>2016-02-19 21:30:53 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-20 05:32:23 +0000
commitfde0aff82c74a78e8cb298f3028e7effd527ae2c (patch)
treeb85de9df6fb9f51d8e24d6ad786d0ab046560065 /content
parentbb917ddb01a8c3e373d6df02046c69ff00b07254 (diff)
downloadchromium_src-fde0aff82c74a78e8cb298f3028e7effd527ae2c.zip
chromium_src-fde0aff82c74a78e8cb298f3028e7effd527ae2c.tar.gz
chromium_src-fde0aff82c74a78e8cb298f3028e7effd527ae2c.tar.bz2
Move StaticApplicationLoader to content/common/mojo
TBR=rockot@chromium.org BUG= Review URL: https://codereview.chromium.org/1716473002 Cr-Commit-Position: refs/heads/master@{#376629}
Diffstat (limited to 'content')
-rw-r--r--content/browser/mojo/mojo_shell_context.cc4
-rw-r--r--content/child/process_control_impl.cc2
-rw-r--r--content/common/mojo/DEPS4
-rw-r--r--content/common/mojo/static_application_loader.cc96
-rw-r--r--content/common/mojo/static_application_loader.h67
-rw-r--r--content/content_common.gypi2
-rw-r--r--content/gpu/gpu_process_control_impl.cc6
-rw-r--r--content/shell/utility/shell_content_utility_client.cc2
-rw-r--r--content/utility/utility_process_control_impl.cc6
9 files changed, 176 insertions, 13 deletions
diff --git a/content/browser/mojo/mojo_shell_context.cc b/content/browser/mojo/mojo_shell_context.cc
index f53618a..980c7a6 100644
--- a/content/browser/mojo/mojo_shell_context.cc
+++ b/content/browser/mojo/mojo_shell_context.cc
@@ -13,6 +13,7 @@
#include "base/thread_task_runner_handle.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/common/gpu/gpu_process_launch_causes.h"
+#include "content/common/mojo/static_application_loader.h"
#include "content/common/process_control.mojom.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
@@ -27,7 +28,6 @@
#include "mojo/shell/connect_to_application_params.h"
#include "mojo/shell/identity.h"
#include "mojo/shell/public/cpp/shell_client.h"
-#include "mojo/shell/static_application_loader.h"
namespace content {
@@ -216,7 +216,7 @@ MojoShellContext::MojoShellContext() {
for (const auto& entry : apps) {
application_manager_->SetLoaderForURL(
scoped_ptr<mojo::shell::ApplicationLoader>(
- new mojo::shell::StaticApplicationLoader(entry.second)),
+ new StaticApplicationLoader(entry.second)),
entry.first);
}
diff --git a/content/child/process_control_impl.cc b/content/child/process_control_impl.cc
index 9f4b474..6cf00e5 100644
--- a/content/child/process_control_impl.cc
+++ b/content/child/process_control_impl.cc
@@ -7,8 +7,8 @@
#include <utility>
#include "base/stl_util.h"
+#include "content/common/mojo/static_application_loader.h"
#include "content/public/common/content_client.h"
-#include "mojo/shell/static_application_loader.h"
#include "url/gurl.h"
namespace content {
diff --git a/content/common/mojo/DEPS b/content/common/mojo/DEPS
index 906af32..0f2f39e 100644
--- a/content/common/mojo/DEPS
+++ b/content/common/mojo/DEPS
@@ -1,7 +1,5 @@
include_rules = [
"+mojo/converters/network",
"+mojo/edk/embedder",
- "+mojo/shell/public/cpp",
- "+mojo/shell/public/interfaces",
- "+mojo/shell/runner/child",
+ "+mojo/shell",
]
diff --git a/content/common/mojo/static_application_loader.cc b/content/common/mojo/static_application_loader.cc
new file mode 100644
index 0000000..263236c
--- /dev/null
+++ b/content/common/mojo/static_application_loader.cc
@@ -0,0 +1,96 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/mojo/static_application_loader.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/task_runner.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/threading/simple_thread.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "mojo/shell/public/cpp/application_runner.h"
+#include "mojo/shell/public/cpp/shell_client.h"
+#include "mojo/shell/public/interfaces/shell_client.mojom.h"
+
+namespace content {
+
+namespace {
+
+class RunnerThread : public base::SimpleThread {
+ public:
+ RunnerThread(const GURL& url,
+ mojo::shell::mojom::ShellClientRequest request,
+ scoped_refptr<base::TaskRunner> exit_task_runner,
+ const base::Closure& exit_callback,
+ const StaticApplicationLoader::ApplicationFactory& factory)
+ : base::SimpleThread("Mojo Application: " + url.spec()),
+ request_(std::move(request)),
+ exit_task_runner_(exit_task_runner),
+ exit_callback_(exit_callback),
+ factory_(factory) {}
+
+ void Run() override {
+ scoped_ptr<mojo::ApplicationRunner> runner(
+ new mojo::ApplicationRunner(factory_.Run().release()));
+ runner->Run(request_.PassMessagePipe().release().value(),
+ false /* init_base */);
+ exit_task_runner_->PostTask(FROM_HERE, exit_callback_);
+ }
+
+ private:
+ mojo::shell::mojom::ShellClientRequest request_;
+ scoped_refptr<base::TaskRunner> exit_task_runner_;
+ base::Closure exit_callback_;
+ StaticApplicationLoader::ApplicationFactory factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(RunnerThread);
+};
+
+} // namespace
+
+StaticApplicationLoader::StaticApplicationLoader(
+ const ApplicationFactory& factory)
+ : StaticApplicationLoader(factory, base::Closure()) {
+}
+
+StaticApplicationLoader::StaticApplicationLoader(
+ const ApplicationFactory& factory,
+ const base::Closure& quit_callback)
+ : factory_(factory), quit_callback_(quit_callback), weak_factory_(this) {
+}
+
+StaticApplicationLoader::~StaticApplicationLoader() {
+ if (thread_)
+ StopAppThread();
+}
+
+void StaticApplicationLoader::Load(
+ const GURL& url,
+ mojo::shell::mojom::ShellClientRequest request) {
+ if (thread_)
+ return;
+
+ // If the application's thread quits on its own before this loader dies, we
+ // reset the Thread object, allowing future Load requests to be fulfilled
+ // with a new app instance.
+ auto exit_callback = base::Bind(&StaticApplicationLoader::StopAppThread,
+ weak_factory_.GetWeakPtr());
+ thread_.reset(new RunnerThread(url, std::move(request),
+ base::ThreadTaskRunnerHandle::Get(),
+ exit_callback, factory_));
+ thread_->Start();
+}
+
+void StaticApplicationLoader::StopAppThread() {
+ thread_->Join();
+ thread_.reset();
+ if (!quit_callback_.is_null())
+ quit_callback_.Run();
+}
+
+} // namespace content
diff --git a/content/common/mojo/static_application_loader.h b/content/common/mojo/static_application_loader.h
new file mode 100644
index 0000000..44402c5
--- /dev/null
+++ b/content/common/mojo/static_application_loader.h
@@ -0,0 +1,67 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_MOJO_STATIC_APPLICATION_LOADER_H_
+#define CONTENT_COMMON_MOJO_STATIC_APPLICATION_LOADER_H_
+
+#include <list>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "mojo/shell/application_loader.h"
+
+namespace base {
+class SimpleThread;
+}
+
+namespace mojo {
+class ShellClient;
+}
+
+namespace content {
+
+// An ApplicationLoader which loads a single type of app from a given
+// mojo::ShellClient factory. A Load() request is fulfilled by creating an
+// instance of the app on a new thread. Only one instance of the app will run at
+// a time. Any Load requests received while the app is running will be dropped.
+class StaticApplicationLoader : public mojo::shell::ApplicationLoader {
+ public:
+ using ApplicationFactory =
+ base::Callback<scoped_ptr<mojo::ShellClient>()>;
+
+ // Constructs a static loader for |factory|.
+ explicit StaticApplicationLoader(const ApplicationFactory& factory);
+
+ // Constructs a static loader for |factory| with a closure that will be called
+ // when the loaded application quits.
+ StaticApplicationLoader(const ApplicationFactory& factory,
+ const base::Closure& quit_callback);
+
+ ~StaticApplicationLoader() override;
+
+ // mojo::shell::ApplicationLoader:
+ void Load(const GURL& url,
+ mojo::shell::mojom::ShellClientRequest request) override;
+
+ private:
+ void StopAppThread();
+
+ // The factory used t create new instances of the application delegate.
+ ApplicationFactory factory_;
+
+ // If not null, this is run when the loaded application quits.
+ base::Closure quit_callback_;
+
+ // Thread for the application if currently running.
+ scoped_ptr<base::SimpleThread> thread_;
+
+ base::WeakPtrFactory<StaticApplicationLoader> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(StaticApplicationLoader);
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_MOJO_STATIC_APPLICATION_LOADER_H_
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 73c1dfc..703edad 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -508,6 +508,8 @@
'common/mojo/mojo_messages.h',
'common/mojo/service_registry_impl.cc',
'common/mojo/service_registry_impl.h',
+ 'common/mojo/static_application_loader.cc',
+ 'common/mojo/static_application_loader.h',
'common/navigation_gesture.h',
'common/navigation_params.cc',
'common/navigation_params.h',
diff --git a/content/gpu/gpu_process_control_impl.cc b/content/gpu/gpu_process_control_impl.cc
index 6e38ffd..615c63b 100644
--- a/content/gpu/gpu_process_control_impl.cc
+++ b/content/gpu/gpu_process_control_impl.cc
@@ -7,8 +7,8 @@
#if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "content/common/mojo/static_application_loader.h"
#include "media/mojo/services/mojo_media_application_factory.h"
-#include "mojo/shell/static_application_loader.h"
#endif
namespace content {
@@ -21,8 +21,8 @@ void GpuProcessControlImpl::RegisterApplicationLoaders(
URLToLoaderMap* url_to_loader_map) {
#if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
(*url_to_loader_map)[GURL("mojo:media")] =
- new mojo::shell::StaticApplicationLoader(
- base::Bind(&media::CreateMojoMediaApplication),
+ new StaticApplicationLoader(
+ base::Bind(&media::CreateMojoMediaApplication),
base::Bind(&base::DoNothing));
#endif
}
diff --git a/content/shell/utility/shell_content_utility_client.cc b/content/shell/utility/shell_content_utility_client.cc
index a21c083..a9819ee 100644
--- a/content/shell/utility/shell_content_utility_client.cc
+++ b/content/shell/utility/shell_content_utility_client.cc
@@ -6,8 +6,8 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
+#include "content/common/mojo/static_application_loader.h"
#include "content/public/test/test_mojo_app.h"
-#include "mojo/shell/static_application_loader.h"
namespace content {
diff --git a/content/utility/utility_process_control_impl.cc b/content/utility/utility_process_control_impl.cc
index f6c59f8..422b0a4 100644
--- a/content/utility/utility_process_control_impl.cc
+++ b/content/utility/utility_process_control_impl.cc
@@ -5,11 +5,11 @@
#include "content/utility/utility_process_control_impl.h"
#include "base/bind.h"
+#include "content/common/mojo/static_application_loader.h"
#include "content/public/common/content_client.h"
#include "content/public/utility/content_utility_client.h"
#include "content/public/utility/utility_thread.h"
#include "content/utility/utility_thread_impl.h"
-#include "mojo/shell/static_application_loader.h"
#if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS)
#include "media/mojo/services/mojo_media_application_factory.h"
@@ -38,12 +38,12 @@ void UtilityProcessControlImpl::RegisterApplicationLoaders(
GetContentClient()->utility()->RegisterMojoApplications(&apps);
for (const auto& entry : apps) {
- map_ref[entry.first] = new mojo::shell::StaticApplicationLoader(
+ map_ref[entry.first] = new StaticApplicationLoader(
entry.second, base::Bind(&QuitProcess));
}
#if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS)
- map_ref[GURL("mojo:media")] = new mojo::shell::StaticApplicationLoader(
+ map_ref[GURL("mojo:media")] = new StaticApplicationLoader(
base::Bind(&media::CreateMojoMediaApplication), base::Bind(&QuitProcess));
#endif
}