Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: chrome/browser/prerender/prerender_tracker.h

Issue 233353003: Only commit cookie changes in prerenders after a prerender is shown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add browser tests, fix a bug in what was changed yesterday. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set>
9 #include <utility> 10 #include <utility>
10 11
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.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"
12 #include "url/gurl.h" 18 #include "url/gurl.h"
13 19
20 namespace net {
21 class URLRequestContextGetter;
22 }
23
14 namespace prerender { 24 namespace prerender {
15 25
16 class PrerenderPendingSwapThrottle; 26 class PrerenderPendingSwapThrottle;
17 27
18 // Global object for maintaining prerender state on the IO thread. 28 // Global object for maintaining prerender state on the IO thread.
19 class PrerenderTracker { 29 class PrerenderTracker : public content::RenderProcessHostObserver {
20 public: 30 public:
21 typedef std::pair<int, int> ChildRouteIdPair; 31 typedef std::pair<int, int> ChildRouteIdPair;
22 32
23 PrerenderTracker(); 33 PrerenderTracker();
24 virtual ~PrerenderTracker(); 34 virtual ~PrerenderTracker();
25 35
26 // Returns whether or not a RenderFrame and URL are regarding a pending 36 // Returns whether or not a RenderFrame and URL are regarding a pending
27 // prerender swap. Can only be called on the IO thread. 37 // prerender swap. Can only be called on the IO thread.
28 bool IsPendingSwapRequestOnIOThread(int render_process_id, 38 bool IsPendingSwapRequestOnIOThread(int render_process_id,
29 int render_frame_id, 39 int render_frame_id,
30 const GURL& url) const; 40 const GURL& url) const;
31 41
32 // Called when a PrerenderPendingSwapThrottle defers a request. Cancel or 42 // Called when a PrerenderPendingSwapThrottle defers a request. Cancel or
33 // Resume will be called on |throttle| when the prerender is canceled or used, 43 // Resume will be called on |throttle| when the prerender is canceled or used,
34 // respectively. 44 // respectively.
35 void AddPendingSwapThrottleOnIOThread( 45 void AddPendingSwapThrottleOnIOThread(
36 int render_process_id, int render_frame_id, const GURL& url, 46 int render_process_id, int render_frame_id, const GURL& url,
37 const base::WeakPtr<PrerenderPendingSwapThrottle>& throttle); 47 const base::WeakPtr<PrerenderPendingSwapThrottle>& throttle);
38 48
39 // Called to add throttles for a pending prerender swap. 49 // Called to add throttles for a pending prerender swap.
40 void AddPrerenderPendingSwap( 50 void AddPrerenderPendingSwap(
41 const ChildRouteIdPair& render_frame_route_id_pair, 51 const ChildRouteIdPair& render_frame_route_id_pair,
42 const GURL& url); 52 const GURL& url);
43 53
44 // Called to remove the throttles for a pending prerender swap. 54 // Called to remove the throttles for a pending prerender swap.
45 void RemovePrerenderPendingSwap( 55 void RemovePrerenderPendingSwap(
46 const ChildRouteIdPair& render_frame_route_id_pair, 56 const ChildRouteIdPair& render_frame_route_id_pair,
47 bool swap_successful); 57 bool swap_successful);
48 58
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);
63
64 bool IsProcessPrerendering(content::RenderProcessHost* process_host);
65
66 // Called when a given render process has changed a cookie for |url|.
67 // Only to be called from the IO thread.
68 void OnCookieChangedForURL(int process_id, const GURL& url);
69
70 // Adds a prerender and creates a corresponding prerender cookie store.
71 // Must be called on the UI thread.
72 void AddPrerender(content::RenderProcessHost* host,
73 net::URLRequestContextGetter* request_context,
74 const base::Closure& cookie_conflict_cb);
75
76 // Called when a prerender was successfully swapped and shown.
77 // The corresponding prerender cookie store will be set to forwarding mode.
78 void OnPrerenderSwapped(content::RenderProcessHost* host);
79
80 // content::RenderProcessHostObserver implementation.
81 virtual void RenderProcessHostDestroyed(
82 content::RenderProcessHost* host) OVERRIDE;
83
49 private: 84 private:
50 // Add/remove prerenders pending swap on the IO Thread. 85 // Add/remove prerenders pending swap on the IO Thread.
51 void AddPrerenderPendingSwapOnIOThread( 86 void AddPrerenderPendingSwapOnIOThread(
52 const ChildRouteIdPair& render_frame_route_id_pair, const GURL& url); 87 const ChildRouteIdPair& render_frame_route_id_pair, const GURL& url);
53 void RemovePrerenderPendingSwapOnIOThread( 88 void RemovePrerenderPendingSwapOnIOThread(
54 const ChildRouteIdPair& render_frame_route_id_pair, 89 const ChildRouteIdPair& render_frame_route_id_pair,
55 bool swap_successful); 90 bool swap_successful);
56 91
92 void AddPrerenderCookieStoreOnIOThread(
93 int process_id,
94 scoped_refptr<net::URLRequestContextGetter> request_context,
95 const base::Closure& cookie_conflict_cb);
96
97 // Removes a prerender cookie store on the IO thread.
98 void RemovePrerenderCookieStoreOnIOThread(int process_id, bool was_swapped);
99
57 struct PendingSwapThrottleData { 100 struct PendingSwapThrottleData {
58 explicit PendingSwapThrottleData(const GURL& swap_url); 101 explicit PendingSwapThrottleData(const GURL& swap_url);
59 ~PendingSwapThrottleData(); 102 ~PendingSwapThrottleData();
60 GURL url; 103 GURL url;
61 base::WeakPtr<PrerenderPendingSwapThrottle> throttle; 104 base::WeakPtr<PrerenderPendingSwapThrottle> throttle;
62 }; 105 };
63 106
64 // Map of pending prerender swaps and their associated throttles, 107 // Map of pending prerender swaps and their associated throttles,
65 // maintained on the IO thread. The key is the routing ID pair 108 // maintained on the IO thread. The key is the routing ID pair
66 // of a RenderFrame. 109 // of a RenderFrame.
67 typedef std::map<ChildRouteIdPair, PendingSwapThrottleData> 110 typedef std::map<ChildRouteIdPair, PendingSwapThrottleData>
68 PendingSwapThrottleMap; 111 PendingSwapThrottleMap;
69 PendingSwapThrottleMap pending_swap_throttle_map_; 112 PendingSwapThrottleMap pending_swap_throttle_map_;
70 113
114 // Map of prerendering render process ids to PrerenderCookieStore used for
115 // the prerender. Only to be used on the IO thread.
116 typedef base::hash_map<int, scoped_refptr<PrerenderCookieStore> >
117 PrerenderCookieStoreMap;
118 PrerenderCookieStoreMap prerender_cookie_store_map_;
119
120 // Set of process hosts being prerendered, maintained on the UI thread.
121 typedef std::set<content::RenderProcessHost*> PrerenderProcessSet;
122 PrerenderProcessSet prerender_process_hosts_;
123
71 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); 124 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker);
72 }; 125 };
73 126
74 } // namespace prerender 127 } // namespace prerender
75 128
76 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 129 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698