summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/net/chrome_net_log.cc11
-rw-r--r--chrome/browser/net/chrome_net_log.h5
-rw-r--r--chrome/browser/net/chrome_net_log_unittest.cc8
-rw-r--r--chrome/browser/net/load_timing_observer.cc203
-rw-r--r--chrome/browser/net/load_timing_observer.h36
-rw-r--r--chrome/browser/net/load_timing_observer_unittest.cc320
-rw-r--r--chrome/browser/net/net_log_logger.cc10
-rw-r--r--chrome/browser/net/net_log_logger.h6
-rw-r--r--chrome/browser/ui/webui/media/media_internals_proxy.cc11
-rw-r--r--chrome/browser/ui/webui/media/media_internals_proxy.h6
-rw-r--r--chrome/browser/ui/webui/net_internals/net_internals_ui.cc24
-rw-r--r--content/browser/debugger/devtools_netlog_observer.cc145
-rw-r--r--content/browser/debugger/devtools_netlog_observer.h26
-rw-r--r--net/base/capturing_net_log.cc22
-rw-r--r--net/base/capturing_net_log.h6
-rw-r--r--net/base/file_stream_unittest.cc15
-rw-r--r--net/base/net_log.cc315
-rw-r--r--net/base/net_log.h203
-rw-r--r--net/base/net_log_unittest.cc35
-rw-r--r--net/http/http_net_log_params.cc59
-rw-r--r--net/http/http_net_log_params.h71
-rw-r--r--net/http/http_network_transaction.cc9
-rw-r--r--net/http/http_network_transaction_spdy2_unittest.cc1
-rw-r--r--net/http/http_network_transaction_spdy3_unittest.cc1
-rw-r--r--net/http/http_proxy_client_socket.cc21
-rw-r--r--net/http/http_request_headers.cc51
-rw-r--r--net/http/http_request_headers.h21
-rw-r--r--net/http/http_request_headers_unittest.cc21
-rw-r--r--net/http/http_response_headers.cc51
-rw-r--r--net/http/http_response_headers.h13
-rw-r--r--net/http/http_response_headers_unittest.cc28
-rw-r--r--net/http/http_stream_parser.cc14
-rw-r--r--net/net.gyp3
-rw-r--r--net/socket/ssl_client_socket_nss.cc55
-rw-r--r--net/spdy/spdy_proxy_client_socket.cc21
-rw-r--r--net/url_request/url_request.cc4
-rw-r--r--net/url_request/url_request_netlog_params.cc37
-rw-r--r--net/url_request/url_request_netlog_params.h50
-rw-r--r--remoting/host/vlog_net_log.cc11
-rw-r--r--remoting/host/vlog_net_log.h6
40 files changed, 1013 insertions, 942 deletions
diff --git a/chrome/browser/net/chrome_net_log.cc b/chrome/browser/net/chrome_net_log.cc
index fb6ccf8..7c345b4f 100644
--- a/chrome/browser/net/chrome_net_log.cc
+++ b/chrome/browser/net/chrome_net_log.cc
@@ -49,18 +49,11 @@ ChromeNetLog::~ChromeNetLog() {
RemoveThreadSafeObserver(net_log_logger_.get());
}
-void ChromeNetLog::AddEntry(
- EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<EventParameters>& params) {
- base::TimeTicks time(base::TimeTicks::Now());
-
+void ChromeNetLog::OnAddEntry(const net::NetLog::Entry& entry) {
base::AutoLock lock(lock_);
// Notify all of the log observers.
- FOR_EACH_OBSERVER(ThreadSafeObserver, observers_,
- OnAddEntry(type, time, source, phase, params));
+ FOR_EACH_OBSERVER(ThreadSafeObserver, observers_, OnAddEntry(entry));
}
uint32 ChromeNetLog::NextID() {
diff --git a/chrome/browser/net/chrome_net_log.h b/chrome/browser/net/chrome_net_log.h
index e297d33..adbad5e 100644
--- a/chrome/browser/net/chrome_net_log.h
+++ b/chrome/browser/net/chrome_net_log.h
@@ -42,10 +42,7 @@ class ChromeNetLog : public net::NetLog {
private:
// NetLog implementation:
- virtual void AddEntry(EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<EventParameters>& params) OVERRIDE;
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
// Called whenever an observer is added or removed, or has its log level
// changed. Must have acquired |lock_| prior to calling.
diff --git a/chrome/browser/net/chrome_net_log_unittest.cc b/chrome/browser/net/chrome_net_log_unittest.cc
index d04dfb7..4f89f7d 100644
--- a/chrome/browser/net/chrome_net_log_unittest.cc
+++ b/chrome/browser/net/chrome_net_log_unittest.cc
@@ -22,11 +22,7 @@ class CountingObserver : public net::NetLog::ThreadSafeObserver {
net_log()->RemoveThreadSafeObserver(this);
}
- virtual void OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) OVERRIDE {
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE {
++count_;
}
@@ -37,7 +33,7 @@ class CountingObserver : public net::NetLog::ThreadSafeObserver {
};
void AddEvent(ChromeNetLog* net_log) {
- net_log->AddGlobalEntry(net::NetLog::TYPE_CANCELLED, NULL);
+ net_log->AddGlobalEntry(net::NetLog::TYPE_CANCELLED);
}
// A thread that waits until an event has been signalled before calling
diff --git a/chrome/browser/net/load_timing_observer.cc b/chrome/browser/net/load_timing_observer.cc
index b6760bc..d230f2b 100644
--- a/chrome/browser/net/load_timing_observer.cc
+++ b/chrome/browser/net/load_timing_observer.cc
@@ -83,22 +83,18 @@ LoadTimingObserver::GetURLRequestRecord(uint32 source_id) {
return NULL;
}
-void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+void LoadTimingObserver::OnAddEntry(const net::NetLog::Entry& entry) {
// The events that the Observer is interested in only occur on the IO thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
return;
- if (source.type == net::NetLog::SOURCE_URL_REQUEST)
- OnAddURLRequestEntry(type, time, source, phase, params);
- else if (source.type == net::NetLog::SOURCE_HTTP_STREAM_JOB)
- OnAddHTTPStreamJobEntry(type, time, source, phase, params);
- else if (source.type == net::NetLog::SOURCE_CONNECT_JOB)
- OnAddConnectJobEntry(type, time, source, phase, params);
- else if (source.type == net::NetLog::SOURCE_SOCKET)
- OnAddSocketEntry(type, time, source, phase, params);
+ if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST)
+ OnAddURLRequestEntry(entry);
+ else if (entry.source().type == net::NetLog::SOURCE_HTTP_STREAM_JOB)
+ OnAddHTTPStreamJobEntry(entry);
+ else if (entry.source().type == net::NetLog::SOURCE_CONNECT_JOB)
+ OnAddConnectJobEntry(entry);
+ else if (entry.source().type == net::NetLog::SOURCE_SOCKET)
+ OnAddSocketEntry(entry);
}
// static
@@ -125,23 +121,23 @@ void LoadTimingObserver::PopulateTimingInfo(
}
}
-void LoadTimingObserver::OnAddURLRequestEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+void LoadTimingObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- bool is_begin = phase == net::NetLog::PHASE_BEGIN;
- bool is_end = phase == net::NetLog::PHASE_END;
+ bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
+ bool is_end = entry.phase() == net::NetLog::PHASE_END;
- if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) {
+ if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) {
if (is_begin) {
// Only record timing for entries with corresponding flag.
- int load_flags =
- static_cast<net::URLRequestStartEventParameters*>(params)->
- load_flags();
+ int load_flags;
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+ if (!net::StartEventLoadFlagsFromEventParams(event_params.get(),
+ &load_flags)) {
+ NOTREACHED();
+ return;
+ }
+
if (!(load_flags & net::LOAD_ENABLE_LOAD_TIMING))
return;
@@ -153,38 +149,48 @@ void LoadTimingObserver::OnAddURLRequestEntry(
url_request_to_record_.clear();
}
- URLRequestRecord& record = url_request_to_record_[source.id];
- record.base_ticks = time;
+ URLRequestRecord& record = url_request_to_record_[entry.source().id];
+ base::TimeTicks now = GetCurrentTime();
+ record.base_ticks = now;
record.timing = ResourceLoadTimingInfo();
- record.timing.base_ticks = time;
- record.timing.base_time = TimeTicksToTime(time);
+ record.timing.base_ticks = now;
+ record.timing.base_time = TimeTicksToTime(now);
}
return;
- } else if (type == net::NetLog::TYPE_REQUEST_ALIVE) {
+ } else if (entry.type() == net::NetLog::TYPE_REQUEST_ALIVE) {
// Cleanup records based on the TYPE_REQUEST_ALIVE entry.
if (is_end)
- url_request_to_record_.erase(source.id);
+ url_request_to_record_.erase(entry.source().id);
return;
}
- URLRequestRecord* record = GetURLRequestRecord(source.id);
+ URLRequestRecord* record = GetURLRequestRecord(entry.source().id);
if (!record)
return;
ResourceLoadTimingInfo& timing = record->timing;
- switch (type) {
+ switch (entry.type()) {
case net::NetLog::TYPE_PROXY_SERVICE:
if (is_begin)
- timing.proxy_start = TimeTicksToOffset(time, record);
+ timing.proxy_start = TimeTicksToOffset(GetCurrentTime(), record);
else if (is_end)
- timing.proxy_end = TimeTicksToOffset(time, record);
+ timing.proxy_end = TimeTicksToOffset(GetCurrentTime(), record);
break;
case net::NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB: {
- uint32 http_stream_job_id = static_cast<net::NetLogSourceParameter*>(
- params)->value().id;
+ net::NetLog::Source http_stream_job_source;
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+ if (!net::NetLog::Source::FromEventParameters(
+ event_params.get(),
+ &http_stream_job_source)) {
+ NOTREACHED();
+ return;
+ }
+ DCHECK_EQ(net::NetLog::SOURCE_HTTP_STREAM_JOB,
+ http_stream_job_source.type);
+
HTTPStreamJobToRecordMap::iterator it =
- http_stream_job_to_record_.find(http_stream_job_id);
+ http_stream_job_to_record_.find(http_stream_job_source.id);
if (it == http_stream_job_to_record_.end())
return;
if (!it->second.connect_start.is_null()) {
@@ -207,15 +213,18 @@ void LoadTimingObserver::OnAddURLRequestEntry(
}
case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST:
if (is_begin)
- timing.send_start = TimeTicksToOffset(time, record);
+ timing.send_start = TimeTicksToOffset(GetCurrentTime(), record);
else if (is_end)
- timing.send_end = TimeTicksToOffset(time, record);
+ timing.send_end = TimeTicksToOffset(GetCurrentTime(), record);
break;
case net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS:
- if (is_begin)
- timing.receive_headers_start = TimeTicksToOffset(time, record);
- else if (is_end)
- timing.receive_headers_end = TimeTicksToOffset(time, record);
+ if (is_begin) {
+ timing.receive_headers_start =
+ TimeTicksToOffset(GetCurrentTime(), record);
+ } else if (is_end) {
+ timing.receive_headers_end =
+ TimeTicksToOffset(GetCurrentTime(), record);
+ }
break;
default:
break;
@@ -223,17 +232,13 @@ void LoadTimingObserver::OnAddURLRequestEntry(
}
void LoadTimingObserver::OnAddHTTPStreamJobEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+ const net::NetLog::Entry& entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- bool is_begin = phase == net::NetLog::PHASE_BEGIN;
- bool is_end = phase == net::NetLog::PHASE_END;
+ bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
+ bool is_end = entry.phase() == net::NetLog::PHASE_END;
- if (type == net::NetLog::TYPE_HTTP_STREAM_JOB) {
+ if (entry.type() == net::NetLog::TYPE_HTTP_STREAM_JOB) {
if (is_begin) {
// Prevents us from passively growing the memory unbounded in
// case something went wrong. Should not happen.
@@ -244,29 +249,36 @@ void LoadTimingObserver::OnAddHTTPStreamJobEntry(
}
http_stream_job_to_record_.insert(
- std::make_pair(source.id, HTTPStreamJobRecord()));
+ std::make_pair(entry.source().id, HTTPStreamJobRecord()));
} else if (is_end) {
- http_stream_job_to_record_.erase(source.id);
+ http_stream_job_to_record_.erase(entry.source().id);
}
return;
}
HTTPStreamJobToRecordMap::iterator it =
- http_stream_job_to_record_.find(source.id);
+ http_stream_job_to_record_.find(entry.source().id);
if (it == http_stream_job_to_record_.end())
return;
- switch (type) {
+ switch (entry.type()) {
case net::NetLog::TYPE_SOCKET_POOL:
if (is_begin)
- it->second.connect_start = time;
+ it->second.connect_start = GetCurrentTime();
else if (is_end)
- it->second.connect_end = time;
+ it->second.connect_end = GetCurrentTime();
break;
case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB: {
- uint32 connect_job_id = static_cast<net::NetLogSourceParameter*>(
- params)->value().id;
- if (last_connect_job_id_ == connect_job_id &&
+ net::NetLog::Source connect_job_source;
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+ if (!net::NetLog::Source::FromEventParameters(event_params.get(),
+ &connect_job_source)) {
+ NOTREACHED();
+ return;
+ }
+ DCHECK_EQ(net::NetLog::SOURCE_CONNECT_JOB, connect_job_source.type);
+
+ if (last_connect_job_id_ == connect_job_source.id &&
!last_connect_job_record_.dns_start.is_null()) {
it->second.dns_start = last_connect_job_record_.dns_start;
it->second.dns_end = last_connect_job_record_.dns_end;
@@ -276,9 +288,17 @@ void LoadTimingObserver::OnAddHTTPStreamJobEntry(
case net::NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET:
it->second.socket_reused = true;
break;
- case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET:
- it->second.socket_log_id = static_cast<net::NetLogSourceParameter*>(
- params)->value().id;
+ case net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET: {
+ net::NetLog::Source socket_source;
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+ if (!net::NetLog::Source::FromEventParameters(event_params.get(),
+ &socket_source)) {
+ NOTREACHED();
+ return;
+ }
+ DCHECK_EQ(net::NetLog::SOURCE_SOCKET, socket_source.type);
+
+ it->second.socket_log_id = socket_source.id;
if (!it->second.socket_reused) {
SocketToRecordMap::iterator socket_it =
socket_to_record_.find(it->second.socket_log_id);
@@ -289,24 +309,20 @@ void LoadTimingObserver::OnAddHTTPStreamJobEntry(
}
}
break;
+ }
default:
break;
}
}
-void LoadTimingObserver::OnAddConnectJobEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+void LoadTimingObserver::OnAddConnectJobEntry(const net::NetLog::Entry& entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- bool is_begin = phase == net::NetLog::PHASE_BEGIN;
- bool is_end = phase == net::NetLog::PHASE_END;
+ bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
+ bool is_end = entry.phase() == net::NetLog::PHASE_END;
// Manage record lifetime based on the SOCKET_POOL_CONNECT_JOB entry.
- if (type == net::NetLog::TYPE_SOCKET_POOL_CONNECT_JOB) {
+ if (entry.type() == net::NetLog::TYPE_SOCKET_POOL_CONNECT_JOB) {
if (is_begin) {
// Prevents us from passively growing the memory unbounded in case
// something went wrong. Should not happen.
@@ -317,41 +333,36 @@ void LoadTimingObserver::OnAddConnectJobEntry(
}
connect_job_to_record_.insert(
- std::make_pair(source.id, ConnectJobRecord()));
+ std::make_pair(entry.source().id, ConnectJobRecord()));
} else if (is_end) {
ConnectJobToRecordMap::iterator it =
- connect_job_to_record_.find(source.id);
+ connect_job_to_record_.find(entry.source().id);
if (it != connect_job_to_record_.end()) {
last_connect_job_id_ = it->first;
last_connect_job_record_ = it->second;
connect_job_to_record_.erase(it);
}
}
- } else if (type == net::NetLog::TYPE_HOST_RESOLVER_IMPL) {
+ } else if (entry.type() == net::NetLog::TYPE_HOST_RESOLVER_IMPL) {
ConnectJobToRecordMap::iterator it =
- connect_job_to_record_.find(source.id);
+ connect_job_to_record_.find(entry.source().id);
if (it != connect_job_to_record_.end()) {
if (is_begin)
- it->second.dns_start = time;
+ it->second.dns_start = GetCurrentTime();
else if (is_end)
- it->second.dns_end = time;
+ it->second.dns_end = GetCurrentTime();
}
}
}
-void LoadTimingObserver::OnAddSocketEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+void LoadTimingObserver::OnAddSocketEntry(const net::NetLog::Entry& entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- bool is_begin = phase == net::NetLog::PHASE_BEGIN;
- bool is_end = phase == net::NetLog::PHASE_END;
+ bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
+ bool is_end = entry.phase() == net::NetLog::PHASE_END;
// Manage record lifetime based on the SOCKET_ALIVE entry.
- if (type == net::NetLog::TYPE_SOCKET_ALIVE) {
+ if (entry.type() == net::NetLog::TYPE_SOCKET_ALIVE) {
if (is_begin) {
// Prevents us from passively growing the memory unbounded in case
// something went wrong. Should not happen.
@@ -362,20 +373,24 @@ void LoadTimingObserver::OnAddSocketEntry(
}
socket_to_record_.insert(
- std::make_pair(source.id, SocketRecord()));
+ std::make_pair(entry.source().id, SocketRecord()));
} else if (is_end) {
- socket_to_record_.erase(source.id);
+ socket_to_record_.erase(entry.source().id);
}
return;
}
- SocketToRecordMap::iterator it = socket_to_record_.find(source.id);
+ SocketToRecordMap::iterator it = socket_to_record_.find(entry.source().id);
if (it == socket_to_record_.end())
return;
- if (type == net::NetLog::TYPE_SSL_CONNECT) {
+ if (entry.type() == net::NetLog::TYPE_SSL_CONNECT) {
if (is_begin)
- it->second.ssl_start = time;
+ it->second.ssl_start = GetCurrentTime();
else if (is_end)
- it->second.ssl_end = time;
+ it->second.ssl_end = GetCurrentTime();
}
}
+
+base::TimeTicks LoadTimingObserver::GetCurrentTime() const {
+ return base::TimeTicks::Now();
+}
diff --git a/chrome/browser/net/load_timing_observer.h b/chrome/browser/net/load_timing_observer.h
index 56d3f8e..7df1c20 100644
--- a/chrome/browser/net/load_timing_observer.h
+++ b/chrome/browser/net/load_timing_observer.h
@@ -70,11 +70,7 @@ class LoadTimingObserver : public net::NetLog::ThreadSafeObserver {
URLRequestRecord* GetURLRequestRecord(uint32 source_id);
// net::NetLog::ThreadSafeObserver implementation:
- virtual void OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) OVERRIDE;
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
static void PopulateTimingInfo(net::URLRequest* request,
content::ResourceResponse* response);
@@ -87,33 +83,17 @@ class LoadTimingObserver : public net::NetLog::ThreadSafeObserver {
FRIEND_TEST_ALL_PREFIXES(LoadTimingObserverTest,
SocketRecord);
- void OnAddURLRequestEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
-
- void OnAddHTTPStreamJobEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
-
- void OnAddConnectJobEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
-
- void OnAddSocketEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
+ void OnAddURLRequestEntry(const net::NetLog::Entry& entry);
+ void OnAddHTTPStreamJobEntry(const net::NetLog::Entry& entry);
+ void OnAddConnectJobEntry(const net::NetLog::Entry& entry);
+ void OnAddSocketEntry(const net::NetLog::Entry& entry);
URLRequestRecord* CreateURLRequestRecord(uint32 source_id);
void DeleteURLRequestRecord(uint32 source_id);
+ // Returns current time. Virtual for unit tests.
+ virtual base::TimeTicks GetCurrentTime() const;
+
typedef base::hash_map<uint32, URLRequestRecord> URLRequestToRecordMap;
typedef base::hash_map<uint32, HTTPStreamJobRecord> HTTPStreamJobToRecordMap;
typedef base::hash_map<uint32, ConnectJobRecord> ConnectJobToRecordMap;
diff --git a/chrome/browser/net/load_timing_observer_unittest.cc b/chrome/browser/net/load_timing_observer_unittest.cc
index 5859aad..564f10a 100644
--- a/chrome/browser/net/load_timing_observer_unittest.cc
+++ b/chrome/browser/net/load_timing_observer_unittest.cc
@@ -20,385 +20,379 @@ using base::TimeDelta;
using content::BrowserThread;
using net::NetLog;
+class TestLoadTimingObserver : public LoadTimingObserver {
+ public:
+ TestLoadTimingObserver() {}
+ virtual ~TestLoadTimingObserver() {}
+
+ void IncementTime(base::TimeDelta delta) {
+ current_time_ += delta;
+ }
+
+ virtual base::TimeTicks GetCurrentTime() const OVERRIDE {
+ return current_time_;
+ }
+
+ private:
+ base::TimeTicks current_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestLoadTimingObserver);
+};
+
// Serves to identify the current thread as the IO thread.
class LoadTimingObserverTest : public testing::Test {
public:
LoadTimingObserverTest() : io_thread_(BrowserThread::IO, &message_loop_) {
}
+ protected:
+ TestLoadTimingObserver observer_;
+
private:
MessageLoop message_loop_;
content::TestBrowserThread io_thread_;
};
-base::TimeTicks current_time;
+void AddStartEntry(LoadTimingObserver& observer,
+ const NetLog::Source& source,
+ NetLog::EventType type) {
+ net::NetLog::Entry entry(type,
+ source,
+ NetLog::PHASE_BEGIN,
+ NULL,
+ NetLog::LOG_BASIC);
+ observer.OnAddEntry(entry);
+}
void AddStartEntry(LoadTimingObserver& observer,
const NetLog::Source& source,
NetLog::EventType type,
- NetLog::EventParameters* params) {
- observer.OnAddEntry(type, current_time, source, NetLog::PHASE_BEGIN, params);
+ const NetLog::ParametersCallback& params_callback) {
+ net::NetLog::Entry entry(type,
+ source,
+ NetLog::PHASE_BEGIN,
+ &params_callback,
+ NetLog::LOG_BASIC);
+ observer.OnAddEntry(entry);
}
void AddEndEntry(LoadTimingObserver& observer,
const NetLog::Source& source,
- NetLog::EventType type,
- NetLog::EventParameters* params) {
- observer.OnAddEntry(type, current_time, source, NetLog::PHASE_END, params);
+ NetLog::EventType type) {
+ net::NetLog::Entry entry(type,
+ source,
+ NetLog::PHASE_END,
+ NULL,
+ NetLog::LOG_BASIC);
+ observer.OnAddEntry(entry);
}
void AddStartURLRequestEntries(LoadTimingObserver& observer,
uint32 id,
bool request_timing) {
- scoped_refptr<net::URLRequestStartEventParameters> params(
- new net::URLRequestStartEventParameters(
- GURL(base::StringPrintf("http://req%d", id)),
- "GET",
- request_timing ? net::LOAD_ENABLE_LOAD_TIMING : 0,
- net::LOW));
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id);
- AddStartEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE, NULL);
- AddStartEntry(observer,
- source,
- NetLog::TYPE_URL_REQUEST_START_JOB,
- params.get());
+ AddStartEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE);
+
+ GURL url(base::StringPrintf("http://req%d", id));
+ std::string method = "GET";
+ AddStartEntry(
+ observer,
+ source,
+ NetLog::TYPE_URL_REQUEST_START_JOB,
+ base::Bind(&net::NetLogURLRequestStartCallback,
+ &url,
+ &method,
+ request_timing ? net::LOAD_ENABLE_LOAD_TIMING : 0,
+ net::LOW));
}
void AddEndURLRequestEntries(LoadTimingObserver& observer, uint32 id) {
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, id);
- AddEndEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE, NULL);
- AddEndEntry(observer,
- source,
- NetLog::TYPE_URL_REQUEST_START_JOB,
- NULL);
+ AddEndEntry(observer, source, NetLog::TYPE_REQUEST_ALIVE);
+ AddEndEntry(observer, source, NetLog::TYPE_URL_REQUEST_START_JOB);
}
void AddStartHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) {
NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id);
- AddStartEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB, NULL);
+ AddStartEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB);
}
void AddEndHTTPStreamJobEntries(LoadTimingObserver& observer, uint32 id) {
NetLog::Source source(NetLog::SOURCE_HTTP_STREAM_JOB, id);
- AddEndEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB, NULL);
+ AddEndEntry(observer, source, NetLog::TYPE_HTTP_STREAM_JOB);
}
void AddStartConnectJobEntries(LoadTimingObserver& observer, uint32 id) {
NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id);
- AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL);
+ AddStartEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB);
}
void AddEndConnectJobEntries(LoadTimingObserver& observer, uint32 id) {
NetLog::Source source(NetLog::SOURCE_CONNECT_JOB, id);
- AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB, NULL);
+ AddEndEntry(observer, source, NetLog::TYPE_SOCKET_POOL_CONNECT_JOB);
}
void AddStartSocketEntries(LoadTimingObserver& observer, uint32 id) {
NetLog::Source source(NetLog::SOURCE_SOCKET, id);
- AddStartEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL);
+ AddStartEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE);
}
void AddEndSocketEntries(LoadTimingObserver& observer, uint32 id) {
NetLog::Source source(NetLog::SOURCE_SOCKET, id);
- AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE, NULL);
+ AddEndEntry(observer, source, NetLog::TYPE_SOCKET_ALIVE);
}
void BindURLRequestToHTTPStreamJob(LoadTimingObserver& observer,
NetLog::Source url_request_source,
NetLog::Source http_stream_job_source) {
- scoped_refptr<net::NetLogSourceParameter> params(
- new net::NetLogSourceParameter("source_dependency",
- http_stream_job_source));
AddStartEntry(observer,
url_request_source,
NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB,
- params.get());
+ http_stream_job_source.ToEventParametersCallback());
}
void BindHTTPStreamJobToConnectJob(LoadTimingObserver& observer,
NetLog::Source& http_stream_job_source,
NetLog::Source& connect_source) {
- scoped_refptr<net::NetLogSourceParameter> params(
- new net::NetLogSourceParameter("source_dependency", connect_source));
AddStartEntry(observer,
http_stream_job_source,
NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
- params.get());
+ connect_source.ToEventParametersCallback());
}
void BindHTTPStreamJobToSocket(LoadTimingObserver& observer,
NetLog::Source& http_stream_job_source,
NetLog::Source& socket_source) {
- scoped_refptr<net::NetLogSourceParameter> params(
- new net::NetLogSourceParameter("source_dependency", socket_source));
AddStartEntry(observer,
http_stream_job_source,
NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET,
- params.get());
+ socket_source.ToEventParametersCallback());
}
} // namespace
// Test that net::URLRequest with no load timing flag is not processed.
TEST_F(LoadTimingObserverTest, NoLoadTimingEnabled) {
- LoadTimingObserver observer;
-
- AddStartURLRequestEntries(observer, 0, false);
+ AddStartURLRequestEntries(observer_, 0, false);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_TRUE(record == NULL);
}
// Test that URLRequestRecord is created, deleted and is not growing unbound.
TEST_F(LoadTimingObserverTest, URLRequestRecord) {
- LoadTimingObserver observer;
-
// Create record.
- AddStartURLRequestEntries(observer, 0, true);
+ AddStartURLRequestEntries(observer_, 0, true);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_FALSE(record == NULL);
// Collect record.
- AddEndURLRequestEntries(observer, 0);
- record = observer.GetURLRequestRecord(0);
+ AddEndURLRequestEntries(observer_, 0);
+ record = observer_.GetURLRequestRecord(0);
ASSERT_TRUE(record == NULL);
// Check unbound growth.
for (size_t i = 1; i < 1100; ++i)
- AddStartURLRequestEntries(observer, i, true);
- record = observer.GetURLRequestRecord(1);
+ AddStartURLRequestEntries(observer_, i, true);
+ record = observer_.GetURLRequestRecord(1);
ASSERT_TRUE(record == NULL);
}
// Test that HTTPStreamJobRecord is created, deleted and is not growing unbound.
TEST_F(LoadTimingObserverTest, HTTPStreamJobRecord) {
- LoadTimingObserver observer;
-
// Create record.
- AddStartHTTPStreamJobEntries(observer, 0);
- ASSERT_FALSE(observer.http_stream_job_to_record_.find(0) ==
- observer.http_stream_job_to_record_.end());
+ AddStartHTTPStreamJobEntries(observer_, 0);
+ ASSERT_FALSE(observer_.http_stream_job_to_record_.find(0) ==
+ observer_.http_stream_job_to_record_.end());
// Collect record.
- AddEndHTTPStreamJobEntries(observer, 0);
- ASSERT_TRUE(observer.http_stream_job_to_record_.find(0) ==
- observer.http_stream_job_to_record_.end());
+ AddEndHTTPStreamJobEntries(observer_, 0);
+ ASSERT_TRUE(observer_.http_stream_job_to_record_.find(0) ==
+ observer_.http_stream_job_to_record_.end());
// Check unbound growth.
for (size_t i = 1; i < 1100; ++i)
- AddStartHTTPStreamJobEntries(observer, i);
- ASSERT_TRUE(observer.http_stream_job_to_record_.find(1) ==
- observer.http_stream_job_to_record_.end());
+ AddStartHTTPStreamJobEntries(observer_, i);
+ ASSERT_TRUE(observer_.http_stream_job_to_record_.find(1) ==
+ observer_.http_stream_job_to_record_.end());
}
// Test that ConnectJobRecord is created, deleted and is not growing unbound.
TEST_F(LoadTimingObserverTest, ConnectJobRecord) {
- LoadTimingObserver observer;
-
// Create record.
- AddStartConnectJobEntries(observer, 0);
- ASSERT_FALSE(observer.connect_job_to_record_.find(0) ==
- observer.connect_job_to_record_.end());
+ AddStartConnectJobEntries(observer_, 0);
+ ASSERT_FALSE(observer_.connect_job_to_record_.find(0) ==
+ observer_.connect_job_to_record_.end());
// Collect record.
- AddEndConnectJobEntries(observer, 0);
- ASSERT_TRUE(observer.connect_job_to_record_.find(0) ==
- observer.connect_job_to_record_.end());
+ AddEndConnectJobEntries(observer_, 0);
+ ASSERT_TRUE(observer_.connect_job_to_record_.find(0) ==
+ observer_.connect_job_to_record_.end());
// Check unbound growth.
for (size_t i = 1; i < 1100; ++i)
- AddStartConnectJobEntries(observer, i);
- ASSERT_TRUE(observer.connect_job_to_record_.find(1) ==
- observer.connect_job_to_record_.end());
+ AddStartConnectJobEntries(observer_, i);
+ ASSERT_TRUE(observer_.connect_job_to_record_.find(1) ==
+ observer_.connect_job_to_record_.end());
}
// Test that SocketRecord is created, deleted and is not growing unbound.
TEST_F(LoadTimingObserverTest, SocketRecord) {
- LoadTimingObserver observer;
-
// Create record.
- AddStartSocketEntries(observer, 0);
- ASSERT_FALSE(observer.socket_to_record_.find(0) ==
- observer.socket_to_record_.end());
+ AddStartSocketEntries(observer_, 0);
+ ASSERT_FALSE(observer_.socket_to_record_.find(0) ==
+ observer_.socket_to_record_.end());
// Collect record.
- AddEndSocketEntries(observer, 0);
- ASSERT_TRUE(observer.socket_to_record_.find(0) ==
- observer.socket_to_record_.end());
-
+ AddEndSocketEntries(observer_, 0);
+ ASSERT_TRUE(observer_.socket_to_record_.find(0) ==
+ observer_.socket_to_record_.end());
// Check unbound growth.
for (size_t i = 1; i < 1100; ++i)
- AddStartSocketEntries(observer, i);
- ASSERT_TRUE(observer.socket_to_record_.find(1) ==
- observer.socket_to_record_.end());
+ AddStartSocketEntries(observer_, i);
+ ASSERT_TRUE(observer_.socket_to_record_.find(1) ==
+ observer_.socket_to_record_.end());
}
// Test that basic time is set to the request.
TEST_F(LoadTimingObserverTest, BaseTicks) {
- LoadTimingObserver observer;
- current_time += TimeDelta::FromSeconds(1);
- AddStartURLRequestEntries(observer, 0, true);
+ observer_.IncementTime(TimeDelta::FromSeconds(1));
+ AddStartURLRequestEntries(observer_, 0, true);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_EQ(1000000, record->base_ticks.ToInternalValue());
}
// Test proxy time detection.
TEST_F(LoadTimingObserverTest, ProxyTime) {
- LoadTimingObserver observer;
- current_time += TimeDelta::FromSeconds(1);
+ observer_.IncementTime(TimeDelta::FromSeconds(1));
- AddStartURLRequestEntries(observer, 0, true);
+ AddStartURLRequestEntries(observer_, 0, true);
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
- current_time += TimeDelta::FromSeconds(2);
- AddStartEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL);
- current_time += TimeDelta::FromSeconds(3);
- AddEndEntry(observer, source, NetLog::TYPE_PROXY_SERVICE, NULL);
+ observer_.IncementTime(TimeDelta::FromSeconds(2));
+ AddStartEntry(observer_, source, NetLog::TYPE_PROXY_SERVICE);
+ observer_.IncementTime(TimeDelta::FromSeconds(3));
+ AddEndEntry(observer_, source, NetLog::TYPE_PROXY_SERVICE);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_EQ(2000, record->timing.proxy_start);
ASSERT_EQ(5000, record->timing.proxy_end);
}
// Test connect time detection.
TEST_F(LoadTimingObserverTest, ConnectTime) {
- LoadTimingObserver observer;
- current_time += TimeDelta::FromSeconds(1);
+ observer_.IncementTime(TimeDelta::FromSeconds(1));
- AddStartURLRequestEntries(observer, 0, true);
+ AddStartURLRequestEntries(observer_, 0, true);
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 1);
- AddStartHTTPStreamJobEntries(observer, 1);
+ AddStartHTTPStreamJobEntries(observer_, 1);
- current_time += TimeDelta::FromSeconds(2);
- AddStartEntry(observer, http_stream_job_source, NetLog::TYPE_SOCKET_POOL,
- NULL);
- current_time += TimeDelta::FromSeconds(3);
- AddEndEntry(observer, http_stream_job_source, NetLog::TYPE_SOCKET_POOL, NULL);
+ observer_.IncementTime(TimeDelta::FromSeconds(2));
+ AddStartEntry(observer_, http_stream_job_source, NetLog::TYPE_SOCKET_POOL);
+ observer_.IncementTime(TimeDelta::FromSeconds(3));
+ AddEndEntry(observer_, http_stream_job_source, NetLog::TYPE_SOCKET_POOL);
- BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source);
+ BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_EQ(2000, record->timing.connect_start);
ASSERT_EQ(5000, record->timing.connect_end);
}
// Test dns time detection.
TEST_F(LoadTimingObserverTest, DnsTime) {
- LoadTimingObserver observer;
-
// Start request.
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
- AddStartURLRequestEntries(observer, 0, true);
- current_time += TimeDelta::FromSeconds(1);
+ AddStartURLRequestEntries(observer_, 0, true);
+ observer_.IncementTime(TimeDelta::FromSeconds(1));
// Add resolver entry.
- AddStartConnectJobEntries(observer, 1);
+ AddStartConnectJobEntries(observer_, 1);
NetLog::Source connect_source(NetLog::SOURCE_CONNECT_JOB, 1);
- AddStartEntry(observer,
- connect_source,
- NetLog::TYPE_HOST_RESOLVER_IMPL,
- NULL);
- current_time += TimeDelta::FromSeconds(2);
- AddEndEntry(observer, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL, NULL);
- AddEndConnectJobEntries(observer, 1);
+ AddStartEntry(observer_, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL);
+ observer_.IncementTime(TimeDelta::FromSeconds(2));
+ AddEndEntry(observer_, connect_source, NetLog::TYPE_HOST_RESOLVER_IMPL);
+ AddEndConnectJobEntries(observer_, 1);
NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2);
- AddStartHTTPStreamJobEntries(observer, 2);
+ AddStartHTTPStreamJobEntries(observer_, 2);
- BindHTTPStreamJobToConnectJob(observer, http_stream_job_source,
+ BindHTTPStreamJobToConnectJob(observer_, http_stream_job_source,
connect_source);
- BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source);
+ BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_EQ(1000, record->timing.dns_start);
ASSERT_EQ(3000, record->timing.dns_end);
}
// Test send time detection.
TEST_F(LoadTimingObserverTest, SendTime) {
- LoadTimingObserver observer;
-
// Start request.
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
- AddStartURLRequestEntries(observer, 0, true);
- current_time += TimeDelta::FromSeconds(2);
+ AddStartURLRequestEntries(observer_, 0, true);
+ observer_.IncementTime(TimeDelta::FromSeconds(2));
// Add send request entry.
- AddStartEntry(observer,
- source,
- NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST,
- NULL);
- current_time += TimeDelta::FromSeconds(5);
- AddEndEntry(observer,
- source,
- NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST,
- NULL);
+ AddStartEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST);
+ observer_.IncementTime(TimeDelta::FromSeconds(5));
+ AddEndEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_EQ(2000, record->timing.send_start);
ASSERT_EQ(7000, record->timing.send_end);
}
// Test receive time detection.
TEST_F(LoadTimingObserverTest, ReceiveTime) {
- LoadTimingObserver observer;
-
// Start request.
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
- AddStartURLRequestEntries(observer, 0, true);
- current_time += TimeDelta::FromSeconds(2);
+ AddStartURLRequestEntries(observer_, 0, true);
+ observer_.IncementTime(TimeDelta::FromSeconds(2));
// Add send request entry.
- AddStartEntry(observer,
- source,
- NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS,
- NULL);
- current_time += TimeDelta::FromSeconds(5);
- AddEndEntry(observer,
- source,
- NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS,
- NULL);
+ AddStartEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS);
+ observer_.IncementTime(TimeDelta::FromSeconds(5));
+ AddEndEntry(observer_, source, NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_EQ(2000, record->timing.receive_headers_start);
ASSERT_EQ(7000, record->timing.receive_headers_end);
}
// Test ssl time detection.
TEST_F(LoadTimingObserverTest, SslTime) {
- LoadTimingObserver observer;
-
// Start request.
NetLog::Source source(NetLog::SOURCE_URL_REQUEST, 0);
- AddStartURLRequestEntries(observer, 0, true);
- current_time += TimeDelta::FromSeconds(1);
+ AddStartURLRequestEntries(observer_, 0, true);
+ observer_.IncementTime(TimeDelta::FromSeconds(1));
// Add resolver entry.
- AddStartSocketEntries(observer, 1);
+ AddStartSocketEntries(observer_, 1);
NetLog::Source socket_source(NetLog::SOURCE_SOCKET, 1);
- AddStartEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL);
- current_time += TimeDelta::FromSeconds(2);
- AddEndEntry(observer, socket_source, NetLog::TYPE_SSL_CONNECT, NULL);
+ AddStartEntry(observer_, socket_source, NetLog::TYPE_SSL_CONNECT);
+ observer_.IncementTime(TimeDelta::FromSeconds(2));
+ AddEndEntry(observer_, socket_source, NetLog::TYPE_SSL_CONNECT);
NetLog::Source http_stream_job_source(NetLog::SOURCE_HTTP_STREAM_JOB, 2);
- AddStartHTTPStreamJobEntries(observer, 2);
+ AddStartHTTPStreamJobEntries(observer_, 2);
- BindHTTPStreamJobToSocket(observer, http_stream_job_source, socket_source);
- BindURLRequestToHTTPStreamJob(observer, source, http_stream_job_source);
+ BindHTTPStreamJobToSocket(observer_, http_stream_job_source, socket_source);
+ BindURLRequestToHTTPStreamJob(observer_, source, http_stream_job_source);
LoadTimingObserver::URLRequestRecord* record =
- observer.GetURLRequestRecord(0);
+ observer_.GetURLRequestRecord(0);
ASSERT_EQ(1000, record->timing.ssl_start);
ASSERT_EQ(3000, record->timing.ssl_end);
}
diff --git a/chrome/browser/net/net_log_logger.cc b/chrome/browser/net/net_log_logger.cc
index 9ef34d5..f91648d 100644
--- a/chrome/browser/net/net_log_logger.cc
+++ b/chrome/browser/net/net_log_logger.cc
@@ -37,14 +37,8 @@ void NetLogLogger::StartObserving(net::NetLog* net_log) {
net_log->AddThreadSafeObserver(this, net::NetLog::LOG_ALL_BUT_BYTES);
}
-void NetLogLogger::OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
- scoped_ptr<Value> value(
- net::NetLog::EntryToDictionaryValue(
- type, time, source, phase, params, false));
+void NetLogLogger::OnAddEntry(const net::NetLog::Entry& entry) {
+ scoped_ptr<Value> value(entry.ToValue());
// Don't pretty print, so each JSON value occupies a single line, with no
// breaks (Line breaks in any text field will be escaped). Using strings
// instead of integer identifiers allows logs from older versions to be
diff --git a/chrome/browser/net/net_log_logger.h b/chrome/browser/net/net_log_logger.h
index fc54462..0aa69a9 100644
--- a/chrome/browser/net/net_log_logger.h
+++ b/chrome/browser/net/net_log_logger.h
@@ -34,11 +34,7 @@ class NetLogLogger : public net::NetLog::ThreadSafeObserver {
void StartObserving(net::NetLog* net_log);
// net::NetLog::ThreadSafeObserver implementation:
- virtual void OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) OVERRIDE;
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
private:
ScopedStdioHandle file_;
diff --git a/chrome/browser/ui/webui/media/media_internals_proxy.cc b/chrome/browser/ui/webui/media/media_internals_proxy.cc
index 792c0ac..d57af78 100644
--- a/chrome/browser/ui/webui/media/media_internals_proxy.cc
+++ b/chrome/browser/ui/webui/media/media_internals_proxy.cc
@@ -80,14 +80,10 @@ void MediaInternalsProxy::OnUpdate(const string16& update) {
base::Bind(&MediaInternalsProxy::UpdateUIOnUIThread, this, update));
}
-void MediaInternalsProxy::OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+void MediaInternalsProxy::OnAddEntry(const net::NetLog::Entry& entry) {
bool is_event_interesting = false;
for (size_t i = 0; i < arraysize(kNetEventTypeFilter); i++) {
- if (type == kNetEventTypeFilter[i]) {
+ if (entry.type() == kNetEventTypeFilter[i]) {
is_event_interesting = true;
break;
}
@@ -99,8 +95,7 @@ void MediaInternalsProxy::OnAddEntry(net::NetLog::EventType type,
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&MediaInternalsProxy::AddNetEventOnUIThread, this,
- net::NetLog::EntryToDictionaryValue(type, time, source, phase,
- params, false)));
+ entry.ToValue()));
}
MediaInternalsProxy::~MediaInternalsProxy() {}
diff --git a/chrome/browser/ui/webui/media/media_internals_proxy.h b/chrome/browser/ui/webui/media/media_internals_proxy.h
index 3757841..1999fca 100644
--- a/chrome/browser/ui/webui/media/media_internals_proxy.h
+++ b/chrome/browser/ui/webui/media/media_internals_proxy.h
@@ -55,11 +55,7 @@ class MediaInternalsProxy
virtual void OnUpdate(const string16& update) OVERRIDE;
// net::NetLog::ThreadSafeObserver implementation. Callable from any thread:
- virtual void OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) OVERRIDE;
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
private:
friend struct content::BrowserThread::DeleteOnThread<
diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc
index d03f19f..9dd1418 100644
--- a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc
+++ b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc
@@ -479,20 +479,16 @@ class NetInternalsMessageHandler::IOThreadImpl
void OnSetLogLevel(const ListValue* list);
// ChromeNetLog::ThreadSafeObserver implementation:
- virtual void OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
// ConnectionTester::Delegate implementation:
- virtual void OnStartConnectionTestSuite();
+ virtual void OnStartConnectionTestSuite() OVERRIDE;
virtual void OnStartConnectionTestExperiment(
- const ConnectionTester::Experiment& experiment);
+ const ConnectionTester::Experiment& experiment) OVERRIDE;
virtual void OnCompletedConnectionTestExperiment(
const ConnectionTester::Experiment& experiment,
- int result);
- virtual void OnCompletedConnectionTestSuite();
+ int result) OVERRIDE;
+ virtual void OnCompletedConnectionTestSuite() OVERRIDE;
// Helper that calls g_browser.receive in the renderer, passing in |command|
// and |arg|. Takes ownership of |arg|. If the renderer is displaying a log
@@ -1503,16 +1499,10 @@ void NetInternalsMessageHandler::IOThreadImpl::OnSetLogLevel(
// Note that unlike other methods of IOThreadImpl, this function
// can be called from ANY THREAD.
void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+ const net::NetLog::Entry& entry) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- base::Bind(&IOThreadImpl::AddEntryToQueue, this,
- net::NetLog::EntryToDictionaryValue(type, time, source, phase,
- params, false)));
+ base::Bind(&IOThreadImpl::AddEntryToQueue, this, entry.ToValue()));
}
void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue(Value* entry) {
diff --git a/content/browser/debugger/devtools_netlog_observer.cc b/content/browser/debugger/devtools_netlog_observer.cc
index bcd53db..31fb9d7 100644
--- a/content/browser/debugger/devtools_netlog_observer.cc
+++ b/content/browser/debugger/devtools_netlog_observer.cc
@@ -11,7 +11,6 @@
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/resource_response.h"
#include "net/base/load_flags.h"
-#include "net/http/http_net_log_params.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
@@ -38,37 +37,35 @@ DevToolsNetLogObserver::GetResourceInfo(uint32 id) {
return NULL;
}
-void DevToolsNetLogObserver::OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+void DevToolsNetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
// The events that the Observer is interested in only occur on the IO thread.
if (!BrowserThread::CurrentlyOn(BrowserThread::IO))
return;
- if (source.type == net::NetLog::SOURCE_URL_REQUEST)
- OnAddURLRequestEntry(type, time, source, phase, params);
- else if (source.type == net::NetLog::SOURCE_HTTP_STREAM_JOB)
- OnAddHTTPStreamJobEntry(type, time, source, phase, params);
- else if (source.type == net::NetLog::SOURCE_SOCKET)
- OnAddSocketEntry(type, time, source, phase, params);
+
+ if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST)
+ OnAddURLRequestEntry(entry);
+ else if (entry.source().type == net::NetLog::SOURCE_HTTP_STREAM_JOB)
+ OnAddHTTPStreamJobEntry(entry);
+ else if (entry.source().type == net::NetLog::SOURCE_SOCKET)
+ OnAddSocketEntry(entry);
}
void DevToolsNetLogObserver::OnAddURLRequestEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+ const net::NetLog::Entry& entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- bool is_begin = phase == net::NetLog::PHASE_BEGIN;
- bool is_end = phase == net::NetLog::PHASE_END;
+ bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN;
+ bool is_end = entry.phase() == net::NetLog::PHASE_END;
- if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) {
+ if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) {
if (is_begin) {
- int load_flags = static_cast<
- net::URLRequestStartEventParameters*>(params)->load_flags();
+ int load_flags;
+ scoped_ptr<Value> event_param(entry.ParametersToValue());
+ if (!net::StartEventLoadFlagsFromEventParams(event_param.get(),
+ &load_flags)) {
+ return;
+ }
+
if (!(load_flags & net::LOAD_REPORT_RAW_HEADERS))
return;
@@ -78,7 +75,7 @@ void DevToolsNetLogObserver::OnAddURLRequestEntry(
request_to_info_.clear();
}
- request_to_info_[source.id] = new ResourceInfo();
+ request_to_info_[entry.source().id] = new ResourceInfo();
if (request_to_encoded_data_length_.size() > kMaxNumEntries) {
LOG(WARNING) << "The encoded data length observer url request count "
@@ -86,28 +83,33 @@ void DevToolsNetLogObserver::OnAddURLRequestEntry(
request_to_encoded_data_length_.clear();
}
- request_to_encoded_data_length_[source.id] = 0;
+ request_to_encoded_data_length_[entry.source().id] = 0;
}
return;
- } else if (type == net::NetLog::TYPE_REQUEST_ALIVE) {
+ } else if (entry.type() == net::NetLog::TYPE_REQUEST_ALIVE) {
// Cleanup records based on the TYPE_REQUEST_ALIVE entry.
if (is_end) {
- request_to_info_.erase(source.id);
- request_to_encoded_data_length_.erase(source.id);
+ request_to_info_.erase(entry.source().id);
+ request_to_encoded_data_length_.erase(entry.source().id);
}
return;
}
- ResourceInfo* info = GetResourceInfo(source.id);
+ ResourceInfo* info = GetResourceInfo(entry.source().id);
if (!info)
return;
- switch (type) {
+ switch (entry.type()) {
case net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS: {
- net::NetLogHttpRequestParameter* request_parameter =
- static_cast<net::NetLogHttpRequestParameter*>(params);
- const net::HttpRequestHeaders &request_headers =
- request_parameter->GetHeaders();
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+ std::string request_line;
+ net::HttpRequestHeaders request_headers;
+
+ if (!net::HttpRequestHeaders::FromNetLogParam(event_params.get(),
+ &request_headers,
+ &request_line)) {
+ NOTREACHED();
+ }
// We need to clear headers in case the same url_request is reused for
// several http requests (e.g. see http://crbug.com/80157).
@@ -115,19 +117,23 @@ void DevToolsNetLogObserver::OnAddURLRequestEntry(
for (net::HttpRequestHeaders::Iterator it(request_headers);
it.GetNext();) {
- info->request_headers.push_back(std::make_pair(it.name(),
- it.value()));
+ info->request_headers.push_back(std::make_pair(it.name(), it.value()));
}
- info->request_headers_text =
- request_parameter->GetLine() +
- request_parameter->GetHeaders().ToString();
+ info->request_headers_text = request_line + request_headers.ToString();
break;
}
case net::NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS: {
- const net::HttpResponseHeaders& response_headers =
- static_cast<net::NetLogHttpResponseParameter*>(params)->GetHeaders();
- info->http_status_code = response_headers.response_code();
- info->http_status_text = response_headers.GetStatusText();
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+
+ scoped_refptr<net::HttpResponseHeaders> response_headers;
+
+ if (!net::HttpResponseHeaders::FromNetLogParam(event_params.get(),
+ &response_headers)) {
+ NOTREACHED();
+ }
+
+ info->http_status_code = response_headers->response_code();
+ info->http_status_text = response_headers->GetStatusText();
std::string name, value;
// We need to clear headers in case the same url_request is reused for
@@ -135,17 +141,24 @@ void DevToolsNetLogObserver::OnAddURLRequestEntry(
info->response_headers.clear();
for (void* it = NULL;
- response_headers.EnumerateHeaderLines(&it, &name, &value); ) {
+ response_headers->EnumerateHeaderLines(&it, &name, &value); ) {
info->response_headers.push_back(std::make_pair(name, value));
}
info->response_headers_text =
net::HttpUtil::ConvertHeadersBackToHTTPResponse(
- response_headers.raw_headers());
+ response_headers->raw_headers());
break;
}
case net::NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB: {
- uint32 http_stream_job_id = static_cast<net::NetLogSourceParameter*>(
- params)->value().id;
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+ net::NetLog::Source http_stream_job_source;
+ if (!net::NetLog::Source::FromEventParameters(event_params.get(),
+ &http_stream_job_source)) {
+ NOTREACHED();
+ break;
+ }
+
+ uint32 http_stream_job_id = http_stream_job_source.id;
HTTPStreamJobToSocketMap::iterator it =
http_stream_job_to_socket_.find(http_stream_job_id);
if (it == http_stream_job_to_socket_.end())
@@ -158,7 +171,7 @@ void DevToolsNetLogObserver::OnAddURLRequestEntry(
socket_to_request_.clear();
}
- socket_to_request_[socket_id] = source.id;
+ socket_to_request_[socket_id] = entry.source().id;
http_stream_job_to_socket_.erase(http_stream_job_id);
break;
}
@@ -168,16 +181,17 @@ void DevToolsNetLogObserver::OnAddURLRequestEntry(
}
void DevToolsNetLogObserver::OnAddHTTPStreamJobEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+ const net::NetLog::Entry& entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (type == net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET) {
- uint32 socket_id = static_cast<net::NetLogSourceParameter*>(
- params)->value().id;
+ if (entry.type() == net::NetLog::TYPE_SOCKET_POOL_BOUND_TO_SOCKET) {
+ scoped_ptr<Value> event_params(entry.ParametersToValue());
+ net::NetLog::Source socket_source;
+ if (!net::NetLog::Source::FromEventParameters(event_params.get(),
+ &socket_source)) {
+ NOTREACHED();
+ return;
+ }
// Prevents us from passively growing the memory unbounded in
// case something went wrong. Should not happen.
@@ -186,28 +200,25 @@ void DevToolsNetLogObserver::OnAddHTTPStreamJobEntry(
"has grown larger than expected, resetting";
http_stream_job_to_socket_.clear();
}
- http_stream_job_to_socket_[source.id] = socket_id;
+ http_stream_job_to_socket_[entry.source().id] = socket_source.id;
}
}
void DevToolsNetLogObserver::OnAddSocketEntry(
- net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) {
+ const net::NetLog::Entry& entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- bool is_end = phase == net::NetLog::PHASE_END;
+ bool is_end = entry.phase() == net::NetLog::PHASE_END;
- SocketToRequestMap::iterator it = socket_to_request_.find(source.id);
+ SocketToRequestMap::iterator it =
+ socket_to_request_.find(entry.source().id);
if (it == socket_to_request_.end())
return;
uint32 request_id = it->second;
- if (type == net::NetLog::TYPE_SOCKET_IN_USE) {
+ if (entry.type() == net::NetLog::TYPE_SOCKET_IN_USE) {
if (is_end)
- socket_to_request_.erase(source.id);
+ socket_to_request_.erase(entry.source().id);
return;
}
@@ -216,9 +227,9 @@ void DevToolsNetLogObserver::OnAddSocketEntry(
if (encoded_data_length_it == request_to_encoded_data_length_.end())
return;
- if (net::NetLog::TYPE_SOCKET_BYTES_RECEIVED == type) {
+ if (net::NetLog::TYPE_SOCKET_BYTES_RECEIVED == entry.type()) {
int byte_count = 0;
- scoped_ptr<Value> value(params->ToValue());
+ scoped_ptr<Value> value(entry.ParametersToValue());
if (!value->IsType(Value::TYPE_DICTIONARY))
return;
diff --git a/content/browser/debugger/devtools_netlog_observer.h b/content/browser/debugger/devtools_netlog_observer.h
index eee61d3..1d6a7ef 100644
--- a/content/browser/debugger/devtools_netlog_observer.h
+++ b/content/browser/debugger/devtools_netlog_observer.h
@@ -31,29 +31,11 @@ class DevToolsNetLogObserver : public net::NetLog::ThreadSafeObserver {
public:
// net::NetLog::ThreadSafeObserver implementation:
- virtual void OnAddEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params) OVERRIDE;
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
- void OnAddURLRequestEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
-
- void OnAddHTTPStreamJobEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
-
- void OnAddSocketEntry(net::NetLog::EventType type,
- const base::TimeTicks& time,
- const net::NetLog::Source& source,
- net::NetLog::EventPhase phase,
- net::NetLog::EventParameters* params);
+ void OnAddURLRequestEntry(const net::NetLog::Entry& entry);
+ void OnAddHTTPStreamJobEntry(const net::NetLog::Entry& entry);
+ void OnAddSocketEntry(const net::NetLog::Entry& entry);
static void Attach();
static void Detach();
diff --git a/net/base/capturing_net_log.cc b/net/base/capturing_net_log.cc
index 0746d62..8c04b78 100644
--- a/net/base/capturing_net_log.cc
+++ b/net/base/capturing_net_log.cc
@@ -80,30 +80,24 @@ void CapturingNetLog::SetLogLevel(NetLog::LogLevel log_level) {
log_level_ = log_level;
}
-void CapturingNetLog::AddEntry(
- EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<EventParameters>& extra_parameters) {
+void CapturingNetLog::OnAddEntry(const net::NetLog::Entry& entry) {
// Only BoundNetLogs without a NetLog should have an invalid source.
- DCHECK(source.is_valid());
+ DCHECK(entry.source().is_valid());
// Using Dictionaries instead of Values makes checking values a little
// simpler.
DictionaryValue* param_dict = NULL;
- if (extra_parameters) {
- Value* param_value = extra_parameters->ToValue();
- if (param_value && !param_value->GetAsDictionary(&param_dict))
- delete param_value;
- }
+ Value* param_value = entry.ParametersToValue();
+ if (param_value && !param_value->GetAsDictionary(&param_dict))
+ delete param_value;
// Only need to acquire the lock when accessing class variables.
base::AutoLock lock(lock_);
captured_entries_.push_back(
- CapturedEntry(type,
+ CapturedEntry(entry.type(),
base::TimeTicks::Now(),
- source,
- phase,
+ entry.source(),
+ entry.phase(),
scoped_ptr<DictionaryValue>(param_dict)));
}
diff --git a/net/base/capturing_net_log.h b/net/base/capturing_net_log.h
index fdc1349..a0dc380 100644
--- a/net/base/capturing_net_log.h
+++ b/net/base/capturing_net_log.h
@@ -76,11 +76,7 @@ class CapturingNetLog : public NetLog {
void SetLogLevel(NetLog::LogLevel log_level);
// NetLog implementation:
- virtual void AddEntry(
- EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<EventParameters>& extra_parameters) OVERRIDE;
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
virtual uint32 NextID() OVERRIDE;
virtual LogLevel GetLogLevel() const OVERRIDE;
virtual void AddThreadSafeObserver(ThreadSafeObserver* observer,
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc
index d3853ca..7cda76d 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -38,7 +38,7 @@ IOBufferWithSize* CreateTestDataBuffer() {
class NetLogForNotifyingFileClosure : public NetLog {
public:
NetLogForNotifyingFileClosure()
- : id_(0),
+ : last_id_(0),
on_closure_(false /* manual_reset */, false /* initially_signaled */) {
}
@@ -51,17 +51,12 @@ class NetLogForNotifyingFileClosure : public NetLog {
}
// NetLog overrides:
- virtual void AddEntry(
- EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<EventParameters>& params) OVERRIDE {
- if (type == TYPE_FILE_STREAM_CLOSE) {
+ virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE {
+ if (entry.type() == TYPE_FILE_STREAM_CLOSE)
on_closure_.Signal();
- }
}
- virtual uint32 NextID() OVERRIDE { return id_++; }
+ virtual uint32 NextID() OVERRIDE { return ++last_id_; }
virtual LogLevel GetLogLevel() const OVERRIDE { return LOG_ALL; }
virtual void AddThreadSafeObserver(ThreadSafeObserver* observer,
LogLevel log_level) OVERRIDE {
@@ -76,7 +71,7 @@ class NetLogForNotifyingFileClosure : public NetLog {
}
private:
- uint32 id_;
+ uint32 last_id_;
base::WaitableEvent on_closure_;
};
diff --git a/net/base/net_log.cc b/net/base/net_log.cc
index 0f0b719..4f18e46c 100644
--- a/net/base/net_log.cc
+++ b/net/base/net_log.cc
@@ -4,6 +4,7 @@
#include "net/base/net_log.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/time.h"
@@ -15,39 +16,43 @@ namespace net {
namespace {
-// Parameters for logging data transferred events. Includes bytes transferred
-// and, if |bytes| is not NULL, the bytes themselves.
-class NetLogBytesTransferredParameter : public NetLog::EventParameters {
- public:
- NetLogBytesTransferredParameter(int byte_count, const char* bytes);
-
- virtual Value* ToValue() const;
-
- protected:
- virtual ~NetLogBytesTransferredParameter() {}
+// Returns parameters for logging data transferred events. Includes number of
+// bytes transferred and, if the log level indicates bytes should be logged and
+// |byte_count| > 0, the bytes themselves. The bytes are hex-encoded, since
+// base::StringValue only supports UTF-8.
+Value* BytesTransferredCallback(int byte_count,
+ const char* bytes,
+ NetLog::LogLevel log_level) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("byte_count", byte_count);
+ if (NetLog::IsLoggingBytes(log_level) && byte_count > 0)
+ dict->SetString("hex_encoded_bytes", base::HexEncode(bytes, byte_count));
+ return dict;
+}
- private:
- const int byte_count_;
- std::string hex_encoded_bytes_;
- bool has_bytes_;
-};
+Value* EventParametersCallback(
+ const scoped_refptr<NetLog::EventParameters>& params,
+ NetLog::LogLevel /* log_level */) {
+ if (!params.get())
+ return NULL;
+ return params->ToValue();
+}
-NetLogBytesTransferredParameter::NetLogBytesTransferredParameter(
- int byte_count, const char* transferred_bytes)
- : byte_count_(byte_count),
- has_bytes_(false) {
- if (transferred_bytes) {
- hex_encoded_bytes_ = base::HexEncode(transferred_bytes, byte_count);
- has_bytes_ = true;
- }
+Value* SourceEventParametersCallback(const NetLog::Source source,
+ NetLog::LogLevel /* log_level */) {
+ DictionaryValue* event_params = new DictionaryValue();
+ source.AddToEventParameters(event_params);
+ return event_params;
}
-Value* NetLogBytesTransferredParameter::ToValue() const {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetInteger("byte_count", byte_count_);
- if (has_bytes_ && byte_count_ > 0)
- dict->SetString("hex_encoded_bytes", hex_encoded_bytes_);
- return dict;
+Value* SingleIntegerCallback(const char* name,
+ int value,
+ NetLog::LogLevel /* log_level */) {
+ if (!value)
+ return NULL;
+ DictionaryValue* event_params = new DictionaryValue();
+ event_params->SetInteger(name, value);
+ return event_params;
}
} // namespace
@@ -59,6 +64,85 @@ Value* NetLog::Source::ToValue() const {
return dict;
}
+void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("type", static_cast<int>(type));
+ dict->SetInteger("id", static_cast<int>(id));
+ event_params->Set("source_dependency", dict);
+}
+
+NetLog::ParametersCallback NetLog::Source::ToEventParametersCallback() const {
+ return base::Bind(&SourceEventParametersCallback, *this);
+}
+
+// static
+bool NetLog::Source::FromEventParameters(Value* event_params, Source* source) {
+ DictionaryValue* dict;
+ DictionaryValue* source_dict;
+ int source_id;
+ int source_type;
+ if (!event_params ||
+ !event_params->GetAsDictionary(&dict) ||
+ !dict->GetDictionary("source_dependency", &source_dict) ||
+ !source_dict->GetInteger("id", &source_id) ||
+ !source_dict->GetInteger("type", &source_type)) {
+ *source = Source();
+ return false;
+ }
+
+ DCHECK_LE(0, source_id);
+ DCHECK_LT(source_type, NetLog::SOURCE_COUNT);
+ *source = Source(static_cast<SourceType>(source_type), source_id);
+ return true;
+}
+
+Value* NetLog::Entry::ToValue() const {
+ DictionaryValue* entry_dict(new DictionaryValue());
+
+ entry_dict->SetString("time", TickCountToString(base::TimeTicks::Now()));
+
+ // Set the entry source.
+ DictionaryValue* source_dict = new DictionaryValue();
+ source_dict->SetInteger("id", source_.id);
+ source_dict->SetInteger("type", static_cast<int>(source_.type));
+ entry_dict->Set("source", source_dict);
+
+ // Set the event info.
+ entry_dict->SetInteger("type", static_cast<int>(type_));
+ entry_dict->SetInteger("phase", static_cast<int>(phase_));
+
+ // Set the event-specific parameters.
+ if (parameters_callback_) {
+ Value* value = parameters_callback_->Run(log_level_);
+ if (value)
+ entry_dict->Set("params", value);
+ }
+
+ return entry_dict;
+}
+
+Value* NetLog::Entry::ParametersToValue() const {
+ if (parameters_callback_)
+ return parameters_callback_->Run(log_level_);
+ return NULL;
+}
+
+NetLog::Entry::Entry(
+ EventType type,
+ Source source,
+ EventPhase phase,
+ const ParametersCallback* parameters_callback,
+ LogLevel log_level)
+ : type_(type),
+ source_(source),
+ phase_(phase),
+ parameters_callback_(parameters_callback),
+ log_level_(log_level) {
+};
+
+NetLog::Entry::~Entry() {
+}
+
NetLog::ThreadSafeObserver::ThreadSafeObserver() : log_level_(LOG_BASIC),
net_log_(NULL) {
}
@@ -79,12 +163,29 @@ NetLog* NetLog::ThreadSafeObserver::net_log() const {
return net_log_;
}
+void NetLog::AddGlobalEntry(EventType type) {
+ AddEntry(type,
+ Source(net::NetLog::SOURCE_NONE, NextID()),
+ net::NetLog::PHASE_NONE,
+ NULL);
+}
+
+void NetLog::AddGlobalEntry(
+ EventType type,
+ const NetLog::ParametersCallback& parameters_callback) {
+ AddEntry(type,
+ Source(net::NetLog::SOURCE_NONE, NextID()),
+ net::NetLog::PHASE_NONE,
+ &parameters_callback);
+}
+
void NetLog::AddGlobalEntry(EventType type,
const scoped_refptr<EventParameters>& params) {
+ ParametersCallback callback = base::Bind(&EventParametersCallback, params);
AddEntry(type,
- Source(net::NetLog::SOURCE_NONE, this->NextID()),
+ Source(net::NetLog::SOURCE_NONE, NextID()),
net::NetLog::PHASE_NONE,
- params);
+ &callback);
}
// static
@@ -150,41 +251,19 @@ const char* NetLog::EventPhaseToString(EventPhase phase) {
}
// static
-Value* NetLog::EntryToDictionaryValue(NetLog::EventType type,
- const base::TimeTicks& time,
- const NetLog::Source& source,
- NetLog::EventPhase phase,
- NetLog::EventParameters* params,
- bool use_strings) {
- DictionaryValue* entry_dict = new DictionaryValue();
-
- entry_dict->SetString("time", TickCountToString(time));
-
- // Set the entry source.
- DictionaryValue* source_dict = new DictionaryValue();
- source_dict->SetInteger("id", source.id);
- if (!use_strings) {
- source_dict->SetInteger("type", static_cast<int>(source.type));
- } else {
- source_dict->SetString("type",
- NetLog::SourceTypeToString(source.type));
- }
- entry_dict->Set("source", source_dict);
-
- // Set the event info.
- if (!use_strings) {
- entry_dict->SetInteger("type", static_cast<int>(type));
- entry_dict->SetInteger("phase", static_cast<int>(phase));
- } else {
- entry_dict->SetString("type", NetLog::EventTypeToString(type));
- entry_dict->SetString("phase", NetLog::EventPhaseToString(phase));
- }
+bool NetLog::IsLoggingBytes(LogLevel log_level) {
+ return log_level == NetLog::LOG_ALL;
+}
- // Set the event-specific parameters.
- if (params)
- entry_dict->Set("params", params->ToValue());
+// static
+bool NetLog::IsLoggingAllEvents(LogLevel log_level) {
+ return log_level <= NetLog::LOG_ALL_BUT_BYTES;
+}
- return entry_dict;
+// static
+NetLog::ParametersCallback NetLog::IntegerCallback(const char* name,
+ int value) {
+ return base::Bind(&SingleIntegerCallback, name, value);
}
void NetLog::OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level) {
@@ -204,12 +283,69 @@ void NetLog::OnRemoveObserver(ThreadSafeObserver* observer) {
observer->net_log_ = NULL;
}
+void NetLog::AddEntry(EventType type,
+ const Source& source,
+ EventPhase phase,
+ const NetLog::ParametersCallback* parameters_callback) {
+ Entry entry(type, source, phase, parameters_callback, GetLogLevel());
+ OnAddEntry(entry);
+}
+
+void BoundNetLog::AddEntry(NetLog::EventType type,
+ NetLog::EventPhase phase) const {
+ if (!net_log_)
+ return;
+ net_log_->AddEntry(type, source_, phase, NULL);
+}
+
+void BoundNetLog::AddEntry(
+ NetLog::EventType type,
+ NetLog::EventPhase phase,
+ const NetLog::ParametersCallback& get_parameters) const {
+ if (!net_log_)
+ return;
+ net_log_->AddEntry(type, source_, phase, &get_parameters);
+}
+
+void BoundNetLog::AddEvent(NetLog::EventType type) const {
+ AddEntry(type, NetLog::PHASE_NONE);
+}
+
+void BoundNetLog::AddEvent(
+ NetLog::EventType type,
+ const NetLog::ParametersCallback& get_parameters) const {
+ AddEntry(type, NetLog::PHASE_NONE, get_parameters);
+}
+
+void BoundNetLog::BeginEvent(NetLog::EventType type) const {
+ AddEntry(type, NetLog::PHASE_BEGIN);
+}
+
+void BoundNetLog::BeginEvent(
+ NetLog::EventType type,
+ const NetLog::ParametersCallback& get_parameters) const {
+ AddEntry(type, NetLog::PHASE_BEGIN, get_parameters);
+}
+
+void BoundNetLog::EndEvent(NetLog::EventType type) const {
+ AddEntry(type, NetLog::PHASE_END);
+}
+
+void BoundNetLog::EndEvent(
+ NetLog::EventType type,
+ const NetLog::ParametersCallback& get_parameters) const {
+ AddEntry(type, NetLog::PHASE_END, get_parameters);
+}
+
void BoundNetLog::AddEntry(
NetLog::EventType type,
NetLog::EventPhase phase,
const scoped_refptr<NetLog::EventParameters>& params) const {
- if (net_log_)
- net_log_->AddEntry(type, source_, phase, params);
+ if (!net_log_)
+ return;
+ NetLog::ParametersCallback callback =
+ base::Bind(&EventParametersCallback, params);
+ net_log_->AddEntry(type, source_, phase, &callback);
}
void BoundNetLog::AddEvent(
@@ -234,33 +370,19 @@ void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type,
int net_error) const {
DCHECK_GT(0, net_error);
DCHECK_NE(ERR_IO_PENDING, net_error);
- AddEvent(
- event_type,
- make_scoped_refptr(new NetLogIntegerParameter("net_error", net_error)));
+ AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error));
}
void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type,
int net_error) const {
DCHECK_NE(ERR_IO_PENDING, net_error);
- if (net_error >= 0) {
- EndEvent(event_type, NULL);
- } else {
- EndEvent(
- event_type,
- make_scoped_refptr(new NetLogIntegerParameter("net_error", net_error)));
- }
+ EndEvent(event_type, NetLog::IntegerCallback("net_error", net_error));
}
void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type,
int byte_count,
const char* bytes) const {
- scoped_refptr<NetLog::EventParameters> params;
- if (IsLoggingBytes()) {
- params = new NetLogBytesTransferredParameter(byte_count, bytes);
- } else {
- params = new NetLogBytesTransferredParameter(byte_count, NULL);
- }
- AddEvent(event_type, params);
+ AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes));
}
NetLog::LogLevel BoundNetLog::GetLogLevel() const {
@@ -270,11 +392,11 @@ NetLog::LogLevel BoundNetLog::GetLogLevel() const {
}
bool BoundNetLog::IsLoggingBytes() const {
- return GetLogLevel() == NetLog::LOG_ALL;
+ return NetLog::IsLoggingBytes(GetLogLevel());
}
bool BoundNetLog::IsLoggingAllEvents() const {
- return GetLogLevel() <= NetLog::LOG_ALL_BUT_BYTES;
+ return NetLog::IsLoggingAllEvents(GetLogLevel());
}
// static
@@ -314,27 +436,4 @@ Value* NetLogSourceParameter::ToValue() const {
return dict;
}
-ScopedNetLogEvent::ScopedNetLogEvent(
- const BoundNetLog& net_log,
- NetLog::EventType event_type,
- const scoped_refptr<NetLog::EventParameters>& params)
- : net_log_(net_log),
- event_type_(event_type) {
- net_log_.BeginEvent(event_type, params);
-}
-
-ScopedNetLogEvent::~ScopedNetLogEvent() {
- net_log_.EndEvent(event_type_, end_event_params_);
-}
-
-void ScopedNetLogEvent::SetEndEventParameters(
- const scoped_refptr<NetLog::EventParameters>& end_event_params) {
- DCHECK(!end_event_params_.get());
- end_event_params_ = end_event_params;
-}
-
-const BoundNetLog& ScopedNetLogEvent::net_log() const {
- return net_log_;
-}
-
} // namespace net
diff --git a/net/base/net_log.h b/net/base/net_log.h
index 777bdf5..d0eee53 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -9,11 +9,14 @@
#include <string>
#include "base/basictypes.h"
+#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "net/base/net_export.h"
namespace base {
+class DictionaryValue;
class TimeTicks;
class Value;
}
@@ -29,6 +32,7 @@ namespace net {
// is usually accessed through a BoundNetLog, which will always pass in a
// specific source ID.
//
+// All NetLog methods must be thread-safe.
class NET_EXPORT NetLog {
public:
enum EventType {
@@ -54,6 +58,26 @@ class NET_EXPORT NetLog {
SOURCE_COUNT
};
+ // Specifies the granularity of events that should be emitted to the log.
+ enum LogLevel {
+ // Log everything possible, even if it is slow and memory expensive.
+ // Includes logging of transferred bytes.
+ LOG_ALL,
+
+ // Log all events, but do not include the actual transferred bytes as
+ // parameters for bytes sent/received events.
+ LOG_ALL_BUT_BYTES,
+
+ // Only log events which are cheap, and don't consume much memory.
+ LOG_BASIC,
+ };
+
+ // A callback function that return a Value representation of the parameters
+ // associated with an event. If called, it will be called synchonously,
+ // so it need not have owning references. May be called more than once, or
+ // not at all. May return NULL.
+ typedef base::Callback<base::Value*(LogLevel)> ParametersCallback;
+
// Identifies the entity that generated this log. The |id| field should
// uniquely identify the source, and is used by log observers to infer
// message groupings. Can use NetLog::NextID() to create unique IDs.
@@ -64,9 +88,24 @@ class NET_EXPORT NetLog {
Source(SourceType type, uint32 id) : type(type), id(id) {}
bool is_valid() const { return id != kInvalidId; }
- // The caller takes ownership of the returned Value*.
+ // Obsolete. The caller takes ownership of the returned Value*.
+ // TODO(mmenke): Remove this.
base::Value* ToValue() const;
+ // Adds the source to a DictionaryValue containing event parameters,
+ // using the name "source_dependency".
+ void AddToEventParameters(base::DictionaryValue* event_params) const;
+
+ // Returns a callback that returns a dictionary with a single entry
+ // named "source_dependecy" that describes |this|.
+ ParametersCallback ToEventParametersCallback() const;
+
+ // Attempts to extract a Source from a set of event parameters. Returns
+ // true and writes the result to |source| on success. Returns false and
+ // makes |source| an invalid source on failure.
+ // TODO(mmenke): Long term, we want to remove this.
+ static bool FromEventParameters(base::Value* event_params, Source* source);
+
SourceType type;
uint32 id;
};
@@ -74,6 +113,8 @@ class NET_EXPORT NetLog {
// Base class for associating additional parameters with an event. Log
// observers need to know what specific derivations of EventParameters a
// particular EventType uses, in order to get at the individual components.
+ // This class is obsolete. New code should use ParametersCallbacks.
+ // TODO(mmenke): Update users of this class and get rid of it.
class NET_EXPORT EventParameters
: public base::RefCountedThreadSafe<EventParameters> {
public:
@@ -93,18 +134,40 @@ class NET_EXPORT NetLog {
DISALLOW_COPY_AND_ASSIGN(EventParameters);
};
- // Specifies the granularity of events that should be emitted to the log.
- enum LogLevel {
- // Log everything possible, even if it is slow and memory expensive.
- // Includes logging of transferred bytes.
- LOG_ALL,
+ class NET_EXPORT Entry {
+ public:
+ Entry(EventType type,
+ Source source,
+ EventPhase phase,
+ const ParametersCallback* parameters_callback,
+ LogLevel log_level);
+ ~Entry();
+
+ EventType type() const { return type_; }
+ Source source() const { return source_; }
+ EventPhase phase() const { return phase_; }
+
+ // Serializes the specified event to a Value. The Value also includes the
+ // current time. Caller takes ownership of returned Value.
+ base::Value* ToValue() const;
- // Log all events, but do not include the actual transferred bytes as
- // parameters for bytes sent/received events.
- LOG_ALL_BUT_BYTES,
+ // Returns the parameters as a Value. Returns NULL if there are no
+ // parameters. Caller takes ownership of returned Value.
+ base::Value* ParametersToValue() const;
- // Only log events which are cheap, and don't consume much memory.
- LOG_BASIC,
+ private:
+ const EventType type_;
+ const Source source_;
+ const EventPhase phase_;
+ const ParametersCallback* parameters_callback_;
+
+ // Log level when the event occurred.
+ const LogLevel log_level_;
+
+ // It is not safe to copy this class, since |parameters_callback_| may
+ // include pointers that become stale immediately after the event is added,
+ // even if the code were modified to keep its own copy of the callback.
+ DISALLOW_COPY_AND_ASSIGN(Entry);
};
// An observer, that must ensure its own thread safety, for events
@@ -136,21 +199,7 @@ class NET_EXPORT NetLog {
//
// It is illegal for an Observer to call any NetLog or
// NetLog::Observer functions in response to a call to OnAddEntry.
- //
- // |type| - The type of the event.
- // |time| - The time when the event occurred.
- // |source| - The source that generated the event.
- // |phase| - An optional parameter indicating whether this is the start/end
- // of an action.
- // |params| - Optional (may be NULL) parameters for this event.
- // The specific subclass of EventParameters is defined
- // by the contract for events of this |type|.
- // TODO(eroman): Take a scoped_refptr<EventParameters> instead.
- virtual void OnAddEntry(EventType type,
- const base::TimeTicks& time,
- const Source& source,
- EventPhase phase,
- EventParameters* params) = 0;
+ virtual void OnAddEntry(const Entry& entry) = 0;
protected:
virtual ~ThreadSafeObserver();
@@ -169,10 +218,18 @@ class NET_EXPORT NetLog {
virtual ~NetLog() {}
// Emits a global event to the log stream, with its own unique source ID.
+ void AddGlobalEntry(EventType type);
+ void AddGlobalEntry(EventType type,
+ const NetLog::ParametersCallback& parameters_callback);
+
+ // Older, obsolete version of above functions. Use the ParametersCallback
+ // versions instead.
+ // TODO(mmenke): Remove this.
void AddGlobalEntry(EventType type,
const scoped_refptr<EventParameters>& params);
- // Returns a unique ID which can be used as a source ID.
+ // Returns a unique ID which can be used as a source ID. All returned IDs
+ // will be unique and greater than 0.
virtual uint32 NextID() = 0;
// Returns the logging level for this NetLog. This is used to avoid computing
@@ -226,22 +283,23 @@ class NET_EXPORT NetLog {
// Returns a C-String symbolic name for |event_phase|.
static const char* EventPhaseToString(EventPhase event_phase);
- // Serializes the specified event to a DictionaryValue.
- // If |use_strings| is true, uses strings rather than numeric ids.
- static base::Value* EntryToDictionaryValue(NetLog::EventType type,
- const base::TimeTicks& time,
- const NetLog::Source& source,
- NetLog::EventPhase phase,
- NetLog::EventParameters* params,
- bool use_strings);
+ // Returns true if |log_level| indicates the actual bytes transferred should
+ // be logged. This is only the case when |log_level| is LOG_ALL.
+ static bool IsLoggingBytes(LogLevel log_level);
+
+ // Returns true if |log_level| indicates that all events should be logged,
+ // including frequently occuring ones that may impact performances.
+ // This is the case when |log_level| is LOG_ALL or LOG_ALL_BUT_BYTES.
+ static bool IsLoggingAllEvents(LogLevel log_level);
+
+ // Creates a ParametersCallback that encapsulates a single integer.
+ // Warning: |name| must remain valid for the life of the callback.
+ static ParametersCallback IntegerCallback(const char* name, int value);
protected:
- // This is the internal function used by AddGlobalEntry and BoundNetLogs.
- virtual void AddEntry(
- EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<NetLog::EventParameters>& params) = 0;
+ // Child classes should respond to the new entry here. This includes
+ // creating the Entry object and alerting their observers.
+ virtual void OnAddEntry(const Entry& entry) = 0;
// Subclasses must call these in the corresponding functions to set an
// observer's |net_log_| and |log_level_| values.
@@ -253,6 +311,11 @@ class NET_EXPORT NetLog {
private:
friend class BoundNetLog;
+ void AddEntry(EventType type,
+ const Source& source,
+ EventPhase phase,
+ const NetLog::ParametersCallback* parameters_callback);
+
DISALLOW_COPY_AND_ASSIGN(NetLog);
};
@@ -262,15 +325,32 @@ class NET_EXPORT BoundNetLog {
public:
BoundNetLog() : net_log_(NULL) {}
- // Convenience methods that call through to the NetLog, passing in the
- // currently bound source.
+ // Add a log entry to the NetLog for the bound source.
+ void AddEntry(NetLog::EventType type, NetLog::EventPhase phase) const;
void AddEntry(NetLog::EventType type,
NetLog::EventPhase phase,
- const scoped_refptr<NetLog::EventParameters>& params) const;
+ const NetLog::ParametersCallback& get_parameters) const;
- // Convenience methods that call through to the NetLog, passing in the
- // currently bound source, current time, and a fixed "capture phase"
+ // Convenience methods that call AddEntry with a fixed "capture phase"
// (begin, end, or none).
+ void BeginEvent(NetLog::EventType type) const;
+ void BeginEvent(NetLog::EventType type,
+ const NetLog::ParametersCallback& get_parameters) const;
+
+ void EndEvent(NetLog::EventType type) const;
+ void EndEvent(NetLog::EventType type,
+ const NetLog::ParametersCallback& get_parameters) const;
+
+ void AddEvent(NetLog::EventType type) const;
+ void AddEvent(NetLog::EventType type,
+ const NetLog::ParametersCallback& get_parameters) const;
+
+ // Obsolete versions of the above functions.
+ // Use the ParametersCallback versions of these functions instead.
+ // TODO(mmenke): Remove these.
+ void AddEntry(NetLog::EventType type,
+ NetLog::EventPhase phase,
+ const scoped_refptr<NetLog::EventParameters>& params) const;
void AddEvent(NetLog::EventType event_type,
const scoped_refptr<NetLog::EventParameters>& params) const;
void BeginEvent(NetLog::EventType event_type,
@@ -299,10 +379,10 @@ class NET_EXPORT BoundNetLog {
NetLog::LogLevel GetLogLevel() const;
- // Returns true if the log level is LOG_ALL.
+ // Shortcut for NetLog::IsLoggingBytes(this->GetLogLevel()).
bool IsLoggingBytes() const;
- // Returns true if the log level is LOG_ALL or LOG_ALL_BUT_BYTES.
+ // Shortcut for NetLog::IsLoggingAllEvents(this->GetLogLevel()).
bool IsLoggingAllEvents() const;
// Helper to create a BoundNetLog given a NetLog and a SourceType. Takes care
@@ -321,6 +401,9 @@ class NET_EXPORT BoundNetLog {
NetLog* net_log_;
};
+// All the classes below are obsolete. New code should use ParametersCallbacks.
+// TODO(mmenke): Update users these classes and get rid of them.
+
// NetLogStringParameter is a subclass of EventParameters that encapsulates a
// single std::string parameter.
class NET_EXPORT NetLogStringParameter : public NetLog::EventParameters {
@@ -386,30 +469,6 @@ class NET_EXPORT NetLogSourceParameter : public NetLog::EventParameters {
const NetLog::Source value_;
};
-// ScopedNetLogEvent logs a begin event on creation, and the corresponding end
-// event on destruction.
-class NET_EXPORT_PRIVATE ScopedNetLogEvent {
- public:
- ScopedNetLogEvent(const BoundNetLog& net_log,
- NetLog::EventType event_type,
- const scoped_refptr<NetLog::EventParameters>& params);
-
- ~ScopedNetLogEvent();
-
- // Sets the parameters that will logged on object destruction. Can be called
- // at most once for a given ScopedNetLogEvent object. If not called, the end
- // event will have no parameters.
- void SetEndEventParameters(
- const scoped_refptr<NetLog::EventParameters>& end_event_params);
-
- const BoundNetLog& net_log() const;
-
- private:
- BoundNetLog net_log_;
- const NetLog::EventType event_type_;
- scoped_refptr<NetLog::EventParameters> end_event_params_;
-};
-
} // namespace net
#endif // NET_BASE_NET_LOG_H_
diff --git a/net/base/net_log_unittest.cc b/net/base/net_log_unittest.cc
deleted file mode 100644
index 3454df3..0000000
--- a/net/base/net_log_unittest.cc
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/scoped_ptr.h"
-#include "net/base/capturing_net_log.h"
-#include "net/base/net_log.h"
-#include "net/base/net_log_unittest.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-
-namespace {
-
-TEST(NetLog, ScopedNetLogEventTest) {
- CapturingNetLog log;
- BoundNetLog net_log(BoundNetLog::Make(&log, NetLog::SOURCE_URL_REQUEST));
-
- scoped_ptr<ScopedNetLogEvent> net_log_event(
- new ScopedNetLogEvent(net_log, NetLog::TYPE_REQUEST_ALIVE, NULL));
-
- CapturingNetLog::CapturedEntryList entries;
- log.GetEntries(&entries);
- EXPECT_EQ(1u, entries.size());
- EXPECT_TRUE(LogContainsBeginEvent(entries, 0, NetLog::TYPE_REQUEST_ALIVE));
-
- net_log_event.reset();
- log.GetEntries(&entries);
- EXPECT_EQ(2u, entries.size());
- EXPECT_TRUE(LogContainsEndEvent(entries, 1, NetLog::TYPE_REQUEST_ALIVE));
-}
-
-} // namespace
-
-} // namespace net
diff --git a/net/http/http_net_log_params.cc b/net/http/http_net_log_params.cc
deleted file mode 100644
index 989d30d..0000000
--- a/net/http/http_net_log_params.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/http/http_net_log_params.h"
-
-#include "base/stringprintf.h"
-#include "base/values.h"
-#include "net/http/http_response_headers.h"
-
-namespace net {
-
-NetLogHttpRequestParameter::NetLogHttpRequestParameter(
- const std::string& line,
- const HttpRequestHeaders& headers)
- : line_(line) {
- headers_.CopyFrom(headers);
-}
-
-Value* NetLogHttpRequestParameter::ToValue() const {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetString("line", line_);
- ListValue* headers = new ListValue();
- HttpRequestHeaders::Iterator iterator(headers_);
- while (iterator.GetNext()) {
- headers->Append(
- new StringValue(base::StringPrintf("%s: %s",
- iterator.name().c_str(),
- iterator.value().c_str())));
- }
- dict->Set("headers", headers);
- return dict;
-}
-
-NetLogHttpRequestParameter::~NetLogHttpRequestParameter() {}
-
-NetLogHttpResponseParameter::NetLogHttpResponseParameter(
- const scoped_refptr<HttpResponseHeaders>& headers)
- : headers_(headers) {}
-
-Value* NetLogHttpResponseParameter::ToValue() const {
- DictionaryValue* dict = new DictionaryValue();
- ListValue* headers = new ListValue();
- headers->Append(new StringValue(headers_->GetStatusLine()));
- void* iterator = NULL;
- std::string name;
- std::string value;
- while (headers_->EnumerateHeaderLines(&iterator, &name, &value)) {
- headers->Append(
- new StringValue(base::StringPrintf("%s: %s", name.c_str(),
- value.c_str())));
- }
- dict->Set("headers", headers);
- return dict;
-}
-
-NetLogHttpResponseParameter::~NetLogHttpResponseParameter() {}
-
-} // namespace net
diff --git a/net/http/http_net_log_params.h b/net/http/http_net_log_params.h
deleted file mode 100644
index daa4770..0000000
--- a/net/http/http_net_log_params.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_HTTP_HTTP_NET_LOG_PARAMS_H_
-#define NET_HTTP_HTTP_NET_LOG_PARAMS_H_
-#pragma once
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
-#include "net/base/net_log.h"
-#include "net/http/http_request_headers.h"
-
-namespace base {
-class Value;
-}
-
-namespace net {
-
-class HttpResponseHeaders;
-
-class NetLogHttpRequestParameter : public NetLog::EventParameters {
- public:
- NetLogHttpRequestParameter(const std::string& line,
- const HttpRequestHeaders& headers);
-
- const HttpRequestHeaders& GetHeaders() const {
- return headers_;
- }
-
- const std::string& GetLine() const {
- return line_;
- }
-
- // NetLog::EventParameters
- virtual base::Value* ToValue() const OVERRIDE;
-
- private:
- virtual ~NetLogHttpRequestParameter();
-
- const std::string line_;
- HttpRequestHeaders headers_;
-
- DISALLOW_COPY_AND_ASSIGN(NetLogHttpRequestParameter);
-};
-
-class NetLogHttpResponseParameter : public NetLog::EventParameters {
- public:
- explicit NetLogHttpResponseParameter(
- const scoped_refptr<HttpResponseHeaders>& headers);
-
- const HttpResponseHeaders& GetHeaders() const {
- return *headers_;
- }
-
- // NetLog::EventParameters
- virtual base::Value* ToValue() const OVERRIDE;
-
- private:
- virtual ~NetLogHttpResponseParameter();
-
- const scoped_refptr<HttpResponseHeaders> headers_;
-
- DISALLOW_COPY_AND_ASSIGN(NetLogHttpResponseParameter);
-};
-
-} // namespace net
-
-#endif // NET_HTTP_HTTP_NET_LOG_PARAMS_H_
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 9babefb..03de2a4 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -36,7 +36,6 @@
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_basic_stream.h"
#include "net/http/http_chunked_decoder.h"
-#include "net/http/http_net_log_params.h"
#include "net/http/http_network_session.h"
#include "net/http/http_proxy_client_socket.h"
#include "net/http/http_proxy_client_socket_pool.h"
@@ -872,11 +871,9 @@ int HttpNetworkTransaction::DoReadHeadersComplete(int result) {
"Net.HttpResponseCode_Nxx_MainFrame", response_code/100, 10);
}
- if (net_log_.IsLoggingAllEvents()) {
- net_log_.AddEvent(
- NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
- make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers)));
- }
+ net_log_.AddEvent(
+ NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
+ base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers));
if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) {
// HTTP/0.9 doesn't support the PUT method, so lack of response headers
diff --git a/net/http/http_network_transaction_spdy2_unittest.cc b/net/http/http_network_transaction_spdy2_unittest.cc
index b7c3023..838c54f 100644
--- a/net/http/http_network_transaction_spdy2_unittest.cc
+++ b/net/http/http_network_transaction_spdy2_unittest.cc
@@ -37,7 +37,6 @@
#include "net/http/http_auth_handler_mock.h"
#include "net/http/http_auth_handler_ntlm.h"
#include "net/http/http_basic_stream.h"
-#include "net/http/http_net_log_params.h"
#include "net/http/http_network_session.h"
#include "net/http/http_network_session_peer.h"
#include "net/http/http_server_properties_impl.h"
diff --git a/net/http/http_network_transaction_spdy3_unittest.cc b/net/http/http_network_transaction_spdy3_unittest.cc
index c9da692..84bd7d3 100644
--- a/net/http/http_network_transaction_spdy3_unittest.cc
+++ b/net/http/http_network_transaction_spdy3_unittest.cc
@@ -37,7 +37,6 @@
#include "net/http/http_auth_handler_mock.h"
#include "net/http/http_auth_handler_ntlm.h"
#include "net/http/http_basic_stream.h"
-#include "net/http/http_net_log_params.h"
#include "net/http/http_network_session.h"
#include "net/http/http_network_session_peer.h"
#include "net/http/http_server_properties_impl.h"
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index d801da0..f09241a 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -15,7 +15,6 @@
#include "net/base/net_log.h"
#include "net/base/net_util.h"
#include "net/http/http_basic_stream.h"
-#include "net/http/http_net_log_params.h"
#include "net/http/http_network_session.h"
#include "net/http/http_request_info.h"
#include "net/http/http_response_headers.h"
@@ -406,12 +405,12 @@ int HttpProxyClientSocket::DoSendRequest() {
auth_->AddAuthorizationHeader(&authorization_headers);
BuildTunnelRequest(request_, authorization_headers, endpoint_,
&request_line_, &request_headers_);
- if (net_log_.IsLoggingAllEvents()) {
- net_log_.AddEvent(
- NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
- make_scoped_refptr(new NetLogHttpRequestParameter(
- request_line_, request_headers_)));
- }
+
+ net_log_.AddEvent(
+ NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
+ base::Bind(&HttpRequestHeaders::NetLogCallback,
+ base::Unretained(&request_headers_),
+ &request_line_));
}
parser_buf_ = new GrowableIOBuffer();
@@ -442,11 +441,9 @@ int HttpProxyClientSocket::DoReadHeadersComplete(int result) {
if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0))
return ERR_TUNNEL_CONNECTION_FAILED;
- if (net_log_.IsLoggingAllEvents()) {
- net_log_.AddEvent(
- NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
- make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers)));
- }
+ net_log_.AddEvent(
+ NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
+ base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers));
switch (response_.headers->response_code()) {
case 200: // OK
diff --git a/net/http/http_request_headers.cc b/net/http/http_request_headers.cc
index fcd2dce..3669140 100644
--- a/net/http/http_request_headers.cc
+++ b/net/http/http_request_headers.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include "base/stringprintf.h"
#include "base/string_split.h"
#include "base/string_util.h"
+#include "base/values.h"
#include "net/http/http_util.h"
namespace net {
@@ -182,6 +183,54 @@ std::string HttpRequestHeaders::ToString() const {
return output;
}
+Value* HttpRequestHeaders::NetLogCallback(
+ const std::string* request_line,
+ NetLog::LogLevel /* log_level */) const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("line", *request_line);
+ ListValue* headers = new ListValue();
+ for (HeaderVector::const_iterator it = headers_.begin();
+ it != headers_.end(); ++it) {
+ headers->Append(
+ new StringValue(base::StringPrintf("%s: %s",
+ it->key.c_str(),
+ it->value.c_str())));
+ }
+ dict->Set("headers", headers);
+ return dict;
+}
+
+// static
+bool HttpRequestHeaders::FromNetLogParam(const base::Value* event_param,
+ HttpRequestHeaders* headers,
+ std::string* request_line) {
+ headers->Clear();
+ *request_line = "";
+
+ const base::DictionaryValue* dict;
+ base::ListValue* header_list;
+
+ if (!event_param ||
+ !event_param->GetAsDictionary(&dict) ||
+ !dict->GetList("headers", &header_list) ||
+ !dict->GetString("line", request_line)) {
+ return false;
+ }
+
+ for (base::ListValue::const_iterator it = header_list->begin();
+ it != header_list->end();
+ ++it) {
+ std::string header_line;
+ if (!(*it)->GetAsString(&header_line)) {
+ headers->Clear();
+ *request_line = "";
+ return false;
+ }
+ headers->AddHeaderFromString(header_line);
+ }
+ return true;
+}
+
HttpRequestHeaders::HeaderVector::iterator
HttpRequestHeaders::FindHeader(const base::StringPiece& key) {
for (HeaderVector::iterator it = headers_.begin();
diff --git a/net/http/http_request_headers.h b/net/http/http_request_headers.h
index cfb2748..675e1e0 100644
--- a/net/http/http_request_headers.h
+++ b/net/http/http_request_headers.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -17,6 +17,7 @@
#include "base/basictypes.h"
#include "base/string_piece.h"
#include "net/base/net_export.h"
+#include "net/base/net_log.h"
namespace net {
@@ -145,6 +146,20 @@ class NET_EXPORT HttpRequestHeaders {
// line, and adds the trailing "\r\n".
std::string ToString() const;
+ // Takes in the request line and returns a Value for use with the NetLog
+ // containing both the request line and all headers fields.
+ base::Value* NetLogCallback(const std::string* request_line,
+ NetLog::LogLevel log_level) const;
+
+ // Takes in a Value created by the above function, and attempts to extract the
+ // request line and create a copy of the original headers. Returns true on
+ // success. On failure, clears |headers| and |request_line|.
+ // TODO(mmenke): Long term, we want to remove this, and migrate external
+ // consumers to be NetworkDelegates.
+ static bool FromNetLogParam(const base::Value* event_param,
+ HttpRequestHeaders* headers,
+ std::string* request_line);
+
private:
HeaderVector::iterator FindHeader(const base::StringPiece& key);
HeaderVector::const_iterator FindHeader(const base::StringPiece& key) const;
@@ -152,9 +167,9 @@ class NET_EXPORT HttpRequestHeaders {
HeaderVector headers_;
// Allow the copy construction and operator= to facilitate copying in
- // HttpRequestInfo.
+ // HttpRequestHeaders.
// TODO(willchan): Investigate to see if we can remove the need to copy
- // HttpRequestInfo.
+ // HttpRequestHeaders.
// DISALLOW_COPY_AND_ASSIGN(HttpRequestHeaders);
};
diff --git a/net/http/http_request_headers_unittest.cc b/net/http/http_request_headers_unittest.cc
index 384ceeb..6346f50 100644
--- a/net/http/http_request_headers_unittest.cc
+++ b/net/http/http_request_headers_unittest.cc
@@ -1,9 +1,10 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/http/http_request_headers.h"
+#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
@@ -163,6 +164,24 @@ TEST(HttpRequestHeaders, CopyFrom) {
EXPECT_EQ("B: b\r\nC: c\r\n\r\n", headers.ToString());
}
+TEST(HttpRequestHeaders, ToNetLogParamAndBackAgain) {
+ HttpRequestHeaders headers;
+ headers.SetHeader("B", "b");
+ headers.SetHeader("A", "a");
+ std::string request_line("GET /stuff");
+
+ scoped_ptr<base::Value> event_param(
+ headers.NetLogCallback(&request_line, NetLog::LOG_ALL_BUT_BYTES));
+ HttpRequestHeaders headers2;
+ std::string request_line2;
+
+ ASSERT_TRUE(HttpRequestHeaders::FromNetLogParam(event_param.get(),
+ &headers2,
+ &request_line2));
+ EXPECT_EQ(request_line, request_line2);
+ EXPECT_EQ("B: b\r\nA: a\r\n\r\n", headers2.ToString());
+}
+
} // namespace
} // namespace net
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index c03fbe9..6fe8e2f 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -14,10 +14,12 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/pickle.h"
+#include "base/stringprintf.h"
#include "base/string_number_conversions.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/time.h"
+#include "base/values.h"
#include "net/base/escape.h"
#include "net/http/http_util.h"
@@ -1306,6 +1308,55 @@ bool HttpResponseHeaders::GetContentRange(int64* first_byte_position,
return true;
}
+Value* HttpResponseHeaders::NetLogCallback(
+ NetLog::LogLevel /* log_level */) const {
+ DictionaryValue* dict = new DictionaryValue();
+ ListValue* headers = new ListValue();
+ headers->Append(new StringValue(GetStatusLine()));
+ void* iterator = NULL;
+ std::string name;
+ std::string value;
+ while (EnumerateHeaderLines(&iterator, &name, &value)) {
+ headers->Append(
+ new StringValue(base::StringPrintf("%s: %s",
+ name.c_str(),
+ value.c_str())));
+ }
+ dict->Set("headers", headers);
+ return dict;
+}
+
+// static
+bool HttpResponseHeaders::FromNetLogParam(
+ const base::Value* event_param,
+ scoped_refptr<HttpResponseHeaders>* http_response_headers) {
+ http_response_headers->release();
+
+ const base::DictionaryValue* dict;
+ base::ListValue* header_list;
+
+ if (!event_param ||
+ !event_param->GetAsDictionary(&dict) ||
+ !dict->GetList("headers", &header_list)) {
+ return false;
+ }
+
+ std::string raw_headers;
+ for (base::ListValue::const_iterator it = header_list->begin();
+ it != header_list->end();
+ ++it) {
+ std::string header_line;
+ if (!(*it)->GetAsString(&header_line))
+ return false;
+
+ raw_headers.append(header_line);
+ raw_headers.push_back('\0');
+ }
+ raw_headers.push_back('\0');
+ *http_response_headers = new HttpResponseHeaders(raw_headers);
+ return true;
+}
+
bool HttpResponseHeaders::IsChunkEncoded() const {
// Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
return GetHttpVersion() >= HttpVersion(1, 1) &&
diff --git a/net/http/http_response_headers.h b/net/http/http_response_headers.h
index 6fbc0bb..1490872 100644
--- a/net/http/http_response_headers.h
+++ b/net/http/http_response_headers.h
@@ -13,6 +13,7 @@
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "net/base/net_export.h"
+#include "net/base/net_log.h"
#include "net/http/http_version.h"
class Pickle;
@@ -244,6 +245,18 @@ class NET_EXPORT HttpResponseHeaders
// Returns true if the response is chunk-encoded.
bool IsChunkEncoded() const;
+ // Creates a Value for use with the NetLog containing the response headers.
+ base::Value* NetLogCallback(NetLog::LogLevel log_level) const;
+
+ // Takes in a Value created by the above function, and attempts to create a
+ // copy of the original headers. Returns true on success. On failure,
+ // clears |http_response_headers|.
+ // TODO(mmenke): Long term, we want to remove this, and migrate external
+ // consumers to be NetworkDelegates.
+ static bool FromNetLogParam(
+ const base::Value* event_param,
+ scoped_refptr<HttpResponseHeaders>* http_response_headers);
+
// Returns the HTTP response code. This is 0 if the response code text seems
// to exist but could not be parsed. Otherwise, it defaults to 200 if the
// response code is not found in the raw headers.
diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc
index f7c5e6f5..d93c5bd 100644
--- a/net/http/http_response_headers_unittest.cc
+++ b/net/http/http_response_headers_unittest.cc
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/pickle.h"
#include "base/time.h"
+#include "base/values.h"
#include "net/http/http_response_headers.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -1756,3 +1757,30 @@ TEST(HttpResponseHeadersTest, ReplaceStatus) {
EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers);
}
}
+
+TEST(HttpResponseHeadersTest, ToNetLogParamAndBackAgain) {
+ std::string headers("HTTP/1.1 404\n"
+ "Content-Length: 450\n"
+ "Connection: keep-alive\n");
+ HeadersToRaw(&headers);
+ scoped_refptr<net::HttpResponseHeaders> parsed(
+ new net::HttpResponseHeaders(headers));
+
+ scoped_ptr<base::Value> event_param(
+ parsed->NetLogCallback(net::NetLog::LOG_ALL_BUT_BYTES));
+ scoped_refptr<net::HttpResponseHeaders> recreated;
+
+ ASSERT_TRUE(net::HttpResponseHeaders::FromNetLogParam(event_param.get(),
+ &recreated));
+ ASSERT_TRUE(recreated.get());
+ EXPECT_EQ(parsed->GetHttpVersion(), recreated->GetHttpVersion());
+ EXPECT_EQ(parsed->response_code(), recreated->response_code());
+ EXPECT_EQ(parsed->GetContentLength(), recreated->GetContentLength());
+ EXPECT_EQ(parsed->IsKeepAlive(), recreated->IsKeepAlive());
+
+ std::string normalized_parsed;
+ parsed->GetNormalizedHeaders(&normalized_parsed);
+ std::string normalized_recreated;
+ parsed->GetNormalizedHeaders(&normalized_recreated);
+ EXPECT_EQ(normalized_parsed, normalized_recreated);
+}
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index b56bd08..7fda009 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -4,6 +4,7 @@
#include "net/http/http_stream_parser.h"
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
@@ -11,7 +12,6 @@
#include "net/base/auth.h"
#include "net/base/io_buffer.h"
#include "net/base/ssl_cert_request_info.h"
-#include "net/http/http_net_log_params.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_request_info.h"
#include "net/http/http_response_headers.h"
@@ -197,12 +197,12 @@ int HttpStreamParser::SendRequest(const std::string& request_line,
DCHECK(!callback.is_null());
DCHECK(response);
- if (net_log_.IsLoggingAllEvents()) {
- net_log_.AddEvent(
- NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
- make_scoped_refptr(new NetLogHttpRequestParameter(
- request_line, headers)));
- }
+ net_log_.AddEvent(
+ NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
+ base::Bind(&HttpRequestHeaders::NetLogCallback,
+ base::Unretained(&headers),
+ &request_line));
+
DVLOG(1) << __FUNCTION__ << "()"
<< " request_line = \"" << request_line << "\""
<< " headers = \"" << headers.ToString() << "\"";
diff --git a/net/net.gyp b/net/net.gyp
index 541cec6..93a6f8d 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -456,8 +456,6 @@
'http/http_content_disposition.h',
'http/http_chunked_decoder.cc',
'http/http_chunked_decoder.h',
- 'http/http_net_log_params.cc',
- 'http/http_net_log_params.h',
'http/http_network_layer.cc',
'http/http_network_layer.h',
'http/http_network_session.cc',
@@ -1070,7 +1068,6 @@
'base/mock_filter_context.cc',
'base/mock_filter_context.h',
'base/multi_threaded_cert_verifier_unittest.cc',
- 'base/net_log_unittest.cc',
'base/net_log_unittest.h',
'base/net_util_unittest.cc',
'base/network_change_notifier_linux_unittest.cc',
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc
index a9c7bba..ff2f259 100644
--- a/net/socket/ssl_client_socket_nss.cc
+++ b/net/socket/ssl_client_socket_nss.cc
@@ -382,6 +382,17 @@ void DestroyCertificates(CERTCertificate** certs, size_t len) {
CERT_DestroyCertificate(certs[i]);
}
+// Helper function to make it possible to log events from within the
+// SSLClientSocketNSS::Core. Can't use Bind with BoundNetLog::AddEntry directly
+// on Windows because it is overloaded.
+void AddLogEvent(BoundNetLog* net_log,
+ NetLog::EventType event_type,
+ const scoped_refptr<NetLog::EventParameters>& event_params) {
+ if (!net_log)
+ return;
+ net_log->AddEvent(event_type, event_params);
+}
+
// Helper function to make it easier to call BoundNetLog::AddByteTransferEvent
// from within the SSLClientSocketNSS::Core.
// AddByteTransferEvent expects to receive a const char*, which within the
@@ -1292,7 +1303,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED,
scoped_refptr<NetLog::EventParameters>()));
@@ -1339,7 +1350,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
// number collision. See crbug.com/97355.
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count", 0))));
@@ -1362,7 +1373,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
CERT_DestroyCertList(cert_chain);
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count", 0))));
@@ -1385,7 +1396,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
int cert_count = 1 + intermediates.size();
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count",
@@ -1398,7 +1409,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
// Send no client certificate.
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count", 0))));
@@ -1420,7 +1431,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count", 0))));
@@ -1565,7 +1576,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
}
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count",
@@ -1589,7 +1600,7 @@ SECStatus SSLClientSocketNSS::Core::PlatformClientAuthHandler(
// Send no client certificate.
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count", 0))));
@@ -1644,7 +1655,7 @@ SECStatus SSLClientSocketNSS::Core::ClientAuthHandler(
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_REQUESTED,
scoped_refptr<NetLog::EventParameters>()));
@@ -1676,7 +1687,7 @@ SECStatus SSLClientSocketNSS::Core::ClientAuthHandler(
// NSS will construct the certificate chain.
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count", -1))));
@@ -1688,7 +1699,7 @@ SECStatus SSLClientSocketNSS::Core::ClientAuthHandler(
// Send no client certificate.
core->PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, core->weak_net_log_,
+ base::Bind(&AddLogEvent, core->weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count", 0))));
@@ -1939,7 +1950,7 @@ int SSLClientSocketNSS::Core::DoReadLoop(int result) {
int rv = ERR_UNEXPECTED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
make_scoped_refptr(new SSLErrorParams(rv, 0))));
return rv;
@@ -1968,7 +1979,7 @@ int SSLClientSocketNSS::Core::DoWriteLoop(int result) {
int rv = ERR_UNEXPECTED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
make_scoped_refptr(new SSLErrorParams(rv, 0))));
return rv;
@@ -2003,7 +2014,7 @@ int SSLClientSocketNSS::Core::DoHandshake() {
net_error = ERR_SSL_CLIENT_AUTH_CERT_NEEDED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_HANDSHAKE_ERROR,
make_scoped_refptr(new SSLErrorParams(net_error, 0))));
@@ -2023,7 +2034,7 @@ int SSLClientSocketNSS::Core::DoHandshake() {
net_error = ERR_SSL_PROTOCOL_ERROR;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_HANDSHAKE_ERROR,
make_scoped_refptr(
new SSLErrorParams(net_error, 0))));
@@ -2084,7 +2095,7 @@ int SSLClientSocketNSS::Core::DoHandshake() {
} else {
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_HANDSHAKE_ERROR,
make_scoped_refptr(
new SSLErrorParams(net_error, prerr))));
@@ -2125,7 +2136,7 @@ int SSLClientSocketNSS::Core::DoGetDBCertComplete(int result) {
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count",
@@ -2151,7 +2162,7 @@ int SSLClientSocketNSS::Core::DoPayloadRead() {
rv = ERR_SSL_CLIENT_AUTH_CERT_NEEDED;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
make_scoped_refptr(new SSLErrorParams(rv, 0))));
return rv;
@@ -2171,7 +2182,7 @@ int SSLClientSocketNSS::Core::DoPayloadRead() {
rv = HandleNSSError(prerr, false);
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_READ_ERROR,
make_scoped_refptr(new SSLErrorParams(rv, prerr))));
return rv;
@@ -2198,7 +2209,7 @@ int SSLClientSocketNSS::Core::DoPayloadWrite() {
rv = HandleNSSError(prerr, false);
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_WRITE_ERROR,
make_scoped_refptr(new SSLErrorParams(rv, prerr))));
return rv;
@@ -2446,7 +2457,7 @@ SECStatus SSLClientSocketNSS::Core::DomainBoundClientAuthHandler(
int cert_count = (rv == SECSuccess) ? 1 : 0;
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_CLIENT_CERT_PROVIDED,
make_scoped_refptr(
new NetLogIntegerParameter("cert_count",
@@ -2506,7 +2517,7 @@ void SSLClientSocketNSS::Core::UpdateServerCert() {
if (nss_handshake_state_.server_cert) {
PostOrRunCallback(
FROM_HERE,
- base::Bind(&BoundNetLog::AddEvent, weak_net_log_,
+ base::Bind(&AddLogEvent, weak_net_log_,
NetLog::TYPE_SSL_CERTIFICATES_RECEIVED,
make_scoped_refptr(
new X509CertificateNetLogParam(
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index 62dcd5e..be4e1e9 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -16,7 +16,6 @@
#include "net/base/net_util.h"
#include "net/http/http_auth_cache.h"
#include "net/http/http_auth_handler_factory.h"
-#include "net/http/http_net_log_params.h"
#include "net/http/http_response_headers.h"
#include "net/spdy/spdy_http_utils.h"
@@ -365,12 +364,12 @@ int SpdyProxyClientSocket::DoSendRequest() {
HttpRequestHeaders request_headers;
BuildTunnelRequest(request_, authorization_headers, endpoint_, &request_line,
&request_headers);
- if (net_log_.IsLoggingAllEvents()) {
- net_log_.AddEvent(
- NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
- make_scoped_refptr(new NetLogHttpRequestParameter(
- request_line, request_headers)));
- }
+
+ net_log_.AddEvent(
+ NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
+ base::Bind(&HttpRequestHeaders::NetLogCallback,
+ base::Unretained(&request_headers),
+ &request_line));
request_.extra_headers.MergeFrom(request_headers);
linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
@@ -410,11 +409,9 @@ int SpdyProxyClientSocket::DoReadReplyComplete(int result) {
return ERR_TUNNEL_CONNECTION_FAILED;
next_state_ = STATE_OPEN;
- if (net_log_.IsLoggingAllEvents()) {
- net_log_.AddEvent(
- NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
- make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers)));
- }
+ net_log_.AddEvent(
+ NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
+ base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers));
if (response_.headers->response_code() == 200) {
return OK;
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index fef10fb..efc83c9 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -445,8 +445,8 @@ void URLRequest::StartJob(URLRequestJob* job) {
net_log_.BeginEvent(
NetLog::TYPE_URL_REQUEST_START_JOB,
- make_scoped_refptr(new URLRequestStartEventParameters(
- url(), method_, load_flags_, priority_)));
+ base::Bind(&NetLogURLRequestStartCallback,
+ &url(), &method_, load_flags_, priority_));
job_ = job;
job_->SetExtraRequestHeaders(extra_request_headers_);
diff --git a/net/url_request/url_request_netlog_params.cc b/net/url_request/url_request_netlog_params.cc
index 29143ba..67d44c3 100644
--- a/net/url_request/url_request_netlog_params.cc
+++ b/net/url_request/url_request_netlog_params.cc
@@ -5,29 +5,32 @@
#include "net/url_request/url_request_netlog_params.h"
#include "base/values.h"
+#include "googleurl/src/gurl.h"
namespace net {
-URLRequestStartEventParameters::URLRequestStartEventParameters(
- const GURL& url,
- const std::string& method,
- int load_flags,
- RequestPriority priority)
- : url_(url),
- method_(method),
- load_flags_(load_flags),
- priority_(priority) {
-}
-
-Value* URLRequestStartEventParameters::ToValue() const {
+Value* NetLogURLRequestStartCallback(const GURL* url,
+ const std::string* method,
+ int load_flags,
+ RequestPriority priority,
+ NetLog::LogLevel /* log_level */) {
DictionaryValue* dict = new DictionaryValue();
- dict->SetString("url", url_.possibly_invalid_spec());
- dict->SetString("method", method_);
- dict->SetInteger("load_flags", load_flags_);
- dict->SetInteger("priority", static_cast<int>(priority_));
+ dict->SetString("url", url->possibly_invalid_spec());
+ dict->SetString("method", *method);
+ dict->SetInteger("load_flags", load_flags);
+ dict->SetInteger("priority", static_cast<int>(priority));
return dict;
}
-URLRequestStartEventParameters::~URLRequestStartEventParameters() {}
+bool StartEventLoadFlagsFromEventParams(const Value* event_params,
+ int* load_flags) {
+ const DictionaryValue* dict;
+ if (!event_params->GetAsDictionary(&dict) ||
+ !dict->GetInteger("load_flags", load_flags)) {
+ *load_flags = 0;
+ return false;
+ }
+ return true;
+}
} // namespace net
diff --git a/net/url_request/url_request_netlog_params.h b/net/url_request/url_request_netlog_params.h
index d084f24..eb84f7c 100644
--- a/net/url_request/url_request_netlog_params.h
+++ b/net/url_request/url_request_netlog_params.h
@@ -8,44 +8,32 @@
#include <string>
-#include "base/basictypes.h"
-#include "googleurl/src/gurl.h"
#include "net/base/net_export.h"
#include "net/base/net_log.h"
#include "net/base/request_priority.h"
-namespace net {
-
-// Holds the parameters to emit to the NetLog when starting a URLRequest.
-class NET_EXPORT URLRequestStartEventParameters
- : public NetLog::EventParameters {
- public:
- URLRequestStartEventParameters(const GURL& url,
- const std::string& method,
- int load_flags,
- RequestPriority priority);
-
- const GURL& url() const {
- return url_;
- }
+class GURL;
- int load_flags() const {
- return load_flags_;
- }
+namespace base {
+class Value;
+}
- virtual base::Value* ToValue() const OVERRIDE;
-
- protected:
- virtual ~URLRequestStartEventParameters();
-
- private:
- const GURL url_;
- const std::string method_;
- const int load_flags_;
- const RequestPriority priority_;
+namespace net {
- DISALLOW_COPY_AND_ASSIGN(URLRequestStartEventParameters);
-};
+// Returns a Value containing NetLog parameters for starting a URLRequest.
+NET_EXPORT base::Value* NetLogURLRequestStartCallback(
+ const GURL* url,
+ const std::string* method,
+ int load_flags,
+ RequestPriority priority,
+ NetLog::LogLevel /* log_level */);
+
+// Attempts to extract the load flags from a Value created by the above
+// function. On success, sets |load_flags| accordingly and returns true.
+// On failure, sets |load_flags| to 0.
+NET_EXPORT bool StartEventLoadFlagsFromEventParams(
+ const base::Value* event_params,
+ int* load_flags);
} // namespace net
diff --git a/remoting/host/vlog_net_log.cc b/remoting/host/vlog_net_log.cc
index f273b09..05e9a35 100644
--- a/remoting/host/vlog_net_log.cc
+++ b/remoting/host/vlog_net_log.cc
@@ -19,15 +19,9 @@ VlogNetLog::VlogNetLog() : id_(0) {
VlogNetLog::~VlogNetLog() {
}
-void VlogNetLog::AddEntry(
- EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<EventParameters>& params) {
+void VlogNetLog::OnAddEntry(const NetLog::Entry& entry) {
if (VLOG_IS_ON(4)) {
- scoped_ptr<Value> value(
- net::NetLog::EntryToDictionaryValue(
- type, base::TimeTicks::Now(), source, phase, params, false));
+ scoped_ptr<Value> value(entry.ToValue());
std::string json;
base::JSONWriter::Write(value.get(), &json);
VLOG(4) << json;
@@ -35,6 +29,7 @@ void VlogNetLog::AddEntry(
}
uint32 VlogNetLog::NextID() {
+ // TODO(mmenke): Make this threadsafe and start with 1 instead of 0.
return id_++;
}
diff --git a/remoting/host/vlog_net_log.h b/remoting/host/vlog_net_log.h
index eae349b..d056a3a 100644
--- a/remoting/host/vlog_net_log.h
+++ b/remoting/host/vlog_net_log.h
@@ -20,11 +20,7 @@ class VlogNetLog : public net::NetLog {
virtual ~VlogNetLog();
// NetLog overrides:
- virtual void AddEntry(
- EventType type,
- const Source& source,
- EventPhase phase,
- const scoped_refptr<NetLog::EventParameters>& params) OVERRIDE;
+ virtual void OnAddEntry(const NetLog::Entry& entry) OVERRIDE;
virtual uint32 NextID() OVERRIDE;
virtual LogLevel GetLogLevel() const OVERRIDE;
virtual void AddThreadSafeObserver(ThreadSafeObserver* observer,