Chromium Code Reviews| Index: services/ui/demo/mus_demo_external.cc |
| diff --git a/services/ui/demo/mus_demo_external.cc b/services/ui/demo/mus_demo_external.cc |
| index f76c0a8dedbb0952bb9b9b23f555755a2acbb644..1d787d598ec21d6fcd5d8aab0ea94264accc68f7 100644 |
| --- a/services/ui/demo/mus_demo_external.cc |
| +++ b/services/ui/demo/mus_demo_external.cc |
| @@ -19,19 +19,6 @@ namespace demo { |
| namespace { |
| -class WindowTreeDataExternal : public WindowTreeData { |
| - public: |
| - // Creates a new window tree host associated to the WindowTreeData. |
| - WindowTreeDataExternal(aura::WindowTreeClient* window_tree_client, |
| - int square_size) |
| - : WindowTreeData(square_size) { |
| - SetWindowTreeHost( |
| - base::MakeUnique<aura::WindowTreeHostMus>(window_tree_client)); |
| - } |
| - |
| - DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal); |
| -}; |
| - |
| int GetSquareSizeForWindow(int window_index) { |
| return 50 * window_index + 400; |
| }; |
| @@ -68,27 +55,35 @@ void MusDemoExternal::OnStartImpl() { |
| // TODO(tonikitoo,fwang): New windows can be launched without need to wait |
| // the respective ::OnEmbed call of the previous instance. |
| - OpenNewWindow(); |
| + for (size_t i = 0; i < number_of_windows_; ++i) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&MusDemoExternal::OpenNewWindow, base::Unretained(this))); |
| + } |
|
fwang
2017/03/15 14:37:56
Do you really need this post task stuff? I think y
msisov
2017/03/16 08:17:52
Done.
|
| } |
| void MusDemoExternal::OpenNewWindow() { |
| - AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>( |
| - window_tree_client(), |
| - GetSquareSizeForWindow(initialized_windows_count_))); |
| + std::unique_ptr<aura::WindowTreeHostMus> mus = |
| + base::MakeUnique<aura::WindowTreeHostMus>(window_tree_client()); |
| + window_tree_host_mus_list_.push_back(std::move(mus)); |
|
fwang
2017/03/15 14:37:56
I believe you should keep appending to window_tree
msisov
2017/03/16 08:17:51
Done.
|
| } |
| -void MusDemoExternal::OnEmbed( |
| - std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| - DCHECK(!window_tree_host); |
| +void MusDemoExternal::OnRootWindowEmbed( |
| + aura::WindowTreeHostMus* window_tree_host) { |
| + DCHECK(window_tree_host); |
| + |
| + auto it = std::find_if( |
| + window_tree_host_mus_list_.begin(), window_tree_host_mus_list_.end(), |
| + [window_tree_host](std::unique_ptr<aura::WindowTreeHostMus>& mus) { |
| + return mus.get() == window_tree_host; |
| + }); |
| - // TODO: Clean up WindowTreeClientDelegate::OnEmbed API so that it passes |
| - // no ownership of WindowTreeHostMus instance. |
| - InitWindowTreeData(nullptr); |
| - initialized_windows_count_++; |
| + DCHECK(it != window_tree_host_mus_list_.end()); |
|
fwang
2017/03/15 14:37:56
This logic exists in RemoveWindowTreeData, so it s
msisov
2017/03/16 08:17:51
Ok, I've made FindWindowTreeData, which returns an
|
| + AppendWindowTreeData(base::MakeUnique<WindowTreeData>( |
| + GetSquareSizeForWindow(initialized_windows_count_++))); |
| + InitWindowTreeData(std::move(*it)); |
|
tonikitoo
2017/03/15 15:34:54
now that you are passing a valid unique_ptr always
msisov
2017/03/16 08:17:51
Logic is changed. So it's still applicable.
|
| - // Open the next window until the requested number of windows is reached. |
| - if (initialized_windows_count_ < number_of_windows_) |
| - OpenNewWindow(); |
| + window_tree_host_mus_list_.erase(it); |
|
fwang
2017/03/15 14:37:56
No need to do that if your use window_tree_data_li
msisov
2017/03/16 08:17:52
Done.
|
| } |
| void MusDemoExternal::OnEmbedRootDestroyed( |