Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: services/ui/demo/mus_demo_external.cc

Issue 2755673003: Allow parallel creation of windows
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/demo/mus_demo_external.h" 5 #include "services/ui/demo/mus_demo_external.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "services/service_manager/public/cpp/service_context.h" 9 #include "services/service_manager/public/cpp/service_context.h"
10 #include "services/ui/demo/window_tree_data.h" 10 #include "services/ui/demo/window_tree_data.h"
11 #include "services/ui/public/interfaces/constants.mojom.h" 11 #include "services/ui/public/interfaces/constants.mojom.h"
12 #include "services/ui/public/interfaces/window_tree_host.mojom.h" 12 #include "services/ui/public/interfaces/window_tree_host.mojom.h"
13 #include "ui/aura/mus/window_tree_client.h" 13 #include "ui/aura/mus/window_tree_client.h"
14 #include "ui/aura/mus/window_tree_host_mus.h" 14 #include "ui/aura/mus/window_tree_host_mus.h"
15 #include "ui/display/display.h" 15 #include "ui/display/display.h"
16 16
17 namespace ui { 17 namespace ui {
18 namespace demo { 18 namespace demo {
19 19
20 namespace { 20 namespace {
21 21
22 class WindowTreeDataExternal : public WindowTreeData {
23 public:
24 // Creates a new window tree host associated to the WindowTreeData.
25 WindowTreeDataExternal(aura::WindowTreeClient* window_tree_client,
26 int square_size)
27 : WindowTreeData(square_size) {
28 SetWindowTreeHost(
29 base::MakeUnique<aura::WindowTreeHostMus>(window_tree_client));
30 }
31
32 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal);
33 };
34
35 int GetSquareSizeForWindow(int window_index) { 22 int GetSquareSizeForWindow(int window_index) {
36 return 50 * window_index + 400; 23 return 50 * window_index + 400;
37 }; 24 };
38 25
39 } // namespace 26 } // namespace
40 27
41 MusDemoExternal::MusDemoExternal() {} 28 MusDemoExternal::MusDemoExternal() {}
42 29
43 MusDemoExternal::~MusDemoExternal() {} 30 MusDemoExternal::~MusDemoExternal() {}
44 31
(...skipping 16 matching lines...) Expand all
61 48
62 window_tree_client()->ConnectViaWindowTreeHostFactory(); 49 window_tree_client()->ConnectViaWindowTreeHostFactory();
63 50
64 // TODO(tonikitoo,fwang): Implement management of displays in external mode. 51 // TODO(tonikitoo,fwang): Implement management of displays in external mode.
65 // For now, a fake display is created in order to work around an assertion in 52 // For now, a fake display is created in order to work around an assertion in
66 // aura::GetDeviceScaleFactorFromDisplay(). 53 // aura::GetDeviceScaleFactorFromDisplay().
67 AddPrimaryDisplay(display::Display(0)); 54 AddPrimaryDisplay(display::Display(0));
68 55
69 // TODO(tonikitoo,fwang): New windows can be launched without need to wait 56 // TODO(tonikitoo,fwang): New windows can be launched without need to wait
70 // the respective ::OnEmbed call of the previous instance. 57 // the respective ::OnEmbed call of the previous instance.
71 OpenNewWindow(); 58 for (size_t i = 0; i < number_of_windows_; ++i) {
59 base::ThreadTaskRunnerHandle::Get()->PostTask(
60 FROM_HERE,
61 base::Bind(&MusDemoExternal::OpenNewWindow, base::Unretained(this)));
62 }
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.
72 } 63 }
73 64
74 void MusDemoExternal::OpenNewWindow() { 65 void MusDemoExternal::OpenNewWindow() {
75 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>( 66 std::unique_ptr<aura::WindowTreeHostMus> mus =
76 window_tree_client(), 67 base::MakeUnique<aura::WindowTreeHostMus>(window_tree_client());
77 GetSquareSizeForWindow(initialized_windows_count_))); 68 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.
78 } 69 }
79 70
80 void MusDemoExternal::OnEmbed( 71 void MusDemoExternal::OnRootWindowEmbed(
81 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { 72 aura::WindowTreeHostMus* window_tree_host) {
82 DCHECK(!window_tree_host); 73 DCHECK(window_tree_host);
83 74
84 // TODO: Clean up WindowTreeClientDelegate::OnEmbed API so that it passes 75 auto it = std::find_if(
85 // no ownership of WindowTreeHostMus instance. 76 window_tree_host_mus_list_.begin(), window_tree_host_mus_list_.end(),
86 InitWindowTreeData(nullptr); 77 [window_tree_host](std::unique_ptr<aura::WindowTreeHostMus>& mus) {
87 initialized_windows_count_++; 78 return mus.get() == window_tree_host;
79 });
88 80
89 // Open the next window until the requested number of windows is reached. 81 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
90 if (initialized_windows_count_ < number_of_windows_) 82 AppendWindowTreeData(base::MakeUnique<WindowTreeData>(
91 OpenNewWindow(); 83 GetSquareSizeForWindow(initialized_windows_count_++)));
84 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.
85
86 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.
92 } 87 }
93 88
94 void MusDemoExternal::OnEmbedRootDestroyed( 89 void MusDemoExternal::OnEmbedRootDestroyed(
95 aura::WindowTreeHostMus* window_tree_host) { 90 aura::WindowTreeHostMus* window_tree_host) {
96 RemoveWindowTreeData(window_tree_host); 91 RemoveWindowTreeData(window_tree_host);
97 } 92 }
98 93
99 } // namespace demo 94 } // namespace demo
100 } // namespace ui 95 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698