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

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

Issue 9288084: Added Net logging to FileStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified SetBoundNetLogSource() again. 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 #include "net/base/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "net/base/file_stream_metrics.h" 14 #include "net/base/file_stream_metrics.h"
15 #include "net/base/file_stream_net_log_parameters.h"
15 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 // Ensure that we can just use our Whence values directly. 20 // Ensure that we can just use our Whence values directly.
20 COMPILE_ASSERT(FROM_BEGIN == FILE_BEGIN, bad_whence_begin); 21 COMPILE_ASSERT(FROM_BEGIN == FILE_BEGIN, bad_whence_begin);
21 COMPILE_ASSERT(FROM_CURRENT == FILE_CURRENT, bad_whence_current); 22 COMPILE_ASSERT(FROM_CURRENT == FILE_CURRENT, bad_whence_current);
22 COMPILE_ASSERT(FROM_END == FILE_END, bad_whence_end); 23 COMPILE_ASSERT(FROM_END == FILE_END, bad_whence_end);
23 24
24 static void SetOffset(OVERLAPPED* overlapped, const LARGE_INTEGER& offset) { 25 static void SetOffset(OVERLAPPED* overlapped, const LARGE_INTEGER& offset) {
25 overlapped->Offset = offset.LowPart; 26 overlapped->Offset = offset.LowPart;
26 overlapped->OffsetHigh = offset.HighPart; 27 overlapped->OffsetHigh = offset.HighPart;
27 } 28 }
28 29
29 static void IncrementOffset(OVERLAPPED* overlapped, DWORD count) { 30 static void IncrementOffset(OVERLAPPED* overlapped, DWORD count) {
30 LARGE_INTEGER offset; 31 LARGE_INTEGER offset;
31 offset.LowPart = overlapped->Offset; 32 offset.LowPart = overlapped->Offset;
32 offset.HighPart = overlapped->OffsetHigh; 33 offset.HighPart = overlapped->OffsetHigh;
33 offset.QuadPart += static_cast<LONGLONG>(count); 34 offset.QuadPart += static_cast<LONGLONG>(count);
34 SetOffset(overlapped, offset); 35 SetOffset(overlapped, offset);
35 } 36 }
36 37
37 namespace { 38 namespace {
38 39
39 int RecordAndMapError(int error, FileErrorSource source, bool record_uma) { 40 int RecordAndMapError(int error,
41 FileErrorSource source,
42 bool record_uma,
43 const net::BoundNetLog& bound_net_log) {
44 bound_net_log.AddEvent(
45 net::NetLog::TYPE_FILE_STREAM_ERROR,
46 make_scoped_refptr(
47 new FileStreamErrorParameters(GetFileErrorSourceName(source),
48 error,
49 MapSystemError(error))));
50
40 RecordFileError(error, source, record_uma); 51 RecordFileError(error, source, record_uma);
41 return MapSystemError(error); 52 return MapSystemError(error);
42 } 53 }
43 54
44 } // namespace 55 } // namespace
45 56
46 // FileStream::AsyncContext ---------------------------------------------- 57 // FileStream::AsyncContext ----------------------------------------------
47 58
48 class FileStream::AsyncContext : public MessageLoopForIO::IOHandler { 59 class FileStream::AsyncContext : public MessageLoopForIO::IOHandler {
49 public: 60 public:
50 AsyncContext(FileStream* owner) 61 explicit AsyncContext(const net::BoundNetLog& bound_net_log)
51 : owner_(owner), context_(), is_closing_(false), 62 : context_(), is_closing_(false),
52 record_uma_(false), error_source_(FILE_ERROR_SOURCE_COUNT) { 63 record_uma_(false), bound_net_log_(bound_net_log),
64 error_source_(FILE_ERROR_SOURCE_COUNT) {
53 context_.handler = this; 65 context_.handler = this;
54 } 66 }
55 ~AsyncContext(); 67 ~AsyncContext();
56 68
57 void IOCompletionIsPending(const CompletionCallback& callback); 69 void IOCompletionIsPending(const CompletionCallback& callback);
58 70
59 OVERLAPPED* overlapped() { return &context_.overlapped; } 71 OVERLAPPED* overlapped() { return &context_.overlapped; }
60 const CompletionCallback& callback() const { return callback_; } 72 const CompletionCallback& callback() const { return callback_; }
61 73
62 void set_error_source(FileErrorSource source) { error_source_ = source; } 74 void set_error_source(FileErrorSource source) { error_source_ = source; }
63 75
64 void EnableErrorStatistics() { 76 void EnableErrorStatistics() {
65 record_uma_ = true; 77 record_uma_ = true;
66 } 78 }
67 79
68 private: 80 private:
69 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, 81 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
70 DWORD bytes_read, DWORD error); 82 DWORD bytes_read, DWORD error);
mmenke 2012/02/01 16:25:52 nit: While you're here, mind adding OVERRIDE here
ahendrickson 2012/02/01 18:38:32 Done.
71 83
72 FileStream* owner_;
73 MessageLoopForIO::IOContext context_; 84 MessageLoopForIO::IOContext context_;
74 CompletionCallback callback_; 85 CompletionCallback callback_;
75 bool is_closing_; 86 bool is_closing_;
76 bool record_uma_; 87 bool record_uma_;
88 net::BoundNetLog bound_net_log_;
mmenke 2012/02/01 16:25:52 nit: Can be const.
ahendrickson 2012/02/01 18:38:32 Done.
77 FileErrorSource error_source_; 89 FileErrorSource error_source_;
78 }; 90 };
79 91
80 FileStream::AsyncContext::~AsyncContext() { 92 FileStream::AsyncContext::~AsyncContext() {
81 is_closing_ = true; 93 is_closing_ = true;
82 bool waited = false; 94 bool waited = false;
83 base::TimeTicks start = base::TimeTicks::Now(); 95 base::TimeTicks start = base::TimeTicks::Now();
84 while (!callback_.is_null()) { 96 while (!callback_.is_null()) {
85 waited = true; 97 waited = true;
86 MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this); 98 MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this);
(...skipping 15 matching lines...) Expand all
102 MessageLoopForIO::IOContext* context, DWORD bytes_read, DWORD error) { 114 MessageLoopForIO::IOContext* context, DWORD bytes_read, DWORD error) {
103 DCHECK_EQ(&context_, context); 115 DCHECK_EQ(&context_, context);
104 DCHECK(!callback_.is_null()); 116 DCHECK(!callback_.is_null());
105 117
106 if (is_closing_) { 118 if (is_closing_) {
107 callback_.Reset(); 119 callback_.Reset();
108 return; 120 return;
109 } 121 }
110 122
111 int result = static_cast<int>(bytes_read); 123 int result = static_cast<int>(bytes_read);
112 if (error && error != ERROR_HANDLE_EOF) 124 if (error && error != ERROR_HANDLE_EOF) {
113 result = RecordAndMapError(error, error_source_, record_uma_); 125 result = RecordAndMapError(error, error_source_, record_uma_,
126 bound_net_log_);
127 }
114 128
115 if (bytes_read) 129 if (bytes_read)
116 IncrementOffset(&context->overlapped, bytes_read); 130 IncrementOffset(&context->overlapped, bytes_read);
117 131
118 CompletionCallback temp; 132 CompletionCallback temp;
119 std::swap(temp, callback_); 133 std::swap(temp, callback_);
120 temp.Run(result); 134 temp.Run(result);
121 } 135 }
122 136
123 // FileStream ------------------------------------------------------------ 137 // FileStream ------------------------------------------------------------
124 138
125 FileStream::FileStream() 139 FileStream::FileStream(net::NetLog* net_log)
126 : file_(INVALID_HANDLE_VALUE), 140 : file_(base::kInvalidPlatformFileValue),
127 open_flags_(0), 141 open_flags_(0),
128 auto_closed_(true), 142 auto_closed_(true),
129 record_uma_(false) { 143 record_uma_(false),
144 bound_net_log_(net::BoundNetLog::Make(net_log,
145 net::NetLog::SOURCE_FILESTREAM)) {
146 bound_net_log_.BeginEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL);
130 } 147 }
131 148
132 FileStream::FileStream(base::PlatformFile file, int flags) 149 FileStream::FileStream(base::PlatformFile file, int flags, net::NetLog* net_log)
133 : file_(file), 150 : file_(file),
134 open_flags_(flags), 151 open_flags_(flags),
135 auto_closed_(false), 152 auto_closed_(false),
136 record_uma_(false) { 153 record_uma_(false),
154 bound_net_log_(net::BoundNetLog::Make(net_log,
155 net::NetLog::SOURCE_FILESTREAM)) {
156 bound_net_log_.BeginEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL);
157
137 // If the file handle is opened with base::PLATFORM_FILE_ASYNC, we need to 158 // If the file handle is opened with base::PLATFORM_FILE_ASYNC, we need to
138 // make sure we will perform asynchronous File IO to it. 159 // make sure we will perform asynchronous File IO to it.
139 if (flags & base::PLATFORM_FILE_ASYNC) { 160 if (flags & base::PLATFORM_FILE_ASYNC) {
140 async_context_.reset(new AsyncContext(this)); 161 async_context_.reset(new AsyncContext(bound_net_log_));
141 MessageLoopForIO::current()->RegisterIOHandler(file_, 162 MessageLoopForIO::current()->RegisterIOHandler(file_,
142 async_context_.get()); 163 async_context_.get());
143 } 164 }
144 } 165 }
145 166
146 FileStream::~FileStream() { 167 FileStream::~FileStream() {
147 if (auto_closed_) 168 if (auto_closed_)
148 Close(); 169 Close();
170
171 bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL);
149 } 172 }
150 173
151 void FileStream::Close() { 174 void FileStream::Close() {
175 bound_net_log_.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE, NULL);
152 if (file_ != INVALID_HANDLE_VALUE) 176 if (file_ != INVALID_HANDLE_VALUE)
153 CancelIo(file_); 177 CancelIo(file_);
154 178
155 async_context_.reset(); 179 async_context_.reset();
156 if (file_ != INVALID_HANDLE_VALUE) { 180 if (file_ != INVALID_HANDLE_VALUE) {
157 CloseHandle(file_); 181 CloseHandle(file_);
158 file_ = INVALID_HANDLE_VALUE; 182 file_ = INVALID_HANDLE_VALUE;
183
184 bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL);
159 } 185 }
160 } 186 }
161 187
162 int FileStream::Open(const FilePath& path, int open_flags) { 188 int FileStream::Open(const FilePath& path, int open_flags) {
163 if (IsOpen()) { 189 if (IsOpen()) {
164 DLOG(FATAL) << "File is already open!"; 190 DLOG(FATAL) << "File is already open!";
165 return ERR_UNEXPECTED; 191 return ERR_UNEXPECTED;
166 } 192 }
167 193
194 bound_net_log_.BeginEvent(
195 net::NetLog::TYPE_FILE_STREAM_OPEN,
196 make_scoped_refptr(
197 new net::NetLogStringParameter("file_name",
198 path.AsUTF8Unsafe())));
199
168 open_flags_ = open_flags; 200 open_flags_ = open_flags;
169 file_ = base::CreatePlatformFile(path, open_flags_, NULL, NULL); 201 file_ = base::CreatePlatformFile(path, open_flags_, NULL, NULL);
170 if (file_ == INVALID_HANDLE_VALUE) { 202 if (file_ == INVALID_HANDLE_VALUE) {
171 DWORD error = GetLastError(); 203 DWORD error = GetLastError();
172 LOG(WARNING) << "Failed to open file: " << error; 204 LOG(WARNING) << "Failed to open file: " << error;
173 return RecordAndMapError(error, FILE_ERROR_SOURCE_OPEN, record_uma_); 205 int net_error = RecordAndMapError(error,
206 FILE_ERROR_SOURCE_OPEN,
207 record_uma_,
208 bound_net_log_);
209 bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL);
210 return net_error;
174 } 211 }
175 212
176 if (open_flags_ & base::PLATFORM_FILE_ASYNC) { 213 if (open_flags_ & base::PLATFORM_FILE_ASYNC) {
177 async_context_.reset(new AsyncContext(this)); 214 async_context_.reset(new AsyncContext(bound_net_log_));
178 if (record_uma_) 215 if (record_uma_)
179 async_context_->EnableErrorStatistics(); 216 async_context_->EnableErrorStatistics();
180 MessageLoopForIO::current()->RegisterIOHandler(file_, 217 MessageLoopForIO::current()->RegisterIOHandler(file_,
181 async_context_.get()); 218 async_context_.get());
182 } 219 }
183 220
184 return OK; 221 return OK;
185 } 222 }
186 223
187 bool FileStream::IsOpen() const { 224 bool FileStream::IsOpen() const {
188 return file_ != INVALID_HANDLE_VALUE; 225 return file_ != INVALID_HANDLE_VALUE;
189 } 226 }
190 227
191 int64 FileStream::Seek(Whence whence, int64 offset) { 228 int64 FileStream::Seek(Whence whence, int64 offset) {
192 if (!IsOpen()) 229 if (!IsOpen())
193 return ERR_UNEXPECTED; 230 return ERR_UNEXPECTED;
194 231
195 DCHECK(!async_context_.get() || async_context_->callback().is_null()); 232 DCHECK(!async_context_.get() || async_context_->callback().is_null());
196 233
197 LARGE_INTEGER distance, result; 234 LARGE_INTEGER distance, result;
198 distance.QuadPart = offset; 235 distance.QuadPart = offset;
199 DWORD move_method = static_cast<DWORD>(whence); 236 DWORD move_method = static_cast<DWORD>(whence);
200 if (!SetFilePointerEx(file_, distance, &result, move_method)) { 237 if (!SetFilePointerEx(file_, distance, &result, move_method)) {
201 DWORD error = GetLastError(); 238 DWORD error = GetLastError();
202 LOG(WARNING) << "SetFilePointerEx failed: " << error; 239 LOG(WARNING) << "SetFilePointerEx failed: " << error;
203 return RecordAndMapError(error, FILE_ERROR_SOURCE_SEEK, record_uma_); 240 return RecordAndMapError(error,
241 FILE_ERROR_SOURCE_SEEK,
242 record_uma_,
243 bound_net_log_);
204 } 244 }
205 if (async_context_.get()) { 245 if (async_context_.get()) {
206 async_context_->set_error_source(FILE_ERROR_SOURCE_SEEK); 246 async_context_->set_error_source(FILE_ERROR_SOURCE_SEEK);
207 SetOffset(async_context_->overlapped(), result); 247 SetOffset(async_context_->overlapped(), result);
208 } 248 }
209 return result.QuadPart; 249 return result.QuadPart;
210 } 250 }
211 251
212 int64 FileStream::Available() { 252 int64 FileStream::Available() {
213 base::ThreadRestrictions::AssertIOAllowed(); 253 base::ThreadRestrictions::AssertIOAllowed();
214 254
215 if (!IsOpen()) 255 if (!IsOpen())
216 return ERR_UNEXPECTED; 256 return ERR_UNEXPECTED;
217 257
218 int64 cur_pos = Seek(FROM_CURRENT, 0); 258 int64 cur_pos = Seek(FROM_CURRENT, 0);
219 if (cur_pos < 0) 259 if (cur_pos < 0)
220 return cur_pos; 260 return cur_pos;
221 261
222 LARGE_INTEGER file_size; 262 LARGE_INTEGER file_size;
223 if (!GetFileSizeEx(file_, &file_size)) { 263 if (!GetFileSizeEx(file_, &file_size)) {
224 DWORD error = GetLastError(); 264 DWORD error = GetLastError();
225 LOG(WARNING) << "GetFileSizeEx failed: " << error; 265 LOG(WARNING) << "GetFileSizeEx failed: " << error;
226 return RecordAndMapError(error, FILE_ERROR_SOURCE_GET_SIZE, record_uma_); 266 return RecordAndMapError(error,
267 FILE_ERROR_SOURCE_GET_SIZE,
268 record_uma_,
269 bound_net_log_);
227 } 270 }
228 271
229 return file_size.QuadPart - cur_pos; 272 return file_size.QuadPart - cur_pos;
230 } 273 }
231 274
232 int FileStream::Read( 275 int FileStream::Read(
233 char* buf, int buf_len, const CompletionCallback& callback) { 276 char* buf, int buf_len, const CompletionCallback& callback) {
234 if (!IsOpen()) 277 if (!IsOpen())
235 return ERR_UNEXPECTED; 278 return ERR_UNEXPECTED;
236 279
(...skipping 15 matching lines...) Expand all
252 DWORD bytes_read; 295 DWORD bytes_read;
253 if (!ReadFile(file_, buf, buf_len, &bytes_read, overlapped)) { 296 if (!ReadFile(file_, buf, buf_len, &bytes_read, overlapped)) {
254 DWORD error = GetLastError(); 297 DWORD error = GetLastError();
255 if (async_context_.get() && error == ERROR_IO_PENDING) { 298 if (async_context_.get() && error == ERROR_IO_PENDING) {
256 async_context_->IOCompletionIsPending(callback); 299 async_context_->IOCompletionIsPending(callback);
257 rv = ERR_IO_PENDING; 300 rv = ERR_IO_PENDING;
258 } else if (error == ERROR_HANDLE_EOF) { 301 } else if (error == ERROR_HANDLE_EOF) {
259 rv = 0; // Report EOF by returning 0 bytes read. 302 rv = 0; // Report EOF by returning 0 bytes read.
260 } else { 303 } else {
261 LOG(WARNING) << "ReadFile failed: " << error; 304 LOG(WARNING) << "ReadFile failed: " << error;
262 rv = RecordAndMapError(error, FILE_ERROR_SOURCE_READ, record_uma_); 305 rv = RecordAndMapError(error,
306 FILE_ERROR_SOURCE_READ,
307 record_uma_,
308 bound_net_log_);
263 } 309 }
264 } else if (overlapped) { 310 } else if (overlapped) {
265 async_context_->IOCompletionIsPending(callback); 311 async_context_->IOCompletionIsPending(callback);
266 rv = ERR_IO_PENDING; 312 rv = ERR_IO_PENDING;
267 } else { 313 } else {
268 rv = static_cast<int>(bytes_read); 314 rv = static_cast<int>(bytes_read);
269 } 315 }
270 return rv; 316 return rv;
271 } 317 }
272 318
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 357
312 int rv; 358 int rv;
313 DWORD bytes_written; 359 DWORD bytes_written;
314 if (!WriteFile(file_, buf, buf_len, &bytes_written, overlapped)) { 360 if (!WriteFile(file_, buf, buf_len, &bytes_written, overlapped)) {
315 DWORD error = GetLastError(); 361 DWORD error = GetLastError();
316 if (async_context_.get() && error == ERROR_IO_PENDING) { 362 if (async_context_.get() && error == ERROR_IO_PENDING) {
317 async_context_->IOCompletionIsPending(callback); 363 async_context_->IOCompletionIsPending(callback);
318 rv = ERR_IO_PENDING; 364 rv = ERR_IO_PENDING;
319 } else { 365 } else {
320 LOG(WARNING) << "WriteFile failed: " << error; 366 LOG(WARNING) << "WriteFile failed: " << error;
321 rv = RecordAndMapError(error, FILE_ERROR_SOURCE_WRITE, record_uma_); 367 rv = RecordAndMapError(error,
368 FILE_ERROR_SOURCE_WRITE,
369 record_uma_,
370 bound_net_log_);
322 } 371 }
323 } else if (overlapped) { 372 } else if (overlapped) {
324 async_context_->IOCompletionIsPending(callback); 373 async_context_->IOCompletionIsPending(callback);
325 rv = ERR_IO_PENDING; 374 rv = ERR_IO_PENDING;
326 } else { 375 } else {
327 rv = static_cast<int>(bytes_written); 376 rv = static_cast<int>(bytes_written);
328 } 377 }
329 return rv; 378 return rv;
330 } 379 }
331 380
332 int FileStream::Flush() { 381 int FileStream::Flush() {
333 base::ThreadRestrictions::AssertIOAllowed(); 382 base::ThreadRestrictions::AssertIOAllowed();
334 383
335 if (!IsOpen()) 384 if (!IsOpen())
336 return ERR_UNEXPECTED; 385 return ERR_UNEXPECTED;
337 386
338 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE); 387 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
339 if (FlushFileBuffers(file_)) { 388 if (FlushFileBuffers(file_)) {
340 return OK; 389 return OK;
341 } 390 }
342 391
343 return RecordAndMapError(GetLastError(), 392 return RecordAndMapError(GetLastError(),
344 FILE_ERROR_SOURCE_FLUSH, 393 FILE_ERROR_SOURCE_FLUSH,
345 record_uma_); 394 record_uma_,
395 bound_net_log_);
346 } 396 }
347 397
348 int64 FileStream::Truncate(int64 bytes) { 398 int64 FileStream::Truncate(int64 bytes) {
349 base::ThreadRestrictions::AssertIOAllowed(); 399 base::ThreadRestrictions::AssertIOAllowed();
350 400
351 if (!IsOpen()) 401 if (!IsOpen())
352 return ERR_UNEXPECTED; 402 return ERR_UNEXPECTED;
353 403
354 // We better be open for reading. 404 // We'd better be open for writing.
355 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE); 405 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
356 406
357 // Seek to the position to truncate from. 407 // Seek to the position to truncate from.
358 int64 seek_position = Seek(FROM_BEGIN, bytes); 408 int64 seek_position = Seek(FROM_BEGIN, bytes);
359 if (seek_position != bytes) 409 if (seek_position != bytes)
360 return ERR_UNEXPECTED; 410 return ERR_UNEXPECTED;
361 411
362 // And truncate the file. 412 // And truncate the file.
363 BOOL result = SetEndOfFile(file_); 413 BOOL result = SetEndOfFile(file_);
364 if (!result) { 414 if (!result) {
365 DWORD error = GetLastError(); 415 DWORD error = GetLastError();
366 LOG(WARNING) << "SetEndOfFile failed: " << error; 416 LOG(WARNING) << "SetEndOfFile failed: " << error;
367 return RecordAndMapError(error, FILE_ERROR_SOURCE_SET_EOF, record_uma_); 417 return RecordAndMapError(error,
418 FILE_ERROR_SOURCE_SET_EOF,
419 record_uma_,
420 bound_net_log_);
368 } 421 }
369 422
370 // Success. 423 // Success.
371 return seek_position; 424 return seek_position;
372 } 425 }
373 426
374 void FileStream::EnableErrorStatistics() { 427 void FileStream::EnableErrorStatistics() {
375 record_uma_ = true; 428 record_uma_ = true;
376 429
377 if (async_context_.get()) 430 if (async_context_.get())
378 async_context_->EnableErrorStatistics(); 431 async_context_->EnableErrorStatistics();
379 } 432 }
380 433
434 void FileStream::SetBoundNetLogSource(
435 const net::BoundNetLog& owner_bound_net_log) {
436 if ((owner_bound_net_log.source().id == net::NetLog::Source::kInvalidId) &&
437 (bound_net_log_.source().id == net::NetLog::Source::kInvalidId)) {
438 // Both |BoundNetLog|s are invalid.
439 return;
440 }
441
442 // Should never connect to itself.
443 DCHECK_NE(bound_net_log_.source().id, owner_bound_net_log.source().id);
444
445 bound_net_log_.AddEvent(
446 net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER,
447 make_scoped_refptr(
448 new net::NetLogSourceParameter("source_dependency",
449 owner_bound_net_log.source())));
450
451 owner_bound_net_log.AddEvent(
452 net::NetLog::TYPE_FILE_STREAM_SOURCE,
453 make_scoped_refptr(
454 new net::NetLogSourceParameter("source_dependency",
455 bound_net_log_.source())));
456 }
457
381 } // namespace net 458 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698