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

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

Issue 2534803002: Move InspectorTask handling from MainThreadTaskRunner to Document (Closed)
Patch Set: s/wrapWeakPersistent/wrapCrossThreadWeakPersistent/ 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 28 matching lines...) Expand all
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 43 // Bind a WeakPtr now to avoid data races creating a WeakPtr inside
44 // postTask. 44 // postTask.
45 m_weakPtr(m_weakFactory.createWeakPtr()) {} 45 m_weakPtr(m_weakFactory.createWeakPtr()) {}
46 46
47 MainThreadTaskRunner::~MainThreadTaskRunner() {} 47 MainThreadTaskRunner::~MainThreadTaskRunner() {}
48 48
49 void MainThreadTaskRunner::postTaskInternal(
50 const WebTraceLocation& location,
51 std::unique_ptr<ExecutionContextTask> task,
52 bool isInspectorTask,
53 bool instrumenting) {
54 Platform::current()->mainThread()->getWebTaskRunner()->postTask(
55 location,
56 crossThreadBind(&MainThreadTaskRunner::perform, m_weakPtr,
57 passed(std::move(task)), isInspectorTask, instrumenting));
58 }
59
60 void MainThreadTaskRunner::postTask(const WebTraceLocation& location, 49 void MainThreadTaskRunner::postTask(const WebTraceLocation& location,
61 std::unique_ptr<ExecutionContextTask> task, 50 std::unique_ptr<ExecutionContextTask> task,
62 const String& taskNameForInstrumentation) { 51 const String& taskNameForInstrumentation) {
63 if (!taskNameForInstrumentation.isEmpty()) 52 if (!taskNameForInstrumentation.isEmpty())
64 InspectorInstrumentation::asyncTaskScheduled( 53 InspectorInstrumentation::asyncTaskScheduled(
65 m_context, taskNameForInstrumentation, task.get()); 54 m_context, taskNameForInstrumentation, task.get());
66 const bool instrumenting = !taskNameForInstrumentation.isEmpty(); 55 const bool instrumenting = !taskNameForInstrumentation.isEmpty();
67 postTaskInternal(location, std::move(task), false, instrumenting); 56 Platform::current()->mainThread()->getWebTaskRunner()->postTask(
68 } 57 location, crossThreadBind(&MainThreadTaskRunner::perform, m_weakPtr,
69 58 passed(std::move(task)), instrumenting));
70 void MainThreadTaskRunner::postInspectorTask(
71 const WebTraceLocation& location,
72 std::unique_ptr<ExecutionContextTask> task) {
73 postTaskInternal(location, std::move(task), true, false);
74 } 59 }
75 60
76 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task, 61 void MainThreadTaskRunner::perform(std::unique_ptr<ExecutionContextTask> task,
77 bool isInspectorTask,
78 bool instrumenting) { 62 bool instrumenting) {
79 // If the owner m_context is about to be swept then it 63 // If the owner m_context is about to be swept then it
80 // is no longer safe to access. 64 // is no longer safe to access.
81 if (ThreadHeap::willObjectBeLazilySwept(m_context.get())) 65 if (ThreadHeap::willObjectBeLazilySwept(m_context.get()))
82 return; 66 return;
83 67
84 if (!isInspectorTask && 68 if (m_context->tasksNeedSuspension() || !m_pendingTasks.isEmpty()) {
85 (m_context->tasksNeedSuspension() || !m_pendingTasks.isEmpty())) {
86 m_pendingTasks.append(make_pair(std::move(task), instrumenting)); 69 m_pendingTasks.append(make_pair(std::move(task), instrumenting));
87 return; 70 return;
88 } 71 }
89 72
90 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), 73 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(),
91 !isInspectorTask); 74 instrumenting);
92 task->performTask(m_context); 75 task->performTask(m_context);
93 } 76 }
94 77
95 void MainThreadTaskRunner::suspend() { 78 void MainThreadTaskRunner::suspend() {
96 DCHECK(!m_suspended); 79 DCHECK(!m_suspended);
97 m_pendingTasksTimer.stop(); 80 m_pendingTasksTimer.stop();
98 m_suspended = true; 81 m_suspended = true;
99 } 82 }
100 83
101 void MainThreadTaskRunner::resume() { 84 void MainThreadTaskRunner::resume() {
(...skipping 15 matching lines...) Expand all
117 std::move(m_pendingTasks[0].first); 100 std::move(m_pendingTasks[0].first);
118 const bool instrumenting = m_pendingTasks[0].second; 101 const bool instrumenting = m_pendingTasks[0].second;
119 m_pendingTasks.remove(0); 102 m_pendingTasks.remove(0);
120 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(), 103 InspectorInstrumentation::AsyncTask asyncTask(m_context, task.get(),
121 instrumenting); 104 instrumenting);
122 task->performTask(m_context); 105 task->performTask(m_context);
123 } 106 }
124 } 107 }
125 108
126 } // namespace blink 109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698