OLD | NEW |
---|---|
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 #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" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 offset.QuadPart += static_cast<LONGLONG>(count); | 39 offset.QuadPart += static_cast<LONGLONG>(count); |
40 SetOffset(overlapped, offset); | 40 SetOffset(overlapped, offset); |
41 } | 41 } |
42 | 42 |
43 int RecordAndMapError(int error, | 43 int RecordAndMapError(int error, |
44 FileErrorSource source, | 44 FileErrorSource source, |
45 bool record_uma, | 45 bool record_uma, |
46 const net::BoundNetLog& bound_net_log) { | 46 const net::BoundNetLog& bound_net_log) { |
47 net::Error net_error = MapSystemError(error); | 47 net::Error net_error = MapSystemError(error); |
48 | 48 |
49 std::string error_name = GetFileErrorSourceName(source); | |
eroman
2012/06/11 23:42:25
Same comment as for posix.
mmenke
2012/06/12 00:42:19
Done.
| |
49 bound_net_log.AddEvent( | 50 bound_net_log.AddEvent( |
50 net::NetLog::TYPE_FILE_STREAM_ERROR, | 51 net::NetLog::TYPE_FILE_STREAM_ERROR, |
51 make_scoped_refptr( | 52 base::Bind(&NetLogFileStreamErrorCallback, |
52 new FileStreamErrorParameters(GetFileErrorSourceName(source), | 53 &error_name, error, net_error)); |
53 error, | |
54 net_error))); | |
55 | 54 |
56 RecordFileError(error, source, record_uma); | 55 RecordFileError(error, source, record_uma); |
57 | 56 |
58 return net_error; | 57 return net_error; |
59 } | 58 } |
60 | 59 |
61 // Opens a file with some network logging. | 60 // Opens a file with some network logging. |
62 // The opened file and the result code are written to |file| and |result|. | 61 // The opened file and the result code are written to |file| and |result|. |
63 void OpenFile(const FilePath& path, | 62 void OpenFile(const FilePath& path, |
64 int open_flags, | 63 int open_flags, |
65 bool record_uma, | 64 bool record_uma, |
66 base::PlatformFile* file, | 65 base::PlatformFile* file, |
67 int* result, | 66 int* result, |
68 const net::BoundNetLog& bound_net_log) { | 67 const net::BoundNetLog& bound_net_log) { |
68 std::string file_name = path.AsUTF8Unsafe(); | |
eroman
2012/06/11 23:42:25
same comment as for posix.
mmenke
2012/06/12 00:42:19
Done.
| |
69 bound_net_log.BeginEvent( | 69 bound_net_log.BeginEvent( |
70 net::NetLog::TYPE_FILE_STREAM_OPEN, | 70 net::NetLog::TYPE_FILE_STREAM_OPEN, |
71 make_scoped_refptr( | 71 NetLog::StringCallback("file_name", &file_name)); |
72 new net::NetLogStringParameter("file_name", | |
73 path.AsUTF8Unsafe()))); | |
74 | 72 |
75 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL); | 73 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL); |
76 if (*file == base::kInvalidPlatformFileValue) { | 74 if (*file == base::kInvalidPlatformFileValue) { |
77 DWORD error = GetLastError(); | 75 DWORD error = GetLastError(); |
78 LOG(WARNING) << "Failed to open file: " << error; | 76 LOG(WARNING) << "Failed to open file: " << error; |
79 *result = RecordAndMapError(error, | 77 *result = RecordAndMapError(error, |
80 FILE_ERROR_SOURCE_OPEN, | 78 FILE_ERROR_SOURCE_OPEN, |
81 record_uma, | 79 record_uma, |
82 bound_net_log); | 80 bound_net_log); |
83 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); | 81 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 (bound_net_log_.source().id == net::NetLog::Source::kInvalidId)) { | 647 (bound_net_log_.source().id == net::NetLog::Source::kInvalidId)) { |
650 // Both |BoundNetLog|s are invalid. | 648 // Both |BoundNetLog|s are invalid. |
651 return; | 649 return; |
652 } | 650 } |
653 | 651 |
654 // Should never connect to itself. | 652 // Should never connect to itself. |
655 DCHECK_NE(bound_net_log_.source().id, owner_bound_net_log.source().id); | 653 DCHECK_NE(bound_net_log_.source().id, owner_bound_net_log.source().id); |
656 | 654 |
657 bound_net_log_.AddEvent( | 655 bound_net_log_.AddEvent( |
658 net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER, | 656 net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER, |
659 make_scoped_refptr( | 657 owner_bound_net_log.source().ToEventParametersCallback()); |
660 new net::NetLogSourceParameter("source_dependency", | |
661 owner_bound_net_log.source()))); | |
662 | 658 |
663 owner_bound_net_log.AddEvent( | 659 owner_bound_net_log.AddEvent( |
664 net::NetLog::TYPE_FILE_STREAM_SOURCE, | 660 net::NetLog::TYPE_FILE_STREAM_SOURCE, |
665 make_scoped_refptr( | 661 bound_net_log_.source().ToEventParametersCallback()); |
666 new net::NetLogSourceParameter("source_dependency", | |
667 bound_net_log_.source()))); | |
668 } | 662 } |
669 | 663 |
670 base::PlatformFile FileStreamWin::GetPlatformFileForTesting() { | 664 base::PlatformFile FileStreamWin::GetPlatformFileForTesting() { |
671 return file_; | 665 return file_; |
672 } | 666 } |
673 | 667 |
674 void FileStreamWin::OnClosed(const CompletionCallback& callback) { | 668 void FileStreamWin::OnClosed(const CompletionCallback& callback) { |
675 file_ = base::kInvalidPlatformFileValue; | 669 file_ = base::kInvalidPlatformFileValue; |
676 | 670 |
677 // Reset this before Run() as Run() may issue a new async operation. | 671 // Reset this before Run() as Run() may issue a new async operation. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 void FileStreamWin::WaitForIOCompletion() { | 723 void FileStreamWin::WaitForIOCompletion() { |
730 // http://crbug.com/115067 | 724 // http://crbug.com/115067 |
731 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 725 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
732 if (on_io_complete_.get()) { | 726 if (on_io_complete_.get()) { |
733 on_io_complete_->Wait(); | 727 on_io_complete_->Wait(); |
734 on_io_complete_.reset(); | 728 on_io_complete_.reset(); |
735 } | 729 } |
736 } | 730 } |
737 | 731 |
738 } // namespace net | 732 } // namespace net |
OLD | NEW |