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

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

Issue 1296243004: Oilpan: Move MainThreadTaskRunner into Oilpan heap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use CrossThreadWeakPersistent. Created 5 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/MainThreadTaskRunner.h ('k') | Source/core/dom/MainThreadTaskRunnerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 #include "core/dom/ExecutionContextTask.h" 31 #include "core/dom/ExecutionContextTask.h"
32 #include "core/inspector/InspectorInstrumentation.h" 32 #include "core/inspector/InspectorInstrumentation.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 class MainThreadTask : public WebThread::Task { 38 class MainThreadTask : public WebThread::Task {
39 WTF_MAKE_NONCOPYABLE(MainThreadTask); WTF_MAKE_FAST_ALLOCATED(MainThreadTask ); 39 WTF_MAKE_NONCOPYABLE(MainThreadTask); WTF_MAKE_FAST_ALLOCATED(MainThreadTask );
40 public: 40 public:
41 MainThreadTask(WeakPtr<MainThreadTaskRunner> runner, PassOwnPtr<ExecutionCon textTask> task, bool isInspectorTask) 41 MainThreadTask(WeakPtrWillBeRawPtr<MainThreadTaskRunner> runner, PassOwnPtr< ExecutionContextTask> task, bool isInspectorTask)
42 : m_runner(runner) 42 : m_runner(runner)
43 , m_task(task) 43 , m_task(task)
44 , m_isInspectorTask(isInspectorTask) 44 , m_isInspectorTask(isInspectorTask)
45 { 45 {
46 } 46 }
47 47
48 void run() override; 48 void run() override;
49 49
50 private: 50 private:
51 #if ENABLE(OILPAN)
52 CrossThreadWeakPersistent<MainThreadTaskRunner> m_runner;
53 #else
51 WeakPtr<MainThreadTaskRunner> m_runner; 54 WeakPtr<MainThreadTaskRunner> m_runner;
55 #endif
52 OwnPtr<ExecutionContextTask> m_task; 56 OwnPtr<ExecutionContextTask> m_task;
53 bool m_isInspectorTask; 57 bool m_isInspectorTask;
54 }; 58 };
55 59
56 void MainThreadTask::run() 60 void MainThreadTask::run()
57 { 61 {
58 ASSERT(isMainThread()); 62 ASSERT(isMainThread());
59 63
60 if (!m_runner.get()) 64 if (!m_runner.get())
61 return; 65 return;
62 m_runner->perform(m_task.release(), m_isInspectorTask); 66 m_runner->perform(m_task.release(), m_isInspectorTask);
63 } 67 }
64 68
65 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context) 69 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context)
66 : m_context(context) 70 : m_context(context)
71 #if !ENABLE(OILPAN)
67 , m_weakFactory(this) 72 , m_weakFactory(this)
73 #endif
68 , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired) 74 , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired)
69 , m_suspended(false) 75 , m_suspended(false)
70 { 76 {
71 } 77 }
72 78
73 MainThreadTaskRunner::~MainThreadTaskRunner() 79 MainThreadTaskRunner::~MainThreadTaskRunner()
74 { 80 {
75 } 81 }
76 82
83 DEFINE_TRACE(MainThreadTaskRunner)
84 {
85 visitor->trace(m_context);
86 }
87
77 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, PassOwnPtr <ExecutionContextTask> task) 88 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, PassOwnPtr <ExecutionContextTask> task)
78 { 89 {
79 if (!task->taskNameForInstrumentation().isEmpty()) 90 if (!task->taskNameForInstrumentation().isEmpty())
80 InspectorInstrumentation::didPostExecutionContextTask(m_context, task.ge t()); 91 InspectorInstrumentation::didPostExecutionContextTask(m_context, task.ge t());
81 Platform::current()->mainThread()->postTask(location, new MainThreadTask(m_w eakFactory.createWeakPtr(), task, false)); 92 Platform::current()->mainThread()->postTask(location, new MainThreadTask(cre ateWeakPointerToSelf(), task, false));
82 } 93 }
83 94
84 void MainThreadTaskRunner::postInspectorTask(const WebTraceLocation& location, P assOwnPtr<ExecutionContextTask> task) 95 void MainThreadTaskRunner::postInspectorTask(const WebTraceLocation& location, P assOwnPtr<ExecutionContextTask> task)
85 { 96 {
86 Platform::current()->mainThread()->postTask(location, new MainThreadTask(m_w eakFactory.createWeakPtr(), task, true)); 97 Platform::current()->mainThread()->postTask(location, new MainThreadTask(cre ateWeakPointerToSelf(), task, true));
87 } 98 }
88 99
89 void MainThreadTaskRunner::perform(PassOwnPtr<ExecutionContextTask> task, bool i sInspectorTask) 100 void MainThreadTaskRunner::perform(PassOwnPtr<ExecutionContextTask> task, bool i sInspectorTask)
90 { 101 {
91 if (!isInspectorTask && (m_context->tasksNeedSuspension() || !m_pendingTasks .isEmpty())) { 102 if (!isInspectorTask && (m_context->tasksNeedSuspension() || !m_pendingTasks .isEmpty())) {
92 m_pendingTasks.append(task); 103 m_pendingTasks.append(task);
93 return; 104 return;
94 } 105 }
95 106
96 const bool instrumenting = !isInspectorTask && !task->taskNameForInstrumenta tion().isEmpty(); 107 const bool instrumenting = !isInspectorTask && !task->taskNameForInstrumenta tion().isEmpty();
(...skipping 27 matching lines...) Expand all
124 m_pendingTasks.remove(0); 135 m_pendingTasks.remove(0);
125 const bool instrumenting = !task->taskNameForInstrumentation().isEmpty() ; 136 const bool instrumenting = !task->taskNameForInstrumentation().isEmpty() ;
126 if (instrumenting) 137 if (instrumenting)
127 InspectorInstrumentation::willPerformExecutionContextTask(m_context, task.get()); 138 InspectorInstrumentation::willPerformExecutionContextTask(m_context, task.get());
128 task->performTask(m_context); 139 task->performTask(m_context);
129 if (instrumenting) 140 if (instrumenting)
130 InspectorInstrumentation::didPerformExecutionContextTask(m_context); 141 InspectorInstrumentation::didPerformExecutionContextTask(m_context);
131 } 142 }
132 } 143 }
133 144
145 WeakPtrWillBeRawPtr<MainThreadTaskRunner> MainThreadTaskRunner::createWeakPointe rToSelf()
146 {
147 #if ENABLE(OILPAN)
148 return this;
149 #else
150 return m_weakFactory.createWeakPtr();
151 #endif
152 }
153
134 } // namespace 154 } // namespace
OLDNEW
« no previous file with comments | « Source/core/dom/MainThreadTaskRunner.h ('k') | Source/core/dom/MainThreadTaskRunnerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698