| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ |
| 6 #define CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "services/shell/public/cpp/shell_client.h" |
| 15 #include "services/shell/public/interfaces/shell_client.mojom.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 // Hosts an in-process application instance that supports multiple ShellClient |
| 20 // connections. The first incoming connection will invoke a provided factory |
| 21 // function to instantiate the application, and the application will |
| 22 // automatically be torn down when its last connection is lost. The application |
| 23 // may be launched and torn down multiple times by a single |
| 24 // EmbeddedApplicationRunner instance. |
| 25 class EmbeddedApplicationRunner { |
| 26 public: |
| 27 using FactoryCallback = |
| 28 base::Callback<std::unique_ptr<mojo::ShellClient>()>; |
| 29 |
| 30 // Constructs a runner which hosts the application on |task_runner|'s thread. |
| 31 // If an existing instance of the app is not running when an incoming |
| 32 // connection is made, |callback| will be run on |task_runner|'s thread to |
| 33 // create a new instance which will live on that thread. |
| 34 EmbeddedApplicationRunner( |
| 35 const FactoryCallback& callback, |
| 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 37 |
| 38 ~EmbeddedApplicationRunner(); |
| 39 |
| 40 // Binds an incoming ShellClientRequest for this application. If the |
| 41 // application isn't already running, it's started. Otherwise the request is |
| 42 // bound to the running instance. |
| 43 void BindShellClientRequest(mojo::shell::mojom::ShellClientRequest request); |
| 44 |
| 45 private: |
| 46 class Instance; |
| 47 |
| 48 // The TaskRunner on which the factory callback will be run. The |
| 49 // mojo::ShellClient it returns will live and die on this TaskRunner's thread. |
| 50 const scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_; |
| 51 |
| 52 // A reference to the application instance which may operate on the |
| 53 // |application_task_runner_|'s thread. |
| 54 scoped_refptr<Instance> instance_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); |
| 57 }; |
| 58 |
| 59 } // namespace content |
| 60 |
| 61 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ |
| OLD | NEW |