| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/common/extensions/extension.h" | 37 #include "chrome/common/extensions/extension.h" |
| 38 #include "chrome/common/render_messages.h" | 38 #include "chrome/common/render_messages.h" |
| 39 #include "chrome/common/chrome_view_types.h" | 39 #include "chrome/common/chrome_view_types.h" |
| 40 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 41 #include "content/browser/browser_child_process_host.h" | 41 #include "content/browser/browser_child_process_host.h" |
| 42 #include "content/browser/browser_thread.h" | 42 #include "content/browser/browser_thread.h" |
| 43 #include "content/browser/renderer_host/render_message_filter.h" | 43 #include "content/browser/renderer_host/render_message_filter.h" |
| 44 #include "content/browser/renderer_host/render_process_host.h" | 44 #include "content/browser/renderer_host/render_process_host.h" |
| 45 #include "content/browser/renderer_host/render_view_host.h" | 45 #include "content/browser/renderer_host/render_view_host.h" |
| 46 #include "content/browser/tab_contents/tab_contents.h" | 46 #include "content/browser/tab_contents/tab_contents.h" |
| 47 #include "content/common/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 48 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
| 49 #include "grit/theme_resources.h" | 49 #include "grit/theme_resources.h" |
| 50 #include "grit/theme_resources_standard.h" | 50 #include "grit/theme_resources_standard.h" |
| 51 #include "third_party/sqlite/sqlite3.h" | 51 #include "third_party/sqlite/sqlite3.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "ui/base/resource/resource_bundle.h" | 53 #include "ui/base/resource/resource_bundle.h" |
| 54 #include "v8/include/v8.h" | 54 #include "v8/include/v8.h" |
| 55 | 55 |
| 56 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
| 57 #include "skia/ext/skia_utils_mac.h" | 57 #include "skia/ext/skia_utils_mac.h" |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 void TaskManagerTabContentsResourceProvider::StartUpdating() { | 347 void TaskManagerTabContentsResourceProvider::StartUpdating() { |
| 348 DCHECK(!updating_); | 348 DCHECK(!updating_); |
| 349 updating_ = true; | 349 updating_ = true; |
| 350 | 350 |
| 351 // Add all the existing TabContents. | 351 // Add all the existing TabContents. |
| 352 for (TabContentsIterator iterator; !iterator.done(); ++iterator) | 352 for (TabContentsIterator iterator; !iterator.done(); ++iterator) |
| 353 Add(*iterator); | 353 Add(*iterator); |
| 354 | 354 |
| 355 // Then we register for notifications to get new tabs. | 355 // Then we register for notifications to get new tabs. |
| 356 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 356 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
| 357 NotificationService::AllBrowserContextsAndSources()); | 357 content::NotificationService::AllBrowserContextsAndSources()); |
| 358 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 358 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
| 359 NotificationService::AllBrowserContextsAndSources()); | 359 content::NotificationService::AllBrowserContextsAndSources()); |
| 360 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 360 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
| 361 NotificationService::AllBrowserContextsAndSources()); | 361 content::NotificationService::AllBrowserContextsAndSources()); |
| 362 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a | 362 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a |
| 363 // resource. This is an attempt at mitigating a crasher that seem to | 363 // resource. This is an attempt at mitigating a crasher that seem to |
| 364 // indicate a resource is still referencing a deleted TabContents | 364 // indicate a resource is still referencing a deleted TabContents |
| 365 // (http://crbug.com/7321). | 365 // (http://crbug.com/7321). |
| 366 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 366 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 367 NotificationService::AllBrowserContextsAndSources()); | 367 content::NotificationService::AllBrowserContextsAndSources()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void TaskManagerTabContentsResourceProvider::StopUpdating() { | 370 void TaskManagerTabContentsResourceProvider::StopUpdating() { |
| 371 DCHECK(updating_); | 371 DCHECK(updating_); |
| 372 updating_ = false; | 372 updating_ = false; |
| 373 | 373 |
| 374 // Then we unregister for notifications to get new tabs. | 374 // Then we unregister for notifications to get new tabs. |
| 375 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 375 registrar_.Remove( |
| 376 NotificationService::AllBrowserContextsAndSources()); | 376 this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
| 377 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 377 content::NotificationService::AllBrowserContextsAndSources()); |
| 378 NotificationService::AllBrowserContextsAndSources()); | 378 registrar_.Remove( |
| 379 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 379 this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, |
| 380 NotificationService::AllBrowserContextsAndSources()); | 380 content::NotificationService::AllBrowserContextsAndSources()); |
| 381 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 381 registrar_.Remove( |
| 382 NotificationService::AllBrowserContextsAndSources()); | 382 this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
| 383 content::NotificationService::AllBrowserContextsAndSources()); |
| 384 registrar_.Remove( |
| 385 this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 386 content::NotificationService::AllBrowserContextsAndSources()); |
| 383 | 387 |
| 384 // Delete all the resources. | 388 // Delete all the resources. |
| 385 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 389 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 386 | 390 |
| 387 resources_.clear(); | 391 resources_.clear(); |
| 388 } | 392 } |
| 389 | 393 |
| 390 void TaskManagerTabContentsResourceProvider::AddToTaskManager( | 394 void TaskManagerTabContentsResourceProvider::AddToTaskManager( |
| 391 TabContentsWrapper* tab_contents) { | 395 TabContentsWrapper* tab_contents) { |
| 392 TaskManagerTabContentsResource* resource = | 396 TaskManagerTabContentsResource* resource = |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 UTF16ToUTF8(application_id), false); | 601 UTF16ToUTF8(application_id), false); |
| 598 if (extension) | 602 if (extension) |
| 599 application_name = UTF8ToUTF16(extension->name()); | 603 application_name = UTF8ToUTF16(extension->name()); |
| 600 } | 604 } |
| 601 Add(*iterator, application_name); | 605 Add(*iterator, application_name); |
| 602 } | 606 } |
| 603 } | 607 } |
| 604 | 608 |
| 605 // Then we register for notifications to get new BackgroundContents. | 609 // Then we register for notifications to get new BackgroundContents. |
| 606 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED, | 610 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED, |
| 607 NotificationService::AllBrowserContextsAndSources()); | 611 content::NotificationService::AllBrowserContextsAndSources()); |
| 608 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | 612 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 609 NotificationService::AllBrowserContextsAndSources()); | 613 content::NotificationService::AllBrowserContextsAndSources()); |
| 610 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 614 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 611 NotificationService::AllBrowserContextsAndSources()); | 615 content::NotificationService::AllBrowserContextsAndSources()); |
| 612 } | 616 } |
| 613 | 617 |
| 614 void TaskManagerBackgroundContentsResourceProvider::StopUpdating() { | 618 void TaskManagerBackgroundContentsResourceProvider::StopUpdating() { |
| 615 DCHECK(updating_); | 619 DCHECK(updating_); |
| 616 updating_ = false; | 620 updating_ = false; |
| 617 | 621 |
| 618 // Unregister for notifications | 622 // Unregister for notifications |
| 619 registrar_.Remove(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED, | 623 registrar_.Remove( |
| 620 NotificationService::AllBrowserContextsAndSources()); | 624 this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED, |
| 621 registrar_.Remove(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | 625 content::NotificationService::AllBrowserContextsAndSources()); |
| 622 NotificationService::AllBrowserContextsAndSources()); | 626 registrar_.Remove( |
| 623 registrar_.Remove(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 627 this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 624 NotificationService::AllBrowserContextsAndSources()); | 628 content::NotificationService::AllBrowserContextsAndSources()); |
| 629 registrar_.Remove( |
| 630 this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
| 631 content::NotificationService::AllBrowserContextsAndSources()); |
| 625 | 632 |
| 626 // Delete all the resources. | 633 // Delete all the resources. |
| 627 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 634 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 628 | 635 |
| 629 resources_.clear(); | 636 resources_.clear(); |
| 630 } | 637 } |
| 631 | 638 |
| 632 void TaskManagerBackgroundContentsResourceProvider::AddToTaskManager( | 639 void TaskManagerBackgroundContentsResourceProvider::AddToTaskManager( |
| 633 BackgroundContents* background_contents, | 640 BackgroundContents* background_contents, |
| 634 const string16& application_name) { | 641 const string16& application_name) { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 else | 905 else |
| 899 return NULL; | 906 return NULL; |
| 900 } | 907 } |
| 901 | 908 |
| 902 void TaskManagerChildProcessResourceProvider::StartUpdating() { | 909 void TaskManagerChildProcessResourceProvider::StartUpdating() { |
| 903 DCHECK(!updating_); | 910 DCHECK(!updating_); |
| 904 updating_ = true; | 911 updating_ = true; |
| 905 | 912 |
| 906 // Register for notifications to get new child processes. | 913 // Register for notifications to get new child processes. |
| 907 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, | 914 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, |
| 908 NotificationService::AllBrowserContextsAndSources()); | 915 content::NotificationService::AllBrowserContextsAndSources()); |
| 909 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, | 916 registrar_.Add(this, content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, |
| 910 NotificationService::AllBrowserContextsAndSources()); | 917 content::NotificationService::AllBrowserContextsAndSources()); |
| 911 | 918 |
| 912 // Get the existing child processes. | 919 // Get the existing child processes. |
| 913 BrowserThread::PostTask( | 920 BrowserThread::PostTask( |
| 914 BrowserThread::IO, FROM_HERE, | 921 BrowserThread::IO, FROM_HERE, |
| 915 NewRunnableMethod( | 922 NewRunnableMethod( |
| 916 this, | 923 this, |
| 917 &TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo)); | 924 &TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo)); |
| 918 } | 925 } |
| 919 | 926 |
| 920 void TaskManagerChildProcessResourceProvider::StopUpdating() { | 927 void TaskManagerChildProcessResourceProvider::StopUpdating() { |
| 921 DCHECK(updating_); | 928 DCHECK(updating_); |
| 922 updating_ = false; | 929 updating_ = false; |
| 923 | 930 |
| 924 // Unregister for notifications to get new plugin processes. | 931 // Unregister for notifications to get new plugin processes. |
| 925 registrar_.Remove(this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, | 932 registrar_.Remove( |
| 926 NotificationService::AllBrowserContextsAndSources()); | 933 this, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, |
| 927 registrar_.Remove(this, | 934 content::NotificationService::AllBrowserContextsAndSources()); |
| 928 content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, | 935 registrar_.Remove( |
| 929 NotificationService::AllBrowserContextsAndSources()); | 936 this, |
| 937 content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED, |
| 938 content::NotificationService::AllBrowserContextsAndSources()); |
| 930 | 939 |
| 931 // Delete all the resources. | 940 // Delete all the resources. |
| 932 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 941 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 933 | 942 |
| 934 resources_.clear(); | 943 resources_.clear(); |
| 935 pid_to_resources_.clear(); | 944 pid_to_resources_.clear(); |
| 936 existing_child_process_info_.clear(); | 945 existing_child_process_info_.clear(); |
| 937 } | 946 } |
| 938 | 947 |
| 939 void TaskManagerChildProcessResourceProvider::Observe( | 948 void TaskManagerChildProcessResourceProvider::Observe( |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 if (process_manager) { | 1161 if (process_manager) { |
| 1153 ExtensionProcessManager::const_iterator jt; | 1162 ExtensionProcessManager::const_iterator jt; |
| 1154 for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) | 1163 for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) |
| 1155 AddToTaskManager(*jt); | 1164 AddToTaskManager(*jt); |
| 1156 } | 1165 } |
| 1157 } | 1166 } |
| 1158 } | 1167 } |
| 1159 | 1168 |
| 1160 // Register for notifications about extension process changes. | 1169 // Register for notifications about extension process changes. |
| 1161 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, | 1170 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, |
| 1162 NotificationService::AllBrowserContextsAndSources()); | 1171 content::NotificationService::AllBrowserContextsAndSources()); |
| 1163 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 1172 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 1164 NotificationService::AllBrowserContextsAndSources()); | 1173 content::NotificationService::AllBrowserContextsAndSources()); |
| 1165 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 1174 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 1166 NotificationService::AllBrowserContextsAndSources()); | 1175 content::NotificationService::AllBrowserContextsAndSources()); |
| 1167 } | 1176 } |
| 1168 | 1177 |
| 1169 void TaskManagerExtensionProcessResourceProvider::StopUpdating() { | 1178 void TaskManagerExtensionProcessResourceProvider::StopUpdating() { |
| 1170 DCHECK(updating_); | 1179 DCHECK(updating_); |
| 1171 updating_ = false; | 1180 updating_ = false; |
| 1172 | 1181 |
| 1173 // Unregister for notifications about extension process changes. | 1182 // Unregister for notifications about extension process changes. |
| 1174 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, | 1183 registrar_.Remove( |
| 1175 NotificationService::AllBrowserContextsAndSources()); | 1184 this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, |
| 1176 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 1185 content::NotificationService::AllBrowserContextsAndSources()); |
| 1177 NotificationService::AllBrowserContextsAndSources()); | 1186 registrar_.Remove( |
| 1178 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 1187 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| 1179 NotificationService::AllBrowserContextsAndSources()); | 1188 content::NotificationService::AllBrowserContextsAndSources()); |
| 1189 registrar_.Remove( |
| 1190 this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 1191 content::NotificationService::AllBrowserContextsAndSources()); |
| 1180 | 1192 |
| 1181 // Delete all the resources. | 1193 // Delete all the resources. |
| 1182 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | 1194 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); |
| 1183 | 1195 |
| 1184 resources_.clear(); | 1196 resources_.clear(); |
| 1185 pid_to_resources_.clear(); | 1197 pid_to_resources_.clear(); |
| 1186 } | 1198 } |
| 1187 | 1199 |
| 1188 void TaskManagerExtensionProcessResourceProvider::Observe( | 1200 void TaskManagerExtensionProcessResourceProvider::Observe( |
| 1189 int type, | 1201 int type, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 | 1381 |
| 1370 return &resource_; | 1382 return &resource_; |
| 1371 } | 1383 } |
| 1372 | 1384 |
| 1373 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1385 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
| 1374 task_manager_->AddResource(&resource_); | 1386 task_manager_->AddResource(&resource_); |
| 1375 } | 1387 } |
| 1376 | 1388 |
| 1377 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1389 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
| 1378 } | 1390 } |
| OLD | NEW |