Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "chrome/browser/net/chrome_net_log.h" | 9 #include "chrome/browser/net/chrome_net_log.h" |
| 10 #include "chrome/common/resource_response.h" | 10 #include "chrome/common/resource_response.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 tick_to_time_offset); | 37 tick_to_time_offset); |
| 38 } | 38 } |
| 39 | 39 |
| 40 static int32 TimeTicksToOffset( | 40 static int32 TimeTicksToOffset( |
| 41 const TimeTicks& time_ticks, | 41 const TimeTicks& time_ticks, |
| 42 LoadTimingObserver::URLRequestRecord* record) { | 42 LoadTimingObserver::URLRequestRecord* record) { |
| 43 return static_cast<int32>( | 43 return static_cast<int32>( |
| 44 (time_ticks - record->base_ticks).InMillisecondsRoundedUp()); | 44 (time_ticks - record->base_ticks).InMillisecondsRoundedUp()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } | 47 } // namespace |
| 48 | 48 |
| 49 LoadTimingObserver::URLRequestRecord::URLRequestRecord() | 49 LoadTimingObserver::URLRequestRecord::URLRequestRecord() |
| 50 : connect_job_id(net::NetLog::Source::kInvalidId), | 50 : connect_job_id(net::NetLog::Source::kInvalidId), |
| 51 socket_log_id(net::NetLog::Source::kInvalidId), | 51 socket_log_id(net::NetLog::Source::kInvalidId), |
| 52 socket_reused(false) { | 52 socket_reused(false) { |
| 53 } | 53 } |
| 54 | 54 |
| 55 LoadTimingObserver::LoadTimingObserver() | 55 LoadTimingObserver::LoadTimingObserver() |
| 56 : Observer(net::NetLog::LOG_BASIC), | 56 : Observer(net::NetLog::LOG_BASIC), |
| 57 last_connect_job_id_(net::NetLog::Source::kInvalidId) { | 57 last_connect_job_id_(net::NetLog::Source::kInvalidId) { |
| 58 } | 58 } |
| 59 | 59 |
| 60 LoadTimingObserver::~LoadTimingObserver() { | 60 LoadTimingObserver::~LoadTimingObserver() { |
| 61 } | 61 } |
| 62 | 62 |
| 63 LoadTimingObserver::URLRequestRecord* | |
| 64 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) { | |
| 65 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id); | |
| 66 if (it != url_request_to_record_.end()) | |
| 67 return &it->second; | |
| 68 return NULL; | |
| 69 } | |
| 70 | |
| 71 void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type, | 63 void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type, |
| 72 const base::TimeTicks& time, | 64 const base::TimeTicks& time, |
| 73 const net::NetLog::Source& source, | 65 const net::NetLog::Source& source, |
| 74 net::NetLog::EventPhase phase, | 66 net::NetLog::EventPhase phase, |
| 75 net::NetLog::EventParameters* params) { | 67 net::NetLog::EventParameters* params) { |
| 76 if (source.type == net::NetLog::SOURCE_URL_REQUEST) | 68 if (source.type == net::NetLog::SOURCE_URL_REQUEST) { |
| 69 AutoLock lock(lock_); | |
|
eroman
2010/11/16 17:51:14
I don't believe we need any locking in this class.
mmenke
2010/11/16 21:34:49
You're right, this is just me being paranoid about
| |
| 77 OnAddURLRequestEntry(type, time, source, phase, params); | 70 OnAddURLRequestEntry(type, time, source, phase, params); |
| 78 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) | 71 } else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) { |
| 72 AutoLock lock(lock_); | |
| 79 OnAddConnectJobEntry(type, time, source, phase, params); | 73 OnAddConnectJobEntry(type, time, source, phase, params); |
| 80 else if (source.type == net::NetLog::SOURCE_SOCKET) | 74 } else if (source.type == net::NetLog::SOURCE_SOCKET) { |
| 75 AutoLock lock(lock_); | |
| 81 OnAddSocketEntry(type, time, source, phase, params); | 76 OnAddSocketEntry(type, time, source, phase, params); |
| 77 } | |
| 82 } | 78 } |
| 83 | 79 |
| 84 // static | 80 // static |
| 85 void LoadTimingObserver::PopulateTimingInfo(URLRequest* request, | 81 void LoadTimingObserver::PopulateTimingInfo(URLRequest* request, |
| 86 ResourceResponse* response) { | 82 ResourceResponse* response) { |
| 87 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)) | 83 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)) |
| 88 return; | 84 return; |
| 89 | 85 |
| 90 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( | 86 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( |
| 91 request->net_log().net_log()); | 87 request->net_log().net_log()); |
| 92 if (chrome_net_log == NULL) | 88 if (chrome_net_log == NULL) |
| 93 return; | 89 return; |
| 94 | 90 |
| 95 uint32 source_id = request->net_log().source().id; | 91 uint32 source_id = request->net_log().source().id; |
| 96 LoadTimingObserver* observer = chrome_net_log->load_timing_observer(); | 92 LoadTimingObserver* observer = chrome_net_log->load_timing_observer(); |
| 93 | |
| 94 AutoLock(observer->lock_); | |
| 97 LoadTimingObserver::URLRequestRecord* record = | 95 LoadTimingObserver::URLRequestRecord* record = |
| 98 observer->GetURLRequestRecord(source_id); | 96 observer->GetURLRequestRecord(source_id); |
| 99 if (record) { | 97 if (record) { |
| 100 response->response_head.connection_id = record->socket_log_id; | 98 response->response_head.connection_id = record->socket_log_id; |
| 101 response->response_head.connection_reused = record->socket_reused; | 99 response->response_head.connection_reused = record->socket_reused; |
| 102 response->response_head.load_timing = record->timing; | 100 response->response_head.load_timing = record->timing; |
| 103 } | 101 } |
| 104 } | 102 } |
| 105 | 103 |
| 106 void LoadTimingObserver::OnAddURLRequestEntry( | 104 void LoadTimingObserver::OnAddURLRequestEntry( |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 if (it == socket_to_record_.end()) | 276 if (it == socket_to_record_.end()) |
| 279 return; | 277 return; |
| 280 | 278 |
| 281 if (type == net::NetLog::TYPE_SSL_CONNECT) { | 279 if (type == net::NetLog::TYPE_SSL_CONNECT) { |
| 282 if (is_begin) | 280 if (is_begin) |
| 283 it->second.ssl_start = time; | 281 it->second.ssl_start = time; |
| 284 else if (is_end) | 282 else if (is_end) |
| 285 it->second.ssl_end = time; | 283 it->second.ssl_end = time; |
| 286 } | 284 } |
| 287 } | 285 } |
| 286 | |
| 287 LoadTimingObserver::URLRequestRecord* | |
| 288 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) { | |
| 289 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id); | |
| 290 if (it != url_request_to_record_.end()) | |
| 291 return &it->second; | |
| 292 return NULL; | |
| 293 } | |
| OLD | NEW |