OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/task_manager_handler.h" | 5 #include "chrome/browser/ui/webui/task_manager_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/task_manager/task_manager.h" | 12 #include "chrome/browser/task_manager/task_manager.h" |
13 #include "chrome/browser/ui/webui/web_ui_util.h" | 13 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "content/common/notification_service.h" |
| 16 #include "content/common/notification_source.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
15 | 18 |
16 namespace { | 19 namespace { |
17 | 20 |
18 static Value* CreateColumnValue(const TaskManagerModel* tm, | 21 static Value* CreateColumnValue(const TaskManagerModel* tm, |
19 const std::string column_name, | 22 const std::string column_name, |
20 const int i) { | 23 const int i) { |
21 if (column_name == "processId") | 24 if (column_name == "processId") |
22 return Value::CreateStringValue(tm->GetResourceProcessId(i)); | 25 return Value::CreateStringValue(tm->GetResourceProcessId(i)); |
23 if (column_name == "processIdValue") | 26 if (column_name == "processIdValue") |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (group_start == group_end) | 240 if (group_start == group_end) |
238 return; | 241 return; |
239 else | 242 else |
240 group_end--; | 243 group_end--; |
241 } | 244 } |
242 | 245 |
243 OnGroupAdded(group_start, group_end - group_start + 1); | 246 OnGroupAdded(group_start, group_end - group_start + 1); |
244 } | 247 } |
245 | 248 |
246 void TaskManagerHandler::OnItemsRemoved(const int start, const int length) { | 249 void TaskManagerHandler::OnItemsRemoved(const int start, const int length) { |
| 250 // Returns if this is called before updating |resource_to_group_table_|. |
| 251 if (resource_to_group_table_.size() < static_cast<size_t>(start + length)) |
| 252 return; |
| 253 |
247 // Converts from an index of resources to an index of groups. | 254 // Converts from an index of resources to an index of groups. |
248 int group_start = resource_to_group_table_[start]; | 255 int group_start = resource_to_group_table_[start]; |
249 int group_end = resource_to_group_table_[start + length - 1]; | 256 int group_end = resource_to_group_table_[start + length - 1]; |
250 | 257 |
251 // First group to remove does not contain all the items in the group. Because | 258 // First group to remove does not contain all the items in the group. Because |
252 // the first item to remove and the previous one are in same group. | 259 // the first item to remove and the previous one are in same group. |
253 if (start != 0 && group_start == resource_to_group_table_[start - 1]) { | 260 if (start != 0 && group_start == resource_to_group_table_[start - 1]) { |
254 OnGroupChanged(group_start, 1); | 261 OnGroupChanged(group_start, 1); |
255 if (group_start == group_end) | 262 if (group_start == group_end) |
256 return; | 263 return; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 model_->RemoveObserver(this); | 332 model_->RemoveObserver(this); |
326 } | 333 } |
327 | 334 |
328 void TaskManagerHandler::EnableTaskManager(const ListValue* indexes) { | 335 void TaskManagerHandler::EnableTaskManager(const ListValue* indexes) { |
329 if (is_enabled_) | 336 if (is_enabled_) |
330 return; | 337 return; |
331 | 338 |
332 is_enabled_ = true; | 339 is_enabled_ = true; |
333 model_->AddObserver(this); | 340 model_->AddObserver(this); |
334 model_->StartUpdating(); | 341 model_->StartUpdating(); |
| 342 |
| 343 NotificationService::current()->Notify( |
| 344 chrome::NOTIFICATION_TASK_MANAGER_WINDOW_READY, |
| 345 Source<TaskManagerModel>(model_), |
| 346 NotificationService::NoDetails()); |
335 } | 347 } |
336 | 348 |
337 void TaskManagerHandler::OpenAboutMemory(const ListValue* indexes) { | 349 void TaskManagerHandler::OpenAboutMemory(const ListValue* indexes) { |
338 task_manager_->OpenAboutMemory(); | 350 task_manager_->OpenAboutMemory(); |
339 } | 351 } |
340 | 352 |
341 // TaskManagerHandler, private: ----------------------------------------------- | 353 // TaskManagerHandler, private: ----------------------------------------------- |
342 | 354 |
343 void TaskManagerHandler::UpdateResourceGroupTable(int start, int length) { | 355 void TaskManagerHandler::UpdateResourceGroupTable(int start, int length) { |
344 if (resource_to_group_table_.size() < static_cast<size_t>(start)) { | 356 if (resource_to_group_table_.size() < static_cast<size_t>(start)) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 } | 398 } |
387 | 399 |
388 void TaskManagerHandler::OnGroupRemoved(const int group_start, | 400 void TaskManagerHandler::OnGroupRemoved(const int group_start, |
389 const int group_length) { | 401 const int group_length) { |
390 FundamentalValue start_value(group_start); | 402 FundamentalValue start_value(group_start); |
391 FundamentalValue length_value(group_length); | 403 FundamentalValue length_value(group_length); |
392 if (is_enabled_) | 404 if (is_enabled_) |
393 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); | 405 web_ui_->CallJavascriptFunction("taskRemoved", start_value, length_value); |
394 } | 406 } |
395 | 407 |
OLD | NEW |