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

Side by Side Diff: content/common/mojo/embedded_application_runner.h

Issue 1978843003: Move in-GPU mojo:media app to new thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
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"
16 #include "content/public/common/mojo_application_info.h"
15 #include "services/shell/public/cpp/shell_client.h" 17 #include "services/shell/public/cpp/shell_client.h"
16 #include "services/shell/public/interfaces/shell_client.mojom.h" 18 #include "services/shell/public/interfaces/shell_client.mojom.h"
17 19
18 namespace content { 20 namespace content {
19 21
20 // Hosts an in-process application instance that supports multiple ShellClient 22 // Hosts an in-process application instance that supports multiple ShellClient
21 // connections. The first incoming connection will invoke a provided factory 23 // connections. The first incoming connection will invoke a provided factory
22 // function to instantiate the application, and the application will 24 // function to instantiate the application, and the application will
23 // 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
24 // may be launched and torn down multiple times by a single 26 // may be launched and torn down multiple times by a single
25 // EmbeddedApplicationRunner instance. 27 // EmbeddedApplicationRunner instance.
26 class EmbeddedApplicationRunner { 28 class EmbeddedApplicationRunner {
27 public: 29 public:
28 // Callback used to construct a new instance of the embedded application. Note 30 // Constructs a runner which hosts a Mojo application. If an existing instance
29 // that |quit_closure| destroys the returned ShellClient instance when run. 31 // of the app is not running when an incoming connection is made, details from
30 using FactoryCallback = base::Callback< 32 // |info| will be used to construct a new instance.
31 std::unique_ptr<shell::ShellClient>(const base::Closure& quit_closure)>; 33 EmbeddedApplicationRunner(const base::StringPiece& name,
32 34 const MojoApplicationInfo& info);
33 // Constructs a runner which hosts the application on |task_runner|'s thread.
34 // If an existing instance of the app is not running when an incoming
35 // connection is made, |callback| will be run on |task_runner|'s thread to
36 // create a new instance which will live on that thread.
37 //
38 // If |task_runner| is null, the calling thread's TaskRunner is used.
39 EmbeddedApplicationRunner(
40 const FactoryCallback& callback,
41 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
42
43 ~EmbeddedApplicationRunner(); 35 ~EmbeddedApplicationRunner();
44 36
45 // Binds an incoming ShellClientRequest for this application. If the 37 // Binds an incoming ShellClientRequest for this application. If the
46 // 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
47 // bound to the running instance. 39 // bound to the running instance.
48 void BindShellClientRequest(shell::mojom::ShellClientRequest request); 40 void BindShellClientRequest(shell::mojom::ShellClientRequest request);
49 41
50 // 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
51 // is torn down. 43 // is torn down.
52 void SetQuitClosure(const base::Closure& quit_closure); 44 void SetQuitClosure(const base::Closure& quit_closure);
53 45
54 private: 46 private:
55 class Instance; 47 class Instance;
56 48
57 void OnQuit(); 49 void OnQuit();
58 50
59 // The TaskRunner on which the factory callback will be run. The
60 // shell::ShellClient it returns will live and die on this TaskRunner's
61 // thread.
62 const scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_;
63
64 // A reference to the application instance which may operate on the 51 // A reference to the application instance which may operate on the
65 // |application_task_runner_|'s thread. 52 // |application_task_runner_|'s thread.
66 scoped_refptr<Instance> instance_; 53 scoped_refptr<Instance> instance_;
67 54
68 base::Closure quit_closure_; 55 base::Closure quit_closure_;
69 56
70 base::WeakPtrFactory<EmbeddedApplicationRunner> weak_factory_; 57 base::WeakPtrFactory<EmbeddedApplicationRunner> weak_factory_;
71 58
72 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); 59 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner);
73 }; 60 };
74 61
75 } // namespace content 62 } // namespace content
76 63
77 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ 64 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_
OLDNEW
« no previous file with comments | « content/child/process_control_impl.cc ('k') | content/common/mojo/embedded_application_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698