Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Unified Diff: third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp

Issue 2618893002: Fix memory leak with ScriptedIdleTaskController (Closed)
Patch Set: Improve test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
diff --git a/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp b/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
index 263766a0c308be166693dd4591c354f6c0ca793f..07077efb027855cbc9d1782a47951cf0f84b0811 100644
--- a/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
+++ b/third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.cpp
@@ -27,7 +27,7 @@ class IdleRequestCallbackWrapper
public:
static PassRefPtr<IdleRequestCallbackWrapper> create(
ScriptedIdleTaskController::CallbackId id,
- ScriptedIdleTaskController* controller) {
+ WTF::WeakPtr<ScriptedIdleTaskController> controller) {
return adoptRef(new IdleRequestCallbackWrapper(id, controller));
}
virtual ~IdleRequestCallbackWrapper() {}
@@ -54,15 +54,16 @@ class IdleRequestCallbackWrapper
void cancel() { m_controller = nullptr; }
ScriptedIdleTaskController::CallbackId id() const { return m_id; }
- ScriptedIdleTaskController* controller() const { return m_controller; }
+ ScriptedIdleTaskController* controller() const { return m_controller.get(); }
private:
- IdleRequestCallbackWrapper(ScriptedIdleTaskController::CallbackId id,
- ScriptedIdleTaskController* controller)
+ IdleRequestCallbackWrapper(
+ ScriptedIdleTaskController::CallbackId id,
+ WTF::WeakPtr<ScriptedIdleTaskController> controller)
: m_id(id), m_controller(controller) {}
ScriptedIdleTaskController::CallbackId m_id;
- Persistent<ScriptedIdleTaskController> m_controller;
+ WTF::WeakPtr<ScriptedIdleTaskController> m_controller;
sof 2017/01/06 09:31:04 WeakPersistent<> is used to hold onto GC-managed o
Xiaocheng 2017/01/06 09:56:28 Done. Thanks!
};
} // namespace internal
@@ -72,6 +73,7 @@ ScriptedIdleTaskController::ScriptedIdleTaskController(
: SuspendableObject(context),
m_scheduler(Platform::current()->currentThread()->scheduler()),
m_nextCallbackId(0),
+ m_weakPtrFactory(this),
m_suspended(false) {
suspendIfNeeded();
}
@@ -104,7 +106,8 @@ ScriptedIdleTaskController::registerCallback(
long long timeoutMillis = options.timeout();
RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper =
- internal::IdleRequestCallbackWrapper::create(id, this);
+ internal::IdleRequestCallbackWrapper::create(
+ id, m_weakPtrFactory.createWeakPtr());
m_scheduler->postIdleTask(
BLINK_FROM_HERE,
WTF::bind(&internal::IdleRequestCallbackWrapper::idleTaskFired,
@@ -190,6 +193,7 @@ void ScriptedIdleTaskController::runCallback(
void ScriptedIdleTaskController::contextDestroyed() {
m_callbacks.clear();
+ m_weakPtrFactory.revokeAll();
}
void ScriptedIdleTaskController::suspend() {
@@ -210,7 +214,8 @@ void ScriptedIdleTaskController::resume() {
// Repost idle tasks for any remaining callbacks.
for (auto& callback : m_callbacks) {
RefPtr<internal::IdleRequestCallbackWrapper> callbackWrapper =
- internal::IdleRequestCallbackWrapper::create(callback.key, this);
+ internal::IdleRequestCallbackWrapper::create(
+ callback.key, m_weakPtrFactory.createWeakPtr());
m_scheduler->postIdleTask(
BLINK_FROM_HERE,
WTF::bind(&internal::IdleRequestCallbackWrapper::idleTaskFired,
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptedIdleTaskController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698