| 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 "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/allocator/allocator_extension.h" | 12 #include "base/allocator/allocator_extension.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/discardable_memory.h" | 17 #include "base/memory/discardable_memory.h" |
| 18 #include "base/memory/discardable_memory_emulated.h" |
| 18 #include "base/memory/shared_memory.h" | 19 #include "base/memory/shared_memory.h" |
| 19 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
| 20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
| 21 #include "base/metrics/stats_table.h" | 22 #include "base/metrics/stats_table.h" |
| 22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 23 #include "base/strings/string16.h" | 24 #include "base/strings/string16.h" |
| 24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/string_tokenizer.h" | 26 #include "base/strings/string_tokenizer.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/thread_local.h" | 28 #include "base/threading/thread_local.h" |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 supported_types.end(), | 528 supported_types.end(), |
| 528 requested_type) != supported_types.end()) { | 529 requested_type) != supported_types.end()) { |
| 529 type = requested_type; | 530 type = requested_type; |
| 530 } else { | 531 } else { |
| 531 LOG(ERROR) << "Requested discardable memory type is not supported."; | 532 LOG(ERROR) << "Requested discardable memory type is not supported."; |
| 532 } | 533 } |
| 533 } | 534 } |
| 534 | 535 |
| 535 base::DiscardableMemory::SetPreferredType(type); | 536 base::DiscardableMemory::SetPreferredType(type); |
| 536 | 537 |
| 537 // Allow discardable memory implementations to register memory pressure | |
| 538 // listeners. | |
| 539 base::DiscardableMemory::RegisterMemoryPressureListeners(); | |
| 540 | |
| 541 // AllocateGpuMemoryBuffer must be used exclusively on one thread but | 538 // AllocateGpuMemoryBuffer must be used exclusively on one thread but |
| 542 // it doesn't have to be the same thread RenderThreadImpl is created on. | 539 // it doesn't have to be the same thread RenderThreadImpl is created on. |
| 543 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); | 540 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); |
| 544 | 541 |
| 545 if (command_line.HasSwitch(switches::kNumRasterThreads)) { | 542 if (command_line.HasSwitch(switches::kNumRasterThreads)) { |
| 546 int num_raster_threads; | 543 int num_raster_threads; |
| 547 std::string string_value = | 544 std::string string_value = |
| 548 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 545 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 549 if (base::StringToInt(string_value, &num_raster_threads) && | 546 if (base::StringToInt(string_value, &num_raster_threads) && |
| 550 num_raster_threads >= kMinRasterThreads && | 547 num_raster_threads >= kMinRasterThreads && |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 | 1599 |
| 1603 void RenderThreadImpl::WidgetDestroyed() { | 1600 void RenderThreadImpl::WidgetDestroyed() { |
| 1604 widget_count_--; | 1601 widget_count_--; |
| 1605 } | 1602 } |
| 1606 | 1603 |
| 1607 void RenderThreadImpl::WidgetHidden() { | 1604 void RenderThreadImpl::WidgetHidden() { |
| 1608 DCHECK_LT(hidden_widget_count_, widget_count_); | 1605 DCHECK_LT(hidden_widget_count_, widget_count_); |
| 1609 hidden_widget_count_++; | 1606 hidden_widget_count_++; |
| 1610 | 1607 |
| 1611 if (widget_count_ && hidden_widget_count_ == widget_count_) { | 1608 if (widget_count_ && hidden_widget_count_ == widget_count_) { |
| 1609 // We emulate a "moderate memory pressure" event for emulated discardable |
| 1610 // memory to make sure that background tabs don't use too much memory. |
| 1611 base::DiscardableMemoryEmulated:: |
| 1612 ReduceMemoryUsageUntilWithinModeratePressureLimit(); |
| 1613 |
| 1612 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) | 1614 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
| 1613 ScheduleIdleHandler(kInitialIdleHandlerDelayMs); | 1615 ScheduleIdleHandler(kInitialIdleHandlerDelayMs); |
| 1614 } | 1616 } |
| 1615 } | 1617 } |
| 1616 | 1618 |
| 1617 void RenderThreadImpl::WidgetRestored() { | 1619 void RenderThreadImpl::WidgetRestored() { |
| 1618 DCHECK_GT(hidden_widget_count_, 0); | 1620 DCHECK_GT(hidden_widget_count_, 0); |
| 1619 hidden_widget_count_--; | 1621 hidden_widget_count_--; |
| 1620 | 1622 |
| 1621 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1623 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
| 1622 return; | 1624 return; |
| 1623 } | 1625 } |
| 1624 | 1626 |
| 1625 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1627 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 1626 } | 1628 } |
| 1627 | 1629 |
| 1628 } // namespace content | 1630 } // namespace content |
| OLD | NEW |