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

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
29 // that |quit_closure| destroys the returned ShellClient instance when run.
30 using FactoryCallback = base::Callback<
31 std::unique_ptr<shell::ShellClient>(const base::Closure& quit_closure)>;
32
33 // Constructs a runner which hosts the application on |task_runner|'s thread. 30 // 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 31 // 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 32 // connection is made, |callback| will be run on |task_runner|'s thread to
36 // create a new instance which will live on that thread. 33 // create a new instance which will live on that thread.
37 // 34 //
38 // If |task_runner| is null, the calling thread's TaskRunner is used. 35 // If |task_runner| is null, the calling thread's TaskRunner is used.
39 EmbeddedApplicationRunner( 36 EmbeddedApplicationRunner(const base::StringPiece& name,
40 const FactoryCallback& callback, 37 const MojoApplicationInfo& info);
41 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
42
43 ~EmbeddedApplicationRunner(); 38 ~EmbeddedApplicationRunner();
44 39
45 // Binds an incoming ShellClientRequest for this application. If the 40 // Binds an incoming ShellClientRequest for this application. If the
46 // 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
47 // bound to the running instance. 42 // bound to the running instance.
48 void BindShellClientRequest(shell::mojom::ShellClientRequest request); 43 void BindShellClientRequest(shell::mojom::ShellClientRequest request);
49 44
50 // Sets a callback to run after the application loses its last connection and 45 // Sets a callback to run after the application loses its last connection and
51 // is torn down. 46 // is torn down.
52 void SetQuitClosure(const base::Closure& quit_closure); 47 void SetQuitClosure(const base::Closure& quit_closure);
53 48
54 private: 49 private:
55 class Instance; 50 class Instance;
56 51
57 void OnQuit(); 52 void OnQuit();
58 53
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 54 // A reference to the application instance which may operate on the
65 // |application_task_runner_|'s thread. 55 // |application_task_runner_|'s thread.
66 scoped_refptr<Instance> instance_; 56 scoped_refptr<Instance> instance_;
67 57
68 base::Closure quit_closure_; 58 base::Closure quit_closure_;
69 59
70 base::WeakPtrFactory<EmbeddedApplicationRunner> weak_factory_; 60 base::WeakPtrFactory<EmbeddedApplicationRunner> weak_factory_;
71 61
72 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner); 62 DISALLOW_COPY_AND_ASSIGN(EmbeddedApplicationRunner);
73 }; 63 };
74 64
75 } // namespace content 65 } // namespace content
76 66
77 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_ 67 #endif // CONTENT_COMMON_MOJO_EMBEDDED_APPLICATION_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698