| 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/renderer/chrome_render_process_observer.h" | 5 #include "chrome/renderer/chrome_render_process_observer.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const std::string& mime_type, | 97 const std::string& mime_type, |
| 98 const GURL& url) { | 98 const GURL& url) { |
| 99 return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( | 99 return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( |
| 100 current_peer, RenderThread::current(), mime_type, url); | 100 current_peer, RenderThread::current(), mime_type, url); |
| 101 } | 101 } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 void InformHostOfCacheStats() { | 104 void InformHostOfCacheStats() { |
| 105 WebCache::UsageStats stats; | 105 WebCache::UsageStats stats; |
| 106 WebCache::getUsageStats(&stats); | 106 WebCache::getUsageStats(&stats); |
| 107 RenderThread::current()->Send(new ViewHostMsg_UpdatedCacheStats(stats)); | 107 RenderThread::current()->Send(new ChromeViewHostMsg_UpdatedCacheStats( |
| 108 stats)); |
| 108 } | 109 } |
| 109 | 110 |
| 110 ScopedRunnableMethodFactory<RendererResourceDelegate> method_factory_; | 111 ScopedRunnableMethodFactory<RendererResourceDelegate> method_factory_; |
| 111 | 112 |
| 112 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate); | 113 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate); |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 class RenderViewContentSettingsSetter : public RenderViewVisitor { | 116 class RenderViewContentSettingsSetter : public RenderViewVisitor { |
| 116 public: | 117 public: |
| 117 RenderViewContentSettingsSetter(const GURL& url, | 118 RenderViewContentSettingsSetter(const GURL& url, |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 media::InitializeMediaLibrary(media_path); | 399 media::InitializeMediaLibrary(media_path); |
| 399 } | 400 } |
| 400 | 401 |
| 401 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { | 402 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { |
| 402 } | 403 } |
| 403 | 404 |
| 404 bool ChromeRenderProcessObserver::OnControlMessageReceived( | 405 bool ChromeRenderProcessObserver::OnControlMessageReceived( |
| 405 const IPC::Message& message) { | 406 const IPC::Message& message) { |
| 406 bool handled = true; | 407 bool handled = true; |
| 407 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) | 408 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) |
| 408 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess) | 409 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetIsIncognitoProcess, |
| 409 IPC_MESSAGE_HANDLER(ViewMsg_SetDefaultContentSettings, | 410 OnSetIsIncognitoProcess) |
| 411 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetDefaultContentSettings, |
| 410 OnSetDefaultContentSettings) | 412 OnSetDefaultContentSettings) |
| 411 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL, | 413 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetContentSettingsForCurrentURL, |
| 412 OnSetContentSettingsForCurrentURL) | 414 OnSetContentSettingsForCurrentURL) |
| 413 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) | 415 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCacheCapacities, OnSetCacheCapacities) |
| 414 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache) | 416 IPC_MESSAGE_HANDLER(ChromeViewMsg_ClearCache, OnClearCache) |
| 415 IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) | 417 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) |
| 416 #if defined(USE_TCMALLOC) | 418 #if defined(USE_TCMALLOC) |
| 417 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc) | 419 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetRendererTcmalloc, |
| 418 IPC_MESSAGE_HANDLER(ViewMsg_SetTcmallocHeapProfiling, | 420 OnGetRendererTcmalloc) |
| 421 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetTcmallocHeapProfiling, |
| 419 OnSetTcmallocHeapProfiling) | 422 OnSetTcmallocHeapProfiling) |
| 420 IPC_MESSAGE_HANDLER(ViewMsg_WriteTcmallocHeapProfile, | 423 IPC_MESSAGE_HANDLER(ChromeViewMsg_WriteTcmallocHeapProfile, |
| 421 OnWriteTcmallocHeapProfile) | 424 OnWriteTcmallocHeapProfile) |
| 422 #endif | 425 #endif |
| 423 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) | 426 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetV8HeapStats, OnGetV8HeapStats) |
| 424 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) | 427 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetCacheResourceStats, |
| 425 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) | 428 OnGetCacheResourceStats) |
| 429 IPC_MESSAGE_HANDLER(ChromeViewMsg_PurgeMemory, OnPurgeMemory) |
| 426 IPC_MESSAGE_UNHANDLED(handled = false) | 430 IPC_MESSAGE_UNHANDLED(handled = false) |
| 427 IPC_END_MESSAGE_MAP() | 431 IPC_END_MESSAGE_MAP() |
| 428 return handled; | 432 return handled; |
| 429 } | 433 } |
| 430 | 434 |
| 431 void ChromeRenderProcessObserver::WebKitInitialized() { | 435 void ChromeRenderProcessObserver::WebKitInitialized() { |
| 432 WebRuntimeFeatures::enableMediaPlayer(media::IsMediaLibraryInitialized()); | 436 WebRuntimeFeatures::enableMediaPlayer(media::IsMediaLibraryInitialized()); |
| 433 } | 437 } |
| 434 | 438 |
| 435 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( | 439 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 456 min_dead_capacity, max_dead_capacity, capacity); | 460 min_dead_capacity, max_dead_capacity, capacity); |
| 457 } | 461 } |
| 458 | 462 |
| 459 void ChromeRenderProcessObserver::OnClearCache() { | 463 void ChromeRenderProcessObserver::OnClearCache() { |
| 460 WebCache::clear(); | 464 WebCache::clear(); |
| 461 } | 465 } |
| 462 | 466 |
| 463 void ChromeRenderProcessObserver::OnGetCacheResourceStats() { | 467 void ChromeRenderProcessObserver::OnGetCacheResourceStats() { |
| 464 WebCache::ResourceTypeStats stats; | 468 WebCache::ResourceTypeStats stats; |
| 465 WebCache::getResourceTypeStats(&stats); | 469 WebCache::getResourceTypeStats(&stats); |
| 466 Send(new ViewHostMsg_ResourceTypeStats(stats)); | 470 Send(new ChromeViewHostMsg_ResourceTypeStats(stats)); |
| 467 } | 471 } |
| 468 | 472 |
| 469 #if defined(USE_TCMALLOC) | 473 #if defined(USE_TCMALLOC) |
| 470 void ChromeRenderProcessObserver::OnGetRendererTcmalloc() { | 474 void ChromeRenderProcessObserver::OnGetRendererTcmalloc() { |
| 471 std::string result; | 475 std::string result; |
| 472 char buffer[1024 * 32]; | 476 char buffer[1024 * 32]; |
| 473 MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); | 477 MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); |
| 474 result.append(buffer); | 478 result.append(buffer); |
| 475 Send(new ViewHostMsg_RendererTcmalloc(result)); | 479 Send(new ChromeViewHostMsg_RendererTcmalloc(result)); |
| 476 } | 480 } |
| 477 | 481 |
| 478 void ChromeRenderProcessObserver::OnSetTcmallocHeapProfiling( | 482 void ChromeRenderProcessObserver::OnSetTcmallocHeapProfiling( |
| 479 bool profiling, const std::string& filename_prefix) { | 483 bool profiling, const std::string& filename_prefix) { |
| 480 #if !defined(OS_WIN) | 484 #if !defined(OS_WIN) |
| 481 // TODO(stevenjb): Create MallocExtension wrappers for HeapProfile functions. | 485 // TODO(stevenjb): Create MallocExtension wrappers for HeapProfile functions. |
| 482 if (profiling) | 486 if (profiling) |
| 483 HeapProfilerStart(filename_prefix.c_str()); | 487 HeapProfilerStart(filename_prefix.c_str()); |
| 484 else | 488 else |
| 485 HeapProfilerStop(); | 489 HeapProfilerStop(); |
| 486 #endif | 490 #endif |
| 487 } | 491 } |
| 488 | 492 |
| 489 void ChromeRenderProcessObserver::OnWriteTcmallocHeapProfile( | 493 void ChromeRenderProcessObserver::OnWriteTcmallocHeapProfile( |
| 490 const FilePath::StringType& filename) { | 494 const FilePath::StringType& filename) { |
| 491 #if !defined(OS_WIN) | 495 #if !defined(OS_WIN) |
| 492 // TODO(stevenjb): Create MallocExtension wrappers for HeapProfile functions. | 496 // TODO(stevenjb): Create MallocExtension wrappers for HeapProfile functions. |
| 493 if (!IsHeapProfilerRunning()) | 497 if (!IsHeapProfilerRunning()) |
| 494 return; | 498 return; |
| 495 char* profile = GetHeapProfile(); | 499 char* profile = GetHeapProfile(); |
| 496 if (!profile) { | 500 if (!profile) { |
| 497 LOG(WARNING) << "Unable to get heap profile."; | 501 LOG(WARNING) << "Unable to get heap profile."; |
| 498 return; | 502 return; |
| 499 } | 503 } |
| 500 // The render process can not write to a file, so copy the result into | 504 // The render process can not write to a file, so copy the result into |
| 501 // a string and pass it to the handler (which runs on the browser host). | 505 // a string and pass it to the handler (which runs on the browser host). |
| 502 std::string result(profile); | 506 std::string result(profile); |
| 503 delete profile; | 507 delete profile; |
| 504 Send(new ViewHostMsg_WriteTcmallocHeapProfile_ACK(filename, result)); | 508 Send(new ChromeViewHostMsg_WriteTcmallocHeapProfile_ACK(filename, result)); |
| 505 #endif | 509 #endif |
| 506 } | 510 } |
| 507 | 511 |
| 508 #endif | 512 #endif |
| 509 | 513 |
| 510 void ChromeRenderProcessObserver::OnSetFieldTrialGroup( | 514 void ChromeRenderProcessObserver::OnSetFieldTrialGroup( |
| 511 const std::string& field_trial_name, | 515 const std::string& field_trial_name, |
| 512 const std::string& group_name) { | 516 const std::string& group_name) { |
| 513 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); | 517 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); |
| 514 } | 518 } |
| 515 | 519 |
| 516 void ChromeRenderProcessObserver::OnGetV8HeapStats() { | 520 void ChromeRenderProcessObserver::OnGetV8HeapStats() { |
| 517 v8::HeapStatistics heap_stats; | 521 v8::HeapStatistics heap_stats; |
| 518 v8::V8::GetHeapStatistics(&heap_stats); | 522 v8::V8::GetHeapStatistics(&heap_stats); |
| 519 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(), | 523 Send(new ChromeViewHostMsg_V8HeapStats(heap_stats.total_heap_size(), |
| 520 heap_stats.used_heap_size())); | 524 heap_stats.used_heap_size())); |
| 521 } | 525 } |
| 522 | 526 |
| 523 void ChromeRenderProcessObserver::OnPurgeMemory() { | 527 void ChromeRenderProcessObserver::OnPurgeMemory() { |
| 524 // Clear the object cache (as much as possible; some live objects cannot be | 528 // Clear the object cache (as much as possible; some live objects cannot be |
| 525 // freed). | 529 // freed). |
| 526 WebCache::clear(); | 530 WebCache::clear(); |
| 527 | 531 |
| 528 // Clear the font/glyph cache. | 532 // Clear the font/glyph cache. |
| 529 WebFontCache::clear(); | 533 WebFontCache::clear(); |
| 530 | 534 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 544 } | 548 } |
| 545 | 549 |
| 546 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 550 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
| 547 // Tell tcmalloc to release any free pages it's still holding. | 551 // Tell tcmalloc to release any free pages it's still holding. |
| 548 MallocExtension::instance()->ReleaseFreeMemory(); | 552 MallocExtension::instance()->ReleaseFreeMemory(); |
| 549 #endif | 553 #endif |
| 550 | 554 |
| 551 if (client_) | 555 if (client_) |
| 552 client_->OnPurgeMemory(); | 556 client_->OnPurgeMemory(); |
| 553 } | 557 } |
| OLD | NEW |