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