Commit 76a76332 authored by Ryo Hashimoto's avatar Ryo Hashimoto Committed by Commit Bot

ash: Fix race condition around Surface finding

exo::Surface might be unavailable when:
- Just after the Activity starts
- It's getting recreated when resizing the window.

BUG=925769
TEST=manually

Change-Id: Ie6dbf9349aeec6f65366fb3d1f077135c0439dd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1493689Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649741}
parent 39a85450
......@@ -72,7 +72,7 @@ mojom::ArcCustomTabViewPtr ArcCustomTabView::Create(int32_t task_id,
return nullptr;
}
auto* parent = widget->widget_delegate()->GetContentsView();
auto* view = new ArcCustomTabView(surface_id, top_margin);
auto* view = new ArcCustomTabView(arc_app_window, surface_id, top_margin);
parent->AddChildView(view);
parent->SetLayoutManager(std::make_unique<views::FillLayout>());
parent->Layout();
......@@ -118,17 +118,32 @@ void ArcCustomTabView::Layout() {
window->parent()->StackChildAtTop(window);
}
ArcCustomTabView::ArcCustomTabView(int32_t surface_id, int32_t top_margin)
void ArcCustomTabView::OnWindowHierarchyChanged(
const HierarchyChangeParams& params) {
auto* surface = exo::Surface::AsSurface(params.target);
if (surface && surface->GetClientSurfaceId() == surface_id_ &&
params.new_parent != nullptr) {
Layout();
}
}
ArcCustomTabView::ArcCustomTabView(aura::Window* arc_app_window,
int32_t surface_id,
int32_t top_margin)
: binding_(this),
remote_view_host_(new ws::ServerRemoteViewHost(
ash::Shell::Get()->window_service_owner()->window_service())),
arc_app_window_(arc_app_window),
surface_id_(surface_id),
top_margin_(top_margin),
weak_ptr_factory_(this) {
AddChildView(remote_view_host_);
arc_app_window_->AddObserver(this);
}
ArcCustomTabView::~ArcCustomTabView() = default;
ArcCustomTabView::~ArcCustomTabView() {
arc_app_window_->RemoveObserver(this);
}
void ArcCustomTabView::Bind(mojom::ArcCustomTabViewPtr* ptr) {
binding_.Bind(mojo::MakeRequest(ptr));
......
......@@ -11,12 +11,15 @@
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/ws/remote_view_host/server_remote_view_host.h"
#include "ui/aura/window_observer.h"
#include "ui/views/view.h"
namespace ash {
// Implementation of ArcCustomTabView interface.
class ArcCustomTabView : public views::View, public mojom::ArcCustomTabView {
class ArcCustomTabView : public views::View,
public mojom::ArcCustomTabView,
public aura::WindowObserver {
public:
// Creates a new ArcCustomTabView instance. The instance will be deleted when
// the pointer is closed. Returns null when the arguments are invalid.
......@@ -30,8 +33,13 @@ class ArcCustomTabView : public views::View, public mojom::ArcCustomTabView {
// views::View:
void Layout() override;
// aura::WindowObserver:
void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
private:
ArcCustomTabView(int32_t surface_id, int32_t top_margin);
ArcCustomTabView(aura::Window* arc_app_window,
int32_t surface_id,
int32_t top_margin);
~ArcCustomTabView() override;
// Binds this instance to the pointer.
......@@ -45,6 +53,7 @@ class ArcCustomTabView : public views::View, public mojom::ArcCustomTabView {
mojo::Binding<mojom::ArcCustomTabView> binding_;
ws::ServerRemoteViewHost* remote_view_host_;
aura::Window* arc_app_window_;
int32_t surface_id_, top_margin_;
base::WeakPtrFactory<ArcCustomTabView> weak_ptr_factory_;
......
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