| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/load_timing_observer.h" | 5 #include "chrome/browser/net/load_timing_observer.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "chrome/browser/net/chrome_net_log.h" | 8 #include "chrome/browser/net/chrome_net_log.h" |
| 9 #include "content/common/resource_response.h" | 9 #include "content/public/common/resource_response.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 12 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
| 13 #include "net/url_request/url_request_netlog_params.h" | 13 #include "net/url_request/url_request_netlog_params.h" |
| 14 | 14 |
| 15 using base::Time; | 15 using base::Time; |
| 16 using base::TimeTicks; | 16 using base::TimeTicks; |
| 17 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 using webkit_glue::ResourceLoaderBridge; | 18 using webkit_glue::ResourceLoaderBridge; |
| 19 using webkit_glue::ResourceLoadTimingInfo; | 19 using webkit_glue::ResourceLoadTimingInfo; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 OnAddURLRequestEntry(type, time, source, phase, params); | 92 OnAddURLRequestEntry(type, time, source, phase, params); |
| 93 else if (source.type == net::NetLog::SOURCE_HTTP_STREAM_JOB) | 93 else if (source.type == net::NetLog::SOURCE_HTTP_STREAM_JOB) |
| 94 OnAddHTTPStreamJobEntry(type, time, source, phase, params); | 94 OnAddHTTPStreamJobEntry(type, time, source, phase, params); |
| 95 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) | 95 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) |
| 96 OnAddConnectJobEntry(type, time, source, phase, params); | 96 OnAddConnectJobEntry(type, time, source, phase, params); |
| 97 else if (source.type == net::NetLog::SOURCE_SOCKET) | 97 else if (source.type == net::NetLog::SOURCE_SOCKET) |
| 98 OnAddSocketEntry(type, time, source, phase, params); | 98 OnAddSocketEntry(type, time, source, phase, params); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // static | 101 // static |
| 102 void LoadTimingObserver::PopulateTimingInfo(net::URLRequest* request, | 102 void LoadTimingObserver::PopulateTimingInfo( |
| 103 ResourceResponse* response) { | 103 net::URLRequest* request, |
| 104 content::ResourceResponse* response) { |
| 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 105 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)) | 106 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)) |
| 106 return; | 107 return; |
| 107 | 108 |
| 108 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( | 109 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( |
| 109 request->net_log().net_log()); | 110 request->net_log().net_log()); |
| 110 if (chrome_net_log == NULL) | 111 if (chrome_net_log == NULL) |
| 111 return; | 112 return; |
| 112 | 113 |
| 113 uint32 source_id = request->net_log().source().id; | 114 uint32 source_id = request->net_log().source().id; |
| 114 LoadTimingObserver* observer = chrome_net_log->load_timing_observer(); | 115 LoadTimingObserver* observer = chrome_net_log->load_timing_observer(); |
| 115 LoadTimingObserver::URLRequestRecord* record = | 116 LoadTimingObserver::URLRequestRecord* record = |
| 116 observer->GetURLRequestRecord(source_id); | 117 observer->GetURLRequestRecord(source_id); |
| 117 if (record) { | 118 if (record) { |
| 118 response->response_head.connection_id = record->socket_log_id; | 119 response->connection_id = record->socket_log_id; |
| 119 response->response_head.connection_reused = record->socket_reused; | 120 response->connection_reused = record->socket_reused; |
| 120 response->response_head.load_timing = record->timing; | 121 response->load_timing = record->timing; |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 void LoadTimingObserver::OnAddURLRequestEntry( | 125 void LoadTimingObserver::OnAddURLRequestEntry( |
| 125 net::NetLog::EventType type, | 126 net::NetLog::EventType type, |
| 126 const base::TimeTicks& time, | 127 const base::TimeTicks& time, |
| 127 const net::NetLog::Source& source, | 128 const net::NetLog::Source& source, |
| 128 net::NetLog::EventPhase phase, | 129 net::NetLog::EventPhase phase, |
| 129 net::NetLog::EventParameters* params) { | 130 net::NetLog::EventParameters* params) { |
| 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 if (it == socket_to_record_.end()) | 368 if (it == socket_to_record_.end()) |
| 368 return; | 369 return; |
| 369 | 370 |
| 370 if (type == net::NetLog::TYPE_SSL_CONNECT) { | 371 if (type == net::NetLog::TYPE_SSL_CONNECT) { |
| 371 if (is_begin) | 372 if (is_begin) |
| 372 it->second.ssl_start = time; | 373 it->second.ssl_start = time; |
| 373 else if (is_end) | 374 else if (is_end) |
| 374 it->second.ssl_end = time; | 375 it->second.ssl_end = time; |
| 375 } | 376 } |
| 376 } | 377 } |
| OLD | NEW |