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

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

Issue 11348357: Add observer interface to PrerenderContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remediate to review Created 8 years 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 <set>
10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
16 #include "chrome/browser/prerender/prerender_contents.h"
15 #include "chrome/browser/prerender/prerender_final_status.h" 17 #include "chrome/browser/prerender/prerender_final_status.h"
16 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
17 19
18 namespace prerender { 20 namespace prerender {
19 21
20 class PrerenderManager; 22 class PrerenderManager;
21 struct RenderViewInfo; 23 struct RenderViewInfo;
22 24
23 // PrerenderTracker is responsible for keeping track of all prerendering 25 // PrerenderTracker is responsible for keeping track of all prerendering
24 // RenderViews and their statuses. Its list is guaranteed to be up to date 26 // RenderViews and their statuses. Its list is guaranteed to be up to date
25 // and can be modified on any thread. 27 // and can be modified on any thread.
26 class PrerenderTracker { 28 class PrerenderTracker : public base::NonThreadSafe,
29 public PrerenderContents::Observer {
27 public: 30 public:
28 PrerenderTracker(); 31 PrerenderTracker();
29 ~PrerenderTracker(); 32 virtual ~PrerenderTracker();
33
34 // Start tracking |prerender_contents|.
35 void AddPrerenderContents(PrerenderContents* prerender_contents);
30 36
31 // Attempts to set the status of the specified RenderViewHost to 37 // Attempts to set the status of the specified RenderViewHost to
32 // FINAL_STATUS_USED. Returns true on success. Returns false if it has 38 // FINAL_STATUS_USED. Returns true on success. Returns false if it has
33 // already been cancelled for any reason or is no longer prerendering. 39 // already been cancelled for any reason or is no longer prerendering.
34 // Can only be called only on the IO thread. This method will not call 40 // Can only be called only on the IO thread. This method will not call
35 // PrerenderContents::set_final_status() on the corresponding 41 // PrerenderContents::set_final_status() on the corresponding
36 // PrerenderContents. 42 // PrerenderContents.
37 // 43 //
38 // If it returns true, all subsequent calls to TryCancel and TryUse for the 44 // If it returns true, all subsequent calls to TryCancel and TryUse for the
39 // RenderView will return false. 45 // RenderView will return false.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple); 82 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple);
77 83
78 typedef std::pair<int, int> ChildRouteIdPair; 84 typedef std::pair<int, int> ChildRouteIdPair;
79 // Map of child/route id pairs to final statuses. 85 // Map of child/route id pairs to final statuses.
80 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap; 86 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap;
81 // Set of child/route id pairs that may be prerendering. 87 // Set of child/route id pairs that may be prerendering.
82 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs; 88 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs;
83 89
84 // Must be called when a RenderView starts prerendering, before the first 90 // Must be called when a RenderView starts prerendering, before the first
85 // navigation starts to avoid any races. 91 // navigation starts to avoid any races.
86 void OnPrerenderingStarted(int child_id, int route_id, 92 virtual void OnPrerenderStart(PrerenderContents* prerender_contents) OVERRIDE;
87 PrerenderManager* prerender_manager);
88 93
89 // Must be called when a RenderView stops prerendering, either because the 94 // Must be called when a RenderView stops prerendering, either because the
90 // RenderView was used or prerendering was cancelled and it is being 95 // RenderView was used or prerendering was cancelled and it is being
91 // destroyed. 96 // destroyed.
92 void OnPrerenderingFinished(int child_id, int route_id); 97 virtual void OnPrerenderStop(PrerenderContents* prerender_contents) OVERRIDE;
93 98
94 // Attempts to set the FinalStatus of the specified RenderView to 99 // Attempts to set the FinalStatus of the specified RenderView to
95 // |desired_final_status|. If non-NULL, |actual_final_status| is set to the 100 // |desired_final_status|. If non-NULL, |actual_final_status| is set to the
96 // FinalStatus of the RenderView. 101 // FinalStatus of the RenderView.
97 // 102 //
98 // If the FinalStatus of the RenderView is successfully set, returns true and 103 // If the FinalStatus of the RenderView is successfully set, returns true and
99 // sets |actual_final_status| to |desired_final_status|. 104 // sets |actual_final_status| to |desired_final_status|.
100 // 105 //
101 // If the FinalStatus of the RenderView was already set, returns false and 106 // If the FinalStatus of the RenderView was already set, returns false and
102 // sets |actual_final_status| to the actual FinalStatus of the RenderView. 107 // sets |actual_final_status| to the actual FinalStatus of the RenderView.
(...skipping 10 matching lines...) Expand all
113 void RemovePrerenderOnIOThread(const ChildRouteIdPair& child_route_id_pair); 118 void RemovePrerenderOnIOThread(const ChildRouteIdPair& child_route_id_pair);
114 119
115 // Tasks posted to the IO Thread to call the above functions. 120 // Tasks posted to the IO Thread to call the above functions.
116 static void AddPrerenderOnIOThreadTask( 121 static void AddPrerenderOnIOThreadTask(
117 const ChildRouteIdPair& child_route_id_pair); 122 const ChildRouteIdPair& child_route_id_pair);
118 static void RemovePrerenderOnIOThreadTask( 123 static void RemovePrerenderOnIOThreadTask(
119 const ChildRouteIdPair& child_route_id_pair); 124 const ChildRouteIdPair& child_route_id_pair);
120 125
121 static PrerenderTracker* GetDefault(); 126 static PrerenderTracker* GetDefault();
122 127
128 // Set of prerender_contents being observed by this tracker. Can only access
129 // on UI thread.
130 std::set<prerender::PrerenderContents*> observing_set_;
mmenke 2012/12/04 18:59:16 Doesn't seem like we need these. This should exac
gavinp 2012/12/04 22:26:07 Done, and a good catch.
131
123 // |final_status_map_lock_| protects access to |final_status_map_|. 132 // |final_status_map_lock_| protects access to |final_status_map_|.
124 mutable base::Lock final_status_map_lock_; 133 mutable base::Lock final_status_map_lock_;
125 // Map containing child/route id pairs and their final statuses. Must only be 134 // Map containing child/route id pairs and their final statuses. Must only be
126 // accessed while the lock is held. Values are always accurate and up to 135 // accessed while the lock is held. Values are always accurate and up to
127 // date. 136 // date.
128 FinalStatusMap final_status_map_; 137 FinalStatusMap final_status_map_;
129 138
130 // Superset of child/route id pairs that are prerendering. Can only access on 139 // Superset of child/route id pairs that are prerendering. Can only access on
131 // the IO thread. May contain entries that have since been displayed. Only 140 // the IO thread. May contain entries that have since been displayed. Only
132 // used to prevent locking when not needed. 141 // used to prevent locking when not needed.
133 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_; 142 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_;
134 143
135 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); 144 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker);
136 }; 145 };
137 146
138 } // namespace prerender 147 } // namespace prerender
139 148
140 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 149 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698