Chromium Code Reviews| 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_CACHE_STATS_H_ | |
| 6 #define CHROME_BROWSER_NET_CACHE_STATS_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/hash_tables.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/message_loop.h" | |
| 16 #include "base/time.h" | |
| 17 #include "content/public/browser/web_contents_observer.h" | |
| 18 #include "net/base/network_delegate.h" | |
| 19 | |
| 20 class TabContents; | |
| 21 | |
| 22 namespace base { | |
| 23 class Histogram; | |
| 24 } | |
| 25 | |
| 26 namespace net { | |
| 27 class URLRequest; | |
| 28 class URLRequestContext; | |
| 29 } | |
| 30 | |
| 31 #if defined(COMPILER_GCC) | |
| 32 | |
| 33 namespace BASE_HASH_NAMESPACE { | |
| 34 template <> | |
| 35 struct hash<const net::URLRequestContext*> { | |
| 36 std::size_t operator()(const net::URLRequestContext* value) const { | |
| 37 return reinterpret_cast<std::size_t>(value); | |
| 38 } | |
| 39 }; | |
| 40 } | |
| 41 | |
| 42 #endif | |
| 43 | |
| 44 namespace chrome_browser_net { | |
| 45 | |
| 46 // This class collects UMA stats about cache performance. It is a singleton | |
|
rvargas (doing something else)
2012/07/26 02:13:43
nit: outdated comment.
tburkard
2012/07/26 02:50:54
Done.
| |
| 47 // and lives on the IO thread. | |
| 48 class CacheStats { | |
|
rvargas (doing something else)
2012/07/26 02:13:43
I'm afraid the class name (and file name) will be
tburkard
2012/07/26 02:50:54
yes
On 2012/07/26 02:13:43, rvargas wrote:
| |
| 49 public: | |
| 50 enum TabEvent { | |
| 51 SPINNER_START, | |
| 52 SPINNER_STOP | |
| 53 }; | |
| 54 void OnCacheWaitStateChange(const net::URLRequest& request, | |
| 55 net::NetworkDelegate::CacheWaitState state); | |
| 56 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event); | |
| 57 void RegisterMainURLRequestContext(const net::URLRequestContext* context); | |
| 58 void UnregisterMainURLRequestContext(const net::URLRequestContext* context); | |
| 59 CacheStats(); | |
| 60 virtual ~CacheStats(); | |
| 61 | |
| 62 private: | |
| 63 struct TabLoadStats; | |
| 64 typedef std::map<std::pair<int, int>, TabLoadStats*> TabLoadStatsMap; | |
|
rvargas (doing something else)
2012/07/26 02:13:43
This map deserves a comment.
tburkard
2012/07/26 02:50:54
Done.
| |
| 65 | |
| 66 // Gets TabLoadStats for a given render view. | |
| 67 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id); | |
| 68 // Deletes TabLoadStats no longer needed for a render view. | |
| 69 void RemoveTabLoadStats(std::pair<int, int> render_view_id); | |
| 70 // Sets a timer for a given tab to collect stats. timer_index indicates | |
| 71 // how many times stats have been collected since the navigation has started | |
| 72 // for this tab. | |
| 73 void ScheduleTimer(TabLoadStats* stats, int timer_index); | |
| 74 // The callback when a timer fires to collect stats again. | |
| 75 void TimerCb(TabLoadStats* stats, int timer_index); | |
| 76 // Helper function to put the current set of cache statistics into an UMA | |
| 77 // histogram. | |
| 78 void RecordCacheFractionHistogram(base::TimeDelta elapsed, | |
| 79 base::TimeDelta cache_time, | |
| 80 bool is_load_done); | |
| 81 | |
| 82 TabLoadStatsMap tab_load_stats_; | |
| 83 std::vector<base::Histogram*> final_histograms_; | |
| 84 std::vector<base::Histogram*> intermediate_histograms_; | |
| 85 base::hash_set<const net::URLRequestContext*> main_request_contexts_; | |
| 86 }; | |
| 87 | |
| 88 // A WebContentsObserver watching all tabs, notifying CacheStats | |
| 89 // whenever the spinner starts or stops for a given tab, and when a renderer | |
| 90 // is no longer used. | |
| 91 class CacheStatsTabHelper : public content::WebContentsObserver { | |
| 92 public: | |
| 93 explicit CacheStatsTabHelper(TabContents* tab); | |
| 94 virtual ~CacheStatsTabHelper(); | |
| 95 virtual void DidStartProvisionalLoadForFrame( | |
| 96 int64 frame_id, | |
| 97 bool is_main_frame, | |
| 98 const GURL& validated_url, | |
| 99 bool is_error_page, | |
| 100 content::RenderViewHost* render_view_host) OVERRIDE; | |
| 101 virtual void DidStopLoading(content::RenderViewHost* render_view_host) | |
| 102 OVERRIDE; | |
|
rvargas (doing something else)
2012/07/26 02:13:43
nit: I believe this cannot be in a line by itself.
tburkard
2012/07/26 02:50:54
Done.
| |
| 103 | |
| 104 private: | |
| 105 // Calls into CacheStats to notify that a reportable event has occurred | |
| 106 // for the tab being observed. | |
| 107 void NotifyCacheStats(CacheStats::TabEvent event, | |
| 108 content::RenderViewHost* render_view_host); | |
| 109 | |
| 110 CacheStats* cache_stats_; | |
| 111 bool is_profile_otr_; | |
|
rvargas (doing something else)
2012/07/26 02:13:43
nit: is_otr_profile_
tburkard
2012/07/26 02:50:54
Done.
| |
| 112 }; | |
| 113 | |
| 114 } // namespace chrome_browser_net | |
| 115 | |
| 116 #endif // CHROME_BROWSER_NET_CACHE_STATS_H_ | |
| OLD | NEW |