| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ | |
| 6 #define CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ | |
| 7 | |
| 8 #include "base/gtest_prod_util.h" | |
| 9 #include "base/hash_tables.h" | |
| 10 #include "base/time.h" | |
| 11 #include "net/base/net_log.h" | |
| 12 #include "webkit/glue/resource_loader_bridge.h" | |
| 13 | |
| 14 namespace content { | |
| 15 struct ResourceResponse; | |
| 16 } | |
| 17 | |
| 18 namespace net { | |
| 19 class URLRequest; | |
| 20 } // namespace net | |
| 21 | |
| 22 // LoadTimingObserver watches the NetLog event stream and collects the network | |
| 23 // timing information. | |
| 24 // | |
| 25 // LoadTimingObserver lives completely on the IOThread and ignores events from | |
| 26 // other threads. It is not safe to use from other threads. | |
| 27 class LoadTimingObserver : public net::NetLog::ThreadSafeObserver { | |
| 28 public: | |
| 29 struct URLRequestRecord { | |
| 30 URLRequestRecord(); | |
| 31 | |
| 32 #if !defined(OS_IOS) | |
| 33 webkit_glue::ResourceLoadTimingInfo timing; | |
| 34 #endif | |
| 35 uint32 connect_job_id; | |
| 36 uint32 socket_log_id; | |
| 37 bool socket_reused; | |
| 38 base::TimeTicks base_ticks; | |
| 39 }; | |
| 40 | |
| 41 struct HTTPStreamJobRecord { | |
| 42 HTTPStreamJobRecord(); | |
| 43 | |
| 44 uint32 socket_log_id; | |
| 45 bool socket_reused; | |
| 46 base::TimeTicks connect_start; | |
| 47 base::TimeTicks connect_end; | |
| 48 base::TimeTicks dns_start; | |
| 49 base::TimeTicks dns_end; | |
| 50 base::TimeTicks ssl_start; | |
| 51 base::TimeTicks ssl_end; | |
| 52 }; | |
| 53 | |
| 54 struct ConnectJobRecord { | |
| 55 base::TimeTicks dns_start; | |
| 56 base::TimeTicks dns_end; | |
| 57 }; | |
| 58 | |
| 59 struct SocketRecord { | |
| 60 base::TimeTicks ssl_start; | |
| 61 base::TimeTicks ssl_end; | |
| 62 }; | |
| 63 | |
| 64 LoadTimingObserver(); | |
| 65 virtual ~LoadTimingObserver(); | |
| 66 | |
| 67 // Starts observing specified NetLog. Must not already be watching a NetLog. | |
| 68 // Separate from constructor to enforce thread safety. | |
| 69 void StartObserving(net::NetLog* net_log); | |
| 70 | |
| 71 URLRequestRecord* GetURLRequestRecord(uint32 source_id); | |
| 72 | |
| 73 // net::NetLog::ThreadSafeObserver implementation: | |
| 74 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | |
| 75 | |
| 76 static void PopulateTimingInfo(net::URLRequest* request, | |
| 77 content::ResourceResponse* response); | |
| 78 | |
| 79 private: | |
| 80 FRIEND_TEST_ALL_PREFIXES(LoadTimingObserverTest, | |
| 81 HTTPStreamJobRecord); | |
| 82 FRIEND_TEST_ALL_PREFIXES(LoadTimingObserverTest, | |
| 83 ConnectJobRecord); | |
| 84 FRIEND_TEST_ALL_PREFIXES(LoadTimingObserverTest, | |
| 85 SocketRecord); | |
| 86 | |
| 87 void OnAddURLRequestEntry(const net::NetLog::Entry& entry); | |
| 88 void OnAddHTTPStreamJobEntry(const net::NetLog::Entry& entry); | |
| 89 void OnAddConnectJobEntry(const net::NetLog::Entry& entry); | |
| 90 void OnAddSocketEntry(const net::NetLog::Entry& entry); | |
| 91 | |
| 92 URLRequestRecord* CreateURLRequestRecord(uint32 source_id); | |
| 93 void DeleteURLRequestRecord(uint32 source_id); | |
| 94 | |
| 95 // Returns current time. Virtual for unit tests. | |
| 96 virtual base::TimeTicks GetCurrentTime() const; | |
| 97 | |
| 98 typedef base::hash_map<uint32, URLRequestRecord> URLRequestToRecordMap; | |
| 99 typedef base::hash_map<uint32, HTTPStreamJobRecord> HTTPStreamJobToRecordMap; | |
| 100 typedef base::hash_map<uint32, ConnectJobRecord> ConnectJobToRecordMap; | |
| 101 typedef base::hash_map<uint32, SocketRecord> SocketToRecordMap; | |
| 102 URLRequestToRecordMap url_request_to_record_; | |
| 103 HTTPStreamJobToRecordMap http_stream_job_to_record_; | |
| 104 ConnectJobToRecordMap connect_job_to_record_; | |
| 105 SocketToRecordMap socket_to_record_; | |
| 106 uint32 last_connect_job_id_; | |
| 107 ConnectJobRecord last_connect_job_record_; | |
| 108 | |
| 109 DISALLOW_COPY_AND_ASSIGN(LoadTimingObserver); | |
| 110 }; | |
| 111 | |
| 112 #endif // CHROME_BROWSER_NET_LOAD_TIMING_OBSERVER_H_ | |
| OLD | NEW |