Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 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) | 40 , m_pendingTasksTimer(this, &MainThreadTaskRunner::pendingTasksTimerFired) |
| 41 , m_suspended(false) | 41 , m_suspended(false) |
| 42 , m_weakFactory(this) | 42 , m_weakFactory(this) |
| 43 // Bind a WeakPtr now to avoid data races creating a WeakPtr inside postTask . | |
| 44 , m_weakPtr(m_weakFactory.createWeakPtr()) | |
| 43 { | 45 { |
| 44 } | 46 } |
| 45 | 47 |
| 46 MainThreadTaskRunner::~MainThreadTaskRunner() | 48 MainThreadTaskRunner::~MainThreadTaskRunner() |
| 47 { | 49 { |
| 48 } | 50 } |
| 49 | 51 |
| 50 void MainThreadTaskRunner::postTaskInternal(const WebTraceLocation& location, st d::unique_ptr<ExecutionContextTask> task, bool isInspectorTask, bool instrumenti ng) | 52 void MainThreadTaskRunner::postTaskInternal(const WebTraceLocation& location, st d::unique_ptr<ExecutionContextTask> task, bool isInspectorTask, bool instrumenti ng) |
| 51 { | 53 { |
| 52 Platform::current()->mainThread()->getWebTaskRunner()->postTask(location, cr ossThreadBind( | 54 Platform::current()->mainThread()->getWebTaskRunner()->postTask(location, cr ossThreadBind( |
| 53 &MainThreadTaskRunner::perform, | 55 &MainThreadTaskRunner::perform, |
| 54 m_weakFactory.createWeakPtr(), | 56 m_weakPtr, |
|
esprehn
2016/09/13 19:44:21
This means we're sharing a weakptr now instead of
dcheng
2016/09/13 19:51:40
It's copied, not shared, when it's bound into the
| |
| 55 passed(std::move(task)), | 57 passed(std::move(task)), |
| 56 isInspectorTask, | 58 isInspectorTask, |
| 57 instrumenting)); | 59 instrumenting)); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, std::uniqu e_ptr<ExecutionContextTask> task, const String& taskNameForInstrumentation) | 62 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, std::uniqu e_ptr<ExecutionContextTask> task, const String& taskNameForInstrumentation) |
| 61 { | 63 { |
| 62 if (!taskNameForInstrumentation.isEmpty()) | 64 if (!taskNameForInstrumentation.isEmpty()) |
| 63 InspectorInstrumentation::asyncTaskScheduled(m_context, taskNameForInstr umentation, task.get()); | 65 InspectorInstrumentation::asyncTaskScheduled(m_context, taskNameForInstr umentation, task.get()); |
| 64 const bool instrumenting = !taskNameForInstrumentation.isEmpty(); | 66 const bool instrumenting = !taskNameForInstrumentation.isEmpty(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 while (!m_pendingTasks.isEmpty()) { | 114 while (!m_pendingTasks.isEmpty()) { |
| 113 std::unique_ptr<ExecutionContextTask> task = std::move(m_pendingTasks[0] .first); | 115 std::unique_ptr<ExecutionContextTask> task = std::move(m_pendingTasks[0] .first); |
| 114 const bool instrumenting = m_pendingTasks[0].second; | 116 const bool instrumenting = m_pendingTasks[0].second; |
| 115 m_pendingTasks.remove(0); | 117 m_pendingTasks.remove(0); |
| 116 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), ins trumenting); | 118 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), ins trumenting); |
| 117 task->performTask(m_context); | 119 task->performTask(m_context); |
| 118 } | 120 } |
| 119 } | 121 } |
| 120 | 122 |
| 121 } // namespace blink | 123 } // namespace blink |
| OLD | NEW |