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

Side by Side Diff: third_party/WebKit/Source/platform/WebTaskRunner.cpp

Issue 2482813002: Cancel a task associated to TaskHandle when the TaskHandle is overridden (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/WebTaskRunnerTest.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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/WebTaskRunner.h" 5 #include "platform/WebTaskRunner.h"
6 6
7 #include "base/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 } 65 }
66 66
67 TaskHandle::TaskHandle() = default; 67 TaskHandle::TaskHandle() = default;
68 68
69 TaskHandle::~TaskHandle() { 69 TaskHandle::~TaskHandle() {
70 cancel(); 70 cancel();
71 } 71 }
72 72
73 TaskHandle::TaskHandle(TaskHandle&&) = default; 73 TaskHandle::TaskHandle(TaskHandle&&) = default;
74 TaskHandle& TaskHandle::operator=(TaskHandle&&) = default; 74
75 TaskHandle& TaskHandle::operator=(TaskHandle&& other) {
76 TaskHandle tmp(std::move(other));
77 m_runner.swap(tmp.m_runner);
78 return *this;
79 }
75 80
76 TaskHandle::TaskHandle(RefPtr<Runner> runner) : m_runner(std::move(runner)) { 81 TaskHandle::TaskHandle(RefPtr<Runner> runner) : m_runner(std::move(runner)) {
77 DCHECK(m_runner); 82 DCHECK(m_runner);
78 } 83 }
79 84
80 void WebTaskRunner::postTask(const WebTraceLocation& location, 85 void WebTaskRunner::postTask(const WebTraceLocation& location,
81 std::unique_ptr<CrossThreadClosure> task) { 86 std::unique_ptr<CrossThreadClosure> task) {
82 toSingleThreadTaskRunner()->PostTask(location, 87 toSingleThreadTaskRunner()->PostTask(location,
83 convertToBaseCallback(std::move(task))); 88 convertToBaseCallback(std::move(task)));
84 } 89 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 DCHECK(runsTasksOnCurrentThread()); 128 DCHECK(runsTasksOnCurrentThread());
124 RefPtr<TaskHandle::Runner> runner = 129 RefPtr<TaskHandle::Runner> runner =
125 adoptRef(new TaskHandle::Runner(std::move(task))); 130 adoptRef(new TaskHandle::Runner(std::move(task)));
126 postDelayedTask(location, WTF::bind(&TaskHandle::Runner::run, 131 postDelayedTask(location, WTF::bind(&TaskHandle::Runner::run,
127 runner->asWeakPtr(), TaskHandle(runner)), 132 runner->asWeakPtr(), TaskHandle(runner)),
128 delayMs); 133 delayMs);
129 return TaskHandle(runner); 134 return TaskHandle(runner);
130 } 135 }
131 136
132 } // namespace blink 137 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/WebTaskRunnerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698