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