| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
| 27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 28 #include "chrome/common/extensions/extension_constants.h" | 28 #include "chrome/common/extensions/extension_constants.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
| 32 #include "content/public/browser/render_process_host.h" | |
| 33 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 34 | 33 |
| 35 using content::BrowserThread; | 34 using content::BrowserThread; |
| 36 using extensions::Extension; | 35 using extensions::Extension; |
| 37 | 36 |
| 38 namespace { | 37 namespace { |
| 39 | 38 |
| 40 std::string TimeToString(base::Time time) { | 39 std::string TimeToString(base::Time time) { |
| 41 int64 time_int64 = time.ToInternalValue(); | 40 int64 time_int64 = time.ToInternalValue(); |
| 42 return base::Int64ToString(time_int64); | 41 return base::Int64ToString(time_int64); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 271 |
| 273 void PerformanceMonitor::DoTimedCollections() { | 272 void PerformanceMonitor::DoTimedCollections() { |
| 274 UpdateLiveProfiles(); | 273 UpdateLiveProfiles(); |
| 275 } | 274 } |
| 276 | 275 |
| 277 void PerformanceMonitor::Observe(int type, | 276 void PerformanceMonitor::Observe(int type, |
| 278 const content::NotificationSource& source, | 277 const content::NotificationSource& source, |
| 279 const content::NotificationDetails& details) { | 278 const content::NotificationDetails& details) { |
| 280 switch (type) { | 279 switch (type) { |
| 281 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | 280 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
| 282 const Extension* extension = content::Details<Extension>(details).ptr(); | 281 HandleExtensionEvent(EVENT_EXTENSION_INSTALL, |
| 283 AddEvent(util::CreateExtensionInstallEvent(base::Time::Now(), | 282 content::Details<Extension>(details).ptr()); |
| 284 extension->id(), | |
| 285 extension->name(), | |
| 286 extension->url().spec(), | |
| 287 extension->location(), | |
| 288 extension->VersionString(), | |
| 289 extension->description())); | |
| 290 break; | 283 break; |
| 291 } | 284 } |
| 292 case chrome::NOTIFICATION_EXTENSION_ENABLED: { | 285 case chrome::NOTIFICATION_EXTENSION_ENABLED: { |
| 293 const Extension* extension = content::Details<Extension>(details).ptr(); | 286 HandleExtensionEvent(EVENT_EXTENSION_ENABLE, |
| 294 AddEvent(util::CreateExtensionEnableEvent(base::Time::Now(), | 287 content::Details<Extension>(details).ptr()); |
| 295 extension->id(), | |
| 296 extension->name(), | |
| 297 extension->url().spec(), | |
| 298 extension->location(), | |
| 299 extension->VersionString(), | |
| 300 extension->description())); | |
| 301 break; | 288 break; |
| 302 } | 289 } |
| 303 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 290 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 304 const extensions::UnloadedExtensionInfo* info = | 291 const extensions::UnloadedExtensionInfo* info = |
| 305 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 292 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
| 306 const Extension* extension = info->extension; | 293 |
| 307 AddEvent(util::CreateExtensionUnloadEvent(base::Time::Now(), | 294 // Check if the extension was unloaded because it was disabled. |
| 308 extension->id(), | 295 if (info->reason == extension_misc::UNLOAD_REASON_DISABLE) { |
| 309 extension->name(), | 296 HandleExtensionEvent(EVENT_EXTENSION_DISABLE, |
| 310 extension->url().spec(), | 297 info->extension); |
| 311 extension->location(), | 298 } |
| 312 extension->VersionString(), | |
| 313 extension->description(), | |
| 314 info->reason)); | |
| 315 break; | 299 break; |
| 316 } | 300 } |
| 317 case chrome::NOTIFICATION_CRX_INSTALLER_DONE: { | 301 case chrome::NOTIFICATION_CRX_INSTALLER_DONE: { |
| 318 const extensions::CrxInstaller* installer = | 302 const extensions::CrxInstaller* installer = |
| 319 content::Source<extensions::CrxInstaller>(source).ptr(); | 303 content::Source<extensions::CrxInstaller>(source).ptr(); |
| 320 | 304 |
| 321 // Check if the reason for the install was due to an extension update. | 305 // Check if the reason for the install was due to an extension update. |
| 322 if (installer->install_cause() != extension_misc::INSTALL_CAUSE_UPDATE) | 306 if (installer->install_cause() == extension_misc::INSTALL_CAUSE_UPDATE) { |
| 323 break; | 307 HandleExtensionEvent(EVENT_EXTENSION_UPDATE, |
| 324 | 308 content::Details<Extension>(details).ptr()); |
| 325 const Extension* extension = content::Details<Extension>(details).ptr(); | 309 } |
| 326 AddEvent(util::CreateExtensionUpdateEvent(base::Time::Now(), | |
| 327 extension->id(), | |
| 328 extension->name(), | |
| 329 extension->url().spec(), | |
| 330 extension->location(), | |
| 331 extension->VersionString(), | |
| 332 extension->description())); | |
| 333 break; | 310 break; |
| 334 } | 311 } |
| 335 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 312 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 336 const Extension* extension = content::Details<Extension>(details).ptr(); | 313 HandleExtensionEvent(EVENT_EXTENSION_UNINSTALL, |
| 337 AddEvent(util::CreateExtensionUninstallEvent(base::Time::Now(), | 314 content::Details<Extension>(details).ptr()); |
| 338 extension->id(), | |
| 339 extension->name(), | |
| 340 extension->url().spec(), | |
| 341 extension->location(), | |
| 342 extension->VersionString(), | |
| 343 extension->description())); | |
| 344 break; | 315 break; |
| 345 } | 316 } |
| 346 case content::NOTIFICATION_RENDERER_PROCESS_HANG: { | 317 case content::NOTIFICATION_RENDERER_PROCESS_HANG: { |
| 347 content::WebContents* contents = | 318 content::WebContents* contents = |
| 348 content::Source<content::WebContents>(source).ptr(); | 319 content::Source<content::WebContents>(source).ptr(); |
| 349 AddEvent(util::CreateRendererFreezeEvent(base::Time::Now(), | 320 AddEvent(util::CreateRendererFreezeEvent(base::Time::Now(), |
| 350 contents->GetURL().spec())); | 321 contents->GetURL().spec())); |
| 351 break; | 322 break; |
| 352 } | 323 } |
| 353 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 324 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 354 content::RenderProcessHost::RendererClosedDetails closed_details = | 325 HandleCrashEvent(*content::Details< |
| 355 *content::Details<content::RenderProcessHost::RendererClosedDetails>( | 326 content::RenderProcessHost::RendererClosedDetails>(details).ptr()); |
| 356 details).ptr(); | |
| 357 | |
| 358 // We only care if this is an invalid termination. | |
| 359 if (closed_details.status == base::TERMINATION_STATUS_NORMAL_TERMINATION | |
| 360 || closed_details.status == base::TERMINATION_STATUS_STILL_RUNNING) | |
| 361 break; | |
| 362 | |
| 363 // Determine the type of crash. | |
| 364 EventType type = | |
| 365 closed_details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? | |
| 366 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; | |
| 367 | |
| 368 AddEvent(util::CreateCrashEvent(base::Time::Now(), | |
| 369 type)); | |
| 370 break; | 327 break; |
| 371 } | 328 } |
| 372 case chrome::NOTIFICATION_PROFILE_ADDED: { | 329 case chrome::NOTIFICATION_PROFILE_ADDED: { |
| 373 Profile* profile = content::Source<Profile>(source).ptr(); | 330 Profile* profile = content::Source<Profile>(source).ptr(); |
| 374 if (!profile->DidLastSessionExitCleanly()) { | 331 if (!profile->DidLastSessionExitCleanly()) { |
| 375 BrowserThread::PostBlockingPoolSequencedTask( | 332 BrowserThread::PostBlockingPoolSequencedTask( |
| 376 Database::kDatabaseSequenceToken, | 333 Database::kDatabaseSequenceToken, |
| 377 FROM_HERE, | 334 FROM_HERE, |
| 378 base::Bind( | 335 base::Bind( |
| 379 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread, | 336 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread, |
| 380 base::Unretained(this), | 337 base::Unretained(this), |
| 381 profile->GetDebugName())); | 338 profile->GetDebugName())); |
| 382 } | 339 } |
| 383 break; | 340 break; |
| 384 } | 341 } |
| 385 default: { | 342 default: { |
| 386 NOTREACHED(); | 343 NOTREACHED(); |
| 387 break; | 344 break; |
| 388 } | 345 } |
| 389 } | 346 } |
| 390 } | 347 } |
| 391 | 348 |
| 349 void PerformanceMonitor::HandleExtensionEvent(EventType type, |
| 350 const Extension* extension) { |
| 351 DCHECK(type == EVENT_EXTENSION_INSTALL || |
| 352 type == EVENT_EXTENSION_UNINSTALL || |
| 353 type == EVENT_EXTENSION_UPDATE || |
| 354 type == EVENT_EXTENSION_ENABLE || |
| 355 type == EVENT_EXTENSION_DISABLE); |
| 356 AddEvent(util::CreateExtensionEvent(type, |
| 357 base::Time::Now(), |
| 358 extension->id(), |
| 359 extension->name(), |
| 360 extension->url().spec(), |
| 361 extension->location(), |
| 362 extension->VersionString(), |
| 363 extension->description())); |
| 364 } |
| 365 |
| 366 void PerformanceMonitor::HandleCrashEvent( |
| 367 const content::RenderProcessHost::RendererClosedDetails& details) { |
| 368 // We only care if this is an invalid termination. |
| 369 if (details.status == base::TERMINATION_STATUS_NORMAL_TERMINATION || |
| 370 details.status == base::TERMINATION_STATUS_STILL_RUNNING) |
| 371 return; |
| 372 |
| 373 // Determine the type of crash. |
| 374 EventType type = |
| 375 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? |
| 376 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; |
| 377 |
| 378 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); |
| 379 } |
| 380 |
| 392 } // namespace performance_monitor | 381 } // namespace performance_monitor |
| OLD | NEW |