Commit 8e466cc1 authored by Abhishek Arya's avatar Abhishek Arya Committed by Commit Bot

Revert "dom: Remove PresentationAttributeCacheCleaner"

This reverts commit 6ed531bd.

Reason for revert: Caused multiple security regressions, see bug 810368.

Original change's description:
> dom: Remove PresentationAttributeCacheCleaner
> 
> PresentationAttributeCacheCleaner was introduced before purging memory
> was introduced.
> 
> This CL removes PresentationAttributeCacheCleaner to clear cache soon
> instead of delyaing with timers.
> 
> This is part of efforts to replace default timer task runners with
> other appropriate task runners in the renderer.
> 
> Bug: 624694, 804694
> Change-Id: I7ed775d4b998be82e35d8eefe1f7bd4e0d0145a2
> Reviewed-on: https://chromium-review.googlesource.com/903942
> Reviewed-by: Alexander Timin <altimin@chromium.org>
> Reviewed-by: Hayato Ito <hayato@chromium.org>
> Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#535306}

TBR=jbroman@chromium.org,hayato@chromium.org,hajimehoshi@chromium.org,altimin@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 624694, 804694
Change-Id: I921fea361197deefd45968c07917cb5bc6fae0a4
Reviewed-on: https://chromium-review.googlesource.com/912091Reviewed-by: default avatarAbhishek Arya <inferno@chromium.org>
Commit-Queue: Abhishek Arya <inferno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535926}
parent 65a5563a
......@@ -37,6 +37,7 @@
#include "core/dom/Attribute.h"
#include "core/dom/Element.h"
#include "core/html/forms/HTMLInputElement.h"
#include "platform/Timer.h"
#include "platform/scheduler/child/web_scheduler.h"
#include "platform/wtf/HashFunctions.h"
#include "platform/wtf/HashMap.h"
......@@ -80,6 +81,53 @@ static PresentationAttributeCache& GetPresentationAttributeCache() {
return cache;
}
// This is a singleton (held via DEFINE_STATIC_LOCAL).
// Thus it is appropriate to use the main thread's timer task runner, rather
// than one associated with a particular frame.
class PresentationAttributeCacheCleaner {
USING_FAST_MALLOC(PresentationAttributeCacheCleaner);
public:
PresentationAttributeCacheCleaner()
: hit_count_(0),
clean_timer_(
Platform::Current()->MainThread()->Scheduler()->TimerTaskRunner(),
this,
&PresentationAttributeCacheCleaner::CleanCache) {}
void DidHitPresentationAttributeCache() {
if (GetPresentationAttributeCache().size() <
kMinimumPresentationAttributeCacheSizeForCleaning)
return;
hit_count_++;
if (!clean_timer_.IsActive()) {
clean_timer_.StartOneShot(kPresentationAttributeCacheCleanTimeInSeconds,
FROM_HERE);
}
}
private:
static const unsigned kPresentationAttributeCacheCleanTimeInSeconds = 60;
static const unsigned kMinimumPresentationAttributeCacheSizeForCleaning = 100;
static const unsigned kMinimumPresentationAttributeCacheHitCountPerMinute =
(100 * kPresentationAttributeCacheCleanTimeInSeconds) / 60;
void CleanCache(TimerBase* timer) {
DCHECK_EQ(timer, &clean_timer_);
unsigned hit_count = hit_count_;
hit_count_ = 0;
if (hit_count > kMinimumPresentationAttributeCacheHitCountPerMinute)
return;
GetPresentationAttributeCache().clear();
}
unsigned hit_count_;
TaskRunnerTimer<PresentationAttributeCacheCleaner> clean_timer_;
DISALLOW_COPY_AND_ASSIGN(PresentationAttributeCacheCleaner);
};
static bool AttributeNameSort(const std::pair<StringImpl*, AtomicString>& p1,
const std::pair<StringImpl*, AtomicString>& p2) {
// Sort based on the attribute name pointers. It doesn't matter what the order
......@@ -131,6 +179,8 @@ static unsigned ComputePresentationAttributeCacheHash(
}
CSSPropertyValueSet* ComputePresentationAttributeStyle(Element& element) {
DEFINE_STATIC_LOCAL(PresentationAttributeCacheCleaner, cache_cleaner, ());
DCHECK(element.IsStyledElement());
PresentationAttributeCacheKey cache_key;
......@@ -152,13 +202,7 @@ CSSPropertyValueSet* ComputePresentationAttributeStyle(Element& element) {
CSSPropertyValueSet* style = nullptr;
if (cache_hash && cache_value->value) {
style = cache_value->value->value;
static const unsigned kMinimumPresentationAttributeCacheSizeForCleaning =
100;
if (GetPresentationAttributeCache().size() >=
kMinimumPresentationAttributeCacheSizeForCleaning) {
GetPresentationAttributeCache().clear();
}
cache_cleaner.DidHitPresentationAttributeCache();
} else {
style = MutableCSSPropertyValueSet::Create(
element.IsSVGElement() ? kSVGAttributeMode : kHTMLStandardMode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment