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/performance_monitor/performance_monitor.h" | 5 #include "chrome/browser/performance_monitor/performance_monitor.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/chrome_version_info.h" | 29 #include "chrome/common/chrome_version_info.h" |
30 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
31 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
32 #include "chrome/test/base/chrome_process_util.h" | 32 #include "chrome/test/base/chrome_process_util.h" |
33 #include "content/public/browser/browser_child_process_host.h" | 33 #include "content/public/browser/browser_child_process_host.h" |
34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/load_notification_details.h" | 35 #include "content/public/browser/load_notification_details.h" |
36 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/notification_types.h" | 37 #include "content/public/browser/notification_types.h" |
38 #include "content/public/browser/render_widget_host.h" | |
39 #include "content/public/browser/render_view_host.h" | |
38 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
39 #include "net/url_request/url_request.h" | 41 #include "net/url_request/url_request.h" |
40 | 42 |
41 using content::BrowserThread; | 43 using content::BrowserThread; |
42 using extensions::Extension; | 44 using extensions::Extension; |
43 | 45 |
44 namespace { | 46 namespace { |
45 const uint32 kAccessFlags = base::kProcessAccessDuplicateHandle | | 47 const uint32 kAccessFlags = base::kProcessAccessDuplicateHandle | |
46 base::kProcessAccessQueryInformation | | 48 base::kProcessAccessQueryInformation | |
47 base::kProcessAccessTerminate | | 49 base::kProcessAccessTerminate | |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 content::Details<Extension>(details).ptr()); | 486 content::Details<Extension>(details).ptr()); |
485 } | 487 } |
486 break; | 488 break; |
487 } | 489 } |
488 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 490 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
489 AddExtensionEvent(EVENT_EXTENSION_UNINSTALL, | 491 AddExtensionEvent(EVENT_EXTENSION_UNINSTALL, |
490 content::Details<Extension>(details).ptr()); | 492 content::Details<Extension>(details).ptr()); |
491 break; | 493 break; |
492 } | 494 } |
493 case content::NOTIFICATION_RENDERER_PROCESS_HANG: { | 495 case content::NOTIFICATION_RENDERER_PROCESS_HANG: { |
494 content::WebContents* contents = | 496 std::string url; |
495 content::Source<content::WebContents>(source).ptr(); | 497 content::RenderWidgetHost* widget = |
496 AddEvent(util::CreateRendererFreezeEvent(base::Time::Now(), | 498 content::Source<content::RenderWidgetHost>(source).ptr(); |
497 contents->GetURL().spec())); | 499 if (widget->IsRenderView()) { |
500 url = content::WebContents::FromRenderViewHost( | |
501 content::RenderViewHost::From(widget))->GetURL().spec(); | |
502 } | |
503 AddEvent(util::CreateRendererFailureEvent(base::Time::Now(), | |
504 EVENT_RENDERER_HANG, | |
505 url)); | |
498 break; | 506 break; |
499 } | 507 } |
500 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 508 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
501 AddCrashEvent(*content::Details< | 509 AddRendererClosedEvent( |
502 content::RenderProcessHost::RendererClosedDetails>(details).ptr()); | 510 content::Source<content::RenderProcessHost>(source).ptr(), |
511 *content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
512 details).ptr()); | |
503 break; | 513 break; |
504 } | 514 } |
505 case chrome::NOTIFICATION_PROFILE_ADDED: { | 515 case chrome::NOTIFICATION_PROFILE_ADDED: { |
506 Profile* profile = content::Source<Profile>(source).ptr(); | 516 Profile* profile = content::Source<Profile>(source).ptr(); |
507 if (!profile->DidLastSessionExitCleanly()) { | 517 if (!profile->DidLastSessionExitCleanly()) { |
508 BrowserThread::PostBlockingPoolSequencedTask( | 518 BrowserThread::PostBlockingPoolSequencedTask( |
509 Database::kDatabaseSequenceToken, | 519 Database::kDatabaseSequenceToken, |
510 FROM_HERE, | 520 FROM_HERE, |
511 base::Bind( | 521 base::Bind( |
512 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread, | 522 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 AddEvent(util::CreateExtensionEvent(type, | 559 AddEvent(util::CreateExtensionEvent(type, |
550 base::Time::Now(), | 560 base::Time::Now(), |
551 extension->id(), | 561 extension->id(), |
552 extension->name(), | 562 extension->name(), |
553 extension->url().spec(), | 563 extension->url().spec(), |
554 extension->location(), | 564 extension->location(), |
555 extension->VersionString(), | 565 extension->VersionString(), |
556 extension->description())); | 566 extension->description())); |
557 } | 567 } |
558 | 568 |
559 void PerformanceMonitor::AddCrashEvent( | 569 void PerformanceMonitor::AddRendererClosedEvent( |
570 content::RenderProcessHost* host, | |
560 const content::RenderProcessHost::RendererClosedDetails& details) { | 571 const content::RenderProcessHost::RendererClosedDetails& details) { |
561 // We only care if this is an invalid termination. | 572 // We only care if this is an invalid termination. |
562 if (details.status == base::TERMINATION_STATUS_NORMAL_TERMINATION || | 573 if (details.status == base::TERMINATION_STATUS_NORMAL_TERMINATION || |
563 details.status == base::TERMINATION_STATUS_STILL_RUNNING) | 574 details.status == base::TERMINATION_STATUS_STILL_RUNNING) |
564 return; | 575 return; |
565 | 576 |
566 // Determine the type of crash. | 577 // Determine the type of crash. |
567 EventType type = | 578 EventType type = |
568 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? | 579 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? |
569 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; | 580 EVENT_RENDERER_KILLED : EVENT_RENDERER_CRASH; |
570 | 581 |
571 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); | 582 content::RenderProcessHost::RenderWidgetHostsIterator iter = |
583 host->GetRenderWidgetHostsIterator(); | |
584 | |
585 // A RenderProcessHost may contain multiple render views - for each valid | |
586 // render view, extract the url, and append it to the string, comma-separating | |
587 // the entries. | |
588 std::string url; | |
589 for (; !iter.IsAtEnd(); iter.Advance()) { | |
590 const content::RenderWidgetHost* widget = iter.GetCurrentValue(); | |
591 DCHECK(widget); | |
592 if (!widget || !widget->IsRenderView()) | |
593 continue; | |
594 | |
595 content::RenderViewHost* view = | |
596 content::RenderViewHost::From( | |
597 const_cast<content::RenderWidgetHost*>(widget)); | |
598 | |
599 if (url.size()) | |
Yoyo Zhou
2012/09/29 01:19:25
I think !url.empty() is better.
Devlin
2012/10/02 23:34:32
Done.
| |
600 url += ", "; | |
601 | |
602 url += content::WebContents::FromRenderViewHost(view)->GetURL().spec(); | |
603 } | |
604 | |
605 AddEvent(util::CreateRendererFailureEvent(base::Time::Now(), type, url)); | |
572 } | 606 } |
573 | 607 |
574 } // namespace performance_monitor | 608 } // namespace performance_monitor |
OLD | NEW |