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

Side by Side Diff: net/base/file_stream_win.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, 4 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 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 9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/platform_file.h" 10 #include "base/platform_file.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "net/base/completion_callback.h" 11 #include "net/base/completion_callback.h"
15 #include "net/base/file_stream_whence.h" 12 #include "net/base/file_stream_whence.h"
16 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
17 #include "net/base/net_log.h" 14 #include "net/base/net_log.h"
18 15
19 class FilePath; 16 class FilePath;
20 17
21 namespace base { 18 namespace base {
22 class WaitableEvent; 19 class WaitableEvent;
23 } 20 }
(...skipping 26 matching lines...) Expand all
50 int WriteSync(const char* buf, int buf_len); 47 int WriteSync(const char* buf, int buf_len);
51 int64 Truncate(int64 bytes); 48 int64 Truncate(int64 bytes);
52 int Flush(); 49 int Flush();
53 void EnableErrorStatistics(); 50 void EnableErrorStatistics();
54 void SetBoundNetLogSource(const net::BoundNetLog& owner_bound_net_log); 51 void SetBoundNetLogSource(const net::BoundNetLog& owner_bound_net_log);
55 base::PlatformFile GetPlatformFileForTesting(); 52 base::PlatformFile GetPlatformFileForTesting();
56 53
57 private: 54 private:
58 class AsyncContext; 55 class AsyncContext;
59 56
60 // A helper method for Seek. 57 bool is_async() { return !!(open_flags_ & base::PLATFORM_FILE_ASYNC); }
61 void SeekFile(Whence whence, int64 offset, int64* result);
62 58
63 // Called when the file_ is opened asynchronously. |result| contains the 59 // Context performing I/O operations. Despite its name the context is used
64 // result as a network error code. 60 // for synchronous operations too, but it was extracted into separate class
65 void OnOpened(const CompletionCallback& callback, int* result); 61 // to perform asynchronous operations correctly.
62 AsyncContext* context_;
66 63
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_; 64 int open_flags_;
86 bool auto_closed_;
87 bool record_uma_;
88 net::BoundNetLog bound_net_log_; 65 net::BoundNetLog bound_net_log_;
89 base::WeakPtrFactory<FileStreamWin> weak_ptr_factory_;
90 scoped_ptr<base::WaitableEvent> on_io_complete_;
91 66
92 DISALLOW_COPY_AND_ASSIGN(FileStreamWin); 67 DISALLOW_COPY_AND_ASSIGN(FileStreamWin);
93 }; 68 };
94 69
95 } // namespace net 70 } // namespace net
96 71
97 #endif // NET_BASE_FILE_STREAM_WIN_H_ 72 #endif // NET_BASE_FILE_STREAM_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698