| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context) | 38 MainThreadTaskRunner::MainThreadTaskRunner(ExecutionContext* context) |
| 39 : m_context(context), | 39 : m_context(context), |
| 40 m_weakFactory(this), | 40 m_weakFactory(this), |
| 41 // 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 |
| 42 // postTask. | 42 // postTask. |
| 43 m_weakPtr(m_weakFactory.createWeakPtr()) {} | 43 m_weakPtr(m_weakFactory.createWeakPtr()) {} |
| 44 | 44 |
| 45 MainThreadTaskRunner::~MainThreadTaskRunner() {} | 45 MainThreadTaskRunner::~MainThreadTaskRunner() {} |
| 46 | 46 |
| 47 void MainThreadTaskRunner::postTaskInternal( | |
| 48 const WebTraceLocation& location, | |
| 49 std::unique_ptr<ExecutionContextTask> task, | |
| 50 bool isInspectorTask, | |
| 51 bool instrumenting) { | |
| 52 Platform::current()->mainThread()->getWebTaskRunner()->postTask( | |
| 53 location, | |
| 54 crossThreadBind(&MainThreadTaskRunner::perform, m_weakPtr, | |
| 55 passed(std::move(task)), isInspectorTask, instrumenting)); | |
| 56 } | |
| 57 | |
| 58 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, | 47 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, |
| 59 std::unique_ptr<ExecutionContextTask> task, | 48 std::unique_ptr<ExecutionContextTask> task, |
| 60 const String& taskNameForInstrumentation) { | 49 const String& taskNameForInstrumentation) { |
| 61 if (!taskNameForInstrumentation.isEmpty()) | 50 if (!taskNameForInstrumentation.isEmpty()) |
| 62 InspectorInstrumentation::asyncTaskScheduled( | 51 InspectorInstrumentation::asyncTaskScheduled( |
| 63 m_context, taskNameForInstrumentation, task.get()); | 52 m_context, taskNameForInstrumentation, task.get()); |
| 64 const bool instrumenting = !taskNameForInstrumentation.isEmpty(); | 53 const bool instrumenting = !taskNameForInstrumentation.isEmpty(); |
| 65 postTaskInternal(location, std::move(task), false, instrumenting); | 54 Platform::current()->mainThread()->getWebTaskRunner()->postTask( |
| 66 } | 55 location, crossThreadBind(&MainThreadTaskRunner::perform, m_weakPtr, |
| 67 | 56 passed(std::move(task)), instrumenting)); |
| 68 void MainThreadTaskRunner::postInspectorTask( | |
| 69 const WebTraceLocation& location, | |
| 70 std::unique_ptr<ExecutionContextTask> task) { | |
| 71 postTaskInternal(location, std::move(task), true, false); | |
| 72 } | 57 } |
| 73 | 58 |
| 74 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task, | 59 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task, |
| 75 bool isInspectorTask, | |
| 76 bool instrumenting) { | 60 bool instrumenting) { |
| 77 // If the owner m_context is about to be swept then it | 61 // If the owner m_context is about to be swept then it |
| 78 // is no longer safe to access. | 62 // is no longer safe to access. |
| 79 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) | 63 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) |
| 80 return; | 64 return; |
| 81 | 65 |
| 82 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), | 66 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), |
| 83 !isInspectorTask); | 67 instrumenting); |
| 84 task->performTask(m_context); | 68 task->performTask(m_context); |
| 85 } | 69 } |
| 86 | 70 |
| 87 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |