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

Side by Side Diff: mash/task_viewer/task_viewer.cc

Issue 2179023004: Make Service own ServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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
« no previous file with comments | « mash/task_viewer/task_viewer.h ('k') | mash/webtest/webtest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 kill_button_->SetStyle(views::Button::STYLE_BUTTON); 67 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
68 AddChildView(kill_button_); 68 AddChildView(kill_button_);
69 } 69 }
70 ~TaskViewerContents() override { 70 ~TaskViewerContents() override {
71 table_view_->SetModel(nullptr); 71 table_view_->SetModel(nullptr);
72 task_viewer_->RemoveWindow(GetWidget()); 72 task_viewer_->RemoveWindow(GetWidget());
73 } 73 }
74 74
75 private: 75 private:
76 struct InstanceInfo { 76 struct InstanceInfo {
77 InstanceInfo(uint32_t id, 77 InstanceInfo(const shell::Identity& identity, base::ProcessId pid)
78 const std::string& url, 78 : identity(identity), pid(pid) {}
79 base::ProcessId pid) 79 shell::Identity identity;
80 : id(id), url(url), pid(pid) {}
81 uint32_t id;
82 std::string url;
83 uint32_t pid; 80 uint32_t pid;
84 std::string name; 81 std::string display_name;
85 }; 82 };
86 83
87 84
88 // Overridden from views::WidgetDelegate: 85 // Overridden from views::WidgetDelegate:
89 views::View* GetContentsView() override { return this; } 86 views::View* GetContentsView() override { return this; }
90 base::string16 GetWindowTitle() const override { 87 base::string16 GetWindowTitle() const override {
91 // TODO(beng): use resources. 88 // TODO(beng): use resources.
92 return base::ASCIIToUTF16("Tasks"); 89 return base::ASCIIToUTF16("Tasks");
93 } 90 }
94 bool CanResize() const override { return true; } 91 bool CanResize() const override { return true; }
(...skipping 22 matching lines...) Expand all
117 } 114 }
118 115
119 // Overridden from ui::TableModel: 116 // Overridden from ui::TableModel:
120 int RowCount() override { 117 int RowCount() override {
121 return static_cast<int>(instances_.size()); 118 return static_cast<int>(instances_.size());
122 } 119 }
123 base::string16 GetText(int row, int column_id) override { 120 base::string16 GetText(int row, int column_id) override {
124 switch(column_id) { 121 switch(column_id) {
125 case 0: 122 case 0:
126 DCHECK(row < static_cast<int>(instances_.size())); 123 DCHECK(row < static_cast<int>(instances_.size()));
127 return base::UTF8ToUTF16(instances_[row]->name); 124 return base::UTF8ToUTF16(instances_[row]->display_name);
128 case 1: 125 case 1:
129 DCHECK(row < static_cast<int>(instances_.size())); 126 DCHECK(row < static_cast<int>(instances_.size()));
130 return base::UTF8ToUTF16(instances_[row]->url); 127 return base::UTF8ToUTF16(instances_[row]->identity.name());
131 case 2: 128 case 2:
132 DCHECK(row < static_cast<int>(instances_.size())); 129 DCHECK(row < static_cast<int>(instances_.size()));
133 return base::IntToString16(instances_[row]->pid); 130 return base::IntToString16(instances_[row]->pid);
134 default: 131 default:
135 NOTREACHED(); 132 NOTREACHED();
136 break; 133 break;
137 } 134 }
138 return base::string16(); 135 return base::string16();
139 } 136 }
140 void SetObserver(ui::TableModelObserver* observer) override { 137 void SetObserver(ui::TableModelObserver* observer) override {
141 observer_ = observer; 138 observer_ = observer;
142 } 139 }
143 140
144 // Overridden from views::ButtonListener: 141 // Overridden from views::ButtonListener:
145 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 142 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
146 DCHECK_EQ(sender, kill_button_); 143 DCHECK_EQ(sender, kill_button_);
147 DCHECK_EQ(table_view_->SelectedRowCount(), 1); 144 DCHECK_EQ(table_view_->SelectedRowCount(), 1);
148 int row = table_view_->FirstSelectedRow(); 145 int row = table_view_->FirstSelectedRow();
149 DCHECK(row < static_cast<int>(instances_.size())); 146 DCHECK(row < static_cast<int>(instances_.size()));
150 base::Process process = base::Process::Open(instances_[row]->pid); 147 base::Process process = base::Process::Open(instances_[row]->pid);
151 process.Terminate(9, true); 148 process.Terminate(9, true);
152 } 149 }
153 150
154 // Overridden from shell::mojom::ServiceManagerListener: 151 // Overridden from shell::mojom::ServiceManagerListener:
155 void OnInit(mojo::Array<ServiceInfoPtr> instances) override { 152 void OnInit(mojo::Array<ServiceInfoPtr> instances) override {
156 // This callback should only be called with an empty model. 153 // This callback should only be called with an empty model.
157 DCHECK(instances_.empty()); 154 DCHECK(instances_.empty());
158 mojo::Array<mojo::String> names; 155 mojo::Array<mojo::String> names;
159 for (size_t i = 0; i < instances.size(); ++i) { 156 for (size_t i = 0; i < instances.size(); ++i) {
160 InsertInstance(instances[i]->id, instances[i]->identity->name, 157 shell::Identity identity = instances[i]->identity.To<shell::Identity>();
161 instances[i]->pid); 158 InsertInstance(identity, instances[i]->pid);
162 names.push_back(instances[i]->identity->name); 159 names.push_back(identity.name());
163 } 160 }
164 catalog_->GetEntries(std::move(names), 161 catalog_->GetEntries(std::move(names),
165 base::Bind(&TaskViewerContents::OnGotCatalogEntries, 162 base::Bind(&TaskViewerContents::OnGotCatalogEntries,
166 weak_ptr_factory_.GetWeakPtr())); 163 weak_ptr_factory_.GetWeakPtr()));
167 } 164 }
168 void OnServiceCreated(ServiceInfoPtr instance) override { 165 void OnServiceCreated(ServiceInfoPtr instance) override {
169 DCHECK(!ContainsId(instance->id)); 166 shell::Identity identity = instance->identity.To<shell::Identity>();
170 InsertInstance(instance->id, instance->identity->name, instance->pid); 167 DCHECK(!ContainsIdentity(identity));
168 InsertInstance(identity, instance->pid);
171 observer_->OnItemsAdded(static_cast<int>(instances_.size()), 1); 169 observer_->OnItemsAdded(static_cast<int>(instances_.size()), 1);
172 mojo::Array<mojo::String> names; 170 mojo::Array<mojo::String> names;
173 names.push_back(instance->identity->name); 171 names.push_back(identity.name());
174 catalog_->GetEntries(std::move(names), 172 catalog_->GetEntries(std::move(names),
175 base::Bind(&TaskViewerContents::OnGotCatalogEntries, 173 base::Bind(&TaskViewerContents::OnGotCatalogEntries,
176 weak_ptr_factory_.GetWeakPtr())); 174 weak_ptr_factory_.GetWeakPtr()));
177 } 175 }
178 void OnServiceStarted(uint32_t id, uint32_t pid) override { 176 void OnServiceStarted(shell::mojom::IdentityPtr identity_ptr,
177 uint32_t pid) override {
178 shell::Identity identity = identity_ptr.To<shell::Identity>();
179 for (auto it = instances_.begin(); it != instances_.end(); ++it) { 179 for (auto it = instances_.begin(); it != instances_.end(); ++it) {
180 if ((*it)->id == id) { 180 if ((*it)->identity == identity) {
181 (*it)->pid = pid; 181 (*it)->pid = pid;
182 observer_->OnItemsChanged( 182 observer_->OnItemsChanged(
183 static_cast<int>(it - instances_.begin()), 1); 183 static_cast<int>(it - instances_.begin()), 1);
184 return; 184 return;
185 } 185 }
186 } 186 }
187 } 187 }
188 void OnServiceStopped(uint32_t id) override { 188 void OnServiceStopped(shell::mojom::IdentityPtr identity_ptr) override {
189 shell::Identity identity = identity_ptr.To<shell::Identity>();
189 for (auto it = instances_.begin(); it != instances_.end(); ++it) { 190 for (auto it = instances_.begin(); it != instances_.end(); ++it) {
190 if ((*it)->id == id) { 191 if ((*it)->identity == identity) {
191 observer_->OnItemsRemoved( 192 observer_->OnItemsRemoved(
192 static_cast<int>(it - instances_.begin()), 1); 193 static_cast<int>(it - instances_.begin()), 1);
193 instances_.erase(it); 194 instances_.erase(it);
194 return; 195 return;
195 } 196 }
196 } 197 }
197 NOTREACHED(); 198 NOTREACHED();
198 } 199 }
199 200
200 bool ContainsId(uint32_t id) const { 201 bool ContainsIdentity(const shell::Identity& identity) const {
201 for (auto& it : instances_) { 202 for (auto& it : instances_) {
202 if (it->id == id) 203 if (it->identity == identity)
203 return true; 204 return true;
204 } 205 }
205 return false; 206 return false;
206 } 207 }
207 208
208 void InsertInstance(uint32_t id, const std::string& url, uint32_t pid) { 209 void InsertInstance(const shell::Identity& identity, uint32_t pid) {
209 instances_.push_back(base::WrapUnique(new InstanceInfo(id, url, pid))); 210 instances_.push_back(
211 base::WrapUnique(new InstanceInfo(identity, pid)));
210 } 212 }
211 213
212 void OnGotCatalogEntries(mojo::Array<catalog::mojom::EntryPtr> entries) { 214 void OnGotCatalogEntries(mojo::Array<catalog::mojom::EntryPtr> entries) {
213 for (auto it = instances_.begin(); it != instances_.end(); ++it) { 215 for (auto it = instances_.begin(); it != instances_.end(); ++it) {
214 for (auto& entry : entries) { 216 for (auto& entry : entries) {
215 if (entry->name == (*it)->url) { 217 if (entry->name == (*it)->identity.name()) {
216 (*it)->name = entry->display_name; 218 (*it)->display_name = entry->display_name;
217 observer_->OnItemsChanged( 219 observer_->OnItemsChanged(
218 static_cast<int>(it - instances_.begin()), 1); 220 static_cast<int>(it - instances_.begin()), 1);
219 break; 221 break;
220 } 222 }
221 } 223 }
222 } 224 }
223 } 225 }
224 226
225 static std::vector<ui::TableColumn> GetColumns() { 227 static std::vector<ui::TableColumn> GetColumns() {
226 std::vector<ui::TableColumn> columns; 228 std::vector<ui::TableColumn> columns;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 TaskViewer::~TaskViewer() {} 278 TaskViewer::~TaskViewer() {}
277 279
278 void TaskViewer::RemoveWindow(views::Widget* widget) { 280 void TaskViewer::RemoveWindow(views::Widget* widget) {
279 auto it = std::find(windows_.begin(), windows_.end(), widget); 281 auto it = std::find(windows_.begin(), windows_.end(), widget);
280 DCHECK(it != windows_.end()); 282 DCHECK(it != windows_.end());
281 windows_.erase(it); 283 windows_.erase(it);
282 if (windows_.empty()) 284 if (windows_.empty())
283 base::MessageLoop::current()->QuitWhenIdle(); 285 base::MessageLoop::current()->QuitWhenIdle();
284 } 286 }
285 287
286 void TaskViewer::OnStart(shell::Connector* connector, 288 void TaskViewer::OnStart(const shell::Identity& identity) {
287 const shell::Identity& identity, 289 tracing_.Initialize(connector(), identity.name());
288 uint32_t id) {
289 connector_ = connector;
290 tracing_.Initialize(connector, identity.name());
291 290
292 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); 291 aura_init_.reset(
292 new views::AuraInit(connector(), "views_mus_resources.pak"));
293 window_manager_connection_ = 293 window_manager_connection_ =
294 views::WindowManagerConnection::Create(connector, identity); 294 views::WindowManagerConnection::Create(connector(), identity);
295 } 295 }
296 296
297 bool TaskViewer::OnConnect(shell::Connection* connection) { 297 bool TaskViewer::OnConnect(shell::Connection* connection) {
298 connection->AddInterface<mojom::Launchable>(this); 298 connection->AddInterface<mojom::Launchable>(this);
299 return true; 299 return true;
300 } 300 }
301 301
302 void TaskViewer::Launch(uint32_t what, mojom::LaunchMode how) { 302 void TaskViewer::Launch(uint32_t what, mojom::LaunchMode how) {
303 bool reuse = how == mojom::LaunchMode::REUSE || 303 bool reuse = how == mojom::LaunchMode::REUSE ||
304 how == mojom::LaunchMode::DEFAULT; 304 how == mojom::LaunchMode::DEFAULT;
305 if (reuse && !windows_.empty()) { 305 if (reuse && !windows_.empty()) {
306 windows_.back()->Activate(); 306 windows_.back()->Activate();
307 return; 307 return;
308 } 308 }
309 309
310 shell::mojom::ServiceManagerPtr service_manager; 310 shell::mojom::ServiceManagerPtr service_manager;
311 connector_->ConnectToInterface("mojo:shell", &service_manager); 311 connector()->ConnectToInterface("mojo:shell", &service_manager);
312 312
313 shell::mojom::ServiceManagerListenerPtr listener; 313 shell::mojom::ServiceManagerListenerPtr listener;
314 shell::mojom::ServiceManagerListenerRequest request = GetProxy(&listener); 314 shell::mojom::ServiceManagerListenerRequest request = GetProxy(&listener);
315 service_manager->AddListener(std::move(listener)); 315 service_manager->AddListener(std::move(listener));
316 316
317 catalog::mojom::CatalogPtr catalog; 317 catalog::mojom::CatalogPtr catalog;
318 connector_->ConnectToInterface("mojo:catalog", &catalog); 318 connector()->ConnectToInterface("mojo:catalog", &catalog);
319 319
320 TaskViewerContents* task_viewer = new TaskViewerContents( 320 TaskViewerContents* task_viewer = new TaskViewerContents(
321 this, std::move(request), std::move(catalog)); 321 this, std::move(request), std::move(catalog));
322 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds( 322 views::Widget* window = views::Widget::CreateWindowWithContextAndBounds(
323 task_viewer, nullptr, gfx::Rect(10, 10, 500, 500)); 323 task_viewer, nullptr, gfx::Rect(10, 10, 500, 500));
324 window->Show(); 324 window->Show();
325 windows_.push_back(window); 325 windows_.push_back(window);
326 } 326 }
327 327
328 void TaskViewer::Create(const shell::Identity& remote_identity, 328 void TaskViewer::Create(const shell::Identity& remote_identity,
329 mojom::LaunchableRequest request) { 329 mojom::LaunchableRequest request) {
330 bindings_.AddBinding(this, std::move(request)); 330 bindings_.AddBinding(this, std::move(request));
331 } 331 }
332 332
333 } // namespace task_viewer 333 } // namespace task_viewer
334 } // namespace main 334 } // namespace main
OLDNEW
« no previous file with comments | « mash/task_viewer/task_viewer.h ('k') | mash/webtest/webtest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698