Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/net/cache_stats.h

Issue 10736066: Adding histograms showing fraction of page load times (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/memory/singleton.h"
16 #include "base/message_loop.h"
17 #include "base/time.h"
18 #include "content/public/browser/render_view_host_observer.h"
19 #include "net/base/network_delegate.h"
20
21 class TabContents;
22
23 namespace base {
24 class Histogram;
25 }
26
27 namespace net {
28 class URLRequest;
29 }
30
31 namespace chrome_browser_net {
32
33 // This class collects UMA stats about cache performance. It is a singleton
34 // and lives on the IO thread.
35
rvargas (doing something else) 2012/07/23 22:22:36 nit: remove line
tburkard 2012/07/24 01:03:12 Done.
36 class CacheStats : public MessageLoop::DestructionObserver {
37 public:
38 enum TabEvent {
39 SPINNER_START,
40 SPINNER_STOP,
41 RENDERER_DESTROY
42 };
43 static CacheStats* GetInstance();
44 void OnCacheWaitStateChange(const net::URLRequest& request,
45 net::NetworkDelegate::CacheWaitState state);
46 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event);
47 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
48 virtual ~CacheStats();
49
50 private:
51 friend struct DefaultSingletonTraits<CacheStats>;
52 struct TabLoadStats;
53 typedef std::map< std::pair<int, int>, TabLoadStats*> TabLoadStatsMap;
rvargas (doing something else) 2012/07/23 22:22:36 nit: remove extra space before std
tburkard 2012/07/24 01:03:12 Done.
54
55 CacheStats();
56 // Gets TabLoadStats for a given render view.
57 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id);
58 // Deletes TabLoadStats no longer needed for a render view.
59 void RemoveTabLoadStats(std::pair<int, int> render_view_id);
60 // Sets a timer for a given tab to collect stats. timer_index indicates
61 // how many times stats have been collected since the navigation has started
62 // for this tab.
63 void ScheduleTimer(TabLoadStats* stats, int timer_index);
64 // The callback when a timer fires to collect stats again.
65 void TimerCb(TabLoadStats* stats, int timer_index);
66 // Helper function to put the current set of cache statistics into an UMA
67 // histogram.
68 void RecordCacheFractionHistogram(base::TimeDelta elapsed,
69 base::TimeDelta cache_time,
70 bool is_load_done);
71
72 TabLoadStatsMap tab_load_stats_;
73 std::vector<base::Histogram*> final_histograms_;
74 std::vector<base::Histogram*> intermediate_histograms_;
75 bool registered_message_loop_destruction_observer_;
76 };
77
78 // Helper class observing all RenderViewHosts, notifying CacheStats
79 // whenever the spinner starts or stops for a given tab, and when a renderer
80 // is no longer used.
81
rvargas (doing something else) 2012/07/23 22:22:36 nit: remove line
tburkard 2012/07/24 01:03:12 Done.
82 class CacheStatsRenderViewHostObserver
83 : public content::RenderViewHostObserver {
84 public:
85 explicit CacheStatsRenderViewHostObserver(content::RenderViewHost* host);
86
87 protected:
88 virtual ~CacheStatsRenderViewHostObserver();
89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
90
91 private:
92 // Calls into CacheStats to notify that a reportable event has occurred
93 // for the tab being observed.
94 void NotifyCacheStats(CacheStats::TabEvent event);
95 void OnDidStartProvisionalLoadForFrame(
96 int64 frame_id,
97 bool is_main_frame,
98 const GURL& opener_url,
99 const GURL& url);
100 void OnDidStopLoading();
101
102 CacheStats* cache_stats_;
103 std::pair<int, int> render_view_id_;
104 bool is_loading_;
105 };
106
107 } // namespace chrome_browser_net
108
109 #endif // CHROME_BROWSER_NET_CACHE_STATS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698