Index: content/public/common/static_mojo_application_loader.h |
diff --git a/content/public/common/static_mojo_application_loader.h b/content/public/common/static_mojo_application_loader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4e0d14aeaa966b31ca401330d33e472204bd1470 |
--- /dev/null |
+++ b/content/public/common/static_mojo_application_loader.h |
@@ -0,0 +1,72 @@ |
+// 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_PUBLIC_COMMON_STATIC_MOJO_APPLICATION_LOADER_H_ |
+#define CONTENT_PUBLIC_COMMON_STATIC_MOJO_APPLICATION_LOADER_H_ |
+ |
+#include <list> |
+ |
+#include "base/callback.h" |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "content/common/content_export.h" |
+#include "mojo/shell/application_loader.h" |
+ |
+namespace base { |
+class Thread; |
+} |
+ |
+namespace mojo { |
+class ApplicationDelegate; |
+} |
+ |
+namespace content { |
+ |
+// An ApplicationLoader which knows how to instantiate a corresponding |
+// ApplicationDelegate directly. Used to load applications which are linked |
+// into content or its embedder. |
+class CONTENT_EXPORT StaticMojoApplicationLoader |
+ : public mojo::shell::ApplicationLoader { |
+ public: |
+ using ApplicationFactory = |
+ base::Callback<scoped_ptr<mojo::ApplicationDelegate>()>; |
+ |
+ // Constructs a static loader for |factory|. |
+ explicit StaticMojoApplicationLoader(const ApplicationFactory& factory); |
+ |
+ // Constructs a static loader for |factory| with a closure that will be called |
+ // when the loaded application quits. |
+ StaticMojoApplicationLoader(const ApplicationFactory& factory, |
+ const base::Closure& quit_callback); |
+ |
+ ~StaticMojoApplicationLoader() override; |
+ |
+ // mojo::shell::ApplicationLoader: |
+ void Load(const GURL& url, |
+ mojo::InterfaceRequest<mojo::Application> request) override; |
+ |
+ private: |
+ using ThreadList = std::list<scoped_ptr<base::Thread>>; |
+ |
+ void CleanUpAppThread(typename ThreadList::iterator iter); |
+ |
+ // The factory used t create new instances of the application delegate. |
+ ApplicationFactory factory_; |
+ |
+ // If not null, this is called when an instance of the loaded application |
+ // quits. |
+ base::Closure quit_callback_; |
+ |
+ // List of all threads started by this loader. Each running instance of an |
+ // application will have a corresponding thread in this list. |
+ ThreadList threads_; |
+ |
+ base::WeakPtrFactory<StaticMojoApplicationLoader> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(StaticMojoApplicationLoader); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_PUBLIC_COMMON_STATIC_MOJO_APPLICATION_LOADER_H_ |