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

Unified Diff: chrome/browser/net/load_timing_observer.cc

Issue 10399083: Make NetLog take in callbacks that return Values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix merge error Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/load_timing_observer.h ('k') | chrome/browser/net/load_timing_observer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/load_timing_observer.cc
===================================================================
--- chrome/browser/net/load_timing_observer.cc (revision 141317)
+++ chrome/browser/net/load_timing_observer.cc (working copy)
@@ -83,22 +83,18 @@
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::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 @@
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 @@
}
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::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 @@
}
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 @@
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 @@
}
}
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 @@
}
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 @@
}
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();
+}
« no previous file with comments | « chrome/browser/net/load_timing_observer.h ('k') | chrome/browser/net/load_timing_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698