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

Unified Diff: services/native_support/main.cc

Issue 1321253010: Add a "native_support" service. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix android? Created 5 years, 3 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
« no previous file with comments | « services/native_support/BUILD.gn ('k') | services/native_support/make_pty_pair.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/native_support/main.cc
diff --git a/services/native_support/main.cc b/services/native_support/main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dc576a212a3b4db7dd97481ff00d11f1ab315bd6
--- /dev/null
+++ b/services/native_support/main.cc
@@ -0,0 +1,62 @@
+// 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 "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop/message_loop.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "mojo/application/application_runner_chromium.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/interface_factory.h"
+#include "mojo/services/native_support/public/interfaces/process.mojom.h"
+#include "services/native_support/process_impl.h"
+
+namespace native_support {
+
+// TODO(vtl): Having to manually choose an arbitrary number is dumb.
+const size_t kMaxWorkerThreads = 16;
+
+class NativeSupportApp : public mojo::ApplicationDelegate,
+ public mojo::InterfaceFactory<Process> {
+ public:
+ NativeSupportApp() {}
+ ~NativeSupportApp() override {
+ if (worker_pool_)
+ worker_pool_->Shutdown();
+ }
+
+ private:
+ // |mojo::ApplicationDelegate| override:
+ bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) override {
+ connection->AddService<Process>(this);
+ return true;
+ }
+
+ // |InterfaceFactory<Process>| implementation:
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<Process> request) override {
+ if (!worker_pool_) {
+ worker_pool_ = new base::SequencedWorkerPool(kMaxWorkerThreads,
+ "NativeSupportWorker");
+ }
+ new ProcessImpl(worker_pool_, connection, request.Pass());
+ }
+
+ scoped_refptr<base::SequencedWorkerPool> worker_pool_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeSupportApp);
+};
+
+} // namespace native_support
+
+MojoResult MojoMain(MojoHandle application_request) {
+ mojo::ApplicationRunnerChromium runner(
+ new native_support::NativeSupportApp());
+ // We need an I/O message loop, since we'll want to watch FDs.
+ runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
+ return runner.Run(application_request);
+}
« no previous file with comments | « services/native_support/BUILD.gn ('k') | services/native_support/make_pty_pair.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698