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

Unified Diff: mojo/shell/static_application_loader.h

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.h
diff --git a/mojo/shell/static_application_loader.h b/mojo/shell/static_application_loader.h
new file mode 100644
index 0000000000000000000000000000000000000000..cbf611a0dac337cbb86cee8dda725e6481b62a6e
--- /dev/null
+++ b/mojo/shell/static_application_loader.h
@@ -0,0 +1,69 @@
+// 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 MOJO_SHELL_STATIC_APPLICATION_LOADER_H_
+#define MOJO_SHELL_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 ApplicationDelegate;
+}
+
+namespace mojo {
+namespace shell {
+
+// An ApplicationLoader which loads a single type of app from a given
+// ApplicationDelegate 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::ApplicationDelegate>()>;
+
+ // 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::InterfaceRequest<mojo::Application> 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 shell
+} // namespace mojo
+
+#endif // MOJO_SHELL_STATIC_APPLICATION_LOADER_H_

Powered by Google App Engine
This is Rietveld 408576698