| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_TIME_STATS_H_ | 5 #ifndef CHROME_BROWSER_NET_LOAD_TIME_STATS_H_ |
| 6 #define CHROME_BROWSER_NET_LOAD_TIME_STATS_H_ | 6 #define CHROME_BROWSER_NET_LOAD_TIME_STATS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 namespace net { | 27 namespace net { |
| 28 class URLRequest; | 28 class URLRequest; |
| 29 class URLRequestContext; | 29 class URLRequestContext; |
| 30 } | 30 } |
| 31 | 31 |
| 32 #if defined(COMPILER_GCC) | 32 #if defined(COMPILER_GCC) |
| 33 | 33 |
| 34 namespace BASE_HASH_NAMESPACE { | 34 namespace BASE_HASH_NAMESPACE { |
| 35 template <> | 35 template <> |
| 36 struct hash<const net::URLRequest*> { |
| 37 std::size_t operator()(const net::URLRequest* value) const { |
| 38 return reinterpret_cast<std::size_t>(value); |
| 39 } |
| 40 }; |
| 41 template <> |
| 36 struct hash<const net::URLRequestContext*> { | 42 struct hash<const net::URLRequestContext*> { |
| 37 std::size_t operator()(const net::URLRequestContext* value) const { | 43 std::size_t operator()(const net::URLRequestContext* value) const { |
| 38 return reinterpret_cast<std::size_t>(value); | 44 return reinterpret_cast<std::size_t>(value); |
| 39 } | 45 } |
| 40 }; | 46 }; |
| 41 } | 47 } |
| 42 | 48 |
| 43 #endif | 49 #endif |
| 44 | 50 |
| 45 namespace chrome_browser_net { | 51 namespace chrome_browser_net { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 HISTOGRAM_INTERMEDIATE_AGGREGATE, | 70 HISTOGRAM_INTERMEDIATE_AGGREGATE, |
| 65 HISTOGRAM_INTERMEDIATE_CUMULATIVE_PERCENTAGE, | 71 HISTOGRAM_INTERMEDIATE_CUMULATIVE_PERCENTAGE, |
| 66 HISTOGRAM_MAX | 72 HISTOGRAM_MAX |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 LoadTimeStats(); | 75 LoadTimeStats(); |
| 70 ~LoadTimeStats(); | 76 ~LoadTimeStats(); |
| 71 | 77 |
| 72 void OnRequestWaitStateChange(const net::URLRequest& request, | 78 void OnRequestWaitStateChange(const net::URLRequest& request, |
| 73 net::NetworkDelegate::RequestWaitState state); | 79 net::NetworkDelegate::RequestWaitState state); |
| 80 void OnURLRequestDestroyed(const net::URLRequest& request); |
| 74 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event); | 81 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event); |
| 75 void RegisterURLRequestContext(const net::URLRequestContext* context, | 82 void RegisterURLRequestContext(const net::URLRequestContext* context, |
| 76 ChromeURLRequestContext::ContextType type); | 83 ChromeURLRequestContext::ContextType type); |
| 77 void UnregisterURLRequestContext(const net::URLRequestContext* context); | 84 void UnregisterURLRequestContext(const net::URLRequestContext* context); |
| 78 | 85 |
| 79 private: | 86 private: |
| 80 class TabLoadStats; | 87 class TabLoadStats; |
| 81 // A map mapping a renderer's process id and route id to a TabLoadStats, | 88 // A map mapping a renderer's process id and route id to a TabLoadStats, |
| 82 // representing that renderer's load statistics. | 89 // representing that renderer's load statistics. |
| 83 typedef std::map<std::pair<int, int>, TabLoadStats*> TabLoadStatsMap; | 90 typedef std::map<std::pair<int, int>, TabLoadStats*> TabLoadStatsMap; |
| 84 | 91 |
| 92 class URLRequestStats; |
| 93 typedef base::hash_map<const net::URLRequest*, |
| 94 URLRequestStats*> RequestStatsMap; |
| 95 |
| 96 // Gets RequestStats for a given request. |
| 97 URLRequestStats* GetRequestStats(const net::URLRequest* request); |
| 85 // Gets TabLoadStats for a given RenderView. | 98 // Gets TabLoadStats for a given RenderView. |
| 86 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id); | 99 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id); |
| 87 // Deletes TabLoadStats no longer needed for a render view. | 100 // Deletes TabLoadStats no longer needed for a render view. |
| 88 void RemoveTabLoadStats(std::pair<int, int> render_view_id); | 101 void RemoveTabLoadStats(std::pair<int, int> render_view_id); |
| 89 // Sets a timer for a given tab to collect stats. |timer_index| indicates | 102 // Sets a timer for a given tab to collect stats. |timer_index| indicates |
| 90 // how many times stats have been collected since the navigation has started | 103 // how many times stats have been collected since the navigation has started |
| 91 // for this tab. | 104 // for this tab. |
| 92 void ScheduleTimer(TabLoadStats* stats); | 105 void ScheduleTimer(TabLoadStats* stats); |
| 93 // The callback when a timer fires to collect stats again. | 106 // The callback when a timer fires to collect stats again. |
| 94 void TimerCallback(TabLoadStats* stats); | 107 void TimerCallback(TabLoadStats* stats); |
| 95 // Helper function to put the current set of statistics into UMA histograms. | 108 // Helper function to put the current set of statistics into UMA histograms. |
| 96 void RecordHistograms(base::TimeDelta elapsed, | 109 void RecordHistograms(base::TimeDelta elapsed, |
| 97 TabLoadStats* stats, | 110 TabLoadStats* stats, |
| 98 bool is_load_done); | 111 bool is_load_done); |
| 99 | 112 |
| 100 TabLoadStatsMap tab_load_stats_; | 113 TabLoadStatsMap tab_load_stats_; |
| 114 RequestStatsMap request_stats_; |
| 101 std::vector<base::Histogram*> histograms_[REQUEST_STATUS_MAX][HISTOGRAM_MAX]; | 115 std::vector<base::Histogram*> histograms_[REQUEST_STATUS_MAX][HISTOGRAM_MAX]; |
| 102 base::hash_set<const net::URLRequestContext*> main_request_contexts_; | 116 base::hash_set<const net::URLRequestContext*> main_request_contexts_; |
| 103 | 117 |
| 104 DISALLOW_COPY_AND_ASSIGN(LoadTimeStats); | 118 DISALLOW_COPY_AND_ASSIGN(LoadTimeStats); |
| 105 }; | 119 }; |
| 106 | 120 |
| 107 // A WebContentsObserver watching all tabs, notifying LoadTimeStats | 121 // A WebContentsObserver watching all tabs, notifying LoadTimeStats |
| 108 // whenever the spinner starts or stops for a given tab, and when a renderer | 122 // whenever the spinner starts or stops for a given tab, and when a renderer |
| 109 // is no longer used. | 123 // is no longer used. |
| 110 class LoadTimeStatsTabHelper : public content::WebContentsObserver { | 124 class LoadTimeStatsTabHelper : public content::WebContentsObserver { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 content::RenderViewHost* render_view_host); | 143 content::RenderViewHost* render_view_host); |
| 130 | 144 |
| 131 bool is_otr_profile_; | 145 bool is_otr_profile_; |
| 132 | 146 |
| 133 DISALLOW_COPY_AND_ASSIGN(LoadTimeStatsTabHelper); | 147 DISALLOW_COPY_AND_ASSIGN(LoadTimeStatsTabHelper); |
| 134 }; | 148 }; |
| 135 | 149 |
| 136 } // namespace chrome_browser_net | 150 } // namespace chrome_browser_net |
| 137 | 151 |
| 138 #endif // CHROME_BROWSER_NET_LOAD_TIME_STATS_H_ | 152 #endif // CHROME_BROWSER_NET_LOAD_TIME_STATS_H_ |
| OLD | NEW |