| 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/package_manager/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/shell.h" | 19 #include "mojo/shell/public/cpp/connector.h" |
| 20 #include "mojo/shell/public/interfaces/application_manager.mojom.h" | 20 #include "mojo/shell/public/interfaces/application_manager.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 ListenerRequest = | 34 using ListenerRequest = |
| 35 mojo::InterfaceRequest<mojo::shell::mojom::ApplicationManagerListener>; | 35 mojo::InterfaceRequest<mojo::shell::mojom::ApplicationManagerListener>; |
| 36 using mojo::shell::mojom::ApplicationInfoPtr; | 36 using mojo::shell::mojom::ApplicationInfoPtr; |
| 37 | 37 |
| 38 class TaskViewerContents | 38 class TaskViewerContents |
| 39 : public views::WidgetDelegateView, | 39 : public views::WidgetDelegateView, |
| 40 public ui::TableModel, | 40 public ui::TableModel, |
| 41 public views::ButtonListener, | 41 public views::ButtonListener, |
| 42 public mojo::shell::mojom::ApplicationManagerListener { | 42 public mojo::shell::mojom::ApplicationManagerListener { |
| 43 public: | 43 public: |
| 44 TaskViewerContents(ListenerRequest request, | 44 TaskViewerContents(ListenerRequest request, |
| 45 package_manager::mojom::CatalogPtr catalog, | 45 package_manager::mojom::CatalogPtr catalog) |
| 46 scoped_ptr<mojo::AppRefCount> app) | |
| 47 : binding_(this, std::move(request)), | 46 : binding_(this, std::move(request)), |
| 48 catalog_(std::move(catalog)), | 47 catalog_(std::move(catalog)), |
| 49 app_(std::move(app)), | |
| 50 table_view_(nullptr), | 48 table_view_(nullptr), |
| 51 table_view_parent_(nullptr), | 49 table_view_parent_(nullptr), |
| 52 kill_button_( | 50 kill_button_( |
| 53 new views::LabelButton(this, base::ASCIIToUTF16("Kill Process"))), | 51 new views::LabelButton(this, base::ASCIIToUTF16("Kill Process"))), |
| 54 observer_(nullptr), | 52 observer_(nullptr), |
| 55 weak_ptr_factory_(this) { | 53 weak_ptr_factory_(this) { |
| 56 // We don't want to show an empty UI on startup, so just block until we | 54 // We don't want to show an empty UI on startup, so just block until we |
| 57 // receive the initial set of applications. | 55 // receive the initial set of applications. |
| 58 binding_.WaitForIncomingMethodCall(); | 56 binding_.WaitForIncomingMethodCall(); |
| 59 | 57 |
| 60 table_view_ = new views::TableView(this, GetColumns(), views::TEXT_ONLY, | 58 table_view_ = new views::TableView(this, GetColumns(), views::TEXT_ONLY, |
| 61 false); | 59 false); |
| 62 set_background(views::Background::CreateStandardPanelBackground()); | 60 set_background(views::Background::CreateStandardPanelBackground()); |
| 63 | 61 |
| 64 table_view_parent_ = table_view_->CreateParentIfNecessary(); | 62 table_view_parent_ = table_view_->CreateParentIfNecessary(); |
| 65 AddChildView(table_view_parent_); | 63 AddChildView(table_view_parent_); |
| 66 | 64 |
| 67 kill_button_->SetStyle(views::Button::STYLE_BUTTON); | 65 kill_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 68 AddChildView(kill_button_); | 66 AddChildView(kill_button_); |
| 69 } | 67 } |
| 70 ~TaskViewerContents() override { | 68 ~TaskViewerContents() override { |
| 71 table_view_->SetModel(nullptr); | 69 table_view_->SetModel(nullptr); |
| 70 base::MessageLoop::current()->QuitWhenIdle(); |
| 72 } | 71 } |
| 73 | 72 |
| 74 private: | 73 private: |
| 75 struct InstanceInfo { | 74 struct InstanceInfo { |
| 76 InstanceInfo(uint32_t id, | 75 InstanceInfo(uint32_t id, |
| 77 const std::string& url, | 76 const std::string& url, |
| 78 base::ProcessId pid) | 77 base::ProcessId pid) |
| 79 : id(id), url(url), pid(pid) {} | 78 : id(id), url(url), pid(pid) {} |
| 80 uint32_t id; | 79 uint32_t id; |
| 81 std::string url; | 80 std::string url; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 pid_column.title = base::ASCIIToUTF16("PID"); | 238 pid_column.title = base::ASCIIToUTF16("PID"); |
| 240 pid_column.width = 50; | 239 pid_column.width = 50; |
| 241 pid_column.sortable = true; | 240 pid_column.sortable = true; |
| 242 columns.push_back(pid_column); | 241 columns.push_back(pid_column); |
| 243 | 242 |
| 244 return columns; | 243 return columns; |
| 245 } | 244 } |
| 246 | 245 |
| 247 mojo::Binding<mojo::shell::mojom::ApplicationManagerListener> binding_; | 246 mojo::Binding<mojo::shell::mojom::ApplicationManagerListener> binding_; |
| 248 package_manager::mojom::CatalogPtr catalog_; | 247 package_manager::mojom::CatalogPtr catalog_; |
| 249 scoped_ptr<mojo::AppRefCount> app_; | |
| 250 | 248 |
| 251 views::TableView* table_view_; | 249 views::TableView* table_view_; |
| 252 views::View* table_view_parent_; | 250 views::View* table_view_parent_; |
| 253 views::LabelButton* kill_button_; | 251 views::LabelButton* kill_button_; |
| 254 ui::TableModelObserver* observer_; | 252 ui::TableModelObserver* observer_; |
| 255 | 253 |
| 256 std::vector<scoped_ptr<InstanceInfo>> instances_; | 254 std::vector<scoped_ptr<InstanceInfo>> instances_; |
| 257 | 255 |
| 258 base::WeakPtrFactory<TaskViewerContents> weak_ptr_factory_; | 256 base::WeakPtrFactory<TaskViewerContents> weak_ptr_factory_; |
| 259 | 257 |
| 260 DISALLOW_COPY_AND_ASSIGN(TaskViewerContents); | 258 DISALLOW_COPY_AND_ASSIGN(TaskViewerContents); |
| 261 }; | 259 }; |
| 262 | 260 |
| 263 } // namespace | 261 } // namespace |
| 264 | 262 |
| 265 TaskViewer::TaskViewer() {} | 263 TaskViewer::TaskViewer() {} |
| 266 TaskViewer::~TaskViewer() {} | 264 TaskViewer::~TaskViewer() {} |
| 267 | 265 |
| 268 void TaskViewer::Initialize(mojo::Shell* shell, const std::string& url, | 266 void TaskViewer::Initialize(mojo::Connector* connector, |
| 267 const std::string& url, |
| 269 uint32_t id, uint32_t user_id) { | 268 uint32_t id, uint32_t user_id) { |
| 270 tracing_.Initialize(shell, url); | 269 tracing_.Initialize(connector, url); |
| 271 | 270 |
| 272 aura_init_.reset(new views::AuraInit(shell, "views_mus_resources.pak")); | 271 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
| 273 views::WindowManagerConnection::Create(shell); | 272 views::WindowManagerConnection::Create(connector); |
| 274 | 273 |
| 275 mojo::shell::mojom::ApplicationManagerPtr application_manager; | 274 mojo::shell::mojom::ApplicationManagerPtr application_manager; |
| 276 shell->ConnectToInterface("mojo:shell", &application_manager); | 275 connector->ConnectToInterface("mojo:shell", &application_manager); |
| 277 | 276 |
| 278 mojo::shell::mojom::ApplicationManagerListenerPtr listener; | 277 mojo::shell::mojom::ApplicationManagerListenerPtr listener; |
| 279 ListenerRequest request = GetProxy(&listener); | 278 ListenerRequest request = GetProxy(&listener); |
| 280 application_manager->AddListener(std::move(listener)); | 279 application_manager->AddListener(std::move(listener)); |
| 281 | 280 |
| 282 package_manager::mojom::CatalogPtr catalog; | 281 package_manager::mojom::CatalogPtr catalog; |
| 283 shell->ConnectToInterface("mojo:package_manager", &catalog); | 282 connector->ConnectToInterface("mojo:package_manager", &catalog); |
| 284 | 283 |
| 285 TaskViewerContents* task_viewer = new TaskViewerContents( | 284 TaskViewerContents* task_viewer = new TaskViewerContents( |
| 286 std::move(request), std::move(catalog), shell->CreateAppRefCount()); | 285 std::move(request), std::move(catalog)); |
| 287 views::Widget* window = views::Widget::CreateWindowWithBounds( | 286 views::Widget* window = views::Widget::CreateWindowWithBounds( |
| 288 task_viewer, gfx::Rect(10, 10, 500, 500)); | 287 task_viewer, gfx::Rect(10, 10, 500, 500)); |
| 289 window->Show(); | 288 window->Show(); |
| 290 } | 289 } |
| 291 | 290 |
| 292 } // namespace task_viewer | 291 } // namespace task_viewer |
| 293 } // namespace main | 292 } // namespace main |
| OLD | NEW |