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_TRACKER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
11 #include "base/memory/weak_ptr.h"
16 class PrerenderPendingSwapThrottle
;
18 // Global object for maintaining prerender state on the IO thread.
19 class PrerenderTracker
{
21 typedef std::pair
<int, int> ChildRouteIdPair
;
24 virtual ~PrerenderTracker();
26 // Returns whether or not a RenderFrame and URL are regarding a pending
27 // prerender swap. Can only be called on the IO thread.
28 bool IsPendingSwapRequestOnIOThread(int render_process_id
,
30 const GURL
& url
) const;
32 // Called when a PrerenderPendingSwapThrottle defers a request. Cancel or
33 // Resume will be called on |throttle| when the prerender is canceled or used,
35 void AddPendingSwapThrottleOnIOThread(
36 int render_process_id
, int render_frame_id
, const GURL
& url
,
37 const base::WeakPtr
<PrerenderPendingSwapThrottle
>& throttle
);
39 // Called to add throttles for a pending prerender swap.
40 void AddPrerenderPendingSwap(
41 const ChildRouteIdPair
& render_frame_route_id_pair
,
44 // Called to remove the throttles for a pending prerender swap.
45 void RemovePrerenderPendingSwap(
46 const ChildRouteIdPair
& render_frame_route_id_pair
,
47 bool swap_successful
);
50 // Add/remove prerenders pending swap on the IO Thread.
51 void AddPrerenderPendingSwapOnIOThread(
52 const ChildRouteIdPair
& render_frame_route_id_pair
, const GURL
& url
);
53 void RemovePrerenderPendingSwapOnIOThread(
54 const ChildRouteIdPair
& render_frame_route_id_pair
,
55 bool swap_successful
);
57 struct PendingSwapThrottleData
{
58 explicit PendingSwapThrottleData(const GURL
& swap_url
);
59 ~PendingSwapThrottleData();
61 base::WeakPtr
<PrerenderPendingSwapThrottle
> throttle
;
64 // Map of pending prerender swaps and their associated throttles,
65 // maintained on the IO thread. The key is the routing ID pair
67 typedef std::map
<ChildRouteIdPair
, PendingSwapThrottleData
>
68 PendingSwapThrottleMap
;
69 PendingSwapThrottleMap pending_swap_throttle_map_
;
71 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker
);
74 } // namespace prerender
76 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_