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

Side by Side Diff: net/base/file_stream_context.cc

Issue 250783002: net: Make sure the FileStream file is closed on the worker thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use an explicit worker pool Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/file_stream_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/file_stream_context.h" 5 #include "net/base/file_stream_context.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return OpenResult(file.Pass(), IOResult(OK, 0)); 175 return OpenResult(file.Pass(), IOResult(OK, 0));
176 } 176 }
177 177
178 FileStream::Context::IOResult FileStream::Context::CloseFileImpl() { 178 FileStream::Context::IOResult FileStream::Context::CloseFileImpl() {
179 file_.Close(); 179 file_.Close();
180 return IOResult(OK, 0); 180 return IOResult(OK, 0);
181 } 181 }
182 182
183 void FileStream::Context::OnOpenCompleted(const CompletionCallback& callback, 183 void FileStream::Context::OnOpenCompleted(const CompletionCallback& callback,
184 OpenResult open_result) { 184 OpenResult open_result) {
185 if (open_result.file.IsValid() && !orphaned_) { 185 file_ = open_result.file.Pass();
186 file_ = open_result.file.Pass(); 186 if (file_.IsValid() && !orphaned_)
187 OnAsyncFileOpened(); 187 OnAsyncFileOpened();
188 } 188
189 OnAsyncCompleted(IntToInt64(callback), open_result.error_code); 189 OnAsyncCompleted(IntToInt64(callback), open_result.error_code);
190 } 190 }
191 191
192 void FileStream::Context::CloseAndDelete() { 192 void FileStream::Context::CloseAndDelete() {
193 DCHECK(!async_in_progress_); 193 DCHECK(!async_in_progress_);
194 194
195 if (file_.IsValid()) { 195 if (file_.IsValid()) {
196 bool posted = task_runner_.get()->PostTask( 196 bool posted = task_runner_.get()->PostTask(
197 FROM_HERE, 197 FROM_HERE,
198 base::Bind(base::IgnoreResult(&Context::CloseFileImpl), 198 base::Bind(base::IgnoreResult(&Context::CloseFileImpl),
(...skipping 16 matching lines...) Expand all
215 // should be reset before CloseAsync() because it shouldn't run if any async 215 // should be reset before CloseAsync() because it shouldn't run if any async
216 // operation is in progress. 216 // operation is in progress.
217 async_in_progress_ = false; 217 async_in_progress_ = false;
218 if (orphaned_) 218 if (orphaned_)
219 CloseAndDelete(); 219 CloseAndDelete();
220 else 220 else
221 callback.Run(result.result); 221 callback.Run(result.result);
222 } 222 }
223 223
224 } // namespace net 224 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/file_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698