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* | 63 LoadTimingObserver::URLRequestRecord* |
| 64 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) { | 64 LoadTimingObserver::GetURLRequestRecord(uint32 source_id) { |
| 65 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id); | 65 URLRequestToRecordMap::iterator it = url_request_to_record_.find(source_id); |
| 66 if (it != url_request_to_record_.end()) | 66 if (it != url_request_to_record_.end()) |
| 67 return &it->second; | 67 return &it->second; |
| 68 return NULL; | 68 return NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type, | 71 void LoadTimingObserver::OnAddEntry(net::NetLog::EventType type, |
| 72 const base::TimeTicks& time, | 72 const base::TimeTicks& time, |
| 73 const net::NetLog::Source& source, | 73 const net::NetLog::Source& source, |
| 74 net::NetLog::EventPhase phase, | 74 net::NetLog::EventPhase phase, |
| 75 net::NetLog::EventParameters* params) { | 75 net::NetLog::EventParameters* params) { |
| 76 // The events that the Observer is interested in only occur on the IO thread. | |
| 77 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) | |
| 78 return; | |
| 76 if (source.type == net::NetLog::SOURCE_URL_REQUEST) | 79 if (source.type == net::NetLog::SOURCE_URL_REQUEST) |
| 77 OnAddURLRequestEntry(type, time, source, phase, params); | 80 OnAddURLRequestEntry(type, time, source, phase, params); |
| 78 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) | 81 else if (source.type == net::NetLog::SOURCE_CONNECT_JOB) |
| 79 OnAddConnectJobEntry(type, time, source, phase, params); | 82 OnAddConnectJobEntry(type, time, source, phase, params); |
| 80 else if (source.type == net::NetLog::SOURCE_SOCKET) | 83 else if (source.type == net::NetLog::SOURCE_SOCKET) |
| 81 OnAddSocketEntry(type, time, source, phase, params); | 84 OnAddSocketEntry(type, time, source, phase, params); |
| 82 } | 85 } |
| 83 | 86 |
| 84 // static | 87 // static |
| 85 void LoadTimingObserver::PopulateTimingInfo(URLRequest* request, | 88 void LoadTimingObserver::PopulateTimingInfo(URLRequest* request, |
| 86 ResourceResponse* response) { | 89 ResourceResponse* response) { |
| 87 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)) | 90 if (!(request->load_flags() & net::LOAD_ENABLE_LOAD_TIMING)) |
|
eroman
2010/11/17 05:59:02
I suggest adding assertions to all the other funct
mmenke
2010/11/17 21:42:14
Wasn't sure if this would break unittests. Done.
| |
| 88 return; | 91 return; |
| 89 | 92 |
| 90 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( | 93 ChromeNetLog* chrome_net_log = static_cast<ChromeNetLog*>( |
| 91 request->net_log().net_log()); | 94 request->net_log().net_log()); |
| 92 if (chrome_net_log == NULL) | 95 if (chrome_net_log == NULL) |
| 93 return; | 96 return; |
| 94 | 97 |
| 95 uint32 source_id = request->net_log().source().id; | 98 uint32 source_id = request->net_log().source().id; |
| 96 LoadTimingObserver* observer = chrome_net_log->load_timing_observer(); | 99 LoadTimingObserver* observer = chrome_net_log->load_timing_observer(); |
| 97 LoadTimingObserver::URLRequestRecord* record = | 100 LoadTimingObserver::URLRequestRecord* record = |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 if (it == socket_to_record_.end()) | 281 if (it == socket_to_record_.end()) |
| 279 return; | 282 return; |
| 280 | 283 |
| 281 if (type == net::NetLog::TYPE_SSL_CONNECT) { | 284 if (type == net::NetLog::TYPE_SSL_CONNECT) { |
| 282 if (is_begin) | 285 if (is_begin) |
| 283 it->second.ssl_start = time; | 286 it->second.ssl_start = time; |
| 284 else if (is_end) | 287 else if (is_end) |
| 285 it->second.ssl_end = time; | 288 it->second.ssl_end = time; |
| 286 } | 289 } |
| 287 } | 290 } |
| OLD | NEW |