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

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

Issue 10539094: NetLogEventParameter to Callback refactoring 1, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix headers Created 8 years, 6 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) 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 // For 64-bit file access (off_t = off64_t, lseek64, etc). 5 // For 64-bit file access (off_t = off64_t, lseek64, etc).
6 #define _FILE_OFFSET_BITS 64 6 #define _FILE_OFFSET_BITS 64
7 7
8 #include "net/base/file_stream.h" 8 #include "net/base/file_stream.h"
9 9
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 FROM_END == SEEK_END, whence_matches_system); 50 FROM_END == SEEK_END, whence_matches_system);
51 51
52 namespace { 52 namespace {
53 53
54 int RecordAndMapError(int error, 54 int RecordAndMapError(int error,
55 FileErrorSource source, 55 FileErrorSource source,
56 bool record_uma, 56 bool record_uma,
57 const net::BoundNetLog& bound_net_log) { 57 const net::BoundNetLog& bound_net_log) {
58 net::Error net_error = MapSystemError(error); 58 net::Error net_error = MapSystemError(error);
59 59
60 std::string error_name = GetFileErrorSourceName(source);
eroman 2012/06/11 23:42:25 Not a big deal either way since this is an error l
mmenke 2012/06/12 00:42:19 Done.
60 bound_net_log.AddEvent( 61 bound_net_log.AddEvent(
61 net::NetLog::TYPE_FILE_STREAM_ERROR, 62 net::NetLog::TYPE_FILE_STREAM_ERROR,
62 make_scoped_refptr( 63 base::Bind(&NetLogFileStreamErrorCallback,
63 new FileStreamErrorParameters(GetFileErrorSourceName(source), 64 &error_name, error, net_error));
64 error,
65 net_error)));
66 65
67 RecordFileError(error, source, record_uma); 66 RecordFileError(error, source, record_uma);
68 67
69 return net_error; 68 return net_error;
70 } 69 }
71 70
72 // Opens a file with some network logging. 71 // Opens a file with some network logging.
73 // The opened file and the result code are written to |file| and |result|. 72 // The opened file and the result code are written to |file| and |result|.
74 void OpenFile(const FilePath& path, 73 void OpenFile(const FilePath& path,
75 int open_flags, 74 int open_flags,
76 bool record_uma, 75 bool record_uma,
77 base::PlatformFile* file, 76 base::PlatformFile* file,
78 int* result, 77 int* result,
79 const net::BoundNetLog& bound_net_log) { 78 const net::BoundNetLog& bound_net_log) {
79 std::string file_name = path.AsUTF8Unsafe();
80 bound_net_log.BeginEvent( 80 bound_net_log.BeginEvent(
81 net::NetLog::TYPE_FILE_STREAM_OPEN, 81 net::NetLog::TYPE_FILE_STREAM_OPEN,
82 make_scoped_refptr( 82 NetLog::StringCallback("file_name", &file_name));
eroman 2012/06/11 23:42:25 Can you take address to to path.AsUTF8Unsafe() dir
mmenke 2012/06/12 00:42:19 The compiler doesn't barf. I had assumed temporar
mmenke 2012/06/12 00:50:58 Correction...MSVC doesn't barf, and the string app
83 new net::NetLogStringParameter("file_name",
84 path.AsUTF8Unsafe())));
85 83
86 *result = OK; 84 *result = OK;
87 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL); 85 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL);
88 if (*file == base::kInvalidPlatformFileValue) { 86 if (*file == base::kInvalidPlatformFileValue) {
89 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); 87 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL);
90 *result = RecordAndMapError(errno, FILE_ERROR_SOURCE_OPEN, record_uma, 88 *result = RecordAndMapError(errno, FILE_ERROR_SOURCE_OPEN, record_uma,
91 bound_net_log); 89 bound_net_log);
92 } 90 }
93 } 91 }
94 92
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 (bound_net_log_.source().id == net::NetLog::Source::kInvalidId)) { 606 (bound_net_log_.source().id == net::NetLog::Source::kInvalidId)) {
609 // Both |BoundNetLog|s are invalid. 607 // Both |BoundNetLog|s are invalid.
610 return; 608 return;
611 } 609 }
612 610
613 // Should never connect to itself. 611 // Should never connect to itself.
614 DCHECK_NE(bound_net_log_.source().id, owner_bound_net_log.source().id); 612 DCHECK_NE(bound_net_log_.source().id, owner_bound_net_log.source().id);
615 613
616 bound_net_log_.AddEvent( 614 bound_net_log_.AddEvent(
617 net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER, 615 net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER,
618 make_scoped_refptr( 616 owner_bound_net_log.source().ToEventParametersCallback());
619 new net::NetLogSourceParameter("source_dependency",
620 owner_bound_net_log.source())));
621 617
622 owner_bound_net_log.AddEvent( 618 owner_bound_net_log.AddEvent(
623 net::NetLog::TYPE_FILE_STREAM_SOURCE, 619 net::NetLog::TYPE_FILE_STREAM_SOURCE,
624 make_scoped_refptr( 620 bound_net_log_.source().ToEventParametersCallback());
625 new net::NetLogSourceParameter("source_dependency",
626 bound_net_log_.source())));
627 } 621 }
628 622
629 base::PlatformFile FileStreamPosix::GetPlatformFileForTesting() { 623 base::PlatformFile FileStreamPosix::GetPlatformFileForTesting() {
630 return file_; 624 return file_;
631 } 625 }
632 626
633 void FileStreamPosix::ResetOnIOComplete() { 627 void FileStreamPosix::ResetOnIOComplete() {
634 on_io_complete_.reset(); 628 on_io_complete_.reset();
635 weak_ptr_factory_.InvalidateWeakPtrs(); 629 weak_ptr_factory_.InvalidateWeakPtrs();
636 } 630 }
637 631
638 void FileStreamPosix::OnClosed(const CompletionCallback& callback) { 632 void FileStreamPosix::OnClosed(const CompletionCallback& callback) {
639 file_ = base::kInvalidPlatformFileValue; 633 file_ = base::kInvalidPlatformFileValue;
640 634
641 // Reset this before Run() as Run() may issue a new async operation. 635 // Reset this before Run() as Run() may issue a new async operation.
642 ResetOnIOComplete(); 636 ResetOnIOComplete();
643 callback.Run(OK); 637 callback.Run(OK);
644 } 638 }
645 639
646 void FileStreamPosix::WaitForIOCompletion() { 640 void FileStreamPosix::WaitForIOCompletion() {
647 // http://crbug.com/115067 641 // http://crbug.com/115067
648 base::ThreadRestrictions::ScopedAllowWait allow_wait; 642 base::ThreadRestrictions::ScopedAllowWait allow_wait;
649 if (on_io_complete_.get()) { 643 if (on_io_complete_.get()) {
650 on_io_complete_->Wait(); 644 on_io_complete_->Wait();
651 on_io_complete_.reset(); 645 on_io_complete_.reset();
652 } 646 }
653 } 647 }
654 648
655 } // namespace net 649 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698