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

Side by Side Diff: base/files/file_descriptor_watcher_posix.cc

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase Created 3 years, 8 months 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 | « base/deferred_sequenced_task_runner_unittest.cc ('k') | base/files/file_path_watcher_linux.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/files/file_descriptor_watcher_posix.h" 5 #include "base/files/file_descriptor_watcher_posix.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 } 118 }
119 119
120 void FileDescriptorWatcher::Controller::Watcher::OnFileCanReadWithoutBlocking( 120 void FileDescriptorWatcher::Controller::Watcher::OnFileCanReadWithoutBlocking(
121 int fd) { 121 int fd) {
122 DCHECK_EQ(fd_, fd); 122 DCHECK_EQ(fd_, fd);
123 DCHECK_EQ(MessageLoopForIO::WATCH_READ, mode_); 123 DCHECK_EQ(MessageLoopForIO::WATCH_READ, mode_);
124 DCHECK(thread_checker_.CalledOnValidThread()); 124 DCHECK(thread_checker_.CalledOnValidThread());
125 125
126 // Run the callback on the sequence on which the watch was initiated. 126 // Run the callback on the sequence on which the watch was initiated.
127 callback_task_runner_->PostTask(FROM_HERE, 127 callback_task_runner_->PostTask(
128 Bind(&Controller::RunCallback, controller_)); 128 FROM_HERE, BindOnce(&Controller::RunCallback, controller_));
129 } 129 }
130 130
131 void FileDescriptorWatcher::Controller::Watcher::OnFileCanWriteWithoutBlocking( 131 void FileDescriptorWatcher::Controller::Watcher::OnFileCanWriteWithoutBlocking(
132 int fd) { 132 int fd) {
133 DCHECK_EQ(fd_, fd); 133 DCHECK_EQ(fd_, fd);
134 DCHECK_EQ(MessageLoopForIO::WATCH_WRITE, mode_); 134 DCHECK_EQ(MessageLoopForIO::WATCH_WRITE, mode_);
135 DCHECK(thread_checker_.CalledOnValidThread()); 135 DCHECK(thread_checker_.CalledOnValidThread());
136 136
137 // Run the callback on the sequence on which the watch was initiated. 137 // Run the callback on the sequence on which the watch was initiated.
138 callback_task_runner_->PostTask(FROM_HERE, 138 callback_task_runner_->PostTask(
139 Bind(&Controller::RunCallback, controller_)); 139 FROM_HERE, BindOnce(&Controller::RunCallback, controller_));
140 } 140 }
141 141
142 void FileDescriptorWatcher::Controller::Watcher:: 142 void FileDescriptorWatcher::Controller::Watcher::
143 WillDestroyCurrentMessageLoop() { 143 WillDestroyCurrentMessageLoop() {
144 DCHECK(thread_checker_.CalledOnValidThread()); 144 DCHECK(thread_checker_.CalledOnValidThread());
145 145
146 // A Watcher is owned by a Controller. When the Controller is deleted, it 146 // A Watcher is owned by a Controller. When the Controller is deleted, it
147 // transfers ownership of the Watcher to a delete task posted to the 147 // transfers ownership of the Watcher to a delete task posted to the
148 // MessageLoopForIO. If the MessageLoopForIO is deleted before the delete task 148 // MessageLoopForIO. If the MessageLoopForIO is deleted before the delete task
149 // runs, the following line takes care of deleting the Watcher. 149 // runs, the following line takes care of deleting the Watcher.
(...skipping 13 matching lines...) Expand all
163 StartWatching(); 163 StartWatching();
164 } 164 }
165 165
166 void FileDescriptorWatcher::Controller::StartWatching() { 166 void FileDescriptorWatcher::Controller::StartWatching() {
167 DCHECK(sequence_checker_.CalledOnValidSequence()); 167 DCHECK(sequence_checker_.CalledOnValidSequence());
168 // It is safe to use Unretained() below because |watcher_| can only be deleted 168 // It is safe to use Unretained() below because |watcher_| can only be deleted
169 // by a delete task posted to |message_loop_for_io_task_runner_| by this 169 // by a delete task posted to |message_loop_for_io_task_runner_| by this
170 // Controller's destructor. Since this delete task hasn't been posted yet, it 170 // Controller's destructor. Since this delete task hasn't been posted yet, it
171 // can't run before the task posted below. 171 // can't run before the task posted below.
172 message_loop_for_io_task_runner_->PostTask( 172 message_loop_for_io_task_runner_->PostTask(
173 FROM_HERE, Bind(&Watcher::StartWatching, Unretained(watcher_.get()))); 173 FROM_HERE, BindOnce(&Watcher::StartWatching, Unretained(watcher_.get())));
174 } 174 }
175 175
176 void FileDescriptorWatcher::Controller::RunCallback() { 176 void FileDescriptorWatcher::Controller::RunCallback() {
177 DCHECK(sequence_checker_.CalledOnValidSequence()); 177 DCHECK(sequence_checker_.CalledOnValidSequence());
178 178
179 WeakPtr<Controller> weak_this = weak_factory_.GetWeakPtr(); 179 WeakPtr<Controller> weak_this = weak_factory_.GetWeakPtr();
180 180
181 callback_.Run(); 181 callback_.Run();
182 182
183 // If |this| wasn't deleted, re-enable the watch. 183 // If |this| wasn't deleted, re-enable the watch.
(...skipping 17 matching lines...) Expand all
201 return WrapUnique(new Controller(MessageLoopForIO::WATCH_READ, fd, callback)); 201 return WrapUnique(new Controller(MessageLoopForIO::WATCH_READ, fd, callback));
202 } 202 }
203 203
204 std::unique_ptr<FileDescriptorWatcher::Controller> 204 std::unique_ptr<FileDescriptorWatcher::Controller>
205 FileDescriptorWatcher::WatchWritable(int fd, const Closure& callback) { 205 FileDescriptorWatcher::WatchWritable(int fd, const Closure& callback) {
206 return WrapUnique( 206 return WrapUnique(
207 new Controller(MessageLoopForIO::WATCH_WRITE, fd, callback)); 207 new Controller(MessageLoopForIO::WATCH_WRITE, fd, callback));
208 } 208 }
209 209
210 } // namespace base 210 } // namespace base
OLDNEW
« no previous file with comments | « base/deferred_sequenced_task_runner_unittest.cc ('k') | base/files/file_path_watcher_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698