| 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 // This file implements FileStream for POSIX. | 5 // This file implements FileStream for POSIX. |
| 6 | 6 |
| 7 #ifndef NET_BASE_FILE_STREAM_POSIX_H_ | 7 #ifndef NET_BASE_FILE_STREAM_POSIX_H_ |
| 8 #define NET_BASE_FILE_STREAM_POSIX_H_ | 8 #define NET_BASE_FILE_STREAM_POSIX_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/synchronization/waitable_event.h" | |
| 14 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 15 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 16 #include "net/base/file_stream_whence.h" | 15 #include "net/base/file_stream_whence.h" |
| 17 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 18 #include "net/base/net_log.h" | 17 #include "net/base/net_log.h" |
| 19 | 18 |
| 20 class FilePath; | 19 class FilePath; |
| 21 | 20 |
| 21 namespace base { |
| 22 class WaitableEvent; |
| 23 } |
| 24 |
| 22 namespace net { | 25 namespace net { |
| 23 | 26 |
| 24 class IOBuffer; | 27 class IOBuffer; |
| 25 | 28 |
| 26 class NET_EXPORT FileStreamPosix { | 29 class NET_EXPORT FileStreamPosix { |
| 27 public: | 30 public: |
| 28 explicit FileStreamPosix(net::NetLog* net_log); | 31 explicit FileStreamPosix(net::NetLog* net_log); |
| 29 FileStreamPosix(base::PlatformFile file, int flags, net::NetLog* net_log); | 32 FileStreamPosix(base::PlatformFile file, int flags, net::NetLog* net_log); |
| 30 ~FileStreamPosix(); | 33 ~FileStreamPosix(); |
| 31 | 34 |
| 32 // FileStream implementations. | 35 // FileStream implementations. |
| 33 void Close(const CompletionCallback& callback); | 36 void Close(const CompletionCallback& callback); |
| 34 void CloseSync(); | 37 void CloseSync(); |
| 35 int Open(const FilePath& path, int open_flags, | 38 int Open(const FilePath& path, int open_flags, |
| 36 const CompletionCallback& callback); | 39 const CompletionCallback& callback); |
| 37 int OpenSync(const FilePath& path, int open_flags); | 40 int OpenSync(const FilePath& path, int open_flags); |
| 38 bool IsOpen() const; | 41 bool IsOpen() const; |
| 39 int64 Seek(Whence whence, int64 offset); | 42 int Seek(Whence whence, int64 offset, |
| 43 const Int64CompletionCallback& callback); |
| 44 int64 SeekSync(Whence whence, int64 offset); |
| 40 int64 Available(); | 45 int64 Available(); |
| 41 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 46 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 42 int ReadSync(char* buf, int buf_len); | 47 int ReadSync(char* buf, int buf_len); |
| 43 int ReadUntilComplete(char *buf, int buf_len); | 48 int ReadUntilComplete(char *buf, int buf_len); |
| 44 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 49 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 45 int WriteSync(const char* buf, int buf_len); | 50 int WriteSync(const char* buf, int buf_len); |
| 46 int64 Truncate(int64 bytes); | 51 int64 Truncate(int64 bytes); |
| 47 int Flush(); | 52 int Flush(); |
| 48 void EnableErrorStatistics(); | 53 void EnableErrorStatistics(); |
| 49 void SetBoundNetLogSource( | 54 void SetBoundNetLogSource( |
| 50 const net::BoundNetLog& owner_bound_net_log); | 55 const net::BoundNetLog& owner_bound_net_log); |
| 51 base::PlatformFile GetPlatformFileForTesting(); | 56 base::PlatformFile GetPlatformFileForTesting(); |
| 52 | 57 |
| 58 // Resets on_io_complete_. |
| 59 // Called when Read() or Write() is completed. |
| 60 void ResetOnIOComplete(); |
| 61 |
| 53 private: | 62 private: |
| 54 // Called when the file_ is closed asynchronously. | 63 // Called when the file_ is closed asynchronously. |
| 55 void OnClosed(); | 64 void OnClosed(const CompletionCallback& callback); |
| 56 | |
| 57 // Called when Read() or Write() is completed (used only for POSIX). | |
| 58 // |result| contains the result as a network error code. | |
| 59 void OnIOComplete(int* result); | |
| 60 | 65 |
| 61 // Waits until the in-flight async open/close/read/write operation is | 66 // Waits until the in-flight async open/close/read/write operation is |
| 62 // complete. | 67 // complete. |
| 63 void WaitForIOCompletion(); | 68 void WaitForIOCompletion(); |
| 64 | 69 |
| 65 base::PlatformFile file_; | 70 base::PlatformFile file_; |
| 66 int open_flags_; | 71 int open_flags_; |
| 67 bool auto_closed_; | 72 bool auto_closed_; |
| 68 bool record_uma_; | 73 bool record_uma_; |
| 69 net::BoundNetLog bound_net_log_; | 74 net::BoundNetLog bound_net_log_; |
| 70 base::WeakPtrFactory<FileStreamPosix> weak_ptr_factory_; | 75 base::WeakPtrFactory<FileStreamPosix> weak_ptr_factory_; |
| 71 CompletionCallback callback_; | |
| 72 scoped_ptr<base::WaitableEvent> on_io_complete_; | 76 scoped_ptr<base::WaitableEvent> on_io_complete_; |
| 73 | 77 |
| 74 DISALLOW_COPY_AND_ASSIGN(FileStreamPosix); | 78 DISALLOW_COPY_AND_ASSIGN(FileStreamPosix); |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 } // namespace net | 81 } // namespace net |
| 78 | 82 |
| 79 #endif // NET_BASE_FILE_STREAM_POSIX_H | 83 #endif // NET_BASE_FILE_STREAM_POSIX_H |
| OLD | NEW |