OLD | NEW |
---|---|
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 Loading... | |
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 WeakPtr<MainThreadTaskRunner> m_runner; | 51 WeakPtrWillBeWeakPersistent<MainThreadTaskRunner> m_runner; |
sof
2015/08/19 06:37:56
The GC plugin ought to warn/disallow WeakPtr<T> if
| |
52 OwnPtr<ExecutionContextTask> m_task; | 52 OwnPtr<ExecutionContextTask> m_task; |
53 bool m_isInspectorTask; | 53 bool m_isInspectorTask; |
54 }; | 54 }; |
55 | 55 |
56 void MainThreadTask::run() | 56 void MainThreadTask::run() |
57 { | 57 { |
58 ASSERT(isMainThread()); | 58 ASSERT(isMainThread()); |
59 | 59 |
60 if (!m_runner.get()) | 60 if (!m_runner.get()) |
61 return; | 61 return; |
62 m_runner->perform(m_task.release(), m_isInspectorTask); | 62 m_runner->perform(m_task.release(), m_isInspectorTask); |
63 } | 63 } |
64 | 64 |
65 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context) | 65 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context) |
66 : m_context(context) | 66 : m_context(context) |
67 #if !ENABLE(OILPAN) | |
67 , m_weakFactory(this) | 68 , m_weakFactory(this) |
69 #endif | |
68 , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired) | 70 , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired) |
69 , m_suspended(false) | 71 , m_suspended(false) |
70 { | 72 { |
71 } | 73 } |
72 | 74 |
73 MainThreadTaskRunner::~MainThreadTaskRunner() | 75 MainThreadTaskRunner::~MainThreadTaskRunner() |
74 { | 76 { |
75 } | 77 } |
76 | 78 |
79 DEFINE_TRACE(MainThreadTaskRunner) | |
80 { | |
81 visitor->trace(m_context); | |
82 } | |
83 | |
77 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, PassOwnPtr <ExecutionContextTask> task) | 84 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, PassOwnPtr <ExecutionContextTask> task) |
78 { | 85 { |
79 if (!task->taskNameForInstrumentation().isEmpty()) | 86 if (!task->taskNameForInstrumentation().isEmpty()) |
80 InspectorInstrumentation::didPostExecutionContextTask(m_context, task.ge t()); | 87 InspectorInstrumentation::didPostExecutionContextTask(m_context, task.ge t()); |
81 Platform::current()->mainThread()->postTask(location, new MainThreadTask(m_w eakFactory.createWeakPtr(), task, false)); | 88 Platform::current()->mainThread()->postTask(location, new MainThreadTask(cre ateWeakPointerToSelf(), task, false)); |
haraken
2015/08/19 05:18:17
Maybe I'm wrong but this task is created on a non-
Yuta Kitamura
2015/08/19 05:56:57
You are right; it indeed can be called from non-ma
| |
82 } | 89 } |
83 | 90 |
84 void MainThreadTaskRunner::postInspectorTask(const WebTraceLocation& location, P assOwnPtr<ExecutionContextTask> task) | 91 void MainThreadTaskRunner::postInspectorTask(const WebTraceLocation& location, P assOwnPtr<ExecutionContextTask> task) |
85 { | 92 { |
86 Platform::current()->mainThread()->postTask(location, new MainThreadTask(m_w eakFactory.createWeakPtr(), task, true)); | 93 Platform::current()->mainThread()->postTask(location, new MainThreadTask(cre ateWeakPointerToSelf(), task, true)); |
87 } | 94 } |
88 | 95 |
89 void MainThreadTaskRunner::perform(PassOwnPtr<ExecutionContextTask> task, bool i sInspectorTask) | 96 void MainThreadTaskRunner::perform(PassOwnPtr<ExecutionContextTask> task, bool i sInspectorTask) |
90 { | 97 { |
91 if (!isInspectorTask && (m_context->tasksNeedSuspension() || !m_pendingTasks .isEmpty())) { | 98 if (!isInspectorTask && (m_context->tasksNeedSuspension() || !m_pendingTasks .isEmpty())) { |
92 m_pendingTasks.append(task); | 99 m_pendingTasks.append(task); |
93 return; | 100 return; |
94 } | 101 } |
95 | 102 |
96 const bool instrumenting = !isInspectorTask && !task->taskNameForInstrumenta tion().isEmpty(); | 103 const bool instrumenting = !isInspectorTask && !task->taskNameForInstrumenta tion().isEmpty(); |
(...skipping 27 matching lines...) Expand all Loading... | |
124 m_pendingTasks.remove(0); | 131 m_pendingTasks.remove(0); |
125 const bool instrumenting = !task->taskNameForInstrumentation().isEmpty() ; | 132 const bool instrumenting = !task->taskNameForInstrumentation().isEmpty() ; |
126 if (instrumenting) | 133 if (instrumenting) |
127 InspectorInstrumentation::willPerformExecutionContextTask(m_context, task.get()); | 134 InspectorInstrumentation::willPerformExecutionContextTask(m_context, task.get()); |
128 task->performTask(m_context); | 135 task->performTask(m_context); |
129 if (instrumenting) | 136 if (instrumenting) |
130 InspectorInstrumentation::didPerformExecutionContextTask(m_context); | 137 InspectorInstrumentation::didPerformExecutionContextTask(m_context); |
131 } | 138 } |
132 } | 139 } |
133 | 140 |
141 WeakPtrWillBeRawPtr<MainThreadTaskRunner> MainThreadTaskRunner::createWeakPointe rToSelf() | |
142 { | |
143 #if ENABLE(OILPAN) | |
144 return this; | |
145 #else | |
146 return m_weakFactory.createWeakPtr(); | |
147 #endif | |
148 } | |
149 | |
134 } // namespace | 150 } // namespace |
OLD | NEW |