diff options
author | eroman <eroman@chromium.org> | 2015-05-06 12:55:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-06 19:56:36 +0000 |
commit | 24bc6a1df2048ee8feeb1d837cdfddd2e9d0cde1 (patch) | |
tree | 7735fe6a9a19f3327c040a237c15c49855d2a23c | |
parent | 1ac5725305a33686747895d6cb960ecbf4899158 (diff) | |
download | chromium_src-24bc6a1df2048ee8feeb1d837cdfddd2e9d0cde1.zip chromium_src-24bc6a1df2048ee8feeb1d837cdfddd2e9d0cde1.tar.gz chromium_src-24bc6a1df2048ee8feeb1d837cdfddd2e9d0cde1.tar.bz2 |
Remove NetLog::GetCaptureMode() and NetLogCaptureMode::None()
* In place of GetCaptureMode() use NetLog::IsCapturing().
* NetLogCaptureMode::None() is no longer needed now.
This clears up some confusion since there are no longer multiple sources of truth for what the capture mode is (per observer vs per log). The removal of NetLogCaptureMode::None() similarly removes confusion over being able to add an observer with a capture mode of None.
BUG=484762
TBR=asanka@chromium.org
Review URL: https://codereview.chromium.org/1122483004
Cr-Commit-Position: refs/heads/master@{#328589}
26 files changed, 134 insertions, 245 deletions
diff --git a/chrome/browser/net/net_log_temp_file_unittest.cc b/chrome/browser/net/net_log_temp_file_unittest.cc index 572f12c..a620bc6 100644 --- a/chrome/browser/net/net_log_temp_file_unittest.cc +++ b/chrome/browser/net/net_log_temp_file_unittest.cc @@ -14,6 +14,7 @@ #include "build/build_config.h" #include "chrome/browser/net/chrome_net_log.h" #include "content/public/test/test_browser_thread.h" +#include "net/log/write_to_file_net_log_observer.h" #include "testing/gtest/include/gtest/gtest.h" using content::BrowserThread; @@ -198,8 +199,8 @@ class NetLogTempFileTest : public ::testing::Test { EXPECT_EQ("LOGGING", GetStateString()); EXPECT_EQ(expected_log_type, net_log_temp_file_->log_type()); EXPECT_EQ(expected_log_type_string, GetLogTypeString()); - - EXPECT_EQ(expected_capture_mode, net_log_->GetCaptureMode()); + EXPECT_EQ(expected_capture_mode, + net_log_temp_file_->write_to_file_observer_->capture_mode()); // Check GetFilePath returns false when still writing to the file. base::FilePath net_export_file_path; diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc index 4c8203d..b15354d 100644 --- a/content/browser/download/download_file_impl.cc +++ b/content/browser/download/download_file_impl.cc @@ -337,7 +337,7 @@ void DownloadFileImpl::StreamActive() { &DownloadDestinationObserver::DestinationCompleted, observer_, hash)); } - if (bound_net_log_.GetCaptureMode().enabled()) { + if (bound_net_log_.IsCapturing()) { bound_net_log_.AddEvent( net::NetLog::TYPE_DOWNLOAD_STREAM_DRAINED, base::Bind(&FileStreamDrainedNetLogCallback, total_incoming_data_size, diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc index be61483..599bc0d 100644 --- a/content/browser/download/download_item_impl.cc +++ b/content/browser/download/download_item_impl.cc @@ -1055,7 +1055,7 @@ void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, if (received_bytes_ > total_bytes_) total_bytes_ = 0; - if (bound_net_log_.GetCaptureMode().enabled()) { + if (bound_net_log_.IsCapturing()) { bound_net_log_.AddEvent( net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); diff --git a/net/disk_cache/blockfile/entry_impl.cc b/net/disk_cache/blockfile/entry_impl.cc index add38de..a4f0ff01 100644 --- a/net/disk_cache/blockfile/entry_impl.cc +++ b/net/disk_cache/blockfile/entry_impl.cc @@ -62,7 +62,7 @@ class SyncCallback: public disk_cache::FileIOCallback { void SyncCallback::OnFileIOComplete(int bytes_copied) { entry_->DecrementIoCount(); if (!callback_.is_null()) { - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().EndEvent( end_event_type_, disk_cache::CreateNetLogReadWriteCompleteCallback(bytes_copied)); @@ -315,7 +315,7 @@ void EntryImpl::DoomImpl() { int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); @@ -323,7 +323,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalReadData(index, offset, buf, buf_len, callback); - if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { + if (result != net::ERR_IO_PENDING && net_log_.IsCapturing()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -334,7 +334,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback, bool truncate) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); @@ -343,7 +343,7 @@ int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalWriteData(index, offset, buf, buf_len, callback, truncate); - if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { + if (result != net::ERR_IO_PENDING && net_log_.IsCapturing()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteCompleteCallback(result)); diff --git a/net/disk_cache/blockfile/entry_impl_v3.cc b/net/disk_cache/blockfile/entry_impl_v3.cc index 78ef1b8..29b063c 100644 --- a/net/disk_cache/blockfile/entry_impl_v3.cc +++ b/net/disk_cache/blockfile/entry_impl_v3.cc @@ -547,7 +547,7 @@ int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len, int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); @@ -555,7 +555,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalReadData(index, offset, buf, buf_len, callback); - if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { + if (result != net::ERR_IO_PENDING && net_log_.IsCapturing()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -586,7 +586,7 @@ int EntryImplV3::WriteData(int index, int offset, IOBuffer* buf, int buf_len, int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback, bool truncate) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); @@ -595,7 +595,7 @@ int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalWriteData(index, offset, buf, buf_len, callback, truncate); - if (result != net::ERR_IO_PENDING && net_log_.GetCaptureMode().enabled()) { + if (result != net::ERR_IO_PENDING && net_log_.IsCapturing()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteCompleteCallback(result)); diff --git a/net/disk_cache/blockfile/sparse_control.cc b/net/disk_cache/blockfile/sparse_control.cc index 8ce659da0..926cf36 100644 --- a/net/disk_cache/blockfile/sparse_control.cc +++ b/net/disk_cache/blockfile/sparse_control.cc @@ -161,7 +161,7 @@ net::NetLog::EventType GetSparseEventType( void LogChildOperationEnd(const net::BoundNetLog& net_log, disk_cache::SparseControl::SparseOperation operation, int result) { - if (net_log.GetCaptureMode().enabled()) { + if (net_log.IsCapturing()) { net::NetLog::EventType event_type; switch (operation) { case disk_cache::SparseControl::kReadOperation: @@ -275,7 +275,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, finished_ = false; abort_ = false; - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().BeginEvent( GetSparseEventType(operation_), CreateNetLogSparseOperationCallback(offset_, buf_len_)); @@ -678,15 +678,13 @@ void SparseControl::DoChildrenIO() { // Range operations are finished synchronously, often without setting // |finished_| to true. - if (kGetRangeOperation == operation_ && - entry_->net_log().GetCaptureMode().enabled()) { + if (kGetRangeOperation == operation_ && entry_->net_log().IsCapturing()) { entry_->net_log().EndEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, CreateNetLogGetAvailableRangeResultCallback(offset_, result_)); } if (finished_) { - if (kGetRangeOperation != operation_ && - entry_->net_log().GetCaptureMode().enabled()) { + if (kGetRangeOperation != operation_ && entry_->net_log().IsCapturing()) { entry_->net_log().EndEvent(GetSparseEventType(operation_)); } if (pending_) @@ -716,7 +714,7 @@ bool SparseControl::DoChildIO() { int rv = 0; switch (operation_) { case kReadOperation: - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -726,7 +724,7 @@ bool SparseControl::DoChildIO() { child_len_, callback); break; case kWriteOperation: - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -856,7 +854,7 @@ void SparseControl::OnChildIOCompleted(int result) { // We'll return the current result of the operation, which may be less than // the bytes to read or write, but the user cancelled the operation. abort_ = false; - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); entry_->net_log().EndEvent(GetSparseEventType(operation_)); } diff --git a/net/disk_cache/blockfile/sparse_control_v3.cc b/net/disk_cache/blockfile/sparse_control_v3.cc index 91492b3..bee23dc 100644 --- a/net/disk_cache/blockfile/sparse_control_v3.cc +++ b/net/disk_cache/blockfile/sparse_control_v3.cc @@ -163,7 +163,7 @@ net::NetLog::EventType GetSparseEventType( void LogChildOperationEnd(const net::BoundNetLog& net_log, disk_cache::SparseControl::SparseOperation operation, int result) { - if (net_log.GetCaptureMode().enabled()) { + if (net_log.IsCapturing()) { net::NetLog::EventType event_type; switch (operation) { case disk_cache::SparseControl::kReadOperation: @@ -254,7 +254,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, finished_ = false; abort_ = false; - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().BeginEvent( GetSparseEventType(operation_), CreateNetLogSparseOperationCallback(offset_, buf_len_)); @@ -563,7 +563,7 @@ bool SparseControl::DoChildIO() { int rv = 0; switch (operation_) { case kReadOperation: - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -573,7 +573,7 @@ bool SparseControl::DoChildIO() { child_len_, callback); break; case kWriteOperation: - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child_->net_log().source(), @@ -846,7 +846,7 @@ void SparseControl::OnChildIOCompleted(int result) { // We'll return the current result of the operation, which may be less than // the bytes to read or write, but the user cancelled the operation. abort_ = false; - if (entry_->net_log().GetCaptureMode().enabled()) { + if (entry_->net_log().IsCapturing()) { entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); entry_->net_log().EndEvent(GetSparseEventType(operation_)); } diff --git a/net/disk_cache/memory/mem_entry_impl.cc b/net/disk_cache/memory/mem_entry_impl.cc index c1dc8cf..a5d9086 100644 --- a/net/disk_cache/memory/mem_entry_impl.cc +++ b/net/disk_cache/memory/mem_entry_impl.cc @@ -185,7 +185,7 @@ int32 MemEntryImpl::GetDataSize(int index) const { int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); @@ -193,7 +193,7 @@ int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalReadData(index, offset, buf, buf_len); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -203,7 +203,7 @@ int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback, bool truncate) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); @@ -211,7 +211,7 @@ int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, int result = InternalWriteData(index, offset, buf, buf_len, truncate); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, CreateNetLogReadWriteCompleteCallback(result)); @@ -221,39 +221,39 @@ int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, int MemEntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_READ, CreateNetLogSparseOperationCallback(offset, buf_len)); } int result = InternalReadSparseData(offset, buf, buf_len); - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ); return result; } int MemEntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_WRITE, CreateNetLogSparseOperationCallback(offset, buf_len)); } int result = InternalWriteSparseData(offset, buf, buf_len); - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE); return result; } int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, const CompletionCallback& callback) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, CreateNetLogSparseOperationCallback(offset, len)); } int result = GetAvailableRange(offset, len, start); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, CreateNetLogGetAvailableRangeResultCallback(*start, result)); @@ -373,7 +373,7 @@ int MemEntryImpl::InternalReadSparseData(int64 offset, IOBuffer* buf, // we should stop. if (child_offset < child->child_first_pos_) break; - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child->net_log().source(), @@ -381,7 +381,7 @@ int MemEntryImpl::InternalReadSparseData(int64 offset, IOBuffer* buf, } int ret = child->ReadData(kSparseData, child_offset, io_buf.get(), io_buf->BytesRemaining(), CompletionCallback()); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEventWithNetErrorCode( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret); } @@ -430,7 +430,7 @@ int MemEntryImpl::InternalWriteSparseData(int64 offset, IOBuffer* buf, // Keep a record of the last byte position (exclusive) in the child. int data_size = child->GetDataSize(kSparseData); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, CreateNetLogSparseReadWriteCallback(child->net_log().source(), @@ -443,7 +443,7 @@ int MemEntryImpl::InternalWriteSparseData(int64 offset, IOBuffer* buf, // continuous we may want to discard this write. int ret = child->WriteData(kSparseData, child_offset, io_buf.get(), write_len, CompletionCallback(), true); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEventWithNetErrorCode( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret); } diff --git a/net/disk_cache/simple/simple_entry_impl.cc b/net/disk_cache/simple/simple_entry_impl.cc index 1817bfc..b7c8524 100644 --- a/net/disk_cache/simple/simple_entry_impl.cc +++ b/net/disk_cache/simple/simple_entry_impl.cc @@ -346,7 +346,7 @@ int SimpleEntryImpl::ReadData(int stream_index, const CompletionCallback& callback) { DCHECK(io_thread_checker_.CalledOnValidThread()); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_CALL, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, false)); @@ -354,7 +354,7 @@ int SimpleEntryImpl::ReadData(int stream_index, if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || buf_len < 0) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); } @@ -364,7 +364,7 @@ int SimpleEntryImpl::ReadData(int stream_index, } if (pending_operations_.empty() && (offset >= GetDataSize(stream_index) || offset < 0 || !buf_len)) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(0)); } @@ -393,7 +393,7 @@ int SimpleEntryImpl::WriteData(int stream_index, bool truncate) { DCHECK(io_thread_checker_.CalledOnValidThread()); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_CALL, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, @@ -402,7 +402,7 @@ int SimpleEntryImpl::WriteData(int stream_index, if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || offset < 0 || buf_len < 0) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); @@ -411,7 +411,7 @@ int SimpleEntryImpl::WriteData(int stream_index, return net::ERR_INVALID_ARGUMENT; } if (backend_.get() && offset + buf_len > backend_->GetMaxFileSize()) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); @@ -453,7 +453,7 @@ int SimpleEntryImpl::WriteData(int stream_index, } op_callback = CompletionCallback(); ret_value = buf_len; - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_OPTIMISTIC, CreateNetLogReadWriteCompleteCallback(buf_len)); @@ -808,7 +808,7 @@ void SimpleEntryImpl::ReadDataInternal(int stream_index, DCHECK(io_thread_checker_.CalledOnValidThread()); ScopedOperationRunner operation_runner(this); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_BEGIN, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, @@ -824,7 +824,7 @@ void SimpleEntryImpl::ReadDataInternal(int stream_index, base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::Bind(callback, net::ERR_FAILED)); } - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); @@ -891,7 +891,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, DCHECK(io_thread_checker_.CalledOnValidThread()); ScopedOperationRunner operation_runner(this); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_BEGIN, CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, @@ -900,7 +900,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { RecordWriteResult(cache_type_, WRITE_RESULT_BAD_STATE); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); @@ -1229,7 +1229,7 @@ void SimpleEntryImpl::ReadOperationComplete( crc_check_state_[stream_index] = CRC_CHECK_NOT_DONE; } } - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(*result)); @@ -1247,7 +1247,7 @@ void SimpleEntryImpl::WriteOperationComplete( RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); else RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, CreateNetLogReadWriteCompleteCallback(*result)); } @@ -1318,7 +1318,7 @@ void SimpleEntryImpl::ChecksumOperationComplete( DCHECK_EQ(STATE_IO_PENDING, state_); DCHECK(result); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEventWithNetErrorCode( net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_END, *result); @@ -1333,7 +1333,7 @@ void SimpleEntryImpl::ChecksumOperationComplete( } else { RecordReadResult(cache_type_, READ_RESULT_SYNC_CHECKSUM_FAILURE); } - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, CreateNetLogReadWriteCompleteCallback(*result)); } diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index fc6b68e..90a98461 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -1589,7 +1589,7 @@ int HttpCache::Transaction::DoTruncateCachedData() { next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; if (!entry_) return OK; - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); // Truncate the stream. return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); @@ -1597,7 +1597,7 @@ int HttpCache::Transaction::DoTruncateCachedData() { int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { if (entry_) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, result); } @@ -1612,14 +1612,14 @@ int HttpCache::Transaction::DoTruncateCachedMetadata() { if (!entry_) return OK; - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); } int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { if (entry_) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, result); } @@ -1756,7 +1756,7 @@ int HttpCache::Transaction::DoCacheWriteResponse() { "422516 HttpCache::Transaction::DoCacheWriteResponse")); if (entry_) { - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); } return WriteResponseInfoToEntry(false); @@ -1764,7 +1764,7 @@ int HttpCache::Transaction::DoCacheWriteResponse() { int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { if (entry_) { - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); } return WriteResponseInfoToEntry(true); @@ -1775,7 +1775,7 @@ int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { target_state_ = STATE_NONE; if (!entry_) return OK; - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, result); } @@ -1827,7 +1827,7 @@ int HttpCache::Transaction::DoCacheReadData() { DCHECK(entry_); next_state_ = STATE_CACHE_READ_DATA_COMPLETE; - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); if (partial_.get()) { return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, @@ -1840,7 +1840,7 @@ int HttpCache::Transaction::DoCacheReadData() { } int HttpCache::Transaction::DoCacheReadDataComplete(int result) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, result); } @@ -1871,7 +1871,7 @@ int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; write_len_ = num_bytes; if (entry_) { - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); } @@ -1880,7 +1880,7 @@ int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { if (entry_) { - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, result); } @@ -2701,7 +2701,7 @@ int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { if ((response_.headers->HasHeaderValue("cache-control", "no-store")) || IsCertStatusError(response_.ssl_info.cert_status)) { DoneWritingToEntry(false); - if (net_log_.GetCaptureMode().enabled()) + if (net_log_.IsCapturing()) net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); return OK; } diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 7939921..9cb8ea9 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -329,7 +329,7 @@ class HttpNetworkTransactionTest TestCompletionCallback callback; - EXPECT_TRUE(log.bound().GetCaptureMode().enabled()); + EXPECT_TRUE(log.bound().IsCapturing()); int rv = trans->Start(&request, callback.callback(), log.bound()); EXPECT_EQ(ERR_IO_PENDING, rv); diff --git a/net/log/net_log.cc b/net/log/net_log.cc index 33243d3..1d893e0 100644 --- a/net/log/net_log.cc +++ b/net/log/net_log.cc @@ -205,10 +205,7 @@ void NetLog::ThreadSafeObserver::OnAddEntryData(const EntryData& entry_data) { OnAddEntry(Entry(&entry_data, capture_mode())); } -NetLog::NetLog() - : last_id_(0), - effective_capture_mode_int32_( - NetLogCaptureMode::None().ToInternalValue()) { +NetLog::NetLog() : last_id_(0), is_capturing_(0) { } NetLog::~NetLog() { @@ -230,36 +227,28 @@ uint32 NetLog::NextID() { return base::subtle::NoBarrier_AtomicIncrement(&last_id_, 1); } -NetLogCaptureMode NetLog::GetCaptureMode() const { - base::subtle::Atomic32 capture_mode = - base::subtle::NoBarrier_Load(&effective_capture_mode_int32_); - return NetLogCaptureMode::FromInternalValue(capture_mode); +bool NetLog::IsCapturing() const { + return base::subtle::NoBarrier_Load(&is_capturing_) != 0; } void NetLog::DeprecatedAddObserver(NetLog::ThreadSafeObserver* observer, NetLogCaptureMode capture_mode) { - DCHECK(capture_mode.enabled()); - base::AutoLock lock(lock_); DCHECK(!observer->net_log_); - DCHECK(!observer->capture_mode_.enabled()); observers_.AddObserver(observer); observer->net_log_ = this; observer->capture_mode_ = capture_mode; - UpdateCaptureMode(); + UpdateIsCapturing(); } void NetLog::SetObserverCaptureMode(NetLog::ThreadSafeObserver* observer, NetLogCaptureMode capture_mode) { - DCHECK(capture_mode.enabled()); base::AutoLock lock(lock_); DCHECK(observers_.HasObserver(observer)); DCHECK_EQ(this, observer->net_log_); - DCHECK(observer->capture_mode_.enabled()); observer->capture_mode_ = capture_mode; - UpdateCaptureMode(); } void NetLog::DeprecatedRemoveObserver(NetLog::ThreadSafeObserver* observer) { @@ -267,26 +256,16 @@ void NetLog::DeprecatedRemoveObserver(NetLog::ThreadSafeObserver* observer) { DCHECK(observers_.HasObserver(observer)); DCHECK_EQ(this, observer->net_log_); - DCHECK(observer->capture_mode_.enabled()); observers_.RemoveObserver(observer); observer->net_log_ = NULL; observer->capture_mode_ = NetLogCaptureMode(); - UpdateCaptureMode(); + UpdateIsCapturing(); } -void NetLog::UpdateCaptureMode() { +void NetLog::UpdateIsCapturing() { lock_.AssertAcquired(); - - // Accumulate the capture mode of all the observers to find the maximum level. - NetLogCaptureMode new_capture_mode = NetLogCaptureMode::None(); - ObserverListBase<ThreadSafeObserver>::Iterator it(&observers_); - ThreadSafeObserver* observer; - while ((observer = it.GetNext()) != NULL) { - new_capture_mode = - NetLogCaptureMode::Max(new_capture_mode, observer->capture_mode()); - } - base::subtle::NoBarrier_Store(&effective_capture_mode_int32_, - new_capture_mode.ToInternalValue()); + base::subtle::NoBarrier_Store(&is_capturing_, + observers_.might_have_observers() ? 1 : 0); } // static @@ -390,7 +369,7 @@ void NetLog::AddEntry(EventType type, const Source& source, EventPhase phase, const NetLog::ParametersCallback* parameters_callback) { - if (!GetCaptureMode().enabled()) + if (!IsCapturing()) return; EntryData entry_data(type, source, phase, base::TimeTicks::Now(), parameters_callback); @@ -480,12 +459,9 @@ void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); } -NetLogCaptureMode BoundNetLog::GetCaptureMode() const { +bool BoundNetLog::IsCapturing() const { CrashIfInvalid(); - - if (net_log_) - return net_log_->GetCaptureMode(); - return NetLogCaptureMode(); + return net_log_ && net_log_->IsCapturing(); } // static diff --git a/net/log/net_log.h b/net/log/net_log.h index 42d40a2..3a1c7bc 100644 --- a/net/log/net_log.h +++ b/net/log/net_log.h @@ -207,9 +207,10 @@ class NET_EXPORT NetLog { // will be unique and greater than 0. uint32 NextID(); - // Returns the capture mode for this NetLog. This is used to avoid computing - // and saving expensive log entries. - NetLogCaptureMode GetCaptureMode() const; + // Returns true if there are any observers attached to the NetLog. This can be + // used as an optimization to avoid emitting log entries when there is no + // chance that the data will be consumed. + bool IsCapturing() const; // Adds an observer and sets its log capture mode. The observer must not be // watching any NetLog, including this one, when this is called. @@ -294,9 +295,9 @@ class NET_EXPORT NetLog { EventPhase phase, const NetLog::ParametersCallback* parameters_callback); - // Called whenever an observer is added or removed, or has its log - // capture mode changed. Must have acquired |lock_| prior to calling. - void UpdateCaptureMode(); + // Called whenever an observer is added or removed, to update + // |has_observers_|. Must have acquired |lock_| prior to calling. + void UpdateIsCapturing(); // |lock_| protects access to |observers_|. base::Lock lock_; @@ -304,10 +305,10 @@ class NET_EXPORT NetLog { // Last assigned source ID. Incremented to get the next one. base::subtle::Atomic32 last_id_; - // The current capture mode. Note that the capture mode is stored as an - // integer rather than a NetLogCaptureMode so that it can be easily - // read/written without a lock using Atomic32. - base::subtle::Atomic32 effective_capture_mode_int32_; + // |is_capturing_| will be 0 when there are no observers watching the NetLog, + // 1 otherwise. Note that this is stored as an Atomic32 rather than a boolean + // so it can be accessed without needing a lock. + base::subtle::Atomic32 is_capturing_; // |lock_| must be acquired whenever reading or writing to this. ObserverList<ThreadSafeObserver, true> observers_; @@ -362,7 +363,7 @@ class NET_EXPORT BoundNetLog { int byte_count, const char* bytes) const; - NetLogCaptureMode GetCaptureMode() const; + bool IsCapturing() const; // Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care // of creating a unique source ID, and handles the case of NULL net_log. diff --git a/net/log/net_log_capture_mode.cc b/net/log/net_log_capture_mode.cc index 501911e..8ac365f 100644 --- a/net/log/net_log_capture_mode.cc +++ b/net/log/net_log_capture_mode.cc @@ -14,9 +14,6 @@ namespace { // for method of NetLogCaptureMode, which expect that higher values imply more // capabilities. enum InternalValue { - // Don't log any events. - NONE, - // Log all events, but do not include the actual transferred bytes and // remove cookies and HTTP credentials. DEFAULT, @@ -32,12 +29,7 @@ enum InternalValue { } // namespace -// Default constructor creates an empty capture mode. -NetLogCaptureMode::NetLogCaptureMode() : NetLogCaptureMode(NONE) { -} - -NetLogCaptureMode NetLogCaptureMode::None() { - return NetLogCaptureMode(NONE); +NetLogCaptureMode::NetLogCaptureMode() : NetLogCaptureMode(DEFAULT) { } NetLogCaptureMode NetLogCaptureMode::Default() { @@ -52,15 +44,6 @@ NetLogCaptureMode NetLogCaptureMode::IncludeSocketBytes() { return NetLogCaptureMode(INCLUDE_SOCKET_BYTES); } -NetLogCaptureMode NetLogCaptureMode::Max(NetLogCaptureMode mode1, - NetLogCaptureMode mode2) { - return NetLogCaptureMode(std::max(mode1.value_, mode2.value_)); -} - -bool NetLogCaptureMode::enabled() const { - return value_ != NONE; -} - bool NetLogCaptureMode::include_cookies_and_credentials() const { return value_ >= INCLUDE_COOKIES_AND_CREDENTIALS; } @@ -78,18 +61,10 @@ bool NetLogCaptureMode::operator!=(NetLogCaptureMode mode) const { } int32_t NetLogCaptureMode::ToInternalValueForTesting() const { - return ToInternalValue(); + return value_; } NetLogCaptureMode::NetLogCaptureMode(uint32_t value) : value_(value) { } -NetLogCaptureMode NetLogCaptureMode::FromInternalValue(int32_t value) { - return NetLogCaptureMode(value); -} - -int32_t NetLogCaptureMode::ToInternalValue() const { - return value_; -} - } // namespace net diff --git a/net/log/net_log_capture_mode.h b/net/log/net_log_capture_mode.h index e4f26a3..2e011b7 100644 --- a/net/log/net_log_capture_mode.h +++ b/net/log/net_log_capture_mode.h @@ -19,43 +19,26 @@ class NET_EXPORT NetLogCaptureMode { public: // NOTE: Default assignment and copy constructor are OK. - // The default constructor creates an empty capture mode (equivalent to - // None()). + // The default constructor creates a capture mode equivalent to + // Default(). NetLogCaptureMode(); - // Constructs a capture mode which logs NOTHING. - // enabled() --> false - // include_cookies_and_credentials() --> false - // include_socket_bytes() --> false - static NetLogCaptureMode None(); - // Constructs a capture mode which logs basic events and event parameters. - // enabled() --> true // include_cookies_and_credentials() --> false // include_socket_bytes() --> false static NetLogCaptureMode Default(); // Constructs a capture mode which logs basic events, and additionally makes // no effort to strip cookies and credentials. - // enabled() --> true // include_cookies_and_credentials() --> true // include_socket_bytes() --> false static NetLogCaptureMode IncludeCookiesAndCredentials(); // Constructs a capture mode which logs the data sent/received from sockets. - // enabled() --> true // include_cookies_and_credentials() --> true // include_socket_bytes() --> true static NetLogCaptureMode IncludeSocketBytes(); - // Returns a capture mode that contains the maximal set of capabilities - // between |mode1| and |mode2|. - static NetLogCaptureMode Max(NetLogCaptureMode mode1, - NetLogCaptureMode mode2); - - // If enabled() is true, then _something_ is being captured. - bool enabled() const; - // If include_cookies_and_credentials() is true , then it is OK to log // events which contain cookies, credentials or other privacy sensitive data. bool include_cookies_and_credentials() const; @@ -70,15 +53,8 @@ class NET_EXPORT NetLogCaptureMode { int32_t ToInternalValueForTesting() const; private: - // NetLog relies on the internal value of NetLogCaptureMode being an integer, - // so it can be read/written atomically across thread. - friend class NetLog; - explicit NetLogCaptureMode(uint32_t value); - static NetLogCaptureMode FromInternalValue(int32_t value); - int32_t ToInternalValue() const; - int32_t value_; }; diff --git a/net/log/net_log_capture_mode_unittest.cc b/net/log/net_log_capture_mode_unittest.cc index b32beb9..f7f9fbd 100644 --- a/net/log/net_log_capture_mode_unittest.cc +++ b/net/log/net_log_capture_mode_unittest.cc @@ -10,29 +10,16 @@ namespace net { namespace { -TEST(NetLogCaptureMode, None) { - NetLogCaptureMode mode = NetLogCaptureMode::None(); - - EXPECT_FALSE(mode.enabled()); - EXPECT_FALSE(mode.include_cookies_and_credentials()); - EXPECT_FALSE(mode.include_socket_bytes()); - - EXPECT_EQ(mode, NetLogCaptureMode::None()); - EXPECT_NE(mode, NetLogCaptureMode::Default()); - EXPECT_NE(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); - EXPECT_NE(mode, NetLogCaptureMode::IncludeSocketBytes()); - EXPECT_EQ(mode.ToInternalValueForTesting(), - NetLogCaptureMode::None().ToInternalValueForTesting()); +TEST(NetLogCaptureMode, DefaultConstructor) { + EXPECT_EQ(NetLogCaptureMode(), NetLogCaptureMode::Default()); } TEST(NetLogCaptureMode, Default) { NetLogCaptureMode mode = NetLogCaptureMode::Default(); - EXPECT_TRUE(mode.enabled()); EXPECT_FALSE(mode.include_cookies_and_credentials()); EXPECT_FALSE(mode.include_socket_bytes()); - EXPECT_NE(mode, NetLogCaptureMode::None()); EXPECT_EQ(mode, NetLogCaptureMode::Default()); EXPECT_NE(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); EXPECT_NE(mode, NetLogCaptureMode::IncludeSocketBytes()); @@ -43,11 +30,9 @@ TEST(NetLogCaptureMode, Default) { TEST(NetLogCaptureMode, IncludeCookiesAndCredentials) { NetLogCaptureMode mode = NetLogCaptureMode::IncludeCookiesAndCredentials(); - EXPECT_TRUE(mode.enabled()); EXPECT_TRUE(mode.include_cookies_and_credentials()); EXPECT_FALSE(mode.include_socket_bytes()); - EXPECT_NE(mode, NetLogCaptureMode::None()); EXPECT_NE(mode, NetLogCaptureMode::Default()); EXPECT_EQ(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); EXPECT_NE(mode, NetLogCaptureMode::IncludeSocketBytes()); @@ -59,11 +44,9 @@ TEST(NetLogCaptureMode, IncludeCookiesAndCredentials) { TEST(NetLogCaptureMode, IncludeSocketBytes) { NetLogCaptureMode mode = NetLogCaptureMode::IncludeSocketBytes(); - EXPECT_TRUE(mode.enabled()); EXPECT_TRUE(mode.include_cookies_and_credentials()); EXPECT_TRUE(mode.include_socket_bytes()); - EXPECT_NE(mode, NetLogCaptureMode::None()); EXPECT_NE(mode, NetLogCaptureMode::Default()); EXPECT_NE(mode, NetLogCaptureMode::IncludeCookiesAndCredentials()); EXPECT_EQ(mode, NetLogCaptureMode::IncludeSocketBytes()); @@ -72,22 +55,6 @@ TEST(NetLogCaptureMode, IncludeSocketBytes) { NetLogCaptureMode::IncludeSocketBytes().ToInternalValueForTesting()); } -TEST(NetLogCaptureMode, Max) { - NetLogCaptureMode none = NetLogCaptureMode::None(); - NetLogCaptureMode all = NetLogCaptureMode::IncludeSocketBytes(); - NetLogCaptureMode cookies = NetLogCaptureMode::IncludeCookiesAndCredentials(); - NetLogCaptureMode def = NetLogCaptureMode::Default(); - - EXPECT_EQ(all, NetLogCaptureMode::Max(none, all)); - EXPECT_EQ(all, NetLogCaptureMode::Max(all, none)); - - EXPECT_EQ(cookies, NetLogCaptureMode::Max(def, cookies)); - EXPECT_EQ(cookies, NetLogCaptureMode::Max(cookies, def)); - - EXPECT_EQ(all, NetLogCaptureMode::Max(def, all)); - EXPECT_EQ(all, NetLogCaptureMode::Max(all, def)); -} - } // namespace } // namespace net diff --git a/net/log/net_log_unittest.cc b/net/log/net_log_unittest.cc index 26e71ce..62c51f1 100644 --- a/net/log/net_log_unittest.cc +++ b/net/log/net_log_unittest.cc @@ -61,7 +61,7 @@ TEST(NetLogTest, CaptureModes) { for (NetLogCaptureMode mode : kModes) { net_log.SetCaptureMode(mode); - EXPECT_EQ(mode, net_log.GetCaptureMode()); + EXPECT_EQ(mode, net_log.GetObserver()->capture_mode()); net_log.AddGlobalEntry(NetLog::TYPE_SOCKET_ALIVE, base::Bind(NetCaptureModeCallback)); @@ -261,16 +261,16 @@ TEST(NetLogTest, NetLogAddRemoveObserver) { AddEvent(&net_log); EXPECT_EQ(0, observer.count()); EXPECT_EQ(NULL, observer.net_log()); - EXPECT_FALSE(net_log.GetCaptureMode().enabled()); + EXPECT_FALSE(net_log.IsCapturing()); // Add the observer and add an event. net_log.DeprecatedAddObserver( &observer, NetLogCaptureMode::IncludeCookiesAndCredentials()); + EXPECT_TRUE(net_log.IsCapturing()); EXPECT_EQ(&net_log, observer.net_log()); EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), observer.capture_mode()); - EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), - net_log.GetCaptureMode()); + EXPECT_TRUE(net_log.IsCapturing()); AddEvent(&net_log); EXPECT_EQ(1, observer.count()); @@ -280,7 +280,7 @@ TEST(NetLogTest, NetLogAddRemoveObserver) { NetLogCaptureMode::IncludeSocketBytes()); EXPECT_EQ(&net_log, observer.net_log()); EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), observer.capture_mode()); - EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), net_log.GetCaptureMode()); + EXPECT_TRUE(net_log.IsCapturing()); AddEvent(&net_log); EXPECT_EQ(2, observer.count()); @@ -288,7 +288,7 @@ TEST(NetLogTest, NetLogAddRemoveObserver) { // Remove observer and add an event. net_log.DeprecatedRemoveObserver(&observer); EXPECT_EQ(NULL, observer.net_log()); - EXPECT_FALSE(net_log.GetCaptureMode().enabled()); + EXPECT_FALSE(net_log.IsCapturing()); AddEvent(&net_log); EXPECT_EQ(2, observer.count()); @@ -298,7 +298,7 @@ TEST(NetLogTest, NetLogAddRemoveObserver) { NetLogCaptureMode::IncludeSocketBytes()); EXPECT_EQ(&net_log, observer.net_log()); EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), observer.capture_mode()); - EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), net_log.GetCaptureMode()); + EXPECT_TRUE(net_log.IsCapturing()); AddEvent(&net_log); EXPECT_EQ(3, observer.count()); @@ -316,8 +316,7 @@ TEST(NetLogTest, NetLogTwoObservers) { EXPECT_EQ(NULL, observer[1].net_log()); EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), observer[0].capture_mode()); - EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), - net_log.GetCaptureMode()); + EXPECT_TRUE(net_log.IsCapturing()); // Add second observer observer. net_log.DeprecatedAddObserver(&observer[1], @@ -328,7 +327,7 @@ TEST(NetLogTest, NetLogTwoObservers) { observer[0].capture_mode()); EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), observer[1].capture_mode()); - EXPECT_EQ(NetLogCaptureMode::IncludeSocketBytes(), net_log.GetCaptureMode()); + EXPECT_TRUE(net_log.IsCapturing()); // Add event and make sure both observers receive it at their respective log // levels. @@ -347,8 +346,7 @@ TEST(NetLogTest, NetLogTwoObservers) { EXPECT_EQ(NULL, observer[1].net_log()); EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), observer[0].capture_mode()); - EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), - net_log.GetCaptureMode()); + EXPECT_TRUE(net_log.IsCapturing()); // Add event and make sure only second observer gets it. AddEvent(&net_log); @@ -359,7 +357,7 @@ TEST(NetLogTest, NetLogTwoObservers) { net_log.DeprecatedRemoveObserver(&observer[0]); EXPECT_EQ(NULL, observer[0].net_log()); EXPECT_EQ(NULL, observer[1].net_log()); - EXPECT_FALSE(net_log.GetCaptureMode().enabled()); + EXPECT_FALSE(net_log.IsCapturing()); // Add event and make sure neither observer gets it. AddEvent(&net_log); diff --git a/net/log/net_log_util.cc b/net/log/net_log_util.cc index 0ac5b41..97d9a76 100644 --- a/net/log/net_log_util.cc +++ b/net/log/net_log_util.cc @@ -521,10 +521,12 @@ NET_EXPORT void CreateNetLogEntriesForActiveObjects( NetLog::ParametersCallback callback = base::Bind(&GetRequestStateAsValue, base::Unretained(request)); + // Note that passing the hardcoded NetLogCaptureMode::Default() below is + // fine, since GetRequestStateAsValue() ignores the capture mode. NetLog::EntryData entry_data( NetLog::TYPE_REQUEST_ALIVE, request->net_log().source(), NetLog::PHASE_BEGIN, request->creation_time(), &callback); - NetLog::Entry entry(&entry_data, request->net_log().GetCaptureMode()); + NetLog::Entry entry(&entry_data, NetLogCaptureMode::Default()); observer->OnAddEntry(entry); } } diff --git a/net/log/write_to_file_net_log_observer_unittest.cc b/net/log/write_to_file_net_log_observer_unittest.cc index 4cabfe8c..6a8280e 100644 --- a/net/log/write_to_file_net_log_observer_unittest.cc +++ b/net/log/write_to_file_net_log_observer_unittest.cc @@ -67,7 +67,6 @@ TEST_F(WriteToFileNetLogObserverTest, CaptureMode) { WriteToFileNetLogObserver logger; logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr); EXPECT_EQ(NetLogCaptureMode::Default(), logger.capture_mode()); - EXPECT_EQ(NetLogCaptureMode::Default(), net_log_.GetCaptureMode()); logger.StopObserving(nullptr); file.reset(base::OpenFile(log_path_, "w")); @@ -76,8 +75,6 @@ TEST_F(WriteToFileNetLogObserverTest, CaptureMode) { logger.StartObserving(&net_log_, file.Pass(), nullptr, nullptr); EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), logger.capture_mode()); - EXPECT_EQ(NetLogCaptureMode::IncludeCookiesAndCredentials(), - net_log_.GetCaptureMode()); logger.StopObserving(nullptr); } diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 10019b8..e3406aa 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -1380,7 +1380,7 @@ int ProxyService::DidFinishResolvingProxy(const GURL& url, network_delegate->NotifyResolveProxy(url, load_flags, *this, result); // When logging all events is enabled, dump the proxy list. - if (net_log.GetCaptureMode().enabled()) { + if (net_log.IsCapturing()) { net_log.AddEvent( NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, base::Bind(&NetLogFinishedResolvingProxyCallback, result)); diff --git a/net/socket/transport_client_socket_pool.cc b/net/socket/transport_client_socket_pool.cc index f2d1247..b728cb9 100644 --- a/net/socket/transport_client_socket_pool.cc +++ b/net/socket/transport_client_socket_pool.cc @@ -506,7 +506,7 @@ int TransportClientSocketPool::RequestSocket( void TransportClientSocketPool::NetLogTcpClientSocketPoolRequestedSocket( const BoundNetLog& net_log, const scoped_refptr<TransportSocketParams>* casted_params) { - if (net_log.GetCaptureMode().enabled()) { + if (net_log.IsCapturing()) { // TODO(eroman): Split out the host and port parameters. net_log.AddEvent( NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, @@ -523,7 +523,7 @@ void TransportClientSocketPool::RequestSockets( const scoped_refptr<TransportSocketParams>* casted_params = static_cast<const scoped_refptr<TransportSocketParams>*>(params); - if (net_log.GetCaptureMode().enabled()) { + if (net_log.IsCapturing()) { // TODO(eroman): Split out the host and port parameters. net_log.AddEvent( NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKETS, diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index ca0e2b8..19a7c86 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -1078,7 +1078,7 @@ scoped_ptr<SpdyFrame> SpdySession::CreateSynStream( streams_initiated_count_++; - if (net_log().GetCaptureMode().enabled()) { + if (net_log().IsCapturing()) { const NetLog::EventType type = (GetProtocolVersion() <= SPDY3) ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM @@ -1188,7 +1188,7 @@ scoped_ptr<SpdyBuffer> SpdySession::CreateDataBuffer(SpdyStreamId stream_id, if (effective_len < len) flags = static_cast<SpdyDataFlags>(flags & ~DATA_FLAG_FIN); - if (net_log().GetCaptureMode().enabled()) { + if (net_log().IsCapturing()) { net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SEND_DATA, base::Bind(&NetLogSpdyDataCallback, stream_id, effective_len, (flags & DATA_FLAG_FIN) != 0)); @@ -2042,7 +2042,7 @@ void SpdySession::OnStreamFrameData(SpdyStreamId stream_id, bool fin) { CHECK(in_io_loop_); DCHECK_LT(len, 1u << 24); - if (net_log().GetCaptureMode().enabled()) { + if (net_log().IsCapturing()) { net_log().AddEvent( NetLog::TYPE_HTTP2_SESSION_RECV_DATA, base::Bind(&NetLogSpdyDataCallback, stream_id, len, fin)); @@ -2115,7 +2115,7 @@ void SpdySession::OnSettings(bool clear_persisted) { if (clear_persisted) http_server_properties_->ClearSpdySettings(host_port_pair()); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_SETTINGS, base::Bind(&NetLogSpdySettingsCallback, host_port_pair(), clear_persisted)); @@ -2228,7 +2228,7 @@ void SpdySession::OnSynStream(SpdyStreamId stream_id, base::Time response_time = base::Time::Now(); base::TimeTicks recv_first_byte_time = time_func_(); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( NetLog::TYPE_HTTP2_SESSION_PUSHED_SYN_STREAM, base::Bind(&NetLogSpdySynStreamReceivedCallback, &headers, fin, @@ -2300,7 +2300,7 @@ void SpdySession::OnSynReply(SpdyStreamId stream_id, base::Time response_time = base::Time::Now(); base::TimeTicks recv_first_byte_time = time_func_(); - if (net_log().GetCaptureMode().enabled()) { + if (net_log().IsCapturing()) { net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_SYN_REPLY, base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, &headers, fin, stream_id)); @@ -2345,7 +2345,7 @@ void SpdySession::OnHeaders(SpdyStreamId stream_id, const SpdyHeaderBlock& headers) { CHECK(in_io_loop_); - if (net_log().GetCaptureMode().enabled()) { + if (net_log().IsCapturing()) { net_log().AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_HEADERS, base::Bind(&NetLogSpdySynReplyOrHeadersReceivedCallback, &headers, fin, stream_id)); @@ -2728,7 +2728,7 @@ void SpdySession::OnPushPromise(SpdyStreamId stream_id, const SpdyHeaderBlock& headers) { CHECK(in_io_loop_); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent(NetLog::TYPE_HTTP2_SESSION_RECV_PUSH_PROMISE, base::Bind(&NetLogSpdyPushPromiseReceivedCallback, &headers, stream_id, promised_stream_id)); @@ -2922,7 +2922,7 @@ void SpdySession::WritePingFrame(SpdyPingId unique_id, bool is_ack) { buffered_spdy_framer_->CreatePingFrame(unique_id, is_ack)); EnqueueSessionWrite(HIGHEST, PING, ping_frame.Pass()); - if (net_log().GetCaptureMode().enabled()) { + if (net_log().IsCapturing()) { net_log().AddEvent( NetLog::TYPE_HTTP2_SESSION_PING, base::Bind(&NetLogSpdyPingCallback, unique_id, is_ack, "sent")); diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc index 270d763..faab9a4 100644 --- a/net/udp/udp_socket_libevent.cc +++ b/net/udp/udp_socket_libevent.cc @@ -414,7 +414,7 @@ void UDPSocketLibevent::LogRead(int result, return; } - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { DCHECK(addr_len > 0); DCHECK(addr); @@ -451,7 +451,7 @@ void UDPSocketLibevent::LogWrite(int result, return; } - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_SENT, CreateNetLogUDPDataTranferCallback(result, bytes, address)); diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc index 8c226f9..907ef22 100644 --- a/net/udp/udp_socket_win.cc +++ b/net/udp/udp_socket_win.cc @@ -681,7 +681,7 @@ void UDPSocketWin::LogRead(int result, return; } - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_RECEIVED, CreateNetLogUDPDataTranferCallback(result, bytes, address)); @@ -698,7 +698,7 @@ void UDPSocketWin::LogWrite(int result, return; } - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( NetLog::TYPE_UDP_BYTES_SENT, CreateNetLogUDPDataTranferCallback(result, bytes, address)); diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 13ba503..c8a0954 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -892,7 +892,7 @@ void URLRequest::OrphanJob() { int URLRequest::Redirect(const RedirectInfo& redirect_info) { // Matches call in NotifyReceivedRedirect. OnCallToDelegateComplete(); - if (net_log_.GetCaptureMode().enabled()) { + if (net_log_.IsCapturing()) { net_log_.AddEvent( NetLog::TYPE_URL_REQUEST_REDIRECTED, NetLog::StringCallback("location", diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index 5b14b6b..e466569 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -698,12 +698,11 @@ bool URLRequestJob::ReadFilteredData(int* bytes_read) { } // If logging all bytes is enabled, log the filtered bytes read. - if (rv && request() && - request()->net_log().GetCaptureMode().include_socket_bytes() && - filtered_data_len > 0) { + if (rv && request() && filtered_data_len > 0 && + request()->net_log().IsCapturing()) { request()->net_log().AddByteTransferEvent( - NetLog::TYPE_URL_REQUEST_JOB_FILTERED_BYTES_READ, - filtered_data_len, filtered_read_buffer_->data()); + NetLog::TYPE_URL_REQUEST_JOB_FILTERED_BYTES_READ, filtered_data_len, + filtered_read_buffer_->data()); } } else { // we are done, or there is no data left. @@ -790,9 +789,8 @@ void URLRequestJob::FollowRedirect(const RedirectInfo& redirect_info) { void URLRequestJob::OnRawReadComplete(int bytes_read) { DCHECK(raw_read_buffer_.get()); // If |filter_| is non-NULL, bytes will be logged after it is applied instead. - if (!filter_.get() && request() && - request()->net_log().GetCaptureMode().include_socket_bytes() && - bytes_read > 0) { + if (!filter_.get() && request() && bytes_read > 0 && + request()->net_log().IsCapturing()) { request()->net_log().AddByteTransferEvent( NetLog::TYPE_URL_REQUEST_JOB_BYTES_READ, bytes_read, raw_read_buffer_->data()); |