| OLD | NEW |
| 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.h" | 5 #include "net/base/file_stream.h" |
| 6 | 6 |
| 7 #include "net/base/file_stream_context.h" | 7 #include "net/base/file_stream_context.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 FileStream::FileStream(const scoped_refptr<base::TaskRunner>& task_runner) | 12 FileStream::FileStream(const scoped_refptr<base::TaskRunner>& task_runner) |
| 13 : context_(new Context(task_runner)) { | 13 : context_(new Context(task_runner)) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 FileStream::FileStream(base::File file, | 16 FileStream::FileStream(base::File file, |
| 17 const scoped_refptr<base::TaskRunner>& task_runner) | 17 const scoped_refptr<base::TaskRunner>& task_runner) |
| 18 : context_(new Context(file.Pass(), task_runner)) { | 18 : context_(new Context(file.Pass(), task_runner)) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 FileStream::~FileStream() { | 21 FileStream::~FileStream() { |
| 22 context_.release()->Orphan(); | 22 context_.release()->Orphan(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 int FileStream::Open(const base::FilePath& path, int open_flags, | 25 int FileStream::Open(const base::FilePath& path, |
| 26 int open_flags, |
| 26 const CompletionCallback& callback) { | 27 const CompletionCallback& callback) { |
| 27 if (IsOpen()) { | 28 if (IsOpen()) { |
| 28 DLOG(FATAL) << "File is already open!"; | 29 DLOG(FATAL) << "File is already open!"; |
| 29 return ERR_UNEXPECTED; | 30 return ERR_UNEXPECTED; |
| 30 } | 31 } |
| 31 | 32 |
| 32 DCHECK(open_flags & base::File::FLAG_ASYNC); | 33 DCHECK(open_flags & base::File::FLAG_ASYNC); |
| 33 context_->Open(path, open_flags, callback); | 34 context_->Open(path, open_flags, callback); |
| 34 return ERR_IO_PENDING; | 35 return ERR_IO_PENDING; |
| 35 } | 36 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 82 |
| 82 context_->Flush(callback); | 83 context_->Flush(callback); |
| 83 return ERR_IO_PENDING; | 84 return ERR_IO_PENDING; |
| 84 } | 85 } |
| 85 | 86 |
| 86 const base::File& FileStream::GetFileForTesting() const { | 87 const base::File& FileStream::GetFileForTesting() const { |
| 87 return context_->file(); | 88 return context_->file(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 } // namespace net | 91 } // namespace net |
| OLD | NEW |