summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prerender/prerender_tab_helper.h
blob: 16318308814e80bae61757da4827e6fe377e97d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_
#define CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_

#include "base/time.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/web_contents_observer.h"
#include "googleurl/src/gurl.h"

class TabContentsWrapper;

namespace prerender {

class PrerenderManager;

// PrerenderTabHelper is responsible for recording perceived pageload times
// to compare PLT's with prerendering enabled and disabled.
class PrerenderTabHelper : public content::WebContentsObserver {
 public:
  explicit PrerenderTabHelper(TabContentsWrapper* tab);
  virtual ~PrerenderTabHelper();

  // content::WebContentsObserver implementation.
  virtual void ProvisionalChangeToMainFrameUrl(
      const GURL& url,
      const GURL& opener_url) OVERRIDE;
  virtual void DidStopLoading() OVERRIDE;
  virtual void DidStartProvisionalLoadForFrame(
      int64 frame_id,
      bool is_main_frame,
      const GURL& validated_url,
      bool is_error_page,
      content::RenderViewHost* render_view_host) OVERRIDE;

  // Called when this prerendered TabContents has just been swapped in.
  void PrerenderSwappedIn();

  void UpdateTargetURL(int32 page_id, const GURL& url);

 private:
  // The data we store for a hover (time the hover occurred & URL).
  class HoverData;

  // Retrieves the PrerenderManager, or NULL, if none was found.
  PrerenderManager* MaybeGetPrerenderManager() const;

  // Returns whether the TabContents being observed is currently prerendering.
  bool IsPrerendering();

  // Records histogram information for the current hover, based on whether
  // it was used or not.  Will not do anything if there is no current hover.
  // Also resets the hover to no hover.
  void MaybeLogCurrentHover(bool was_used);

  bool IsTopSite(const GURL& url);

  // TabContentsWrapper we're created for.
  TabContentsWrapper* tab_;

  // System time at which the current load was started for the purpose of
  // the perceived page load time (PPLT).
  base::TimeTicks pplt_load_start_;

  // System time at which the actual pageload started (pre-swapin), if
  // a applicable (in cases when a prerender that was still loading was
  // swapped in).
  base::TimeTicks actual_load_start_;

  // Information about the last hover for each hover threshold.
  scoped_array<HoverData> last_hovers_;

  // Information about the current hover independent of thresholds.
  GURL current_hover_url_;
  base::TimeTicks current_hover_time_;

  // Current URL being loaded.
  GURL url_;

  DISALLOW_COPY_AND_ASSIGN(PrerenderTabHelper);
};

}  // namespace prerender

#endif  // CHROME_BROWSER_PRERENDER_PRERENDER_TAB_HELPER_H_