Commit 3e0000af authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert SystemInfo to new Mojo types

This CL converts SystemInfo{Ptr, Request} in services to the
new Mojo types.

Bug: 955171
Change-Id: Ie5d39d40751a95a20cafbddcc118d76c2090b01a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787636
Commit-Queue: Olga Sharonova <olka@chromium.org>
Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697558}
parent 0b18317e
...@@ -227,14 +227,10 @@ OnInputDeviceInfoCallback WrapGetInputDeviceInfoReply( ...@@ -227,14 +227,10 @@ OnInputDeviceInfoCallback WrapGetInputDeviceInfoReply(
AudioSystemToServiceAdapter::AudioSystemToServiceAdapter( AudioSystemToServiceAdapter::AudioSystemToServiceAdapter(
std::unique_ptr<service_manager::Connector> connector, std::unique_ptr<service_manager::Connector> connector,
base::TimeDelta disconnect_timeout) base::TimeDelta disconnect_timeout)
: connector_(std::move(connector)) { : connector_(std::move(connector)),
disconnect_timeout_(disconnect_timeout) {
DCHECK(connector_); DCHECK(connector_);
DETACH_FROM_THREAD(thread_checker_); DETACH_FROM_THREAD(thread_checker_);
if (disconnect_timeout > base::TimeDelta()) {
disconnect_timer_.emplace(
FROM_HERE, disconnect_timeout, this,
&AudioSystemToServiceAdapter::DisconnectOnTimeout);
}
} }
AudioSystemToServiceAdapter::AudioSystemToServiceAdapter( AudioSystemToServiceAdapter::AudioSystemToServiceAdapter(
...@@ -324,30 +320,17 @@ mojom::SystemInfo* AudioSystemToServiceAdapter::GetSystemInfo() { ...@@ -324,30 +320,17 @@ mojom::SystemInfo* AudioSystemToServiceAdapter::GetSystemInfo() {
if (!system_info_) { if (!system_info_) {
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0( TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
"audio", "AudioSystemToServiceAdapter bound", this); "audio", "AudioSystemToServiceAdapter bound", this);
connector_->BindInterface(mojom::kServiceName, connector_->Connect(mojom::kServiceName,
mojo::MakeRequest(&system_info_)); system_info_.BindNewPipeAndPassReceiver());
system_info_.set_connection_error_handler( system_info_.set_disconnect_handler(
base::BindOnce(&AudioSystemToServiceAdapter::OnConnectionError, base::BindOnce(&AudioSystemToServiceAdapter::OnConnectionError,
base::Unretained(this))); base::Unretained(this)));
if (!disconnect_timeout_.is_zero())
system_info_.reset_on_idle_timeout(disconnect_timeout_);
DCHECK(system_info_); DCHECK(system_info_);
} }
if (disconnect_timer_)
disconnect_timer_->Reset();
return system_info_.get();
}
void AudioSystemToServiceAdapter::DisconnectOnTimeout() { return system_info_.get();
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (system_info_.IsExpectingResponse()) {
if (disconnect_timer_)
disconnect_timer_->Reset();
TRACE_EVENT_NESTABLE_ASYNC_INSTANT0("audio", "Timeout: expecting responce",
this);
return;
}
TRACE_EVENT_NESTABLE_ASYNC_END1("audio", "AudioSystemToServiceAdapter bound",
this, "disconnect reason", "timeout");
system_info_.reset();
} }
void AudioSystemToServiceAdapter::OnConnectionError() { void AudioSystemToServiceAdapter::OnConnectionError() {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "media/audio/audio_system.h" #include "media/audio/audio_system.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/audio/public/mojom/system_info.mojom.h" #include "services/audio/public/mojom/system_info.mojom.h"
namespace service_manager { namespace service_manager {
...@@ -57,15 +58,14 @@ class AudioSystemToServiceAdapter : public media::AudioSystem { ...@@ -57,15 +58,14 @@ class AudioSystemToServiceAdapter : public media::AudioSystem {
private: private:
mojom::SystemInfo* GetSystemInfo(); mojom::SystemInfo* GetSystemInfo();
void DisconnectOnTimeout();
void OnConnectionError(); void OnConnectionError();
// Will be bound to the thread AudioSystemToServiceAdapter is used on. // Will be bound to the thread AudioSystemToServiceAdapter is used on.
const std::unique_ptr<service_manager::Connector> connector_; const std::unique_ptr<service_manager::Connector> connector_;
mojom::SystemInfoPtr system_info_; mojo::Remote<mojom::SystemInfo> system_info_;
// To disconnect from the audio service when not in use. // To disconnect from the audio service when not in use.
base::Optional<base::DelayTimer> disconnect_timer_; const base::TimeDelta disconnect_timeout_;
THREAD_CHECKER(thread_checker_); THREAD_CHECKER(thread_checker_);
DISALLOW_COPY_AND_ASSIGN(AudioSystemToServiceAdapter); DISALLOW_COPY_AND_ASSIGN(AudioSystemToServiceAdapter);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/system/message_pipe.h"
#include "services/audio/public/mojom/system_info.mojom.h" #include "services/audio/public/mojom/system_info.mojom.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment