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

Side by Side Diff: third_party/WebKit/Source/core/dom/MainThreadTaskRunner.cpp

Issue 2527143002: Suspend frame schedulers on a page suspension (Closed)
Patch Set: mod a comment Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All Rights Reserved. 2 * Copyright (C) 2013 Google Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 19 matching lines...) Expand all
30 #include "core/dom/ExecutionContextTask.h" 30 #include "core/dom/ExecutionContextTask.h"
31 #include "core/inspector/InspectorInstrumentation.h" 31 #include "core/inspector/InspectorInstrumentation.h"
32 #include "platform/CrossThreadFunctional.h" 32 #include "platform/CrossThreadFunctional.h"
33 #include "public/platform/Platform.h" 33 #include "public/platform/Platform.h"
34 #include "wtf/Assertions.h" 34 #include "wtf/Assertions.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context) 38 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context)
39 : m_context(context), 39 : m_context(context),
40 m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired),
41 m_suspended(false),
42 m_weakFactory(this), 40 m_weakFactory(this),
43 // Bind a WeakPtr now to avoid data races creating a WeakPtr inside 41 // Bind a WeakPtr now to avoid data races creating a WeakPtr inside
44 // postTask. 42 // postTask.
45 m_weakPtr(m_weakFactory.createWeakPtr()) {} 43 m_weakPtr(m_weakFactory.createWeakPtr()) {}
46 44
47 MainThreadTaskRunner::~MainThreadTaskRunner() {} 45 MainThreadTaskRunner::~MainThreadTaskRunner() {}
48 46
49 void MainThreadTaskRunner::postTaskInternal( 47 void MainThreadTaskRunner::postTaskInternal(
50 const WebTraceLocation& location, 48 const WebTraceLocation& location,
51 std::unique_ptr<ExecutionContextTask> task, 49 std::unique_ptr<ExecutionContextTask> task,
(...skipping 22 matching lines...) Expand all
74 } 72 }
75 73
76 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task, 74 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task,
77 bool isInspectorTask, 75 bool isInspectorTask,
78 bool instrumenting) { 76 bool instrumenting) {
79 // If the owner m_context is about to be swept then it 77 // If the owner m_context is about to be swept then it
80 // is no longer safe to access. 78 // is no longer safe to access.
81 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) 79 if (ThreadHeap::willObjectBeLazilySwept(m_context.get()))
82 return; 80 return;
83 81
84 if (!isInspectorTask &&
85 (m_context->tasksNeedSuspension() || !m_pendingTasks.isEmpty())) {
86 m_pendingTasks.append(make_pair(std::move(task), instrumenting));
87 return;
88 }
89
90 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), 82 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(),
91 !isInspectorTask); 83 !isInspectorTask);
92 task->performTask(m_context); 84 task->performTask(m_context);
93 } 85 }
94 86
95 void MainThreadTaskRunner::suspend() {
96 DCHECK(!m_suspended);
97 m_pendingTasksTimer.stop();
98 m_suspended = true;
99 }
100
101 void MainThreadTaskRunner::resume() {
102 DCHECK(m_suspended);
103 if (!m_pendingTasks.isEmpty())
104 m_pendingTasksTimer.startOneShot(0, BLINK_FROM_HERE);
105
106 m_suspended = false;
107 }
108
109 void MainThreadTaskRunner::pendingTasksTimerFired(TimerBase*) {
110 // If the owner m_context is about to be swept then it
111 // is no longer safe to access.
112 if (ThreadHeap::willObjectBeLazilySwept(m_context.get()))
113 return;
114
115 while (!m_pendingTasks.isEmpty()) {
116 std::unique_ptr<ExecutionContextTask> task =
117 std::move(m_pendingTasks[0].first);
118 const bool instrumenting = m_pendingTasks[0].second;
119 m_pendingTasks.remove(0);
120 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(),
121 instrumenting);
122 task->performTask(m_context);
123 }
124 }
125
126 } // namespace blink 87 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698