| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This file implements FileStream for Windows. | |
| 6 | |
| 7 #ifndef NET_BASE_FILE_STREAM_WIN_H_ | |
| 8 #define NET_BASE_FILE_STREAM_WIN_H_ | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/platform_file.h" | |
| 13 #include "base/synchronization/waitable_event.h" | |
| 14 #include "net/base/completion_callback.h" | |
| 15 #include "net/base/file_stream_whence.h" | |
| 16 #include "net/base/net_export.h" | |
| 17 #include "net/base/net_log.h" | |
| 18 | |
| 19 class FilePath; | |
| 20 | |
| 21 namespace base { | |
| 22 class WaitableEvent; | |
| 23 } | |
| 24 | |
| 25 namespace net { | |
| 26 | |
| 27 class IOBuffer; | |
| 28 | |
| 29 class NET_EXPORT FileStreamWin { | |
| 30 public: | |
| 31 explicit FileStreamWin(net::NetLog* net_log); | |
| 32 FileStreamWin(base::PlatformFile file, int flags, net::NetLog* net_log); | |
| 33 ~FileStreamWin(); | |
| 34 | |
| 35 // FileStream implementations. | |
| 36 void Close(const CompletionCallback& callback); | |
| 37 void CloseSync(); | |
| 38 int Open(const FilePath& path, int open_flags, | |
| 39 const CompletionCallback& callback); | |
| 40 int OpenSync(const FilePath& path, int open_flags); | |
| 41 bool IsOpen() const; | |
| 42 int Seek(Whence whence, int64 offset, | |
| 43 const Int64CompletionCallback& callback); | |
| 44 int64 SeekSync(Whence whence, int64 offset); | |
| 45 int64 Available(); | |
| 46 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | |
| 47 int ReadSync(char* buf, int buf_len); | |
| 48 int ReadUntilComplete(char *buf, int buf_len); | |
| 49 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | |
| 50 int WriteSync(const char* buf, int buf_len); | |
| 51 int64 Truncate(int64 bytes); | |
| 52 int Flush(const CompletionCallback& callback); | |
| 53 int FlushSync(); | |
| 54 void EnableErrorStatistics(); | |
| 55 void SetBoundNetLogSource(const net::BoundNetLog& owner_bound_net_log); | |
| 56 base::PlatformFile GetPlatformFileForTesting(); | |
| 57 | |
| 58 private: | |
| 59 class AsyncContext; | |
| 60 | |
| 61 // A helper method for Seek. | |
| 62 void SeekFile(Whence whence, int64 offset, int64* result); | |
| 63 | |
| 64 // A helper method for Flush. | |
| 65 void FlushFile(int* result); | |
| 66 | |
| 67 // Called when the file_ is opened asynchronously. |result| contains the | |
| 68 // result as a network error code. | |
| 69 void OnOpened(const CompletionCallback& callback, int* result); | |
| 70 | |
| 71 // Called when the file_ is closed asynchronously. | |
| 72 void OnClosed(const CompletionCallback& callback); | |
| 73 | |
| 74 // Called when the file_ is seeked asynchronously. | |
| 75 void OnSeeked(const Int64CompletionCallback& callback, int64* result); | |
| 76 | |
| 77 // Called when the file_ is flushed asynchronously. | |
| 78 void OnFlushed(const CompletionCallback& callback, int* result); | |
| 79 | |
| 80 // Resets on_io_complete_ and WeakPtr's. | |
| 81 // Called in OnOpened, OnClosed and OnSeeked. | |
| 82 void ResetOnIOComplete(); | |
| 83 | |
| 84 // Waits until the in-flight async open/close operation is complete. | |
| 85 void WaitForIOCompletion(); | |
| 86 | |
| 87 // This member is used to support asynchronous reads. It is non-null when | |
| 88 // the FileStreamWin was opened with PLATFORM_FILE_ASYNC. | |
| 89 scoped_ptr<AsyncContext> async_context_; | |
| 90 | |
| 91 base::PlatformFile file_; | |
| 92 int open_flags_; | |
| 93 bool auto_closed_; | |
| 94 bool record_uma_; | |
| 95 net::BoundNetLog bound_net_log_; | |
| 96 base::WeakPtrFactory<FileStreamWin> weak_ptr_factory_; | |
| 97 scoped_ptr<base::WaitableEvent> on_io_complete_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(FileStreamWin); | |
| 100 }; | |
| 101 | |
| 102 } // namespace net | |
| 103 | |
| 104 #endif // NET_BASE_FILE_STREAM_WIN_H_ | |
| OLD | NEW |