OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/callback.h" | |
6 #include "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
7 #include "media/mojo/interfaces/service_factory.mojom.h" | 6 #include "media/mojo/interfaces/service_factory.mojom.h" |
8 #include "mojo/shell/public/cpp/interface_factory_impl.h" | 7 #include "mojo/shell/public/cpp/interface_factory_impl.h" |
9 #include "mojo/shell/public/cpp/shell_client.h" | 8 #include "mojo/shell/public/cpp/shell_client.h" |
10 #include "url/gurl.h" | 9 #include "url/gurl.h" |
11 | 10 |
12 namespace media { | 11 namespace media { |
13 | 12 |
14 class MediaLog; | 13 class MediaLog; |
15 class MojoMediaClient; | 14 class MojoMediaClient; |
16 | 15 |
17 class MojoMediaApplication | 16 class MojoMediaApplication |
18 : public mojo::ShellClient, | 17 : public mojo::ShellClient, |
19 public mojo::InterfaceFactory<interfaces::ServiceFactory> { | 18 public mojo::InterfaceFactory<interfaces::ServiceFactory> { |
20 public: | 19 public: |
21 // Callback to create a MojoMediaClient. | |
22 using CreateMojoMediaClientCB = base::Callback<scoped_ptr<MojoMediaClient>()>; | |
23 | |
24 // Creates MojoMediaApplication using the default MojoMediaClient. | |
25 static scoped_ptr<mojo::ShellClient> CreateApp(); | 20 static scoped_ptr<mojo::ShellClient> CreateApp(); |
26 | 21 |
27 // Creates MojoMediaApplication using the MojoMediaClient provided by | 22 explicit MojoMediaApplication(scoped_ptr<MojoMediaClient> mojo_media_client); |
28 // |create_mojo_media_client_cb|. | |
29 static scoped_ptr<mojo::ShellClient> CreateAppWithClient( | |
30 const CreateMojoMediaClientCB& create_mojo_media_client_cb); | |
31 | |
32 ~MojoMediaApplication() final; | 23 ~MojoMediaApplication() final; |
33 | 24 |
34 private: | 25 private: |
35 explicit MojoMediaApplication(scoped_ptr<MojoMediaClient> mojo_media_client); | |
36 | |
37 // mojo::ShellClient implementation. | 26 // mojo::ShellClient implementation. |
38 void Initialize(mojo::Shell* shell, | 27 void Initialize(mojo::Shell* shell, |
39 const std::string& url, | 28 const std::string& url, |
40 uint32_t id) final; | 29 uint32_t id) final; |
41 bool AcceptConnection(mojo::Connection* connection) final; | 30 bool AcceptConnection(mojo::Connection* connection) final; |
42 | 31 |
43 // mojo::InterfaceFactory<interfaces::ServiceFactory> implementation. | 32 // mojo::InterfaceFactory<interfaces::ServiceFactory> implementation. |
44 void Create(mojo::Connection* connection, | 33 void Create(mojo::Connection* connection, |
45 mojo::InterfaceRequest<interfaces::ServiceFactory> request) final; | 34 mojo::InterfaceRequest<interfaces::ServiceFactory> request) final; |
46 | 35 |
47 // Note: Since each instance runs on a different thread, do not share a common | |
48 // MojoMediaClient with other instances to avoid threading issues. Hence using | |
49 // a scoped_ptr here. | |
50 scoped_ptr<MojoMediaClient> mojo_media_client_; | 36 scoped_ptr<MojoMediaClient> mojo_media_client_; |
51 | |
52 mojo::Shell* shell_; | 37 mojo::Shell* shell_; |
53 scoped_refptr<MediaLog> media_log_; | 38 scoped_refptr<MediaLog> media_log_; |
54 }; | 39 }; |
55 | 40 |
56 } // namespace media | 41 } // namespace media |
OLD | NEW |