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

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: Remove unneeded line 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bound_net_log.AddEvent( 60 bound_net_log.AddEvent(
61 net::NetLog::TYPE_FILE_STREAM_ERROR, 61 net::NetLog::TYPE_FILE_STREAM_ERROR,
62 make_scoped_refptr( 62 base::Bind(&NetLogFileStreamErrorCallback,
63 new FileStreamErrorParameters(GetFileErrorSourceName(source), 63 source, error, net_error));
64 error,
65 net_error)));
66 64
67 RecordFileError(error, source, record_uma); 65 RecordFileError(error, source, record_uma);
68 66
69 return net_error; 67 return net_error;
70 } 68 }
71 69
72 // Opens a file with some network logging. 70 // Opens a file with some network logging.
73 // The opened file and the result code are written to |file| and |result|. 71 // The opened file and the result code are written to |file| and |result|.
74 void OpenFile(const FilePath& path, 72 void OpenFile(const FilePath& path,
75 int open_flags, 73 int open_flags,
76 bool record_uma, 74 bool record_uma,
77 base::PlatformFile* file, 75 base::PlatformFile* file,
78 int* result, 76 int* result,
79 const net::BoundNetLog& bound_net_log) { 77 const net::BoundNetLog& bound_net_log) {
78 std::string file_name = path.AsUTF8Unsafe();
80 bound_net_log.BeginEvent( 79 bound_net_log.BeginEvent(
81 net::NetLog::TYPE_FILE_STREAM_OPEN, 80 net::NetLog::TYPE_FILE_STREAM_OPEN,
82 make_scoped_refptr( 81 NetLog::StringCallback("file_name", &file_name));
83 new net::NetLogStringParameter("file_name",
84 path.AsUTF8Unsafe())));
85 82
86 *result = OK; 83 *result = OK;
87 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL); 84 *file = base::CreatePlatformFile(path, open_flags, NULL, NULL);
88 if (*file == base::kInvalidPlatformFileValue) { 85 if (*file == base::kInvalidPlatformFileValue) {
89 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); 86 bound_net_log.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL);
90 *result = RecordAndMapError(errno, FILE_ERROR_SOURCE_OPEN, record_uma, 87 *result = RecordAndMapError(errno, FILE_ERROR_SOURCE_OPEN, record_uma,
91 bound_net_log); 88 bound_net_log);
92 } 89 }
93 } 90 }
94 91
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 (bound_net_log_.source().id == net::NetLog::Source::kInvalidId)) { 605 (bound_net_log_.source().id == net::NetLog::Source::kInvalidId)) {
609 // Both |BoundNetLog|s are invalid. 606 // Both |BoundNetLog|s are invalid.
610 return; 607 return;
611 } 608 }
612 609
613 // Should never connect to itself. 610 // Should never connect to itself.
614 DCHECK_NE(bound_net_log_.source().id, owner_bound_net_log.source().id); 611 DCHECK_NE(bound_net_log_.source().id, owner_bound_net_log.source().id);
615 612
616 bound_net_log_.AddEvent( 613 bound_net_log_.AddEvent(
617 net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER, 614 net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER,
618 make_scoped_refptr( 615 owner_bound_net_log.source().ToEventParametersCallback());
619 new net::NetLogSourceParameter("source_dependency",
620 owner_bound_net_log.source())));
621 616
622 owner_bound_net_log.AddEvent( 617 owner_bound_net_log.AddEvent(
623 net::NetLog::TYPE_FILE_STREAM_SOURCE, 618 net::NetLog::TYPE_FILE_STREAM_SOURCE,
624 make_scoped_refptr( 619 bound_net_log_.source().ToEventParametersCallback());
625 new net::NetLogSourceParameter("source_dependency",
626 bound_net_log_.source())));
627 } 620 }
628 621
629 base::PlatformFile FileStreamPosix::GetPlatformFileForTesting() { 622 base::PlatformFile FileStreamPosix::GetPlatformFileForTesting() {
630 return file_; 623 return file_;
631 } 624 }
632 625
633 void FileStreamPosix::ResetOnIOComplete() { 626 void FileStreamPosix::ResetOnIOComplete() {
634 on_io_complete_.reset(); 627 on_io_complete_.reset();
635 weak_ptr_factory_.InvalidateWeakPtrs(); 628 weak_ptr_factory_.InvalidateWeakPtrs();
636 } 629 }
637 630
638 void FileStreamPosix::OnClosed(const CompletionCallback& callback) { 631 void FileStreamPosix::OnClosed(const CompletionCallback& callback) {
639 file_ = base::kInvalidPlatformFileValue; 632 file_ = base::kInvalidPlatformFileValue;
640 633
641 // Reset this before Run() as Run() may issue a new async operation. 634 // Reset this before Run() as Run() may issue a new async operation.
642 ResetOnIOComplete(); 635 ResetOnIOComplete();
643 callback.Run(OK); 636 callback.Run(OK);
644 } 637 }
645 638
646 void FileStreamPosix::WaitForIOCompletion() { 639 void FileStreamPosix::WaitForIOCompletion() {
647 // http://crbug.com/115067 640 // http://crbug.com/115067
648 base::ThreadRestrictions::ScopedAllowWait allow_wait; 641 base::ThreadRestrictions::ScopedAllowWait allow_wait;
649 if (on_io_complete_.get()) { 642 if (on_io_complete_.get()) {
650 on_io_complete_->Wait(); 643 on_io_complete_->Wait();
651 on_io_complete_.reset(); 644 on_io_complete_.reset();
652 } 645 }
653 } 646 }
654 647
655 } // namespace net 648 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698