Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: net/base/file_stream_win.h

Issue 9949011: Make FileStream::Seek async and add FileStream::SeekSync for sync operation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream_unittest.cc ('k') | net/base/file_stream_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 Windows. 5 // This file implements FileStream for Windows.
6 6
7 #ifndef NET_BASE_FILE_STREAM_WIN_H_ 7 #ifndef NET_BASE_FILE_STREAM_WIN_H_
8 #define NET_BASE_FILE_STREAM_WIN_H_ 8 #define NET_BASE_FILE_STREAM_WIN_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/platform_file.h" 13 #include "base/platform_file.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/file_stream_whence.h" 16 #include "net/base/file_stream_whence.h"
17 #include "net/base/net_export.h" 17 #include "net/base/net_export.h"
18 #include "net/base/net_log.h" 18 #include "net/base/net_log.h"
19 19
20 class FilePath; 20 class FilePath;
21 21
22 namespace base {
23 class WaitableEvent;
24 }
25
22 namespace net { 26 namespace net {
23 27
24 class IOBuffer; 28 class IOBuffer;
25 29
26 class NET_EXPORT FileStreamWin { 30 class NET_EXPORT FileStreamWin {
27 public: 31 public:
28 explicit FileStreamWin(net::NetLog* net_log); 32 explicit FileStreamWin(net::NetLog* net_log);
29 FileStreamWin(base::PlatformFile file, int flags, net::NetLog* net_log); 33 FileStreamWin(base::PlatformFile file, int flags, net::NetLog* net_log);
30 ~FileStreamWin(); 34 ~FileStreamWin();
31 35
32 // FileStream implementations. 36 // FileStream implementations.
33 void Close(const CompletionCallback& callback); 37 void Close(const CompletionCallback& callback);
34 void CloseSync(); 38 void CloseSync();
35 int Open(const FilePath& path, int open_flags, 39 int Open(const FilePath& path, int open_flags,
36 const CompletionCallback& callback); 40 const CompletionCallback& callback);
37 int OpenSync(const FilePath& path, int open_flags); 41 int OpenSync(const FilePath& path, int open_flags);
38 bool IsOpen() const; 42 bool IsOpen() const;
39 int64 Seek(Whence whence, int64 offset); 43 int Seek(Whence whence, int64 offset,
44 const Int64CompletionCallback& callback);
45 int64 SeekSync(Whence whence, int64 offset);
40 int64 Available(); 46 int64 Available();
41 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); 47 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
42 int ReadSync(char* buf, int buf_len); 48 int ReadSync(char* buf, int buf_len);
43 int ReadUntilComplete(char *buf, int buf_len); 49 int ReadUntilComplete(char *buf, int buf_len);
44 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); 50 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
45 int WriteSync(const char* buf, int buf_len); 51 int WriteSync(const char* buf, int buf_len);
46 int64 Truncate(int64 bytes); 52 int64 Truncate(int64 bytes);
47 int Flush(); 53 int Flush();
48 void EnableErrorStatistics(); 54 void EnableErrorStatistics();
49 void SetBoundNetLogSource(const net::BoundNetLog& owner_bound_net_log); 55 void SetBoundNetLogSource(const net::BoundNetLog& owner_bound_net_log);
50 base::PlatformFile GetPlatformFileForTesting(); 56 base::PlatformFile GetPlatformFileForTesting();
51 57
52 private: 58 private:
53 class AsyncContext; 59 class AsyncContext;
54 friend class AsyncContext; 60
61 // A helper method for Seek.
62 void SeekFile(Whence whence, int64 offset, int64* result);
55 63
56 // Called when the file_ is opened asynchronously. |result| contains the 64 // Called when the file_ is opened asynchronously. |result| contains the
57 // result as a network error code. 65 // result as a network error code.
58 void OnOpened(int* result); 66 void OnOpened(const CompletionCallback& callback, int* result);
59 67
60 // Called when the file_ is closed asynchronously. 68 // Called when the file_ is closed asynchronously.
61 void OnClosed(); 69 void OnClosed(const CompletionCallback& callback);
70
71 // Called when the file_ is seeked asynchronously.
72 void OnSeeked(const Int64CompletionCallback& callback, int64* result);
73
74 // Resets on_io_complete_ and WeakPtr's.
75 // Called in OnOpened, OnClosed and OnSeeked.
76 void ResetOnIOComplete();
62 77
63 // Waits until the in-flight async open/close operation is complete. 78 // Waits until the in-flight async open/close operation is complete.
64 void WaitForIOCompletion(); 79 void WaitForIOCompletion();
65 80
66 // This member is used to support asynchronous reads. It is non-null when 81 // This member is used to support asynchronous reads. It is non-null when
67 // the FileStreamWin was opened with PLATFORM_FILE_ASYNC. 82 // the FileStreamWin was opened with PLATFORM_FILE_ASYNC.
68 scoped_ptr<AsyncContext> async_context_; 83 scoped_ptr<AsyncContext> async_context_;
69 84
70 base::PlatformFile file_; 85 base::PlatformFile file_;
71 int open_flags_; 86 int open_flags_;
72 bool auto_closed_; 87 bool auto_closed_;
73 bool record_uma_; 88 bool record_uma_;
74 net::BoundNetLog bound_net_log_; 89 net::BoundNetLog bound_net_log_;
75 base::WeakPtrFactory<FileStreamWin> weak_ptr_factory_; 90 base::WeakPtrFactory<FileStreamWin> weak_ptr_factory_;
76 CompletionCallback callback_;
77 scoped_ptr<base::WaitableEvent> on_io_complete_; 91 scoped_ptr<base::WaitableEvent> on_io_complete_;
78 92
79 DISALLOW_COPY_AND_ASSIGN(FileStreamWin); 93 DISALLOW_COPY_AND_ASSIGN(FileStreamWin);
80 }; 94 };
81 95
82 } // namespace net 96 } // namespace net
83 97
84 #endif // NET_BASE_FILE_STREAM_WIN_H_ 98 #endif // NET_BASE_FILE_STREAM_WIN_H_
OLDNEW
« no previous file with comments | « net/base/file_stream_unittest.cc ('k') | net/base/file_stream_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698