| 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" | |
| 19 #include "base/memory/shared_memory.h" | 18 #include "base/memory/shared_memory.h" |
| 20 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
| 21 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 22 #include "base/metrics/stats_table.h" | 21 #include "base/metrics/stats_table.h" |
| 23 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 24 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 25 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/strings/string_tokenizer.h" | 25 #include "base/strings/string_tokenizer.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 28 #include "base/threading/thread_local.h" | 27 #include "base/threading/thread_local.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 const int kIdleCPUUsageThresholdInPercents = 3; | 171 const int kIdleCPUUsageThresholdInPercents = 3; |
| 173 const int kMinRasterThreads = 1; | 172 const int kMinRasterThreads = 1; |
| 174 const int kMaxRasterThreads = 64; | 173 const int kMaxRasterThreads = 64; |
| 175 | 174 |
| 176 // Maximum allocation size allowed for image scaling filters that | 175 // Maximum allocation size allowed for image scaling filters that |
| 177 // require pre-scaling. Skia will fallback to a filter that doesn't | 176 // require pre-scaling. Skia will fallback to a filter that doesn't |
| 178 // require pre-scaling if the default filter would require an | 177 // require pre-scaling if the default filter would require an |
| 179 // allocation that exceeds this limit. | 178 // allocation that exceeds this limit. |
| 180 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; | 179 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
| 181 | 180 |
| 182 const size_t kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden = | |
| 183 4 * 1024 * 1024; | |
| 184 | |
| 185 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access | 181 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access |
| 186 // incorrectly from the wrong thread. | 182 // incorrectly from the wrong thread. |
| 187 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > | 183 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > |
| 188 lazy_tls = LAZY_INSTANCE_INITIALIZER; | 184 lazy_tls = LAZY_INSTANCE_INITIALIZER; |
| 189 | 185 |
| 190 class RenderViewZoomer : public RenderViewVisitor { | 186 class RenderViewZoomer : public RenderViewVisitor { |
| 191 public: | 187 public: |
| 192 RenderViewZoomer(const std::string& scheme, | 188 RenderViewZoomer(const std::string& scheme, |
| 193 const std::string& host, | 189 const std::string& host, |
| 194 double zoom_level) : scheme_(scheme), | 190 double zoom_level) : scheme_(scheme), |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 supported_types.end(), | 527 supported_types.end(), |
| 532 requested_type) != supported_types.end()) { | 528 requested_type) != supported_types.end()) { |
| 533 type = requested_type; | 529 type = requested_type; |
| 534 } else { | 530 } else { |
| 535 LOG(ERROR) << "Requested discardable memory type is not supported."; | 531 LOG(ERROR) << "Requested discardable memory type is not supported."; |
| 536 } | 532 } |
| 537 } | 533 } |
| 538 | 534 |
| 539 base::DiscardableMemory::SetPreferredType(type); | 535 base::DiscardableMemory::SetPreferredType(type); |
| 540 | 536 |
| 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 | 541 // AllocateGpuMemoryBuffer must be used exclusively on one thread but |
| 542 // it doesn't have to be the same thread RenderThreadImpl is created on. | 542 // it doesn't have to be the same thread RenderThreadImpl is created on. |
| 543 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); | 543 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); |
| 544 | 544 |
| 545 if (command_line.HasSwitch(switches::kNumRasterThreads)) { | 545 if (command_line.HasSwitch(switches::kNumRasterThreads)) { |
| 546 int num_raster_threads; | 546 int num_raster_threads; |
| 547 std::string string_value = | 547 std::string string_value = |
| 548 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 548 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 549 if (base::StringToInt(string_value, &num_raster_threads) && | 549 if (base::StringToInt(string_value, &num_raster_threads) && |
| 550 num_raster_threads >= kMinRasterThreads && | 550 num_raster_threads >= kMinRasterThreads && |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 | 1602 |
| 1603 void RenderThreadImpl::WidgetDestroyed() { | 1603 void RenderThreadImpl::WidgetDestroyed() { |
| 1604 widget_count_--; | 1604 widget_count_--; |
| 1605 } | 1605 } |
| 1606 | 1606 |
| 1607 void RenderThreadImpl::WidgetHidden() { | 1607 void RenderThreadImpl::WidgetHidden() { |
| 1608 DCHECK_LT(hidden_widget_count_, widget_count_); | 1608 DCHECK_LT(hidden_widget_count_, widget_count_); |
| 1609 hidden_widget_count_++; | 1609 hidden_widget_count_++; |
| 1610 | 1610 |
| 1611 if (widget_count_ && hidden_widget_count_ == widget_count_) { | 1611 if (widget_count_ && hidden_widget_count_ == widget_count_) { |
| 1612 // TODO(reveman): Remove this when we have a better mechanism to prevent | |
| 1613 // total discardable memory used by all renderers from growing too large. | |
| 1614 base::internal::DiscardableMemoryEmulated:: | |
| 1615 ReduceMemoryUsageUntilWithinLimit( | |
| 1616 kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden); | |
| 1617 | |
| 1618 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) | 1612 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) |
| 1619 ScheduleIdleHandler(kInitialIdleHandlerDelayMs); | 1613 ScheduleIdleHandler(kInitialIdleHandlerDelayMs); |
| 1620 } | 1614 } |
| 1621 } | 1615 } |
| 1622 | 1616 |
| 1623 void RenderThreadImpl::WidgetRestored() { | 1617 void RenderThreadImpl::WidgetRestored() { |
| 1624 DCHECK_GT(hidden_widget_count_, 0); | 1618 DCHECK_GT(hidden_widget_count_, 0); |
| 1625 hidden_widget_count_--; | 1619 hidden_widget_count_--; |
| 1626 | 1620 |
| 1627 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1621 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
| 1628 return; | 1622 return; |
| 1629 } | 1623 } |
| 1630 | 1624 |
| 1631 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1625 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 1632 } | 1626 } |
| 1633 | 1627 |
| 1634 } // namespace content | 1628 } // namespace content |
| OLD | NEW |