| 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/memory/weak_ptr.h" | |
| 14 #include "base/single_thread_task_runner.h" | |
| 15 #include "base/strings/string_piece.h" | |
| 16 #include "content/public/common/mojo_application_info.h" | |
| 17 #include "services/shell/public/cpp/service.h" | |
| 18 #include "services/shell/public/interfaces/service.mojom.h" | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 // Hosts an in-process application instance that supports multiple Service | |
| 23 // connections. The first incoming connection will invoke a provided factory | |
| 24 // function to instantiate the application, and the application will | |
| 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 | |
| 27 // EmbeddedApplicationRunner instance. | |
| 28 class EmbeddedApplicationRunner { | |
| 29 public: | |
| 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 | |
| 32 // |info| will be used to construct a new instance. | |
| 33 EmbeddedApplicationRunner(const base::StringPiece& name, | |
| 34 const MojoApplicationInfo& info); | |
| 35 ~EmbeddedApplicationRunner(); | |
| 36 | |
| 37 // Binds an incoming ServiceRequest for this application. If the | |
| 38 // application isn't already running, it's started. Otherwise the request is | |
| 39 // bound to the running instance. | |
| 40 void BindServiceRequest(shell::mojom::ServiceRequest request); | |
| 41 | |
| 42 // Sets a callback to run after the application loses its last connection and | |
| 43 // is torn down. | |
| 44 void SetQuitClosure(const base::Closure& quit_closure); | |
| 45 | |
| 46 private: | |
| 47 class Instance; | |
| 48 | |
| 49 void OnQuit(); | |
| 50 | |
| 51 // A reference to the application instance which may operate on the | |
| 52 // |application_task_runner_|'s thread. | |
| 53 scoped_refptr<Instance> instance_; | |
| 54 | |
| 55 base::Closure quit_closure_; | |
| 56 | |
| 57 base::WeakPtrFactory<EmbeddedApplicationRunner> weak_factory_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); | |
| 60 }; | |
| 61 | |
| 62 } // namespace content | |
| 63 | |
| 64 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ | |
| OLD | NEW |