Chromium Code Reviews| Index: ui/aura/mus/capture_synchronizer.cc |
| diff --git a/ui/aura/mus/capture_synchronizer.cc b/ui/aura/mus/capture_synchronizer.cc |
| index 67dacb4e9d5672b55204f2980242e71c5ca52f0f..2b3fab75e1367524da4482cfc4497c38e6c310bd 100644 |
| --- a/ui/aura/mus/capture_synchronizer.cc |
| +++ b/ui/aura/mus/capture_synchronizer.cc |
| @@ -10,49 +10,60 @@ |
| #include "ui/aura/mus/capture_synchronizer_delegate.h" |
| #include "ui/aura/mus/window_mus.h" |
| #include "ui/aura/window.h" |
| +#include "ui/aura/window_property.h" |
| namespace aura { |
| CaptureSynchronizer::CaptureSynchronizer(CaptureSynchronizerDelegate* delegate, |
| - ui::mojom::WindowTree* window_tree, |
| - client::CaptureClient* capture_client) |
| - : delegate_(delegate), |
| - window_tree_(window_tree), |
| - capture_client_(capture_client) { |
| - capture_client_->AddObserver(this); |
| -} |
| + ui::mojom::WindowTree* window_tree) |
| + : delegate_(delegate), window_tree_(window_tree) {} |
| -CaptureSynchronizer::~CaptureSynchronizer() { |
| - SetCaptureWindow(nullptr); |
| - capture_client_->RemoveObserver(this); |
| -} |
| +CaptureSynchronizer::~CaptureSynchronizer() {} |
| void CaptureSynchronizer::SetCaptureFromServer(WindowMus* window) { |
| if (window == capture_window_) |
| return; |
| DCHECK(!setting_capture_); |
| - // Don't immediately set |capture_client_|. It's possible the change will be |
| + // Don't immediately set capture client. It's possible the change will be |
| // rejected. |
| base::AutoReset<bool> capture_reset(&setting_capture_, true); |
| base::AutoReset<WindowMus*> window_setting_capture_to_reset( |
| &window_setting_capture_to_, window); |
| - capture_client_->SetCapture(window ? window->GetWindow() : nullptr); |
| + client::CaptureClient* capture_client = |
| + window ? client::GetCaptureClient(window->GetWindow()->GetRootWindow()) |
| + : client::GetCaptureClient( |
| + capture_window_->GetWindow()->GetRootWindow()); |
| + capture_client->SetCapture(window ? window->GetWindow() : nullptr); |
| +} |
| + |
| +void CaptureSynchronizer::Attach(client::CaptureClient* capture_client) { |
| + if (capture_client) |
| + capture_client->AddObserver(this); |
| } |
| void CaptureSynchronizer::SetCaptureWindow(WindowMus* window) { |
| if (capture_window_) |
| capture_window_->GetWindow()->RemoveObserver(this); |
| capture_window_ = window; |
| - if (capture_window_) |
| + if (capture_window_ && !capture_window_->GetWindow()->HasObserver(this)) |
| capture_window_->GetWindow()->AddObserver(this); |
| } |
| +void CaptureSynchronizer::OnWindowPropertyChanged(Window* window, |
| + const void* key, |
| + intptr_t old) { |
| + if (key == client::kRootWindowCaptureClientKey) |
| + Attach(client::GetCaptureClient(window)); |
|
sadrul
2017/01/18 22:14:44
So, this sort of suck a little bit. I know this is
riajiang
2017/01/20 20:14:28
As discussed offline, CaptureSynchronizer has to b
|
| +} |
| + |
| void CaptureSynchronizer::OnWindowDestroying(Window* window) { |
| // The CaptureClient implementation handles resetting capture when a window |
| // is destroyed, but because of observer ordering this may be called first. |
| - DCHECK_EQ(window, capture_window_->GetWindow()); |
| - SetCaptureWindow(nullptr); |
| + if (capture_window_) { |
| + DCHECK_EQ(window, capture_window_->GetWindow()); |
| + SetCaptureWindow(nullptr); |
| + } |
| // The server will release capture when a window is destroyed, so no need |
| // explicitly schedule a change. |
| } |