| 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 "media/mojo/services/mojo_media_application.h" | 5 #include "media/mojo/services/mojo_media_application.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "media/mojo/services/mojo_cdm_service.h" | 10 #include "media/mojo/services/mojo_cdm_service.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // static | 23 // static |
| 24 GURL MojoMediaApplication::AppUrl() { | 24 GURL MojoMediaApplication::AppUrl() { |
| 25 return GURL(kMojoMediaAppUrl); | 25 return GURL(kMojoMediaAppUrl); |
| 26 } | 26 } |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 scoped_ptr<mojo::ApplicationDelegate> MojoMediaApplication::CreateApp() { | 29 scoped_ptr<mojo::ApplicationDelegate> MojoMediaApplication::CreateApp() { |
| 30 return scoped_ptr<mojo::ApplicationDelegate>(new MojoMediaApplication()); | 30 return scoped_ptr<mojo::ApplicationDelegate>(new MojoMediaApplication()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 MojoMediaApplication::MojoMediaApplication() {} | 33 MojoMediaApplication::MojoMediaApplication() { |
| 34 } |
| 34 | 35 |
| 35 MojoMediaApplication::~MojoMediaApplication() {} | 36 MojoMediaApplication::~MojoMediaApplication() { |
| 37 } |
| 36 | 38 |
| 37 void MojoMediaApplication::Initialize(mojo::ApplicationImpl* app) { | 39 void MojoMediaApplication::Initialize(mojo::ApplicationImpl* app) { |
| 38 app_impl_ = app; | 40 app_impl_ = app; |
| 39 | 41 |
| 40 // Enable logging. | 42 // Enable logging. |
| 41 logging::LoggingSettings settings; | 43 logging::LoggingSettings settings; |
| 42 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 44 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 43 logging::InitLogging(settings); | 45 logging::InitLogging(settings); |
| 44 // Display process ID, thread ID and timestamp in logs. | 46 // Display process ID, thread ID and timestamp in logs. |
| 45 logging::SetLogItems(true, true, true, false); | 47 logging::SetLogItems(true, true, true, false); |
| 46 | 48 |
| 47 StartIdleTimer(); | 49 StartIdleTimer(); |
| 48 } | 50 } |
| 49 | 51 |
| 50 bool MojoMediaApplication::ConfigureIncomingConnection( | 52 bool MojoMediaApplication::ConfigureIncomingConnection( |
| 51 mojo::ApplicationConnection* connection) { | 53 mojo::ApplicationConnection* connection) { |
| 52 connection->AddService<mojo::ContentDecryptionModule>(this); | 54 connection->AddService<mojo::ContentDecryptionModule>(this); |
| 53 connection->AddService<mojo::MediaRenderer>(this); | 55 connection->AddService<mojo::MediaRenderer>(this); |
| 54 return true; | 56 return true; |
| 55 } | 57 } |
| 56 | 58 |
| 59 void MojoMediaApplication::Quit() { |
| 60 app_impl_ = nullptr; |
| 61 } |
| 62 |
| 57 void MojoMediaApplication::Create( | 63 void MojoMediaApplication::Create( |
| 58 mojo::ApplicationConnection* connection, | 64 mojo::ApplicationConnection* connection, |
| 59 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) { | 65 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) { |
| 60 // The created object is owned by the pipe. | 66 // The created object is owned by the pipe. |
| 61 MojoCdmService* mojo_cdm_service = | 67 MojoCdmService* mojo_cdm_service = new MojoCdmService( |
| 62 new MojoCdmService(&cdm_service_context_, request.Pass()); | 68 &cdm_service_context_, connection->GetServiceProvider(), request.Pass()); |
| 63 | 69 |
| 64 // Passing unretained |this| is safe here because the app is guaranteed to | 70 // Passing unretained |this| is safe here because the app is guaranteed to |
| 65 // outlive all services. | 71 // outlive all services. |
| 66 mojo_cdm_service->set_connection_error_handler(base::Bind( | 72 mojo_cdm_service->set_connection_error_handler(base::Bind( |
| 67 &MojoMediaApplication::OnConnectionError, base::Unretained(this))); | 73 &MojoMediaApplication::OnConnectionError, base::Unretained(this))); |
| 68 | 74 |
| 69 active_service_count_++; | 75 active_service_count_++; |
| 70 idle_timeout_callback_.Cancel(); | 76 idle_timeout_callback_.Cancel(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 void MojoMediaApplication::Create( | 79 void MojoMediaApplication::Create( |
| 74 mojo::ApplicationConnection* connection, | 80 mojo::ApplicationConnection* connection, |
| 75 mojo::InterfaceRequest<mojo::MediaRenderer> request) { | 81 mojo::InterfaceRequest<mojo::MediaRenderer> request) { |
| 76 // The created object is owned by the pipe. | 82 // The created object is owned by the pipe. |
| 77 MojoRendererService* mojo_renderer_service = | 83 MojoRendererService* mojo_renderer_service = |
| 78 new MojoRendererService(&cdm_service_context_, request.Pass()); | 84 new MojoRendererService(&cdm_service_context_, request.Pass()); |
| 79 | 85 |
| 80 // Passing unretained |this| is safe here because the app is guaranteed to | 86 // Passing unretained |this| is safe here because the app is guaranteed to |
| 81 // outlive all services. | 87 // outlive all services. |
| 82 mojo_renderer_service->set_connection_error_handler(base::Bind( | 88 mojo_renderer_service->set_connection_error_handler(base::Bind( |
| 83 &MojoMediaApplication::OnConnectionError, base::Unretained(this))); | 89 &MojoMediaApplication::OnConnectionError, base::Unretained(this))); |
| 84 | 90 |
| 85 active_service_count_++; | 91 active_service_count_++; |
| 86 idle_timeout_callback_.Cancel(); | 92 idle_timeout_callback_.Cancel(); |
| 87 } | 93 } |
| 88 | 94 |
| 89 void MojoMediaApplication::Quit() { | |
| 90 app_impl_ = nullptr; | |
| 91 } | |
| 92 | |
| 93 void MojoMediaApplication::StartIdleTimer() { | 95 void MojoMediaApplication::StartIdleTimer() { |
| 94 // Passing unretained |app_impl_| is safe here because |app_impl_| is | 96 // Passing unretained |app_impl_| is safe here because |app_impl_| is |
| 95 // guaranteed to outlive |this|, and the callback is canceled if |this| is | 97 // guaranteed to outlive |this|, and the callback is canceled if |this| is |
| 96 // destroyed. | 98 // destroyed. |
| 97 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Terminate, | 99 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Terminate, |
| 98 base::Unretained(app_impl_))); | 100 base::Unretained(app_impl_))); |
| 99 const int destruction_delay_ms = | 101 const int destruction_delay_ms = |
| 100 base::CommandLine::ForCurrentProcess()->HasSwitch(kFastAppDestruction) | 102 base::CommandLine::ForCurrentProcess()->HasSwitch(kFastAppDestruction) |
| 101 ? 10 | 103 ? 10 |
| 102 : kIdleTimeoutInSeconds * 1000; | 104 : kIdleTimeoutInSeconds * 1000; |
| 103 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 105 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 104 FROM_HERE, idle_timeout_callback_.callback(), | 106 FROM_HERE, idle_timeout_callback_.callback(), |
| 105 base::TimeDelta::FromMilliseconds(destruction_delay_ms)); | 107 base::TimeDelta::FromMilliseconds(destruction_delay_ms)); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void MojoMediaApplication::OnConnectionError() { | 110 void MojoMediaApplication::OnConnectionError() { |
| 109 DCHECK_GT(active_service_count_, 0u); | 111 DCHECK_GT(active_service_count_, 0u); |
| 110 active_service_count_--; | 112 active_service_count_--; |
| 111 if (active_service_count_ == 0) { | 113 if (active_service_count_ == 0) { |
| 112 // If the last service connection has been dropped, kick off an idle timeout | 114 // If the last service connection has been dropped, kick off an idle timeout |
| 113 // to shut ourselves down. | 115 // to shut ourselves down. |
| 114 StartIdleTimer(); | 116 StartIdleTimer(); |
| 115 } | 117 } |
| 116 } | 118 } |
| 117 | 119 |
| 118 } // namespace media | 120 } // namespace media |
| OLD | NEW |