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

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

Issue 211483004: Remove some PlatformFile instances from ChromeOS Drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change FileStream destruction logic Created 6 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 | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream_context.h ('k') | no next file » | 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 file_ = open_result.file.Pass(); 267 file_ = open_result.file.Pass();
268 OnAsyncFileOpened(); 268 OnAsyncFileOpened();
269 } 269 }
270 OnAsyncCompleted(IntToInt64(callback), open_result.error_code.result); 270 OnAsyncCompleted(IntToInt64(callback), open_result.error_code.result);
271 } 271 }
272 272
273 void FileStream::Context::CloseAndDelete() { 273 void FileStream::Context::CloseAndDelete() {
274 DCHECK(!async_in_progress_); 274 DCHECK(!async_in_progress_);
275 275
276 if (file_.IsValid()) { 276 if (file_.IsValid()) {
277 bool posted = task_runner_.get()->PostTaskAndReply( 277 bool posted = task_runner_.get()->PostTask(
278 FROM_HERE, 278 FROM_HERE,
279 base::Bind(base::IgnoreResult(&Context::CloseFileImpl), 279 base::Bind(base::IgnoreResult(&Context::CloseFileImpl),
280 base::Unretained(this)), 280 base::Owned(this)));
281 base::Bind(&Context::OnCloseCompleted, base::Unretained(this)));
282 DCHECK(posted); 281 DCHECK(posted);
283 } else { 282 } else {
284 delete this; 283 delete this;
285 } 284 }
286 } 285 }
287 286
288 void FileStream::Context::OnCloseCompleted() {
289 delete this;
290 }
291
292 Int64CompletionCallback FileStream::Context::IntToInt64( 287 Int64CompletionCallback FileStream::Context::IntToInt64(
293 const CompletionCallback& callback) { 288 const CompletionCallback& callback) {
294 return base::Bind(&CallInt64ToInt, callback); 289 return base::Bind(&CallInt64ToInt, callback);
295 } 290 }
296 291
297 void FileStream::Context::ProcessAsyncResult( 292 void FileStream::Context::ProcessAsyncResult(
298 const Int64CompletionCallback& callback, 293 const Int64CompletionCallback& callback,
299 FileErrorSource source, 294 FileErrorSource source,
300 const IOResult& result) { 295 const IOResult& result) {
301 RecordError(result, source); 296 RecordError(result, source);
302 OnAsyncCompleted(callback, result.result); 297 OnAsyncCompleted(callback, result.result);
303 } 298 }
304 299
305 void FileStream::Context::OnAsyncCompleted( 300 void FileStream::Context::OnAsyncCompleted(
306 const Int64CompletionCallback& callback, 301 const Int64CompletionCallback& callback,
307 int64 result) { 302 int64 result) {
308 // Reset this before Run() as Run() may issue a new async operation. Also it 303 // Reset this before Run() as Run() may issue a new async operation. Also it
309 // should be reset before CloseAsync() because it shouldn't run if any async 304 // should be reset before CloseAsync() because it shouldn't run if any async
310 // operation is in progress. 305 // operation is in progress.
311 async_in_progress_ = false; 306 async_in_progress_ = false;
312 if (orphaned_) 307 if (orphaned_)
313 CloseAndDelete(); 308 CloseAndDelete();
314 else 309 else
315 callback.Run(result); 310 callback.Run(result);
316 } 311 }
317 312
318 } // namespace net 313 } // namespace net
319 314
OLDNEW
« no previous file with comments | « net/base/file_stream_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698