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" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/process/process.h" | 13 #include "base/process/process.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "mojo/public/cpp/bindings/binding.h" | 16 #include "mojo/public/cpp/bindings/binding.h" |
17 #include "mojo/services/package_manager/public/interfaces/catalog.mojom.h" | 17 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" |
18 #include "mojo/shell/public/cpp/connection.h" | 18 #include "mojo/shell/public/cpp/connection.h" |
19 #include "mojo/shell/public/cpp/connector.h" | 19 #include "mojo/shell/public/cpp/connector.h" |
20 #include "mojo/shell/public/interfaces/shell.mojom.h" | 20 #include "mojo/shell/public/interfaces/shell.mojom.h" |
21 #include "ui/base/models/table_model.h" | 21 #include "ui/base/models/table_model.h" |
22 #include "ui/views/background.h" | 22 #include "ui/views/background.h" |
23 #include "ui/views/controls/button/label_button.h" | 23 #include "ui/views/controls/button/label_button.h" |
24 #include "ui/views/controls/table/table_view.h" | 24 #include "ui/views/controls/table/table_view.h" |
25 #include "ui/views/controls/table/table_view_observer.h" | 25 #include "ui/views/controls/table/table_view_observer.h" |
26 #include "ui/views/mus/aura_init.h" | 26 #include "ui/views/mus/aura_init.h" |
27 #include "ui/views/mus/window_manager_connection.h" | 27 #include "ui/views/mus/window_manager_connection.h" |
28 #include "ui/views/widget/widget_delegate.h" | 28 #include "ui/views/widget/widget_delegate.h" |
29 | 29 |
30 namespace mash { | 30 namespace mash { |
31 namespace task_viewer { | 31 namespace task_viewer { |
32 namespace { | 32 namespace { |
33 | 33 |
34 using mojo::shell::mojom::InstanceInfoPtr; | 34 using mojo::shell::mojom::InstanceInfoPtr; |
35 | 35 |
36 class TaskViewerContents : public views::WidgetDelegateView, | 36 class TaskViewerContents : public views::WidgetDelegateView, |
37 public ui::TableModel, | 37 public ui::TableModel, |
38 public views::ButtonListener, | 38 public views::ButtonListener, |
39 public mojo::shell::mojom::InstanceListener { | 39 public mojo::shell::mojom::InstanceListener { |
40 public: | 40 public: |
41 TaskViewerContents(mojo::shell::mojom::InstanceListenerRequest request, | 41 TaskViewerContents(mojo::shell::mojom::InstanceListenerRequest request, |
42 package_manager::mojom::CatalogPtr catalog) | 42 catalog::mojom::CatalogPtr catalog) |
43 : binding_(this, std::move(request)), | 43 : binding_(this, std::move(request)), |
44 catalog_(std::move(catalog)), | 44 catalog_(std::move(catalog)), |
45 table_view_(nullptr), | 45 table_view_(nullptr), |
46 table_view_parent_(nullptr), | 46 table_view_parent_(nullptr), |
47 kill_button_( | 47 kill_button_( |
48 new views::LabelButton(this, base::ASCIIToUTF16("Kill Process"))), | 48 new views::LabelButton(this, base::ASCIIToUTF16("Kill Process"))), |
49 observer_(nullptr), | 49 observer_(nullptr), |
50 weak_ptr_factory_(this) { | 50 weak_ptr_factory_(this) { |
51 // We don't want to show an empty UI on startup, so just block until we | 51 // We don't want to show an empty UI on startup, so just block until we |
52 // receive the initial set of applications. | 52 // receive the initial set of applications. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 return true; | 188 return true; |
189 } | 189 } |
190 return false; | 190 return false; |
191 } | 191 } |
192 | 192 |
193 void InsertInstance(uint32_t id, const std::string& url, uint32_t pid) { | 193 void InsertInstance(uint32_t id, const std::string& url, uint32_t pid) { |
194 instances_.push_back(make_scoped_ptr(new InstanceInfo(id, url, pid))); | 194 instances_.push_back(make_scoped_ptr(new InstanceInfo(id, url, pid))); |
195 } | 195 } |
196 | 196 |
197 void OnGotCatalogEntries( | 197 void OnGotCatalogEntries( |
198 mojo::Map<mojo::String, | 198 mojo::Map<mojo::String, catalog::mojom::CatalogEntryPtr> entries) { |
199 package_manager::mojom::CatalogEntryPtr> entries) { | |
200 for (auto it = instances_.begin(); it != instances_.end(); ++it) { | 199 for (auto it = instances_.begin(); it != instances_.end(); ++it) { |
201 auto entry_it = entries.find((*it)->url); | 200 auto entry_it = entries.find((*it)->url); |
202 if (entry_it != entries.end()) { | 201 if (entry_it != entries.end()) { |
203 (*it)->name = entry_it->second->display_name; | 202 (*it)->name = entry_it->second->display_name; |
204 observer_->OnItemsChanged( | 203 observer_->OnItemsChanged( |
205 static_cast<int>(it - instances_.begin()), 1); | 204 static_cast<int>(it - instances_.begin()), 1); |
206 } | 205 } |
207 } | 206 } |
208 } | 207 } |
209 | 208 |
(...skipping 23 matching lines...) Expand all Loading... |
233 // TODO(beng): use resources. | 232 // TODO(beng): use resources. |
234 pid_column.title = base::ASCIIToUTF16("PID"); | 233 pid_column.title = base::ASCIIToUTF16("PID"); |
235 pid_column.width = 50; | 234 pid_column.width = 50; |
236 pid_column.sortable = true; | 235 pid_column.sortable = true; |
237 columns.push_back(pid_column); | 236 columns.push_back(pid_column); |
238 | 237 |
239 return columns; | 238 return columns; |
240 } | 239 } |
241 | 240 |
242 mojo::Binding<mojo::shell::mojom::InstanceListener> binding_; | 241 mojo::Binding<mojo::shell::mojom::InstanceListener> binding_; |
243 package_manager::mojom::CatalogPtr catalog_; | 242 catalog::mojom::CatalogPtr catalog_; |
244 | 243 |
245 views::TableView* table_view_; | 244 views::TableView* table_view_; |
246 views::View* table_view_parent_; | 245 views::View* table_view_parent_; |
247 views::LabelButton* kill_button_; | 246 views::LabelButton* kill_button_; |
248 ui::TableModelObserver* observer_; | 247 ui::TableModelObserver* observer_; |
249 | 248 |
250 std::vector<scoped_ptr<InstanceInfo>> instances_; | 249 std::vector<scoped_ptr<InstanceInfo>> instances_; |
251 | 250 |
252 base::WeakPtrFactory<TaskViewerContents> weak_ptr_factory_; | 251 base::WeakPtrFactory<TaskViewerContents> weak_ptr_factory_; |
253 | 252 |
(...skipping 13 matching lines...) Expand all Loading... |
267 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); | 266 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
268 views::WindowManagerConnection::Create(connector); | 267 views::WindowManagerConnection::Create(connector); |
269 | 268 |
270 mojo::shell::mojom::ShellPtr shell; | 269 mojo::shell::mojom::ShellPtr shell; |
271 connector->ConnectToInterface("mojo:shell", &shell); | 270 connector->ConnectToInterface("mojo:shell", &shell); |
272 | 271 |
273 mojo::shell::mojom::InstanceListenerPtr listener; | 272 mojo::shell::mojom::InstanceListenerPtr listener; |
274 mojo::shell::mojom::InstanceListenerRequest request = GetProxy(&listener); | 273 mojo::shell::mojom::InstanceListenerRequest request = GetProxy(&listener); |
275 shell->AddInstanceListener(std::move(listener)); | 274 shell->AddInstanceListener(std::move(listener)); |
276 | 275 |
277 package_manager::mojom::CatalogPtr catalog; | 276 catalog::mojom::CatalogPtr catalog; |
278 connector->ConnectToInterface("mojo:package_manager", &catalog); | 277 connector->ConnectToInterface("mojo:catalog", &catalog); |
279 | 278 |
280 TaskViewerContents* task_viewer = new TaskViewerContents( | 279 TaskViewerContents* task_viewer = new TaskViewerContents( |
281 std::move(request), std::move(catalog)); | 280 std::move(request), std::move(catalog)); |
282 views::Widget* window = views::Widget::CreateWindowWithBounds( | 281 views::Widget* window = views::Widget::CreateWindowWithBounds( |
283 task_viewer, gfx::Rect(10, 10, 500, 500)); | 282 task_viewer, gfx::Rect(10, 10, 500, 500)); |
284 window->Show(); | 283 window->Show(); |
285 } | 284 } |
286 | 285 |
287 } // namespace task_viewer | 286 } // namespace task_viewer |
288 } // namespace main | 287 } // namespace main |
OLD | NEW |