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