| 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/task_manager/task_manager_resource_providers.h" | 5 #include "chrome/browser/task_manager/task_manager_resource_providers.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 17 #include "chrome/browser/background/background_contents_service.h" | 17 #include "chrome/browser/background/background_contents_service.h" |
| 18 #include "chrome/browser/background/background_contents_service_factory.h" | 18 #include "chrome/browser/background/background_contents_service_factory.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/extensions/extension_host.h" | 20 #include "chrome/browser/extensions/extension_host.h" |
| 21 #include "chrome/browser/extensions/extension_process_manager.h" | 21 #include "chrome/browser/extensions/extension_process_manager.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/favicon/favicon_tab_helper.h" | 23 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 24 #include "chrome/browser/prerender/prerender_manager.h" | 24 #include "chrome/browser/prerender/prerender_manager.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/tab_contents/background_contents.h" | 26 #include "chrome/browser/tab_contents/background_contents.h" |
| 27 #include "chrome/browser/tab_contents/tab_util.h" | 27 #include "chrome/browser/tab_contents/tab_util.h" |
| 28 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
| 29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 30 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
| 32 #include "chrome/common/render_messages.h" | 33 #include "chrome/common/render_messages.h" |
| 33 #include "content/browser/browser_child_process_host.h" | 34 #include "content/browser/browser_child_process_host.h" |
| 34 #include "content/browser/browser_thread.h" | 35 #include "content/browser/browser_thread.h" |
| 35 #include "content/browser/renderer_host/render_message_filter.h" | 36 #include "content/browser/renderer_host/render_message_filter.h" |
| 36 #include "content/browser/renderer_host/render_process_host.h" | 37 #include "content/browser/renderer_host/render_process_host.h" |
| 37 #include "content/browser/renderer_host/render_view_host.h" | 38 #include "content/browser/renderer_host/render_view_host.h" |
| 38 #include "content/browser/tab_contents/tab_contents.h" | 39 #include "content/browser/tab_contents/tab_contents.h" |
| 39 #include "content/common/notification_service.h" | 40 #include "content/common/notification_service.h" |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 const Extension* extension = extensions_service->GetExtensionById( | 559 const Extension* extension = extensions_service->GetExtensionById( |
| 559 UTF16ToUTF8(application_id), false); | 560 UTF16ToUTF8(application_id), false); |
| 560 if (extension) | 561 if (extension) |
| 561 application_name = UTF8ToUTF16(extension->name()); | 562 application_name = UTF8ToUTF16(extension->name()); |
| 562 } | 563 } |
| 563 Add(*iterator, application_name); | 564 Add(*iterator, application_name); |
| 564 } | 565 } |
| 565 } | 566 } |
| 566 | 567 |
| 567 // Then we register for notifications to get new BackgroundContents. | 568 // Then we register for notifications to get new BackgroundContents. |
| 568 registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_OPENED, | 569 registrar_.Add(this, chrome::BACKGROUND_CONTENTS_OPENED, |
| 569 NotificationService::AllSources()); | 570 NotificationService::AllSources()); |
| 570 registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_NAVIGATED, | 571 registrar_.Add(this, chrome::BACKGROUND_CONTENTS_NAVIGATED, |
| 571 NotificationService::AllSources()); | 572 NotificationService::AllSources()); |
| 572 registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_DELETED, | 573 registrar_.Add(this, chrome::BACKGROUND_CONTENTS_DELETED, |
| 573 NotificationService::AllSources()); | 574 NotificationService::AllSources()); |
| 574 } | 575 } |
| 575 | 576 |
| 576 void TaskManagerBackgroundContentsResourceProvider::StopUpdating() { | 577 void TaskManagerBackgroundContentsResourceProvider::StopUpdating() { |
| 577 DCHECK(updating_); | 578 DCHECK(updating_); |
| 578 updating_ = false; | 579 updating_ = false; |
| 579 | 580 |
| 580 // Unregister for notifications | 581 // Unregister for notifications |
| 581 registrar_.Remove(this, NotificationType::BACKGROUND_CONTENTS_OPENED, | 582 registrar_.Remove(this, chrome::BACKGROUND_CONTENTS_OPENED, |
| 582 NotificationService::AllSources()); | 583 NotificationService::AllSources()); |
| 583 registrar_.Remove(this, NotificationType::BACKGROUND_CONTENTS_NAVIGATED, | 584 registrar_.Remove(this, chrome::BACKGROUND_CONTENTS_NAVIGATED, |
| 584 NotificationService::AllSources()); | 585 NotificationService::AllSources()); |
| 585 registrar_.Remove(this, NotificationType::BACKGROUND_CONTENTS_DELETED, | 586 registrar_.Remove(this, chrome::BACKGROUND_CONTENTS_DELETED, |
| 586 NotificationService::AllSources()); | 587 NotificationService::AllSources()); |
| 587 | 588 |
| 588 // Delete all the resources. | 589 // Delete all the resources. |
| 589 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 590 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 590 | 591 |
| 591 resources_.clear(); | 592 resources_.clear(); |
| 592 } | 593 } |
| 593 | 594 |
| 594 void TaskManagerBackgroundContentsResourceProvider::AddToTaskManager( | 595 void TaskManagerBackgroundContentsResourceProvider::AddToTaskManager( |
| 595 BackgroundContents* background_contents, | 596 BackgroundContents* background_contents, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 resources_.erase(iter); | 632 resources_.erase(iter); |
| 632 // Finally, delete the resource. | 633 // Finally, delete the resource. |
| 633 delete resource; | 634 delete resource; |
| 634 } | 635 } |
| 635 | 636 |
| 636 void TaskManagerBackgroundContentsResourceProvider::Observe( | 637 void TaskManagerBackgroundContentsResourceProvider::Observe( |
| 637 NotificationType type, | 638 NotificationType type, |
| 638 const NotificationSource& source, | 639 const NotificationSource& source, |
| 639 const NotificationDetails& details) { | 640 const NotificationDetails& details) { |
| 640 switch (type.value) { | 641 switch (type.value) { |
| 641 case NotificationType::BACKGROUND_CONTENTS_OPENED: { | 642 case chrome::BACKGROUND_CONTENTS_OPENED: { |
| 642 // Get the name from the parent application. If no parent application is | 643 // Get the name from the parent application. If no parent application is |
| 643 // found, just pass an empty string - BackgroundContentsResource::GetTitle | 644 // found, just pass an empty string - BackgroundContentsResource::GetTitle |
| 644 // will display the URL instead in this case. This should never happen | 645 // will display the URL instead in this case. This should never happen |
| 645 // except in rare cases when an extension is being unloaded or chrome is | 646 // except in rare cases when an extension is being unloaded or chrome is |
| 646 // exiting while the task manager is displayed. | 647 // exiting while the task manager is displayed. |
| 647 string16 application_name; | 648 string16 application_name; |
| 648 ExtensionService* service = | 649 ExtensionService* service = |
| 649 Source<Profile>(source)->GetExtensionService(); | 650 Source<Profile>(source)->GetExtensionService(); |
| 650 if (service) { | 651 if (service) { |
| 651 std::string application_id = UTF16ToUTF8( | 652 std::string application_id = UTF16ToUTF8( |
| 652 Details<BackgroundContentsOpenedDetails>(details)->application_id); | 653 Details<BackgroundContentsOpenedDetails>(details)->application_id); |
| 653 const Extension* extension = | 654 const Extension* extension = |
| 654 service->GetExtensionById(application_id, false); | 655 service->GetExtensionById(application_id, false); |
| 655 // Extension can be NULL when running unit tests. | 656 // Extension can be NULL when running unit tests. |
| 656 if (extension) | 657 if (extension) |
| 657 application_name = UTF8ToUTF16(extension->name()); | 658 application_name = UTF8ToUTF16(extension->name()); |
| 658 } | 659 } |
| 659 Add(Details<BackgroundContentsOpenedDetails>(details)->contents, | 660 Add(Details<BackgroundContentsOpenedDetails>(details)->contents, |
| 660 application_name); | 661 application_name); |
| 661 // Opening a new BackgroundContents needs to force the display to refresh | 662 // Opening a new BackgroundContents needs to force the display to refresh |
| 662 // (applications may now be considered "background" that weren't before). | 663 // (applications may now be considered "background" that weren't before). |
| 663 task_manager_->ModelChanged(); | 664 task_manager_->ModelChanged(); |
| 664 break; | 665 break; |
| 665 } | 666 } |
| 666 case NotificationType::BACKGROUND_CONTENTS_NAVIGATED: { | 667 case chrome::BACKGROUND_CONTENTS_NAVIGATED: { |
| 667 BackgroundContents* contents = Details<BackgroundContents>(details).ptr(); | 668 BackgroundContents* contents = Details<BackgroundContents>(details).ptr(); |
| 668 // Should never get a NAVIGATED before OPENED. | 669 // Should never get a NAVIGATED before OPENED. |
| 669 DCHECK(resources_.find(contents) != resources_.end()); | 670 DCHECK(resources_.find(contents) != resources_.end()); |
| 670 // Preserve the application name. | 671 // Preserve the application name. |
| 671 string16 application_name( | 672 string16 application_name( |
| 672 resources_.find(contents)->second->application_name()); | 673 resources_.find(contents)->second->application_name()); |
| 673 Remove(contents); | 674 Remove(contents); |
| 674 Add(contents, application_name); | 675 Add(contents, application_name); |
| 675 break; | 676 break; |
| 676 } | 677 } |
| 677 case NotificationType::BACKGROUND_CONTENTS_DELETED: | 678 case chrome::BACKGROUND_CONTENTS_DELETED: |
| 678 Remove(Details<BackgroundContents>(details).ptr()); | 679 Remove(Details<BackgroundContents>(details).ptr()); |
| 679 // Closing a BackgroundContents needs to force the display to refresh | 680 // Closing a BackgroundContents needs to force the display to refresh |
| 680 // (applications may now be considered "foreground" that weren't before). | 681 // (applications may now be considered "foreground" that weren't before). |
| 681 task_manager_->ModelChanged(); | 682 task_manager_->ModelChanged(); |
| 682 break; | 683 break; |
| 683 default: | 684 default: |
| 684 NOTREACHED() << "Unexpected notification."; | 685 NOTREACHED() << "Unexpected notification."; |
| 685 return; | 686 return; |
| 686 } | 687 } |
| 687 } | 688 } |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 profiles[i]->GetOffTheRecordProfile()->GetExtensionProcessManager(); | 1086 profiles[i]->GetOffTheRecordProfile()->GetExtensionProcessManager(); |
| 1086 if (process_manager) { | 1087 if (process_manager) { |
| 1087 ExtensionProcessManager::const_iterator jt; | 1088 ExtensionProcessManager::const_iterator jt; |
| 1088 for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) | 1089 for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) |
| 1089 AddToTaskManager(*jt); | 1090 AddToTaskManager(*jt); |
| 1090 } | 1091 } |
| 1091 } | 1092 } |
| 1092 } | 1093 } |
| 1093 | 1094 |
| 1094 // Register for notifications about extension process changes. | 1095 // Register for notifications about extension process changes. |
| 1095 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_CREATED, | 1096 registrar_.Add(this, chrome::EXTENSION_PROCESS_CREATED, |
| 1096 NotificationService::AllSources()); | 1097 NotificationService::AllSources()); |
| 1097 registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, | 1098 registrar_.Add(this, chrome::EXTENSION_PROCESS_TERMINATED, |
| 1098 NotificationService::AllSources()); | 1099 NotificationService::AllSources()); |
| 1099 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, | 1100 registrar_.Add(this, chrome::EXTENSION_HOST_DESTROYED, |
| 1100 NotificationService::AllSources()); | 1101 NotificationService::AllSources()); |
| 1101 } | 1102 } |
| 1102 | 1103 |
| 1103 void TaskManagerExtensionProcessResourceProvider::StopUpdating() { | 1104 void TaskManagerExtensionProcessResourceProvider::StopUpdating() { |
| 1104 DCHECK(updating_); | 1105 DCHECK(updating_); |
| 1105 updating_ = false; | 1106 updating_ = false; |
| 1106 | 1107 |
| 1107 // Unregister for notifications about extension process changes. | 1108 // Unregister for notifications about extension process changes. |
| 1108 registrar_.Remove(this, NotificationType::EXTENSION_PROCESS_CREATED, | 1109 registrar_.Remove(this, chrome::EXTENSION_PROCESS_CREATED, |
| 1109 NotificationService::AllSources()); | 1110 NotificationService::AllSources()); |
| 1110 registrar_.Remove(this, NotificationType::EXTENSION_PROCESS_TERMINATED, | 1111 registrar_.Remove(this, chrome::EXTENSION_PROCESS_TERMINATED, |
| 1111 NotificationService::AllSources()); | 1112 NotificationService::AllSources()); |
| 1112 registrar_.Remove(this, NotificationType::EXTENSION_HOST_DESTROYED, | 1113 registrar_.Remove(this, chrome::EXTENSION_HOST_DESTROYED, |
| 1113 NotificationService::AllSources()); | 1114 NotificationService::AllSources()); |
| 1114 | 1115 |
| 1115 // Delete all the resources. | 1116 // Delete all the resources. |
| 1116 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 1117 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 1117 | 1118 |
| 1118 resources_.clear(); | 1119 resources_.clear(); |
| 1119 pid_to_resources_.clear(); | 1120 pid_to_resources_.clear(); |
| 1120 } | 1121 } |
| 1121 | 1122 |
| 1122 void TaskManagerExtensionProcessResourceProvider::Observe( | 1123 void TaskManagerExtensionProcessResourceProvider::Observe( |
| 1123 NotificationType type, | 1124 NotificationType type, |
| 1124 const NotificationSource& source, | 1125 const NotificationSource& source, |
| 1125 const NotificationDetails& details) { | 1126 const NotificationDetails& details) { |
| 1126 switch (type.value) { | 1127 switch (type.value) { |
| 1127 case NotificationType::EXTENSION_PROCESS_CREATED: | 1128 case chrome::EXTENSION_PROCESS_CREATED: |
| 1128 AddToTaskManager(Details<ExtensionHost>(details).ptr()); | 1129 AddToTaskManager(Details<ExtensionHost>(details).ptr()); |
| 1129 break; | 1130 break; |
| 1130 case NotificationType::EXTENSION_PROCESS_TERMINATED: | 1131 case chrome::EXTENSION_PROCESS_TERMINATED: |
| 1131 case NotificationType::EXTENSION_HOST_DESTROYED: | 1132 case chrome::EXTENSION_HOST_DESTROYED: |
| 1132 RemoveFromTaskManager(Details<ExtensionHost>(details).ptr()); | 1133 RemoveFromTaskManager(Details<ExtensionHost>(details).ptr()); |
| 1133 break; | 1134 break; |
| 1134 default: | 1135 default: |
| 1135 NOTREACHED() << "Unexpected notification."; | 1136 NOTREACHED() << "Unexpected notification."; |
| 1136 return; | 1137 return; |
| 1137 } | 1138 } |
| 1138 } | 1139 } |
| 1139 | 1140 |
| 1140 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( | 1141 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( |
| 1141 ExtensionHost* extension_host) { | 1142 ExtensionHost* extension_host) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 | 1307 |
| 1307 return &resource_; | 1308 return &resource_; |
| 1308 } | 1309 } |
| 1309 | 1310 |
| 1310 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1311 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
| 1311 task_manager_->AddResource(&resource_); | 1312 task_manager_->AddResource(&resource_); |
| 1312 } | 1313 } |
| 1313 | 1314 |
| 1314 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1315 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
| 1315 } | 1316 } |
| OLD | NEW |