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/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "services/shell/public/cpp/shell_client.h" | 15 #include "services/shell/public/cpp/shell_client.h" |
15 #include "services/shell/public/interfaces/shell_client.mojom.h" | 16 #include "services/shell/public/interfaces/shell_client.mojom.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // Hosts an in-process application instance that supports multiple ShellClient | 20 // Hosts an in-process application instance that supports multiple ShellClient |
20 // connections. The first incoming connection will invoke a provided factory | 21 // connections. The first incoming connection will invoke a provided factory |
21 // function to instantiate the application, and the application will | 22 // function to instantiate the application, and the application will |
22 // automatically be torn down when its last connection is lost. The application | 23 // automatically be torn down when its last connection is lost. The application |
(...skipping 11 matching lines...) Expand all Loading... |
34 const FactoryCallback& callback, | 35 const FactoryCallback& callback, |
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
36 | 37 |
37 ~EmbeddedApplicationRunner(); | 38 ~EmbeddedApplicationRunner(); |
38 | 39 |
39 // Binds an incoming ShellClientRequest for this application. If the | 40 // Binds an incoming ShellClientRequest for this application. If the |
40 // application isn't already running, it's started. Otherwise the request is | 41 // application isn't already running, it's started. Otherwise the request is |
41 // bound to the running instance. | 42 // bound to the running instance. |
42 void BindShellClientRequest(shell::mojom::ShellClientRequest request); | 43 void BindShellClientRequest(shell::mojom::ShellClientRequest request); |
43 | 44 |
| 45 // Sets a callback to run after the application loses its last connection and |
| 46 // is torn down. |
| 47 void SetQuitClosure(const base::Closure& quit_closure); |
| 48 |
44 private: | 49 private: |
45 class Instance; | 50 class Instance; |
46 | 51 |
| 52 void OnQuit(); |
| 53 |
47 // The TaskRunner on which the factory callback will be run. The | 54 // The TaskRunner on which the factory callback will be run. The |
48 // shell::ShellClient it returns will live and die on this TaskRunner's | 55 // shell::ShellClient it returns will live and die on this TaskRunner's |
49 // thread. | 56 // thread. |
50 const scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_; | 57 const scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_; |
51 | 58 |
52 // A reference to the application instance which may operate on the | 59 // A reference to the application instance which may operate on the |
53 // |application_task_runner_|'s thread. | 60 // |application_task_runner_|'s thread. |
54 scoped_refptr<Instance> instance_; | 61 scoped_refptr<Instance> instance_; |
55 | 62 |
| 63 base::Closure quit_closure_; |
| 64 |
| 65 base::WeakPtrFactory<EmbeddedApplicationRunner> weak_factory_; |
| 66 |
56 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); | 67 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); |
57 }; | 68 }; |
58 | 69 |
59 } // namespace content | 70 } // namespace content |
60 | 71 |
61 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ | 72 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ |
OLD | NEW |