| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // performed. | 376 // performed. |
| 377 return NULL; | 377 return NULL; |
| 378 } | 378 } |
| 379 return res_iter->second; | 379 return res_iter->second; |
| 380 } | 380 } |
| 381 | 381 |
| 382 void TaskManagerTabContentsResourceProvider::StartUpdating() { | 382 void TaskManagerTabContentsResourceProvider::StartUpdating() { |
| 383 DCHECK(!updating_); | 383 DCHECK(!updating_); |
| 384 updating_ = true; | 384 updating_ = true; |
| 385 | 385 |
| 386 // Add all the existing TabContents. | 386 // Add all the existing TabContentsWrappers. |
| 387 for (TabContentsIterator iterator; !iterator.done(); ++iterator) | 387 for (TabContentsIterator iterator; !iterator.done(); ++iterator) |
| 388 Add(*iterator); | 388 Add(*iterator); |
| 389 | 389 |
| 390 // Then we register for notifications to get new tabs. | 390 // Then we register for notifications to get new tabs. |
| 391 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 391 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 392 content::NotificationService::AllBrowserContextsAndSources()); | 392 content::NotificationService::AllBrowserContextsAndSources()); |
| 393 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 393 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 394 content::NotificationService::AllBrowserContextsAndSources()); | 394 content::NotificationService::AllBrowserContextsAndSources()); |
| 395 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 395 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 396 content::NotificationService::AllBrowserContextsAndSources()); | 396 content::NotificationService::AllBrowserContextsAndSources()); |
| 397 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a | 397 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a |
| 398 // resource. This is an attempt at mitigating a crasher that seem to | 398 // resource. This is an attempt at mitigating a crasher that seem to |
| 399 // indicate a resource is still referencing a deleted TabContents | 399 // indicate a resource is still referencing a deleted WebContents |
| 400 // (http://crbug.com/7321). | 400 // (http://crbug.com/7321). |
| 401 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 401 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 402 content::NotificationService::AllBrowserContextsAndSources()); | 402 content::NotificationService::AllBrowserContextsAndSources()); |
| 403 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 403 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
| 404 content::NotificationService::AllBrowserContextsAndSources()); | 404 content::NotificationService::AllBrowserContextsAndSources()); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void TaskManagerTabContentsResourceProvider::StopUpdating() { | 407 void TaskManagerTabContentsResourceProvider::StopUpdating() { |
| 408 DCHECK(updating_); | 408 DCHECK(updating_); |
| 409 updating_ = false; | 409 updating_ = false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 446 |
| 447 // Don't add dead tabs or tabs that haven't yet connected. | 447 // Don't add dead tabs or tabs that haven't yet connected. |
| 448 if (!tab_contents->web_contents()->GetRenderProcessHost()->GetHandle() || | 448 if (!tab_contents->web_contents()->GetRenderProcessHost()->GetHandle() || |
| 449 !tab_contents->web_contents()->WillNotifyDisconnection()) { | 449 !tab_contents->web_contents()->WillNotifyDisconnection()) { |
| 450 return; | 450 return; |
| 451 } | 451 } |
| 452 | 452 |
| 453 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::const_iterator | 453 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::const_iterator |
| 454 iter = resources_.find(tab_contents); | 454 iter = resources_.find(tab_contents); |
| 455 if (iter != resources_.end()) { | 455 if (iter != resources_.end()) { |
| 456 // The case may happen that we have added a TabContents as part of the | 456 // The case may happen that we have added a WebContents as part of the |
| 457 // iteration performed during StartUpdating() call but the notification that | 457 // iteration performed during StartUpdating() call but the notification that |
| 458 // it has connected was not fired yet. So when the notification happens, we | 458 // it has connected was not fired yet. So when the notification happens, we |
| 459 // already know about this tab and just ignore it. | 459 // already know about this tab and just ignore it. |
| 460 return; | 460 return; |
| 461 } | 461 } |
| 462 AddToTaskManager(tab_contents); | 462 AddToTaskManager(tab_contents); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void TaskManagerTabContentsResourceProvider::Remove( | 465 void TaskManagerTabContentsResourceProvider::Remove( |
| 466 TabContentsWrapper* tab_contents) { | 466 TabContentsWrapper* tab_contents) { |
| 467 if (!updating_) | 467 if (!updating_) |
| 468 return; | 468 return; |
| 469 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator | 469 std::map<TabContentsWrapper*, TaskManagerTabContentsResource*>::iterator |
| 470 iter = resources_.find(tab_contents); | 470 iter = resources_.find(tab_contents); |
| 471 if (iter == resources_.end()) { | 471 if (iter == resources_.end()) { |
| 472 // Since TabContents are destroyed asynchronously (see TabContentsCollector | 472 // Since WebContents are destroyed asynchronously (see TabContentsCollector |
| 473 // in navigation_controller.cc), we can be notified of a tab being removed | 473 // in navigation_controller.cc), we can be notified of a tab being removed |
| 474 // that we don't know. This can happen if the user closes a tab and quickly | 474 // that we don't know. This can happen if the user closes a tab and quickly |
| 475 // opens the task manager, before the tab is actually destroyed. | 475 // opens the task manager, before the tab is actually destroyed. |
| 476 return; | 476 return; |
| 477 } | 477 } |
| 478 | 478 |
| 479 // Remove the resource from the Task Manager. | 479 // Remove the resource from the Task Manager. |
| 480 TaskManagerTabContentsResource* resource = iter->second; | 480 TaskManagerTabContentsResource* resource = iter->second; |
| 481 task_manager_->RemoveResource(resource); | 481 task_manager_->RemoveResource(resource); |
| 482 // And from the provider. | 482 // And from the provider. |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 | 1462 |
| 1463 return &resource_; | 1463 return &resource_; |
| 1464 } | 1464 } |
| 1465 | 1465 |
| 1466 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1466 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
| 1467 task_manager_->AddResource(&resource_); | 1467 task_manager_->AddResource(&resource_); |
| 1468 } | 1468 } |
| 1469 | 1469 |
| 1470 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1470 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
| 1471 } | 1471 } |
| OLD | NEW |