NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_tracker.h
blobf9dd17beebae0d30ffe48934544a7b3a32fd4b12
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_
8 #include <map>
9 #include <utility>
11 #include "base/memory/weak_ptr.h"
12 #include "url/gurl.h"
14 namespace prerender {
16 class PrerenderPendingSwapThrottle;
18 // Global object for maintaining prerender state on the IO thread.
19 class PrerenderTracker {
20 public:
21 typedef std::pair<int, int> ChildRouteIdPair;
23 PrerenderTracker();
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,
29 int render_frame_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,
34 // respectively.
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,
42 const GURL& url);
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);
49 private:
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();
60 GURL url;
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
66 // of a RenderFrame.
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_