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

Side by Side Diff: services/ui/ws/user_display_manager.cc

Issue 2607063002: Remove mojo::Array. (Closed)
Patch Set: Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ws/user_display_manager.h" 5 #include "services/ui/ws/user_display_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "services/ui/display/screen_manager.h" 9 #include "services/ui/display/screen_manager.h"
10 #include "services/ui/ws/display.h" 10 #include "services/ui/ws/display.h"
11 #include "services/ui/ws/display_manager.h" 11 #include "services/ui/ws/display_manager.h"
12 #include "services/ui/ws/user_display_manager_delegate.h" 12 #include "services/ui/ws/user_display_manager_delegate.h"
13 #include "ui/display/types/display_constants.h" 13 #include "ui/display/types/display_constants.h"
14 14
15 namespace ui { 15 namespace ui {
16 namespace ws { 16 namespace ws {
17 namespace {
18
19 std::vector<mojom::WsDisplayPtr> CloneDisplays(
20 const std::vector<mojom::WsDisplayPtr>& input) {
21 std::vector<mojom::WsDisplayPtr> result;
22 result.reserve(input.size());
23 for (const auto& display : input) {
24 result.push_back(display.Clone());
25 }
26 return result;
27 }
28
29 } // namespace
17 30
18 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager, 31 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager,
19 UserDisplayManagerDelegate* delegate, 32 UserDisplayManagerDelegate* delegate,
20 const UserId& user_id) 33 const UserId& user_id)
21 : display_manager_(display_manager), 34 : display_manager_(display_manager),
22 delegate_(delegate), 35 delegate_(delegate),
23 user_id_(user_id), 36 user_id_(user_id),
24 got_valid_frame_decorations_( 37 got_valid_frame_decorations_(
25 delegate->GetFrameDecorationsForUser(user_id, nullptr)), 38 delegate->GetFrameDecorationsForUser(user_id, nullptr)),
26 current_cursor_location_(0) {} 39 current_cursor_location_(0) {}
27 40
28 UserDisplayManager::~UserDisplayManager() {} 41 UserDisplayManager::~UserDisplayManager() {}
29 42
30 void UserDisplayManager::OnFrameDecorationValuesChanged() { 43 void UserDisplayManager::OnFrameDecorationValuesChanged() {
31 if (!got_valid_frame_decorations_) { 44 if (!got_valid_frame_decorations_) {
32 got_valid_frame_decorations_ = true; 45 got_valid_frame_decorations_ = true;
33 display_manager_observers_.ForAllPtrs([this]( 46 display_manager_observers_.ForAllPtrs([this](
34 mojom::DisplayManagerObserver* observer) { CallOnDisplays(observer); }); 47 mojom::DisplayManagerObserver* observer) { CallOnDisplays(observer); });
35 return; 48 return;
36 } 49 }
37 50
38 mojo::Array<mojom::WsDisplayPtr> displays = GetAllDisplays(); 51 std::vector<mojom::WsDisplayPtr> displays = GetAllDisplays();
39 display_manager_observers_.ForAllPtrs( 52 display_manager_observers_.ForAllPtrs(
40 [this, &displays](mojom::DisplayManagerObserver* observer) { 53 [this, &displays](mojom::DisplayManagerObserver* observer) {
41 observer->OnDisplaysChanged(displays.Clone().PassStorage()); 54 observer->OnDisplaysChanged(CloneDisplays(displays));
42 }); 55 });
43 } 56 }
44 57
45 void UserDisplayManager::AddDisplayManagerBinding( 58 void UserDisplayManager::AddDisplayManagerBinding(
46 mojo::InterfaceRequest<mojom::DisplayManager> request) { 59 mojo::InterfaceRequest<mojom::DisplayManager> request) {
47 display_manager_bindings_.AddBinding(this, std::move(request)); 60 display_manager_bindings_.AddBinding(this, std::move(request));
48 } 61 }
49 62
50 void UserDisplayManager::OnDisplayUpdate(Display* display) { 63 void UserDisplayManager::OnDisplayUpdate(Display* display) {
51 if (!got_valid_frame_decorations_) 64 if (!got_valid_frame_decorations_)
52 return; 65 return;
53 66
54 mojo::Array<mojom::WsDisplayPtr> displays(1); 67 std::vector<mojom::WsDisplayPtr> displays(1);
55 displays[0] = GetWsDisplayPtr(*display); 68 displays[0] = GetWsDisplayPtr(*display);
56 69
57 display_manager_observers_.ForAllPtrs( 70 display_manager_observers_.ForAllPtrs(
58 [&displays](mojom::DisplayManagerObserver* observer) { 71 [&displays](mojom::DisplayManagerObserver* observer) {
59 observer->OnDisplaysChanged(displays.Clone().PassStorage()); 72 observer->OnDisplaysChanged(CloneDisplays(displays));
60 }); 73 });
61 } 74 }
62 75
63 void UserDisplayManager::OnWillDestroyDisplay(Display* display) { 76 void UserDisplayManager::OnWillDestroyDisplay(Display* display) {
64 if (!got_valid_frame_decorations_) 77 if (!got_valid_frame_decorations_)
65 return; 78 return;
66 79
67 display_manager_observers_.ForAllPtrs( 80 display_manager_observers_.ForAllPtrs(
68 [&display](mojom::DisplayManagerObserver* observer) { 81 [&display](mojom::DisplayManagerObserver* observer) {
69 observer->OnDisplayRemoved(display->GetId()); 82 observer->OnDisplayRemoved(display->GetId());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 145
133 mojom::WsDisplayPtr UserDisplayManager::GetWsDisplayPtr( 146 mojom::WsDisplayPtr UserDisplayManager::GetWsDisplayPtr(
134 const Display& display) { 147 const Display& display) {
135 mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New(); 148 mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New();
136 ws_display->display = display.ToDisplay(); 149 ws_display->display = display.ToDisplay();
137 delegate_->GetFrameDecorationsForUser(user_id_, 150 delegate_->GetFrameDecorationsForUser(user_id_,
138 &ws_display->frame_decoration_values); 151 &ws_display->frame_decoration_values);
139 return ws_display; 152 return ws_display;
140 } 153 }
141 154
142 mojo::Array<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() { 155 std::vector<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() {
143 const auto& displays = display_manager_->displays(); 156 const auto& displays = display_manager_->displays();
144 mojo::Array<mojom::WsDisplayPtr> display_ptrs(displays.size()); 157 std::vector<mojom::WsDisplayPtr> display_ptrs;
158 display_ptrs.reserve(displays.size());
145 159
146 size_t i = 0;
147 // TODO(sky): need ordering! 160 // TODO(sky): need ordering!
148 for (Display* display : displays) { 161 for (Display* display : displays) {
149 display_ptrs[i] = GetWsDisplayPtr(*display); 162 display_ptrs.push_back(GetWsDisplayPtr(*display));
150 ++i;
151 } 163 }
152 164
153 return display_ptrs; 165 return display_ptrs;
154 } 166 }
155 167
156 void UserDisplayManager::CallOnDisplays( 168 void UserDisplayManager::CallOnDisplays(
157 mojom::DisplayManagerObserver* observer) { 169 mojom::DisplayManagerObserver* observer) {
158 // TODO(kylechar): Pass internal display id to clients here. 170 // TODO(kylechar): Pass internal display id to clients here.
159 observer->OnDisplays( 171 observer->OnDisplays(
160 GetAllDisplays().PassStorage(), 172 GetAllDisplays(),
161 display::ScreenManager::GetInstance()->GetPrimaryDisplayId(), 173 display::ScreenManager::GetInstance()->GetPrimaryDisplayId(),
162 display::kInvalidDisplayId); 174 display::kInvalidDisplayId);
163 } 175 }
164 176
165 } // namespace ws 177 } // namespace ws
166 } // namespace ui 178 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698