| 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 "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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (IsOpen()) { | 86 if (IsOpen()) { |
| 87 DLOG(FATAL) << "File is already open!"; | 87 DLOG(FATAL) << "File is already open!"; |
| 88 return ERR_UNEXPECTED; | 88 return ERR_UNEXPECTED; |
| 89 } | 89 } |
| 90 | 90 |
| 91 open_flags_ = open_flags; | 91 open_flags_ = open_flags; |
| 92 DCHECK(!is_async()); | 92 DCHECK(!is_async()); |
| 93 return context_->OpenSync(path, open_flags_); | 93 return context_->OpenSync(path, open_flags_); |
| 94 } | 94 } |
| 95 | 95 |
| 96 int FileStream::Close(const CompletionCallback& callback) { |
| 97 if (!is_async()) { |
| 98 context_->CloseSync(); |
| 99 context_.reset(); |
| 100 return OK; |
| 101 } |
| 102 context_->CloseAsync(callback); |
| 103 return ERR_IO_PENDING; |
| 104 } |
| 105 |
| 96 bool FileStream::IsOpen() const { | 106 bool FileStream::IsOpen() const { |
| 97 return context_->file() != base::kInvalidPlatformFileValue; | 107 return context_->file() != base::kInvalidPlatformFileValue; |
| 98 } | 108 } |
| 99 | 109 |
| 100 int FileStream::Seek(Whence whence, | 110 int FileStream::Seek(Whence whence, |
| 101 int64 offset, | 111 int64 offset, |
| 102 const Int64CompletionCallback& callback) { | 112 const Int64CompletionCallback& callback) { |
| 103 if (!IsOpen()) | 113 if (!IsOpen()) |
| 104 return ERR_UNEXPECTED; | 114 return ERR_UNEXPECTED; |
| 105 | 115 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 286 |
| 277 owner_bound_net_log.AddEvent(NetLog::TYPE_FILE_STREAM_SOURCE, | 287 owner_bound_net_log.AddEvent(NetLog::TYPE_FILE_STREAM_SOURCE, |
| 278 bound_net_log_.source().ToEventParametersCallback()); | 288 bound_net_log_.source().ToEventParametersCallback()); |
| 279 } | 289 } |
| 280 | 290 |
| 281 base::PlatformFile FileStream::GetPlatformFileForTesting() { | 291 base::PlatformFile FileStream::GetPlatformFileForTesting() { |
| 282 return context_->file(); | 292 return context_->file(); |
| 283 } | 293 } |
| 284 | 294 |
| 285 } // namespace net | 295 } // namespace net |
| OLD | NEW |