OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mash/task_viewer/task_viewer.h" | 5 #include "mash/task_viewer/task_viewer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "ui/views/controls/table/table_view.h" | 27 #include "ui/views/controls/table/table_view.h" |
28 #include "ui/views/controls/table/table_view_observer.h" | 28 #include "ui/views/controls/table/table_view_observer.h" |
29 #include "ui/views/mus/aura_init.h" | 29 #include "ui/views/mus/aura_init.h" |
30 #include "ui/views/mus/window_manager_connection.h" | 30 #include "ui/views/mus/window_manager_connection.h" |
31 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
32 | 32 |
33 namespace mash { | 33 namespace mash { |
34 namespace task_viewer { | 34 namespace task_viewer { |
35 namespace { | 35 namespace { |
36 | 36 |
37 using shell::mojom::ServiceInfoPtr; | 37 using service_manager::mojom::ServiceInfoPtr; |
38 | 38 |
39 class TaskViewerContents : public views::WidgetDelegateView, | 39 class TaskViewerContents |
40 public ui::TableModel, | 40 : public views::WidgetDelegateView, |
41 public views::ButtonListener, | 41 public ui::TableModel, |
42 public shell::mojom::ServiceManagerListener { | 42 public views::ButtonListener, |
| 43 public service_manager::mojom::ServiceManagerListener { |
43 public: | 44 public: |
44 TaskViewerContents(TaskViewer* task_viewer, | 45 TaskViewerContents( |
45 shell::mojom::ServiceManagerListenerRequest request, | 46 TaskViewer* task_viewer, |
46 catalog::mojom::CatalogPtr catalog) | 47 service_manager::mojom::ServiceManagerListenerRequest request, |
| 48 catalog::mojom::CatalogPtr catalog) |
47 : task_viewer_(task_viewer), | 49 : task_viewer_(task_viewer), |
48 binding_(this, std::move(request)), | 50 binding_(this, std::move(request)), |
49 catalog_(std::move(catalog)), | 51 catalog_(std::move(catalog)), |
50 table_view_(nullptr), | 52 table_view_(nullptr), |
51 table_view_parent_(nullptr), | 53 table_view_parent_(nullptr), |
52 kill_button_( | 54 kill_button_( |
53 views::MdTextButton::Create(this, | 55 views::MdTextButton::Create(this, |
54 base::ASCIIToUTF16("Kill Process"))), | 56 base::ASCIIToUTF16("Kill Process"))), |
55 observer_(nullptr), | 57 observer_(nullptr), |
56 weak_ptr_factory_(this) { | 58 weak_ptr_factory_(this) { |
(...skipping 10 matching lines...) Expand all Loading... |
67 | 69 |
68 AddChildView(kill_button_); | 70 AddChildView(kill_button_); |
69 } | 71 } |
70 ~TaskViewerContents() override { | 72 ~TaskViewerContents() override { |
71 table_view_->SetModel(nullptr); | 73 table_view_->SetModel(nullptr); |
72 task_viewer_->RemoveWindow(GetWidget()); | 74 task_viewer_->RemoveWindow(GetWidget()); |
73 } | 75 } |
74 | 76 |
75 private: | 77 private: |
76 struct InstanceInfo { | 78 struct InstanceInfo { |
77 InstanceInfo(const shell::Identity& identity, base::ProcessId pid) | 79 InstanceInfo(const service_manager::Identity& identity, base::ProcessId pid) |
78 : identity(identity), pid(pid) {} | 80 : identity(identity), pid(pid) {} |
79 shell::Identity identity; | 81 service_manager::Identity identity; |
80 uint32_t pid; | 82 uint32_t pid; |
81 std::string display_name; | 83 std::string display_name; |
82 }; | 84 }; |
83 | 85 |
84 | 86 |
85 // Overridden from views::WidgetDelegate: | 87 // Overridden from views::WidgetDelegate: |
86 base::string16 GetWindowTitle() const override { | 88 base::string16 GetWindowTitle() const override { |
87 // TODO(beng): use resources. | 89 // TODO(beng): use resources. |
88 return base::ASCIIToUTF16("Tasks"); | 90 return base::ASCIIToUTF16("Tasks"); |
89 } | 91 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // Overridden from views::ButtonListener: | 142 // Overridden from views::ButtonListener: |
141 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 143 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
142 DCHECK_EQ(sender, kill_button_); | 144 DCHECK_EQ(sender, kill_button_); |
143 DCHECK_EQ(table_view_->SelectedRowCount(), 1); | 145 DCHECK_EQ(table_view_->SelectedRowCount(), 1); |
144 int row = table_view_->FirstSelectedRow(); | 146 int row = table_view_->FirstSelectedRow(); |
145 DCHECK(row < static_cast<int>(instances_.size())); | 147 DCHECK(row < static_cast<int>(instances_.size())); |
146 base::Process process = base::Process::Open(instances_[row]->pid); | 148 base::Process process = base::Process::Open(instances_[row]->pid); |
147 process.Terminate(9, true); | 149 process.Terminate(9, true); |
148 } | 150 } |
149 | 151 |
150 // Overridden from shell::mojom::ServiceManagerListener: | 152 // Overridden from service_manager::mojom::ServiceManagerListener: |
151 void OnInit(std::vector<ServiceInfoPtr> instances) override { | 153 void OnInit(std::vector<ServiceInfoPtr> instances) override { |
152 // This callback should only be called with an empty model. | 154 // This callback should only be called with an empty model. |
153 DCHECK(instances_.empty()); | 155 DCHECK(instances_.empty()); |
154 std::vector<std::string> names; | 156 std::vector<std::string> names; |
155 names.reserve(instances.size()); | 157 names.reserve(instances.size()); |
156 for (size_t i = 0; i < instances.size(); ++i) { | 158 for (size_t i = 0; i < instances.size(); ++i) { |
157 const shell::Identity& identity = instances[i]->identity; | 159 const service_manager::Identity& identity = instances[i]->identity; |
158 InsertInstance(identity, instances[i]->pid); | 160 InsertInstance(identity, instances[i]->pid); |
159 names.push_back(identity.name()); | 161 names.push_back(identity.name()); |
160 } | 162 } |
161 catalog_->GetEntries(std::move(names), | 163 catalog_->GetEntries(std::move(names), |
162 base::Bind(&TaskViewerContents::OnGotCatalogEntries, | 164 base::Bind(&TaskViewerContents::OnGotCatalogEntries, |
163 weak_ptr_factory_.GetWeakPtr())); | 165 weak_ptr_factory_.GetWeakPtr())); |
164 } | 166 } |
165 void OnServiceCreated(ServiceInfoPtr instance) override { | 167 void OnServiceCreated(ServiceInfoPtr instance) override { |
166 shell::Identity identity = instance->identity; | 168 service_manager::Identity identity = instance->identity; |
167 DCHECK(!ContainsIdentity(identity)); | 169 DCHECK(!ContainsIdentity(identity)); |
168 InsertInstance(identity, instance->pid); | 170 InsertInstance(identity, instance->pid); |
169 observer_->OnItemsAdded(static_cast<int>(instances_.size()), 1); | 171 observer_->OnItemsAdded(static_cast<int>(instances_.size()), 1); |
170 std::vector<std::string> names; | 172 std::vector<std::string> names; |
171 names.push_back(identity.name()); | 173 names.push_back(identity.name()); |
172 catalog_->GetEntries(std::move(names), | 174 catalog_->GetEntries(std::move(names), |
173 base::Bind(&TaskViewerContents::OnGotCatalogEntries, | 175 base::Bind(&TaskViewerContents::OnGotCatalogEntries, |
174 weak_ptr_factory_.GetWeakPtr())); | 176 weak_ptr_factory_.GetWeakPtr())); |
175 } | 177 } |
176 void OnServiceStarted(const shell::Identity& identity, | 178 void OnServiceStarted(const service_manager::Identity& identity, |
177 uint32_t pid) override { | 179 uint32_t pid) override { |
178 for (auto it = instances_.begin(); it != instances_.end(); ++it) { | 180 for (auto it = instances_.begin(); it != instances_.end(); ++it) { |
179 if ((*it)->identity == identity) { | 181 if ((*it)->identity == identity) { |
180 (*it)->pid = pid; | 182 (*it)->pid = pid; |
181 observer_->OnItemsChanged( | 183 observer_->OnItemsChanged( |
182 static_cast<int>(it - instances_.begin()), 1); | 184 static_cast<int>(it - instances_.begin()), 1); |
183 return; | 185 return; |
184 } | 186 } |
185 } | 187 } |
186 } | 188 } |
187 void OnServiceStopped(const shell::Identity& identity) override { | 189 void OnServiceStopped(const service_manager::Identity& identity) override { |
188 for (auto it = instances_.begin(); it != instances_.end(); ++it) { | 190 for (auto it = instances_.begin(); it != instances_.end(); ++it) { |
189 if ((*it)->identity == identity) { | 191 if ((*it)->identity == identity) { |
190 observer_->OnItemsRemoved( | 192 observer_->OnItemsRemoved( |
191 static_cast<int>(it - instances_.begin()), 1); | 193 static_cast<int>(it - instances_.begin()), 1); |
192 instances_.erase(it); | 194 instances_.erase(it); |
193 return; | 195 return; |
194 } | 196 } |
195 } | 197 } |
196 NOTREACHED(); | 198 NOTREACHED(); |
197 } | 199 } |
198 | 200 |
199 bool ContainsIdentity(const shell::Identity& identity) const { | 201 bool ContainsIdentity(const service_manager::Identity& identity) const { |
200 for (auto& it : instances_) { | 202 for (auto& it : instances_) { |
201 if (it->identity == identity) | 203 if (it->identity == identity) |
202 return true; | 204 return true; |
203 } | 205 } |
204 return false; | 206 return false; |
205 } | 207 } |
206 | 208 |
207 void InsertInstance(const shell::Identity& identity, uint32_t pid) { | 209 void InsertInstance(const service_manager::Identity& identity, uint32_t pid) { |
208 instances_.push_back(base::MakeUnique<InstanceInfo>(identity, pid)); | 210 instances_.push_back(base::MakeUnique<InstanceInfo>(identity, pid)); |
209 } | 211 } |
210 | 212 |
211 void OnGotCatalogEntries(std::vector<catalog::mojom::EntryPtr> entries) { | 213 void OnGotCatalogEntries(std::vector<catalog::mojom::EntryPtr> entries) { |
212 for (auto it = instances_.begin(); it != instances_.end(); ++it) { | 214 for (auto it = instances_.begin(); it != instances_.end(); ++it) { |
213 for (auto& entry : entries) { | 215 for (auto& entry : entries) { |
214 if (entry->name == (*it)->identity.name()) { | 216 if (entry->name == (*it)->identity.name()) { |
215 (*it)->display_name = entry->display_name; | 217 (*it)->display_name = entry->display_name; |
216 observer_->OnItemsChanged( | 218 observer_->OnItemsChanged( |
217 static_cast<int>(it - instances_.begin()), 1); | 219 static_cast<int>(it - instances_.begin()), 1); |
(...skipping 29 matching lines...) Expand all Loading... |
247 // TODO(beng): use resources. | 249 // TODO(beng): use resources. |
248 pid_column.title = base::ASCIIToUTF16("PID"); | 250 pid_column.title = base::ASCIIToUTF16("PID"); |
249 pid_column.width = 50; | 251 pid_column.width = 50; |
250 pid_column.sortable = true; | 252 pid_column.sortable = true; |
251 columns.push_back(pid_column); | 253 columns.push_back(pid_column); |
252 | 254 |
253 return columns; | 255 return columns; |
254 } | 256 } |
255 | 257 |
256 TaskViewer* task_viewer_; | 258 TaskViewer* task_viewer_; |
257 mojo::Binding<shell::mojom::ServiceManagerListener> binding_; | 259 mojo::Binding<service_manager::mojom::ServiceManagerListener> binding_; |
258 catalog::mojom::CatalogPtr catalog_; | 260 catalog::mojom::CatalogPtr catalog_; |
259 | 261 |
260 views::TableView* table_view_; | 262 views::TableView* table_view_; |
261 views::View* table_view_parent_; | 263 views::View* table_view_parent_; |
262 views::MdTextButton* kill_button_; | 264 views::MdTextButton* kill_button_; |
263 ui::TableModelObserver* observer_; | 265 ui::TableModelObserver* observer_; |
264 | 266 |
265 std::vector<std::unique_ptr<InstanceInfo>> instances_; | 267 std::vector<std::unique_ptr<InstanceInfo>> instances_; |
266 | 268 |
267 base::WeakPtrFactory<TaskViewerContents> weak_ptr_factory_; | 269 base::WeakPtrFactory<TaskViewerContents> weak_ptr_factory_; |
268 | 270 |
269 DISALLOW_COPY_AND_ASSIGN(TaskViewerContents); | 271 DISALLOW_COPY_AND_ASSIGN(TaskViewerContents); |
270 }; | 272 }; |
271 | 273 |
272 } // namespace | 274 } // namespace |
273 | 275 |
274 TaskViewer::TaskViewer() {} | 276 TaskViewer::TaskViewer() {} |
275 TaskViewer::~TaskViewer() {} | 277 TaskViewer::~TaskViewer() {} |
276 | 278 |
277 void TaskViewer::RemoveWindow(views::Widget* widget) { | 279 void TaskViewer::RemoveWindow(views::Widget* widget) { |
278 auto it = std::find(windows_.begin(), windows_.end(), widget); | 280 auto it = std::find(windows_.begin(), windows_.end(), widget); |
279 DCHECK(it != windows_.end()); | 281 DCHECK(it != windows_.end()); |
280 windows_.erase(it); | 282 windows_.erase(it); |
281 if (windows_.empty()) | 283 if (windows_.empty()) |
282 base::MessageLoop::current()->QuitWhenIdle(); | 284 base::MessageLoop::current()->QuitWhenIdle(); |
283 } | 285 } |
284 | 286 |
285 void TaskViewer::OnStart(const shell::Identity& identity) { | 287 void TaskViewer::OnStart(const service_manager::Identity& identity) { |
286 tracing_.Initialize(connector(), identity.name()); | 288 tracing_.Initialize(connector(), identity.name()); |
287 | 289 |
288 aura_init_.reset( | 290 aura_init_.reset( |
289 new views::AuraInit(connector(), "views_mus_resources.pak")); | 291 new views::AuraInit(connector(), "views_mus_resources.pak")); |
290 window_manager_connection_ = | 292 window_manager_connection_ = |
291 views::WindowManagerConnection::Create(connector(), identity); | 293 views::WindowManagerConnection::Create(connector(), identity); |
292 } | 294 } |
293 | 295 |
294 bool TaskViewer::OnConnect(const shell::Identity& remote_identity, | 296 bool TaskViewer::OnConnect(const service_manager::Identity& remote_identity, |
295 shell::InterfaceRegistry* registry) { | 297 service_manager::InterfaceRegistry* registry) { |
296 registry->AddInterface<mojom::Launchable>(this); | 298 registry->AddInterface<mojom::Launchable>(this); |
297 return true; | 299 return true; |
298 } | 300 } |
299 | 301 |
300 void TaskViewer::Launch(uint32_t what, mojom::LaunchMode how) { | 302 void TaskViewer::Launch(uint32_t what, mojom::LaunchMode how) { |
301 bool reuse = how == mojom::LaunchMode::REUSE || | 303 bool reuse = how == mojom::LaunchMode::REUSE || |
302 how == mojom::LaunchMode::DEFAULT; | 304 how == mojom::LaunchMode::DEFAULT; |
303 if (reuse && !windows_.empty()) { | 305 if (reuse && !windows_.empty()) { |
304 windows_.back()->Activate(); | 306 windows_.back()->Activate(); |
305 return; | 307 return; |
306 } | 308 } |
307 | 309 |
308 shell::mojom::ServiceManagerPtr service_manager; | 310 service_manager::mojom::ServiceManagerPtr service_manager; |
309 connector()->ConnectToInterface("service:shell", &service_manager); | 311 connector()->ConnectToInterface("service:shell", &service_manager); |
310 | 312 |
311 shell::mojom::ServiceManagerListenerPtr listener; | 313 service_manager::mojom::ServiceManagerListenerPtr listener; |
312 shell::mojom::ServiceManagerListenerRequest request = GetProxy(&listener); | 314 service_manager::mojom::ServiceManagerListenerRequest request = |
| 315 GetProxy(&listener); |
313 service_manager->AddListener(std::move(listener)); | 316 service_manager->AddListener(std::move(listener)); |
314 | 317 |
315 catalog::mojom::CatalogPtr catalog; | 318 catalog::mojom::CatalogPtr catalog; |
316 connector()->ConnectToInterface("service:catalog", &catalog); | 319 connector()->ConnectToInterface("service:catalog", &catalog); |
317 | 320 |
318 TaskViewerContents* task_viewer = new TaskViewerContents( | 321 TaskViewerContents* task_viewer = new TaskViewerContents( |
319 this, std::move(request), std::move(catalog)); | 322 this, std::move(request), std::move(catalog)); |
320 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( | 323 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( |
321 task_viewer, nullptr, gfx::Rect(10, 10, 500, 500)); | 324 task_viewer, nullptr, gfx::Rect(10, 10, 500, 500)); |
322 window->Show(); | 325 window->Show(); |
323 windows_.push_back(window); | 326 windows_.push_back(window); |
324 } | 327 } |
325 | 328 |
326 void TaskViewer::Create(const shell::Identity& remote_identity, | 329 void TaskViewer::Create(const service_manager::Identity& remote_identity, |
327 mojom::LaunchableRequest request) { | 330 mojom::LaunchableRequest request) { |
328 bindings_.AddBinding(this, std::move(request)); | 331 bindings_.AddBinding(this, std::move(request)); |
329 } | 332 } |
330 | 333 |
331 } // namespace task_viewer | 334 } // namespace task_viewer |
332 } // namespace main | 335 } // namespace main |
OLD | NEW |