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

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

Issue 9288084: Added Net logging to FileStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed copyright issue. Created 8 years, 10 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
OLDNEW
1 // Copyright (c) 2011 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 defines FileStream, a basic interface for reading and writing files 5 // This file defines FileStream, a basic interface for reading and writing files
6 // synchronously or asynchronously with support for seeking to an offset. 6 // synchronously or asynchronously with support for seeking to an offset.
7 // Note that even when used asynchronously, only one operation is supported at 7 // Note that even when used asynchronously, only one operation is supported at
8 // a time. 8 // a time.
9 9
10 #ifndef NET_BASE_FILE_STREAM_H_ 10 #ifndef NET_BASE_FILE_STREAM_H_
11 #define NET_BASE_FILE_STREAM_H_ 11 #define NET_BASE_FILE_STREAM_H_
12 #pragma once 12 #pragma once
13 13
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "net/base/completion_callback.h" 16 #include "net/base/completion_callback.h"
17 #include "net/base/net_export.h" 17 #include "net/base/net_export.h"
18 #include "net/base/net_log.h"
18 19
19 class FilePath; 20 class FilePath;
20 21
21 namespace net { 22 namespace net {
22 23
23 // TODO(darin): Move this to a more generic location. 24 // TODO(darin): Move this to a more generic location.
24 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux. 25 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux.
25 enum Whence { 26 enum Whence {
26 FROM_BEGIN = 0, 27 FROM_BEGIN = 0,
27 FROM_CURRENT = 1, 28 FROM_CURRENT = 1,
28 FROM_END = 2 29 FROM_END = 2
29 }; 30 };
30 31
31 class NET_EXPORT FileStream { 32 class NET_EXPORT FileStream {
32 public: 33 public:
33 FileStream(); 34 // Creates a |FileStream| with a new |BoundNetLog| (based on |net_log|)
35 // attached. |net_log| may be NULL if no logging is needed.
36 explicit FileStream(net::NetLog* net_log);
34 37
35 // Construct a FileStream with an existing file handle and opening flags. 38 // Construct a FileStream with an existing file handle and opening flags.
36 // |file| is valid file handle. 39 // |file| is valid file handle.
37 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was 40 // |flags| is a bitfield of base::PlatformFileFlags when the file handle was
38 // opened. 41 // opened.
42 // |net_log| is the net log pointer to use to create a |BoundNetLog|. May be
43 // NULL if logging is not needed.
39 // The already opened file will not be automatically closed when FileStream 44 // The already opened file will not be automatically closed when FileStream
40 // is destructed. 45 // is destructed.
41 FileStream(base::PlatformFile file, int flags); 46 FileStream(base::PlatformFile file, int flags, net::NetLog* net_log);
42 47
43 virtual ~FileStream(); 48 virtual ~FileStream();
44 49
45 // Call this method to close the FileStream. It is OK to call Close 50 // Call this method to close the FileStream. It is OK to call Close
46 // multiple times. Redundant calls are ignored. 51 // multiple times. Redundant calls are ignored.
47 // Note that if there are any pending async operations, they'll be aborted. 52 // Note that if there are any pending async operations, they'll be aborted.
48 virtual void Close(); 53 virtual void Close();
49 54
50 // Call this method to open the FileStream. The remaining methods 55 // Call this method to open the FileStream. The remaining methods
51 // cannot be used unless this method returns OK. If the file cannot be 56 // cannot be used unless this method returns OK. If the file cannot be
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // calling. 134 // calling.
130 // 135 //
131 /// Returns an error code if the operation could not be performed. 136 /// Returns an error code if the operation could not be performed.
132 // 137 //
133 // This method should not be called if the stream was opened READ_ONLY. 138 // This method should not be called if the stream was opened READ_ONLY.
134 virtual int Flush(); 139 virtual int Flush();
135 140
136 // Turns on UMA error statistics gathering. 141 // Turns on UMA error statistics gathering.
137 void EnableErrorStatistics(); 142 void EnableErrorStatistics();
138 143
144 // Sets the source reference for net-internals logging.
145 // Creates source dependency events between |owner_bound_net_log| and
146 // |bound_net_log_|. Each gets an event showing the dependency on the other.
147 // If only one of those is valid, it gets an event showing that a change
148 // of ownership happened, but without details.
149 void SetBoundNetLogSource(const net::BoundNetLog& owner_bound_net_log);
150
139 private: 151 private:
140 class AsyncContext; 152 class AsyncContext;
141 friend class AsyncContext; 153 friend class AsyncContext;
142 friend class FileStreamTest; 154 friend class FileStreamTest;
143 155
144 // This member is used to support asynchronous reads. It is non-null when 156 // This member is used to support asynchronous reads. It is non-null when
145 // the FileStream was opened with PLATFORM_FILE_ASYNC. 157 // the FileStream was opened with PLATFORM_FILE_ASYNC.
146 scoped_ptr<AsyncContext> async_context_; 158 scoped_ptr<AsyncContext> async_context_;
147 159
148 base::PlatformFile file_; 160 base::PlatformFile file_;
149 int open_flags_; 161 int open_flags_;
150 bool auto_closed_; 162 bool auto_closed_;
151 bool record_uma_; 163 bool record_uma_;
164 net::BoundNetLog bound_net_log_;
152 165
153 DISALLOW_COPY_AND_ASSIGN(FileStream); 166 DISALLOW_COPY_AND_ASSIGN(FileStream);
154 }; 167 };
155 168
156 } // namespace net 169 } // namespace net
157 170
158 #endif // NET_BASE_FILE_STREAM_H_ 171 #endif // NET_BASE_FILE_STREAM_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/redirect_to_file_resource_handler.cc ('k') | net/base/file_stream_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698