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/bind.h" | 10 #include "base/bind.h" |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 DCHECK(!updating_); | 381 DCHECK(!updating_); |
382 updating_ = true; | 382 updating_ = true; |
383 | 383 |
384 // Add all the existing TabContents. | 384 // Add all the existing TabContents. |
385 for (TabContentsIterator iterator; !iterator.done(); ++iterator) | 385 for (TabContentsIterator iterator; !iterator.done(); ++iterator) |
386 Add(*iterator); | 386 Add(*iterator); |
387 | 387 |
388 // Then we register for notifications to get new tabs. | 388 // Then we register for notifications to get new tabs. |
389 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 389 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
390 content::NotificationService::AllBrowserContextsAndSources()); | 390 content::NotificationService::AllBrowserContextsAndSources()); |
391 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 391 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
392 content::NotificationService::AllBrowserContextsAndSources()); | 392 content::NotificationService::AllBrowserContextsAndSources()); |
393 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 393 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
394 content::NotificationService::AllBrowserContextsAndSources()); | 394 content::NotificationService::AllBrowserContextsAndSources()); |
395 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a | 395 // TAB_CONTENTS_DISCONNECTED should be enough to know when to remove a |
396 // resource. This is an attempt at mitigating a crasher that seem to | 396 // resource. This is an attempt at mitigating a crasher that seem to |
397 // indicate a resource is still referencing a deleted TabContents | 397 // indicate a resource is still referencing a deleted TabContents |
398 // (http://crbug.com/7321). | 398 // (http://crbug.com/7321). |
399 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 399 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
400 content::NotificationService::AllBrowserContextsAndSources()); | 400 content::NotificationService::AllBrowserContextsAndSources()); |
401 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 401 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
402 content::NotificationService::AllBrowserContextsAndSources()); | 402 content::NotificationService::AllBrowserContextsAndSources()); |
403 } | 403 } |
404 | 404 |
405 void TaskManagerTabContentsResourceProvider::StopUpdating() { | 405 void TaskManagerTabContentsResourceProvider::StopUpdating() { |
406 DCHECK(updating_); | 406 DCHECK(updating_); |
407 updating_ = false; | 407 updating_ = false; |
408 | 408 |
409 // Then we unregister for notifications to get new tabs. | 409 // Then we unregister for notifications to get new tabs. |
410 registrar_.Remove( | 410 registrar_.Remove( |
411 this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 411 this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
412 content::NotificationService::AllBrowserContextsAndSources()); | 412 content::NotificationService::AllBrowserContextsAndSources()); |
413 registrar_.Remove( | 413 registrar_.Remove( |
414 this, content::NOTIFICATION_TAB_CONTENTS_SWAPPED, | 414 this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
415 content::NotificationService::AllBrowserContextsAndSources()); | 415 content::NotificationService::AllBrowserContextsAndSources()); |
416 registrar_.Remove( | 416 registrar_.Remove( |
417 this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 417 this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
418 content::NotificationService::AllBrowserContextsAndSources()); | 418 content::NotificationService::AllBrowserContextsAndSources()); |
419 registrar_.Remove( | 419 registrar_.Remove( |
420 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 420 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
421 content::NotificationService::AllBrowserContextsAndSources()); | 421 content::NotificationService::AllBrowserContextsAndSources()); |
422 registrar_.Remove( | 422 registrar_.Remove( |
423 this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 423 this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
424 content::NotificationService::AllBrowserContextsAndSources()); | 424 content::NotificationService::AllBrowserContextsAndSources()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 if (iter != resources_.end()) | 493 if (iter != resources_.end()) |
494 iter->second->InstantCommitted(); | 494 iter->second->InstantCommitted(); |
495 } | 495 } |
496 | 496 |
497 void TaskManagerTabContentsResourceProvider::Observe(int type, | 497 void TaskManagerTabContentsResourceProvider::Observe(int type, |
498 const content::NotificationSource& source, | 498 const content::NotificationSource& source, |
499 const content::NotificationDetails& details) { | 499 const content::NotificationDetails& details) { |
500 TabContentsWrapper* tab_contents; | 500 TabContentsWrapper* tab_contents; |
501 if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) { | 501 if (type == chrome::NOTIFICATION_INSTANT_COMMITTED) { |
502 tab_contents = content::Source<TabContentsWrapper>(source).ptr(); | 502 tab_contents = content::Source<TabContentsWrapper>(source).ptr(); |
503 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 503 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED || |
| 504 type == content::NOTIFICATION_WEB_CONTENTS_SWAPPED) { |
504 WebContents* web_contents = content::Source<WebContents>(source).ptr(); | 505 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
505 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents( | 506 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents( |
506 web_contents); | 507 web_contents); |
507 } else { | 508 } else { |
508 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents( | 509 tab_contents = TabContentsWrapper::GetCurrentWrapperForContents( |
509 content::Source<TabContents>(source).ptr()); | 510 content::Source<TabContents>(source).ptr()); |
510 } | 511 } |
511 // A background page does not have a TabContentsWrapper. | 512 // A background page does not have a TabContentsWrapper. |
512 if (!tab_contents) | 513 if (!tab_contents) |
513 return; | 514 return; |
514 switch (type) { | 515 switch (type) { |
515 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: | 516 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: |
516 Add(tab_contents); | 517 Add(tab_contents); |
517 break; | 518 break; |
518 case content::NOTIFICATION_TAB_CONTENTS_SWAPPED: | 519 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: |
519 Remove(tab_contents); | 520 Remove(tab_contents); |
520 Add(tab_contents); | 521 Add(tab_contents); |
521 break; | 522 break; |
522 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: | 523 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: |
523 // If this DCHECK is triggered, it could explain http://crbug.com/7321 . | 524 // If this DCHECK is triggered, it could explain http://crbug.com/7321 . |
524 DCHECK(resources_.find(tab_contents) == | 525 DCHECK(resources_.find(tab_contents) == |
525 resources_.end()) << "TAB_CONTENTS_DESTROYED with no associated " | 526 resources_.end()) << "TAB_CONTENTS_DESTROYED with no associated " |
526 "TAB_CONTENTS_DISCONNECTED"; | 527 "TAB_CONTENTS_DISCONNECTED"; |
527 // Fall through. | 528 // Fall through. |
528 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: | 529 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 | 1446 |
1446 return &resource_; | 1447 return &resource_; |
1447 } | 1448 } |
1448 | 1449 |
1449 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1450 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
1450 task_manager_->AddResource(&resource_); | 1451 task_manager_->AddResource(&resource_); |
1451 } | 1452 } |
1452 | 1453 |
1453 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1454 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
1454 } | 1455 } |
OLD | NEW |