Commit a1d88aae authored by Saman Sami's avatar Saman Sami Committed by Commit Bot

Make ash::VideoDetector recover from viz crashes

Observe mojo connection errors and re-establish the connection once
it's lost.

Bug: 780514
Change-Id: Ic393f737bee97b97ed588ea47040327a4b639a4b
Reviewed-on: https://chromium-review.googlesource.com/c/1340945Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Saman Sami <samans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609009}
parent 70b4aa44
......@@ -1175,12 +1175,7 @@ void Shell::Init(
std::make_unique<DockedMagnifierController>();
}
viz::mojom::VideoDetectorObserverPtr observer;
video_detector_ =
std::make_unique<VideoDetector>(mojo::MakeRequest(&observer));
aura_env_->context_factory_private()
->GetHostFrameSinkManager()
->AddVideoDetectorObserver(std::move(observer));
video_detector_ = std::make_unique<VideoDetector>();
tooltip_controller_.reset(new views::corewm::TooltipController(
std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
......
......@@ -23,8 +23,7 @@ class VideoActivityNotifierTest : public AshTestBase {
AshTestBase::SetUp();
power_client_ = static_cast<chromeos::FakePowerManagerClient*>(
chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
detector_ = std::make_unique<VideoDetector>(
viz::mojom::VideoDetectorObserverRequest());
detector_ = std::make_unique<VideoDetector>();
notifier_.reset(new VideoActivityNotifier(detector_.get()));
}
......
......@@ -7,6 +7,7 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/window_state.h"
#include "components/viz/host/host_frame_sink_manager.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
......@@ -15,15 +16,25 @@
namespace ash {
VideoDetector::VideoDetector(viz::mojom::VideoDetectorObserverRequest request)
namespace {
// How long to wait before attempting to re-establish a lost connection.
constexpr base::TimeDelta kReEstablishConnectionDelay =
base::TimeDelta::FromMilliseconds(100);
} // namespace
VideoDetector::VideoDetector()
: state_(State::NOT_PLAYING),
video_is_playing_(false),
window_observer_manager_(this),
scoped_session_observer_(this),
is_shutting_down_(false),
binding_(this, std::move(request)) {
binding_(this),
weak_factory_(this) {
Shell::Get()->aura_env()->AddObserver(this);
Shell::Get()->AddShellObserver(this);
EstablishConnectionToViz();
}
VideoDetector::~VideoDetector() {
......@@ -101,4 +112,28 @@ void VideoDetector::OnVideoActivityEnded() {
UpdateState();
}
void VideoDetector::EstablishConnectionToViz() {
viz::mojom::VideoDetectorObserverPtr observer;
if (binding_.is_bound())
binding_.Close();
binding_.Bind(mojo::MakeRequest(&observer));
binding_.set_connection_error_handler(base::BindOnce(
&VideoDetector::OnConnectionError, base::Unretained(this)));
Shell::Get()
->aura_env()
->context_factory_private()
->GetHostFrameSinkManager()
->AddVideoDetectorObserver(std::move(observer));
}
void VideoDetector::OnConnectionError() {
if (video_is_playing_)
OnVideoActivityEnded();
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&VideoDetector::EstablishConnectionToViz,
weak_factory_.GetWeakPtr()),
kReEstablishConnectionDelay);
}
} // namespace ash
......@@ -59,7 +59,7 @@ class ASH_EXPORT VideoDetector : public aura::EnvObserver,
virtual ~Observer() {}
};
VideoDetector(viz::mojom::VideoDetectorObserverRequest request);
VideoDetector();
~VideoDetector() override;
State state() const { return state_; }
......@@ -89,6 +89,13 @@ class ASH_EXPORT VideoDetector : public aura::EnvObserver,
// Updates |state_| and notifies |observers_| if it changed.
void UpdateState();
// Connects to Viz and starts observing video activities.
void EstablishConnectionToViz();
// Called when connection to Viz is lost. The connection will be
// re-established after a short delay.
void OnConnectionError();
// Current playback state.
State state_;
......@@ -107,6 +114,8 @@ class ASH_EXPORT VideoDetector : public aura::EnvObserver,
mojo::Binding<viz::mojom::VideoDetectorObserver> binding_;
base::WeakPtrFactory<VideoDetector> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(VideoDetector);
};
......
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