[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_tracker.h
blob6020658f0fae0be17bcd9ab35d07f98d13a79a3c
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 <set>
10 #include <utility>
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "chrome/browser/prerender/prerender_cookie_store.h"
17 #include "content/public/browser/render_process_host_observer.h"
18 #include "url/gurl.h"
20 namespace net {
21 class URLRequestContextGetter;
24 namespace prerender {
26 class PrerenderPendingSwapThrottle;
28 // Global object for maintaining various prerender state on the IO thread.
29 class PrerenderTracker {
30 public:
31 typedef std::pair<int, int> ChildRouteIdPair;
33 PrerenderTracker();
34 virtual ~PrerenderTracker();
36 // Returns whether or not a RenderFrame and URL are regarding a pending
37 // prerender swap. Can only be called on the IO thread.
38 bool IsPendingSwapRequestOnIOThread(int render_process_id,
39 int render_frame_id,
40 const GURL& url) const;
42 // Called when a PrerenderPendingSwapThrottle defers a request. Cancel or
43 // Resume will be called on |throttle| when the prerender is canceled or used,
44 // respectively.
45 void AddPendingSwapThrottleOnIOThread(
46 int render_process_id, int render_frame_id, const GURL& url,
47 const base::WeakPtr<PrerenderPendingSwapThrottle>& throttle);
49 // Called to add throttles for a pending prerender swap.
50 void AddPrerenderPendingSwap(
51 const ChildRouteIdPair& render_frame_route_id_pair,
52 const GURL& url);
54 // Called to remove the throttles for a pending prerender swap.
55 void RemovePrerenderPendingSwap(
56 const ChildRouteIdPair& render_frame_route_id_pair,
57 bool swap_successful);
59 // Gets the Prerender Cookie Store for a specific render process, if it
60 // is a prerender. Only to be called from the IO thread.
61 scoped_refptr<PrerenderCookieStore> GetPrerenderCookieStoreForRenderProcess(
62 int process_id);
64 // Called when a given render process has changed a cookie for |url|,
65 // in |cookie_monster|.
66 // Only to be called from the IO thread.
67 void OnCookieChangedForURL(int process_id,
68 net::CookieMonster* cookie_monster,
69 const GURL& url);
71 void AddPrerenderCookieStoreOnIOThread(
72 int process_id,
73 scoped_refptr<net::URLRequestContextGetter> request_context,
74 const base::Closure& cookie_conflict_cb);
76 void RemovePrerenderCookieStoreOnIOThread(int process_id, bool was_swapped);
78 private:
79 // Add/remove prerenders pending swap on the IO Thread.
80 void AddPrerenderPendingSwapOnIOThread(
81 const ChildRouteIdPair& render_frame_route_id_pair, const GURL& url);
82 void RemovePrerenderPendingSwapOnIOThread(
83 const ChildRouteIdPair& render_frame_route_id_pair,
84 bool swap_successful);
86 struct PendingSwapThrottleData {
87 explicit PendingSwapThrottleData(const GURL& swap_url);
88 ~PendingSwapThrottleData();
89 GURL url;
90 base::WeakPtr<PrerenderPendingSwapThrottle> throttle;
93 // Map of pending prerender swaps and their associated throttles,
94 // maintained on the IO thread. The key is the routing ID pair
95 // of a RenderFrame.
96 typedef std::map<ChildRouteIdPair, PendingSwapThrottleData>
97 PendingSwapThrottleMap;
98 PendingSwapThrottleMap pending_swap_throttle_map_;
100 // Map of prerendering render process ids to PrerenderCookieStore used for
101 // the prerender. Only to be used on the IO thread.
102 typedef base::hash_map<int, scoped_refptr<PrerenderCookieStore> >
103 PrerenderCookieStoreMap;
104 PrerenderCookieStoreMap prerender_cookie_store_map_;
106 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker);
109 } // namespace prerender
111 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_