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(); | |
53 void EnableErrorStatistics(); | |
54 void SetBoundNetLogSource(const net::BoundNetLog& owner_bound_net_log); | |
55 base::PlatformFile GetPlatformFileForTesting(); | |
56 | |
57 private: | |
58 class AsyncContext; | |
59 | |
60 // A helper method for Seek. | |
61 void SeekFile(Whence whence, int64 offset, int64* result); | |
62 | |
63 // Called when the file_ is opened asynchronously. |result| contains the | |
64 // result as a network error code. | |
65 void OnOpened(const CompletionCallback& callback, int* result); | |
66 | |
67 // Called when the file_ is closed asynchronously. | |
68 void OnClosed(const CompletionCallback& callback); | |
69 | |
70 // Called when the file_ is seeked asynchronously. | |
71 void OnSeeked(const Int64CompletionCallback& callback, int64* result); | |
72 | |
73 // Resets on_io_complete_ and WeakPtr's. | |
74 // Called in OnOpened, OnClosed and OnSeeked. | |
75 void ResetOnIOComplete(); | |
76 | |
77 // Waits until the in-flight async open/close operation is complete. | |
78 void WaitForIOCompletion(); | |
79 | |
80 // This member is used to support asynchronous reads. It is non-null when | |
81 // the FileStreamWin was opened with PLATFORM_FILE_ASYNC. | |
82 scoped_ptr<AsyncContext> async_context_; | |
83 | |
84 base::PlatformFile file_; | |
85 int open_flags_; | |
86 bool auto_closed_; | |
87 bool record_uma_; | |
88 net::BoundNetLog bound_net_log_; | |
89 base::WeakPtrFactory<FileStreamWin> weak_ptr_factory_; | |
90 scoped_ptr<base::WaitableEvent> on_io_complete_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(FileStreamWin); | |
93 }; | |
94 | |
95 } // namespace net | |
96 | |
97 #endif // NET_BASE_FILE_STREAM_WIN_H_ | |
OLD | NEW |