Chromium Code Reviews| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "media/mojo/services/mojo_cdm_factory_service.h" | |
| 9 #include "media/mojo/services/mojo_cdm_service_context.h" | |
| 8 #include "media/mojo/services/mojo_renderer_service.h" | 10 #include "media/mojo/services/mojo_renderer_service.h" |
| 9 #include "mojo/application/application_runner_chromium.h" | 11 #include "mojo/application/application_runner_chromium.h" |
| 10 #include "third_party/mojo/src/mojo/public/c/system/main.h" | 12 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
| 11 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h" | 13 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h" |
| 12 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h" | 14 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate. h" |
| 13 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" | 15 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h" |
| 14 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp l.h" | 16 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory_imp l.h" |
| 15 | 17 |
| 16 namespace media { | 18 namespace media { |
| 17 | 19 |
| 20 static void EnableLoggingFromArgs(const std::vector<std::string>& args) { | |
| 21 base::CommandLine::StringVector command_line_args; | |
| 22 #if defined(OS_WIN) | |
| 23 for (const auto& arg : args) | |
| 24 command_line_args.push_back(base::UTF8ToUTF16(arg)); | |
| 25 #elif defined(OS_POSIX) | |
| 26 command_line_args = args; | |
| 27 #endif | |
| 28 | |
| 29 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 30 command_line->InitFromArgv(command_line_args); | |
|
ddorwin
2015/05/15 19:10:07
What is all this command line stuff used for? The
| |
| 31 | |
| 32 logging::LoggingSettings settings; | |
| 33 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
| 34 logging::InitLogging(settings); | |
| 35 // Display process ID, thread ID and timestamp in logs. | |
| 36 logging::SetLogItems(true, true, true, false); | |
| 37 } | |
| 38 | |
| 39 // mojo:media app that provides multiple media services. | |
| 18 class MojoMediaApplication | 40 class MojoMediaApplication |
| 19 : public mojo::ApplicationDelegate, | 41 : public mojo::ApplicationDelegate, |
| 42 public mojo::InterfaceFactory<mojo::ContentDecryptionModuleFactory>, | |
| 20 public mojo::InterfaceFactory<mojo::MediaRenderer> { | 43 public mojo::InterfaceFactory<mojo::MediaRenderer> { |
| 21 public: | 44 public: |
| 22 // mojo::ApplicationDelegate implementation. | 45 // mojo::ApplicationDelegate implementation. |
| 23 void Initialize(mojo::ApplicationImpl* app) override { | 46 void Initialize(mojo::ApplicationImpl* app) final { |
| 24 base::CommandLine::StringVector command_line_args; | 47 EnableLoggingFromArgs(app->args()); |
| 25 #if defined(OS_WIN) | |
| 26 for (const auto& arg : app->args()) | |
| 27 command_line_args.push_back(base::UTF8ToUTF16(arg)); | |
| 28 #elif defined(OS_POSIX) | |
| 29 command_line_args = app->args(); | |
| 30 #endif | |
| 31 | |
| 32 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 33 command_line->InitFromArgv(command_line_args); | |
| 34 | |
| 35 logging::LoggingSettings settings; | |
| 36 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
| 37 logging::InitLogging(settings); | |
| 38 // Display process ID, thread ID and timestamp in logs. | |
| 39 logging::SetLogItems(true, true, true, false); | |
| 40 } | 48 } |
| 41 | 49 |
| 42 bool ConfigureIncomingConnection( | 50 bool ConfigureIncomingConnection( |
| 43 mojo::ApplicationConnection* connection) override { | 51 mojo::ApplicationConnection* connection) final { |
| 44 connection->AddService(this); | 52 connection->AddService<mojo::ContentDecryptionModuleFactory>(this); |
| 53 connection->AddService<mojo::MediaRenderer>(this); | |
| 45 return true; | 54 return true; |
| 46 } | 55 } |
| 47 | 56 |
| 57 // mojo::InterfaceFactory<mojo::ContentDecryptionModuleFactory> | |
| 58 // implementation. | |
| 59 void Create(mojo::ApplicationConnection* connection, | |
| 60 mojo::InterfaceRequest<mojo::ContentDecryptionModuleFactory> | |
| 61 request) final { | |
| 62 mojo::BindToRequest(new MojoCdmFactoryService(&cdm_service_context_), | |
| 63 &request); | |
| 64 } | |
| 65 | |
| 48 // mojo::InterfaceFactory<mojo::MediaRenderer> implementation. | 66 // mojo::InterfaceFactory<mojo::MediaRenderer> implementation. |
| 49 void Create(mojo::ApplicationConnection* connection, | 67 void Create(mojo::ApplicationConnection* connection, |
| 50 mojo::InterfaceRequest<mojo::MediaRenderer> request) override { | 68 mojo::InterfaceRequest<mojo::MediaRenderer> request) final { |
| 51 mojo::BindToRequest(new MojoRendererService(), &request); | 69 mojo::BindToRequest(new MojoRendererService(&cdm_service_context_), |
| 70 &request); | |
| 52 } | 71 } |
| 72 | |
| 73 private: | |
| 74 MojoCdmServiceContext cdm_service_context_; | |
| 53 }; | 75 }; |
| 54 | 76 |
| 55 } // namespace media | 77 } // namespace media |
| 56 | 78 |
| 57 MojoResult MojoMain(MojoHandle mojo_handle) { | 79 MojoResult MojoMain(MojoHandle mojo_handle) { |
| 58 mojo::ApplicationRunnerChromium runner(new media::MojoMediaApplication()); | 80 mojo::ApplicationRunnerChromium runner(new media::MojoMediaApplication()); |
| 59 return runner.Run(mojo_handle); | 81 return runner.Run(mojo_handle); |
| 60 } | 82 } |
| OLD | NEW |