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_application_delegate.h" | 5 #include "mash/task_viewer/task_viewer_application_delegate.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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 kill_button_->SetStyle(views::Button::STYLE_BUTTON); | 59 kill_button_->SetStyle(views::Button::STYLE_BUTTON); |
60 AddChildView(kill_button_); | 60 AddChildView(kill_button_); |
61 } | 61 } |
62 ~TaskViewer() override { | 62 ~TaskViewer() override { |
63 table_view_->SetModel(nullptr); | 63 table_view_->SetModel(nullptr); |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 struct ApplicationInfo { | 67 struct ApplicationInfo { |
68 int id; | 68 uint32_t id; |
69 std::string url; | 69 std::string url; |
70 uint32_t pid; | 70 uint32_t pid; |
71 | 71 |
72 ApplicationInfo(int id, const std::string url, base::ProcessId pid) | 72 ApplicationInfo(uint32_t id, const std::string url, base::ProcessId pid) |
73 : id(id), url(url), pid(pid) {} | 73 : id(id), url(url), pid(pid) {} |
74 }; | 74 }; |
75 | 75 |
76 // Overridden from views::WidgetDelegate: | 76 // Overridden from views::WidgetDelegate: |
77 views::View* GetContentsView() override { return this; } | 77 views::View* GetContentsView() override { return this; } |
78 base::string16 GetWindowTitle() const override { | 78 base::string16 GetWindowTitle() const override { |
79 // TODO(beng): use resources. | 79 // TODO(beng): use resources. |
80 return base::ASCIIToUTF16("Tasks"); | 80 return base::ASCIIToUTF16("Tasks"); |
81 } | 81 } |
82 | 82 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 applications[i]->pid))); | 138 applications[i]->pid))); |
139 } | 139 } |
140 } | 140 } |
141 void ApplicationInstanceCreated(ApplicationInfoPtr application) override { | 141 void ApplicationInstanceCreated(ApplicationInfoPtr application) override { |
142 DCHECK(!ContainsId(application->id)); | 142 DCHECK(!ContainsId(application->id)); |
143 applications_.push_back(make_scoped_ptr( | 143 applications_.push_back(make_scoped_ptr( |
144 new ApplicationInfo(application->id, application->url, | 144 new ApplicationInfo(application->id, application->url, |
145 application->pid))); | 145 application->pid))); |
146 observer_->OnItemsAdded(static_cast<int>(applications_.size()), 1); | 146 observer_->OnItemsAdded(static_cast<int>(applications_.size()), 1); |
147 } | 147 } |
148 void ApplicationInstanceDestroyed(int32_t id) override { | 148 void ApplicationInstanceDestroyed(uint32_t id) override { |
149 for (auto it = applications_.begin(); it != applications_.end(); ++it) { | 149 for (auto it = applications_.begin(); it != applications_.end(); ++it) { |
150 if ((*it)->id == id) { | 150 if ((*it)->id == id) { |
151 observer_->OnItemsRemoved( | 151 observer_->OnItemsRemoved( |
152 static_cast<int>(it - applications_.begin()), 1); | 152 static_cast<int>(it - applications_.begin()), 1); |
153 applications_.erase(it); | 153 applications_.erase(it); |
154 return; | 154 return; |
155 } | 155 } |
156 } | 156 } |
157 NOTREACHED(); | 157 NOTREACHED(); |
158 } | 158 } |
159 void ApplicationPIDAvailable(int id, uint32_t pid) override { | 159 void ApplicationPIDAvailable(uint32_t id, uint32_t pid) override { |
160 for (auto it = applications_.begin(); it != applications_.end(); ++it) { | 160 for (auto it = applications_.begin(); it != applications_.end(); ++it) { |
161 if ((*it)->id == id) { | 161 if ((*it)->id == id) { |
162 (*it)->pid = pid; | 162 (*it)->pid = pid; |
163 observer_->OnItemsChanged( | 163 observer_->OnItemsChanged( |
164 static_cast<int>(it - applications_.begin()), 1); | 164 static_cast<int>(it - applications_.begin()), 1); |
165 return; | 165 return; |
166 } | 166 } |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 bool ContainsId(int id) const { | 170 bool ContainsId(uint32_t id) const { |
171 for (auto& it : applications_) { | 171 for (auto& it : applications_) { |
172 if (it->id == id) | 172 if (it->id == id) |
173 return true; | 173 return true; |
174 } | 174 } |
175 return false; | 175 return false; |
176 } | 176 } |
177 | 177 |
178 static std::vector<ui::TableColumn> GetColumns() { | 178 static std::vector<ui::TableColumn> GetColumns() { |
179 std::vector<ui::TableColumn> columns; | 179 std::vector<ui::TableColumn> columns; |
180 | 180 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 application_manager->AddListener(std::move(listener)); | 230 application_manager->AddListener(std::move(listener)); |
231 | 231 |
232 TaskViewer* task_viewer = new TaskViewer(std::move(request)); | 232 TaskViewer* task_viewer = new TaskViewer(std::move(request)); |
233 views::Widget* window = views::Widget::CreateWindowWithBounds( | 233 views::Widget* window = views::Widget::CreateWindowWithBounds( |
234 task_viewer, gfx::Rect(10, 10, 500, 500)); | 234 task_viewer, gfx::Rect(10, 10, 500, 500)); |
235 window->Show(); | 235 window->Show(); |
236 } | 236 } |
237 | 237 |
238 } // namespace task_viewer | 238 } // namespace task_viewer |
239 } // namespace main | 239 } // namespace main |
OLD | NEW |