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

Unified Diff: content/public/common/static_mojo_application_loader.h

Issue 1128453004: Embed a simple Mojo shell in content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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: 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..e312ac5a14f2b4b2afeb880751bbb5a539f9d52a
--- /dev/null
+++ b/content/public/common/static_mojo_application_loader.h
@@ -0,0 +1,66 @@
+// 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 <string>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "mojo/shell/application_loader.h"
+
+namespace base {
+class Thread;
+}
+
+namespace mojo {
+class ApplicationDelegate;
+}
+
+namespace content {
+
+// This ApplicationLoader may be used to load applications which are linked into
+// the content embedder's binary.
+class StaticMojoApplicationLoader : public mojo::shell::ApplicationLoader {
+ public:
+ using ApplicationFactory =
+ base::Callback<scoped_ptr<mojo::ApplicationDelegate>()>;
+
+ // Create a new loader for a static applications. |name| is used to identify
+ // application-main threads. |factory| MUST be safe to run on any thread.
+ StaticMojoApplicationLoader(const std::string& name,
+ const ApplicationFactory& factory);
+ ~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 ClearThread(typename ThreadList::iterator iter);
+
+ // The name to use this app's threads.
+ std::string name_;
+
+ // The factory used to create new instances of the application's delegate.
+ ApplicationFactory factory_;
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698