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 #ifndef CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ |
6 #define CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ | 6 #define CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "chrome/browser/net/chrome_net_log.h" | 12 #include "chrome/browser/net/chrome_net_log.h" |
13 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
14 #include "webkit/glue/resource_loader_bridge.h" | 14 #include "webkit/glue/resource_loader_bridge.h" |
15 | 15 |
16 class URLRequest; | 16 class URLRequest; |
17 struct ResourceResponse; | 17 struct ResourceResponse; |
18 | 18 |
19 // LoadTimingObserver watches the NetLog event stream and collects the network | 19 // LoadTimingObserver watches the NetLog event stream and collects the network |
20 // timing information. | 20 // timing information. |
21 class LoadTimingObserver : public ChromeNetLog::Observer { | 21 // |
| 22 // LoadTimingObserver lives completely on the IOThread and ignores events from |
| 23 // other threads. It is not safe to use from other threads. |
| 24 class LoadTimingObserver : public ChromeNetLog::ThreadSafeObserver { |
22 public: | 25 public: |
23 struct URLRequestRecord { | 26 struct URLRequestRecord { |
24 URLRequestRecord(); | 27 URLRequestRecord(); |
25 | 28 |
26 webkit_glue::ResourceLoadTimingInfo timing; | 29 webkit_glue::ResourceLoadTimingInfo timing; |
27 uint32 connect_job_id; | 30 uint32 connect_job_id; |
28 uint32 socket_log_id; | 31 uint32 socket_log_id; |
29 bool socket_reused; | 32 bool socket_reused; |
30 base::TimeTicks base_ticks; | 33 base::TimeTicks base_ticks; |
31 }; | 34 }; |
32 | 35 |
33 struct ConnectJobRecord { | 36 struct ConnectJobRecord { |
34 base::TimeTicks dns_start; | 37 base::TimeTicks dns_start; |
35 base::TimeTicks dns_end; | 38 base::TimeTicks dns_end; |
36 }; | 39 }; |
37 | 40 |
38 struct SocketRecord { | 41 struct SocketRecord { |
39 base::TimeTicks ssl_start; | 42 base::TimeTicks ssl_start; |
40 base::TimeTicks ssl_end; | 43 base::TimeTicks ssl_end; |
41 }; | 44 }; |
42 | 45 |
43 LoadTimingObserver(); | 46 LoadTimingObserver(); |
44 ~LoadTimingObserver(); | 47 ~LoadTimingObserver(); |
45 | 48 |
46 URLRequestRecord* GetURLRequestRecord(uint32 source_id); | 49 URLRequestRecord* GetURLRequestRecord(uint32 source_id); |
47 | 50 |
48 // Observer implementation: | 51 // ThreadSafeObserver implementation: |
49 virtual void OnAddEntry(net::NetLog::EventType type, | 52 virtual void OnAddEntry(net::NetLog::EventType type, |
50 const base::TimeTicks& time, | 53 const base::TimeTicks& time, |
51 const net::NetLog::Source& source, | 54 const net::NetLog::Source& source, |
52 net::NetLog::EventPhase phase, | 55 net::NetLog::EventPhase phase, |
53 net::NetLog::EventParameters* params); | 56 net::NetLog::EventParameters* params); |
54 | 57 |
55 static void PopulateTimingInfo(URLRequest* request, | 58 static void PopulateTimingInfo(URLRequest* request, |
56 ResourceResponse* response); | 59 ResourceResponse* response); |
57 | 60 |
58 private: | 61 private: |
(...skipping 29 matching lines...) Expand all Loading... |
88 URLRequestToRecordMap url_request_to_record_; | 91 URLRequestToRecordMap url_request_to_record_; |
89 ConnectJobToRecordMap connect_job_to_record_; | 92 ConnectJobToRecordMap connect_job_to_record_; |
90 SocketToRecordMap socket_to_record_; | 93 SocketToRecordMap socket_to_record_; |
91 uint32 last_connect_job_id_; | 94 uint32 last_connect_job_id_; |
92 ConnectJobRecord last_connect_job_record_; | 95 ConnectJobRecord last_connect_job_record_; |
93 | 96 |
94 DISALLOW_COPY_AND_ASSIGN(LoadTimingObserver); | 97 DISALLOW_COPY_AND_ASSIGN(LoadTimingObserver); |
95 }; | 98 }; |
96 | 99 |
97 #endif // CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ | 100 #endif // CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ |
OLD | NEW |