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

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

Issue 10701050: net: Implement canceling of all async operations in FileStream. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
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 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"
12 #include "base/memory/weak_ptr.h"
13 #include "base/platform_file.h" 11 #include "base/platform_file.h"
14 #include "net/base/completion_callback.h" 12 #include "net/base/completion_callback.h"
15 #include "net/base/file_stream_whence.h" 13 #include "net/base/file_stream_whence.h"
16 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
17 #include "net/base/net_log.h" 15 #include "net/base/net_log.h"
18 16
19 class FilePath; 17 class FilePath;
20 18
21 namespace base { 19 namespace base {
22 class WaitableEvent; 20 class WaitableEvent;
23 } 21 }
24 22
25 namespace net { 23 namespace net {
26 24
27 class IOBuffer; 25 class IOBuffer;
28 26
29 class NET_EXPORT FileStreamPosix { 27 class NET_EXPORT FileStreamPosix {
30 public: 28 public:
31 explicit FileStreamPosix(net::NetLog* net_log); 29 explicit FileStreamPosix(net::NetLog* net_log);
32 FileStreamPosix(base::PlatformFile file, int flags, net::NetLog* net_log); 30 FileStreamPosix(base::PlatformFile file, int flags, net::NetLog* net_log);
33 ~FileStreamPosix(); 31 ~FileStreamPosix();
34 32
35 // FileStream implementations. 33 // FileStream implementations.
36 void Close(const CompletionCallback& callback); 34 void Close(const CompletionCallback& callback);
37 void CloseSync(); 35 void CloseSync();
36 void CloseAndCancelAsync();
38 int Open(const FilePath& path, int open_flags, 37 int Open(const FilePath& path, int open_flags,
39 const CompletionCallback& callback); 38 const CompletionCallback& callback);
40 int OpenSync(const FilePath& path, int open_flags); 39 int OpenSync(const FilePath& path, int open_flags);
41 bool IsOpen() const; 40 bool IsOpen() const;
42 int Seek(Whence whence, int64 offset, 41 int Seek(Whence whence, int64 offset,
43 const Int64CompletionCallback& callback); 42 const Int64CompletionCallback& callback);
44 int64 SeekSync(Whence whence, int64 offset); 43 int64 SeekSync(Whence whence, int64 offset);
45 int64 Available(); 44 int64 Available();
46 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); 45 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
47 int ReadSync(char* buf, int buf_len); 46 int ReadSync(char* buf, int buf_len);
48 int ReadUntilComplete(char *buf, int buf_len); 47 int ReadUntilComplete(char *buf, int buf_len);
49 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); 48 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
50 int WriteSync(const char* buf, int buf_len); 49 int WriteSync(const char* buf, int buf_len);
51 int64 Truncate(int64 bytes); 50 int64 Truncate(int64 bytes);
52 int Flush(); 51 int Flush();
53 void EnableErrorStatistics(); 52 void EnableErrorStatistics();
54 void SetBoundNetLogSource( 53 void SetBoundNetLogSource(
55 const net::BoundNetLog& owner_bound_net_log); 54 const net::BoundNetLog& owner_bound_net_log);
56 base::PlatformFile GetPlatformFileForTesting(); 55 base::PlatformFile GetPlatformFileForTesting();
57 56
58 // Resets on_io_complete_ and WeakPtr's. 57 private:
59 // Called when Read() or Write() is completed. 58 class AsyncContext;
60 void ResetOnIOComplete();
61 59
62 private: 60 bool is_async() { return !!(open_flags_ & base::PLATFORM_FILE_ASYNC); }
63 // Called when the file_ is closed asynchronously.
64 void OnClosed(const CompletionCallback& callback);
65 61
66 // Waits until the in-flight async open/close/read/write operation is 62 // Context performing I/O operations. Despite its name the context is used
67 // complete. 63 // for synchronous operations too, but it was extracted into separate class
68 void WaitForIOCompletion(); 64 // to perform asynchronous operations correctly.
65 AsyncContext* context_;
69 66
70 base::PlatformFile file_;
71 int open_flags_; 67 int open_flags_;
72 bool auto_closed_;
73 bool record_uma_;
74 net::BoundNetLog bound_net_log_; 68 net::BoundNetLog bound_net_log_;
75 base::WeakPtrFactory<FileStreamPosix> weak_ptr_factory_;
76 scoped_ptr<base::WaitableEvent> on_io_complete_;
77 69
78 DISALLOW_COPY_AND_ASSIGN(FileStreamPosix); 70 DISALLOW_COPY_AND_ASSIGN(FileStreamPosix);
79 }; 71 };
80 72
81 } // namespace net 73 } // namespace net
82 74
83 #endif // NET_BASE_FILE_STREAM_POSIX_H 75 #endif // NET_BASE_FILE_STREAM_POSIX_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698