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

Unified Diff: mojo/shell/static_application_loader.cc

Issue 1149833007: Embed a mojo ApplicationManager in content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/shell/static_application_loader.cc
diff --git a/mojo/shell/static_application_loader.cc b/mojo/shell/static_application_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a0f90a87d9020cc184786954bec45a33cc8c9031
--- /dev/null
+++ b/mojo/shell/static_application_loader.cc
@@ -0,0 +1,95 @@
+// 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 "mojo/shell/static_application_loader.h"
+
+#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/application/public/cpp/application_delegate.h"
+#include "mojo/application/public/cpp/application_runner.h"
+#include "mojo/application/public/interfaces/application.mojom.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
+
+namespace mojo {
+namespace shell {
+
+namespace {
+
+class RunnerThread : public base::SimpleThread {
+ public:
+ RunnerThread(const GURL& url,
+ InterfaceRequest<Application> request,
+ scoped_refptr<base::TaskRunner> exit_task_runner,
+ const base::Closure& exit_callback,
+ const StaticApplicationLoader::ApplicationFactory& factory)
+ : base::SimpleThread("Mojo Application: " + url.spec()),
+ request_(request.Pass()),
+ exit_task_runner_(exit_task_runner),
+ exit_callback_(exit_callback),
+ factory_(factory) {}
+
+ void Run() override {
+ scoped_ptr<ApplicationRunner> runner(
+ new ApplicationRunner(factory_.Run().release()));
+ runner->Run(request_.PassMessagePipe().release().value(),
+ false /* init_base */);
+ exit_task_runner_->PostTask(FROM_HERE, exit_callback_);
+ }
+
+ private:
+ InterfaceRequest<Application> 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,
+ InterfaceRequest<Application> 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, request.Pass(), base::ThreadTaskRunnerHandle::Get(),
+ exit_callback, factory_));
+ thread_->Start();
+}
+
+void StaticApplicationLoader::StopAppThread() {
+ thread_->Join();
+ thread_.reset();
+ if (!quit_callback_.is_null())
+ quit_callback_.Run();
+}
+
+} // namespace shell
+} // namespace mojo
« content/browser/mojo/mojo_shell_context.cc ('K') | « mojo/shell/static_application_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698