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" |
11 #include "base/native_library.h" | 11 #include "base/native_library.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/extension_localization_peer.h" | 17 #include "chrome/common/extensions/extension_localization_peer.h" |
18 #include "chrome/common/net/net_resource_provider.h" | 18 #include "chrome/common/net/net_resource_provider.h" |
19 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
20 #include "chrome/renderer/content_settings_observer.h" | 20 #include "chrome/renderer/content_settings_observer.h" |
21 #include "chrome/renderer/security_filter_peer.h" | 21 #include "chrome/renderer/security_filter_peer.h" |
| 22 #include "content/common/notification_source.h" |
22 #include "content/common/resource_dispatcher.h" | 23 #include "content/common/resource_dispatcher.h" |
23 #include "content/common/resource_dispatcher_delegate.h" | 24 #include "content/common/resource_dispatcher_delegate.h" |
24 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
25 #include "content/renderer/render_thread.h" | 26 #include "content/renderer/render_thread.h" |
26 #include "content/renderer/render_view.h" | 27 #include "content/renderer/render_view.h" |
27 #include "content/renderer/render_view_visitor.h" | 28 #include "content/renderer/render_view_visitor.h" |
28 #include "crypto/nss_util.h" | 29 #include "crypto/nss_util.h" |
29 #include "media/base/media.h" | 30 #include "media/base/media.h" |
30 #include "media/base/media_switches.h" | 31 #include "media/base/media_switches.h" |
31 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 std::string error; | 385 std::string error; |
385 base::LoadNativeLibrary(FilePath(L"crypt32.dll"), &error); | 386 base::LoadNativeLibrary(FilePath(L"crypt32.dll"), &error); |
386 #endif | 387 #endif |
387 | 388 |
388 // Note that under Linux, the media library will normally already have | 389 // Note that under Linux, the media library will normally already have |
389 // been initialized by the Zygote before this instance became a Renderer. | 390 // been initialized by the Zygote before this instance became a Renderer. |
390 FilePath media_path; | 391 FilePath media_path; |
391 PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path); | 392 PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path); |
392 if (!media_path.empty()) | 393 if (!media_path.empty()) |
393 media::InitializeMediaLibrary(media_path); | 394 media::InitializeMediaLibrary(media_path); |
| 395 |
| 396 registrar_.Add(this, content::NOTIFICATION_PURGE_MEMORY, Source<void>(NULL)); |
394 } | 397 } |
395 | 398 |
396 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { | 399 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { |
397 } | 400 } |
398 | 401 |
399 bool ChromeRenderProcessObserver::OnControlMessageReceived( | 402 bool ChromeRenderProcessObserver::OnControlMessageReceived( |
400 const IPC::Message& message) { | 403 const IPC::Message& message) { |
401 bool handled = true; | 404 bool handled = true; |
402 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) | 405 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) |
403 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess) | 406 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess) |
404 IPC_MESSAGE_HANDLER(ViewMsg_SetDefaultContentSettings, | 407 IPC_MESSAGE_HANDLER(ViewMsg_SetDefaultContentSettings, |
405 OnSetDefaultContentSettings) | 408 OnSetDefaultContentSettings) |
406 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL, | 409 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL, |
407 OnSetContentSettingsForCurrentURL) | 410 OnSetContentSettingsForCurrentURL) |
408 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) | 411 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) |
409 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache) | 412 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache) |
410 IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) | 413 IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) |
411 #if defined(USE_TCMALLOC) | 414 #if defined(USE_TCMALLOC) |
412 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc) | 415 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc) |
413 #endif | 416 #endif |
414 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) | 417 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) |
415 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) | 418 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) |
416 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) | |
417 IPC_MESSAGE_UNHANDLED(handled = false) | 419 IPC_MESSAGE_UNHANDLED(handled = false) |
418 IPC_END_MESSAGE_MAP() | 420 IPC_END_MESSAGE_MAP() |
419 return handled; | 421 return handled; |
420 } | 422 } |
421 | 423 |
422 void ChromeRenderProcessObserver::WebKitInitialized() { | 424 void ChromeRenderProcessObserver::WebKitInitialized() { |
423 WebRuntimeFeatures::enableMediaPlayer(media::IsMediaLibraryInitialized()); | 425 WebRuntimeFeatures::enableMediaPlayer(media::IsMediaLibraryInitialized()); |
424 } | 426 } |
425 | 427 |
426 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( | 428 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); | 476 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); |
475 } | 477 } |
476 | 478 |
477 void ChromeRenderProcessObserver::OnGetV8HeapStats() { | 479 void ChromeRenderProcessObserver::OnGetV8HeapStats() { |
478 v8::HeapStatistics heap_stats; | 480 v8::HeapStatistics heap_stats; |
479 v8::V8::GetHeapStatistics(&heap_stats); | 481 v8::V8::GetHeapStatistics(&heap_stats); |
480 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(), | 482 Send(new ViewHostMsg_V8HeapStats(heap_stats.total_heap_size(), |
481 heap_stats.used_heap_size())); | 483 heap_stats.used_heap_size())); |
482 } | 484 } |
483 | 485 |
| 486 void ChromeRenderProcessObserver::Observe(int type, |
| 487 const NotificationSource& source, |
| 488 const NotificationDetails& details) { |
| 489 if (type == content::NOTIFICATION_PURGE_MEMORY) |
| 490 OnPurgeMemory(); |
| 491 } |
| 492 |
484 void ChromeRenderProcessObserver::OnPurgeMemory() { | 493 void ChromeRenderProcessObserver::OnPurgeMemory() { |
| 494 LOG(INFO) << "CRPO purging memory!"; |
485 // Clear the object cache (as much as possible; some live objects cannot be | 495 // Clear the object cache (as much as possible; some live objects cannot be |
486 // freed). | 496 // freed). |
487 WebCache::clear(); | 497 WebCache::clear(); |
488 | 498 |
489 // Clear the font/glyph cache. | 499 // Clear the font/glyph cache. |
490 WebFontCache::clear(); | 500 WebFontCache::clear(); |
491 | 501 |
492 // Clear the Cross-Origin Preflight cache. | 502 // Clear the Cross-Origin Preflight cache. |
493 WebCrossOriginPreflightResultCache::clear(); | 503 WebCrossOriginPreflightResultCache::clear(); |
494 | 504 |
495 // Release all freeable memory from the SQLite process-global page cache (a | 505 // Release all freeable memory from the SQLite process-global page cache (a |
496 // low-level object which backs the Connection-specific page caches). | 506 // low-level object which backs the Connection-specific page caches). |
497 while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) { | 507 while (sqlite3_release_memory(std::numeric_limits<int>::max()) > 0) { |
498 } | 508 } |
499 | 509 |
500 // Repeatedly call the V8 idle notification until it returns true ("nothing | 510 // Repeatedly call the V8 idle notification until it returns true ("nothing |
501 // more to free"). Note that it makes more sense to do this than to implement | 511 // more to free"). Note that it makes more sense to do this than to implement |
502 // a new "delete everything" pass because object references make it difficult | 512 // a new "delete everything" pass because object references make it difficult |
503 // to free everything possible in just one pass. | 513 // to free everything possible in just one pass. |
504 while (!v8::V8::IdleNotification()) { | 514 while (!v8::V8::IdleNotification()) { |
505 } | 515 } |
506 | 516 |
507 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 517 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
508 // Tell tcmalloc to release any free pages it's still holding. | 518 // Tell tcmalloc to release any free pages it's still holding. |
509 MallocExtension::instance()->ReleaseFreeMemory(); | 519 MallocExtension::instance()->ReleaseFreeMemory(); |
510 #endif | 520 #endif |
511 } | 521 } |
OLD | NEW |