Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_tab_helper.h
blob4fb6013878d82a2d69fe116af9895093f27f0ea5
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.
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h"
11 #include "chrome/browser/prerender/prerender_histograms.h"
12 #include "chrome/browser/prerender/prerender_origin.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_user_data.h"
15 #include "url/gurl.h"
17 namespace autofill {
18 struct PasswordForm;
21 namespace password_manager {
22 class PasswordManager;
25 namespace prerender {
27 class PrerenderManager;
29 // PrerenderTabHelper is responsible for recording perceived pageload times
30 // to compare PLT's with prerendering enabled and disabled.
31 class PrerenderTabHelper
32 : public content::WebContentsObserver,
33 public content::WebContentsUserData<PrerenderTabHelper> {
34 public:
35 enum Event {
36 EVENT_LOGGED_IN_TABLE_REQUESTED = 0,
37 EVENT_LOGGED_IN_TABLE_PRESENT = 1,
38 EVENT_MAINFRAME_CHANGE = 2,
39 EVENT_MAINFRAME_CHANGE_DOMAIN_LOGGED_IN = 3,
40 EVENT_MAINFRAME_COMMIT = 4,
41 EVENT_MAINFRAME_COMMIT_DOMAIN_LOGGED_IN = 5,
42 EVENT_LOGIN_ACTION_ADDED = 6,
43 EVENT_LOGIN_ACTION_ADDED_PW_EMPTY = 7,
44 EVENT_MAX_VALUE
47 static void CreateForWebContentsWithPasswordManager(
48 content::WebContents* web_contents,
49 password_manager::PasswordManager* password_manager);
51 virtual ~PrerenderTabHelper();
53 // content::WebContentsObserver implementation.
54 virtual void ProvisionalChangeToMainFrameUrl(
55 const GURL& url,
56 content::RenderFrameHost* render_frame_host) OVERRIDE;
57 virtual void DidStopLoading(
58 content::RenderViewHost* render_view_host) OVERRIDE;
59 virtual void DidStartProvisionalLoadForFrame(
60 int64 frame_id,
61 int64 parent_frame_id,
62 bool is_main_frame,
63 const GURL& validated_url,
64 bool is_error_page,
65 bool is_iframe_srcdoc,
66 content::RenderViewHost* render_view_host) OVERRIDE;
67 virtual void DidCommitProvisionalLoadForFrame(
68 int64 frame_id,
69 const base::string16& frame_unique_name,
70 bool is_main_frame,
71 const GURL& validated_url,
72 content::PageTransition transition_type,
73 content::RenderViewHost* render_view_host) OVERRIDE;
75 // Called when a password form has been submitted.
76 void PasswordSubmitted(const autofill::PasswordForm& form);
78 // Called when this prerendered WebContents has just been swapped in.
79 void PrerenderSwappedIn();
81 // Called when a control prerender is resolved. Applies to the next load.
82 void WouldHavePrerenderedNextLoad(Origin origin);
84 private:
85 PrerenderTabHelper(content::WebContents* web_contents,
86 password_manager::PasswordManager* password_manager);
87 friend class content::WebContentsUserData<PrerenderTabHelper>;
89 void RecordEvent(Event event) const;
90 void RecordEventIfLoggedInURL(Event event, const GURL& url);
91 void RecordEventIfLoggedInURLResult(Event event, scoped_ptr<bool> is_present,
92 scoped_ptr<bool> lookup_succeeded);
94 void RecordPerceivedPageLoadTime(
95 base::TimeDelta perceived_page_load_time,
96 double fraction_plt_elapsed_at_swap_in);
98 // Retrieves the PrerenderManager, or NULL, if none was found.
99 PrerenderManager* MaybeGetPrerenderManager() const;
101 // Returns whether the WebContents being observed is currently prerendering.
102 bool IsPrerendering();
104 // The type the current pending navigation, if there is one. If the tab is a
105 // prerender before swap, the value is always NAVIGATION_TYPE_PRERENDERED,
106 // even if the prerender is not currently loading.
107 NavigationType navigation_type_;
109 // If |navigation_type_| is not NAVIGATION_TYPE_NORMAL, the origin of the
110 // relevant prerender. Otherwise, ORIGIN_NONE.
111 Origin origin_;
113 // True if the next load will be associated with a control prerender. This
114 // extra state is needed because control prerenders are resolved before the
115 // actual load begins. |next_load_origin_| gives the origin of the control
116 // prerender.
117 bool next_load_is_control_prerender_;
118 Origin next_load_origin_;
120 // System time at which the current load was started for the purpose of
121 // the perceived page load time (PPLT). If null, there is no current
122 // load.
123 base::TimeTicks pplt_load_start_;
125 // System time at which the actual pageload started (pre-swapin), if
126 // a applicable (in cases when a prerender that was still loading was
127 // swapped in).
128 base::TimeTicks actual_load_start_;
130 // Current URL being loaded.
131 GURL url_;
133 base::WeakPtrFactory<PrerenderTabHelper> weak_factory_;
135 DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper);
138 } // namespace prerender
140 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_