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

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: 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 void AddPrerenderContents(PrerenderContents* prerender_contents);
30 35
31 // Attempts to set the status of the specified RenderViewHost to 36 // Attempts to set the status of the specified RenderViewHost to
32 // FINAL_STATUS_USED. Returns true on success. Returns false if it has 37 // FINAL_STATUS_USED. Returns true on success. Returns false if it has
33 // already been cancelled for any reason or is no longer prerendering. 38 // 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 39 // Can only be called only on the IO thread. This method will not call
35 // PrerenderContents::set_final_status() on the corresponding 40 // PrerenderContents::set_final_status() on the corresponding
36 // PrerenderContents. 41 // PrerenderContents.
37 // 42 //
38 // If it returns true, all subsequent calls to TryCancel and TryUse for the 43 // If it returns true, all subsequent calls to TryCancel and TryUse for the
39 // RenderView will return false. 44 // RenderView will return false.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple); 81 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple);
77 82
78 typedef std::pair<int, int> ChildRouteIdPair; 83 typedef std::pair<int, int> ChildRouteIdPair;
79 // Map of child/route id pairs to final statuses. 84 // Map of child/route id pairs to final statuses.
80 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap; 85 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap;
81 // Set of child/route id pairs that may be prerendering. 86 // Set of child/route id pairs that may be prerendering.
82 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs; 87 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs;
83 88
84 // Must be called when a RenderView starts prerendering, before the first 89 // Must be called when a RenderView starts prerendering, before the first
85 // navigation starts to avoid any races. 90 // navigation starts to avoid any races.
86 void OnPrerenderingStarted(int child_id, int route_id, 91 virtual void OnPrerenderStart(PrerenderContents* prerender_contents) OVERRIDE;
87 PrerenderManager* prerender_manager);
88 92
89 // Must be called when a RenderView stops prerendering, either because the 93 // Must be called when a RenderView stops prerendering, either because the
90 // RenderView was used or prerendering was cancelled and it is being 94 // RenderView was used or prerendering was cancelled and it is being
91 // destroyed. 95 // destroyed.
92 void OnPrerenderingFinished(int child_id, int route_id); 96 virtual void OnPrerenderStop(PrerenderContents* prerender_contents) OVERRIDE;
93 97
94 // Attempts to set the FinalStatus of the specified RenderView to 98 // Attempts to set the FinalStatus of the specified RenderView to
95 // |desired_final_status|. If non-NULL, |actual_final_status| is set to the 99 // |desired_final_status|. If non-NULL, |actual_final_status| is set to the
96 // FinalStatus of the RenderView. 100 // FinalStatus of the RenderView.
97 // 101 //
98 // If the FinalStatus of the RenderView is successfully set, returns true and 102 // If the FinalStatus of the RenderView is successfully set, returns true and
99 // sets |actual_final_status| to |desired_final_status|. 103 // sets |actual_final_status| to |desired_final_status|.
100 // 104 //
101 // If the FinalStatus of the RenderView was already set, returns false and 105 // If the FinalStatus of the RenderView was already set, returns false and
102 // sets |actual_final_status| to the actual FinalStatus of the RenderView. 106 // 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); 117 void RemovePrerenderOnIOThread(const ChildRouteIdPair& child_route_id_pair);
114 118
115 // Tasks posted to the IO Thread to call the above functions. 119 // Tasks posted to the IO Thread to call the above functions.
116 static void AddPrerenderOnIOThreadTask( 120 static void AddPrerenderOnIOThreadTask(
117 const ChildRouteIdPair& child_route_id_pair); 121 const ChildRouteIdPair& child_route_id_pair);
118 static void RemovePrerenderOnIOThreadTask( 122 static void RemovePrerenderOnIOThreadTask(
119 const ChildRouteIdPair& child_route_id_pair); 123 const ChildRouteIdPair& child_route_id_pair);
120 124
121 static PrerenderTracker* GetDefault(); 125 static PrerenderTracker* GetDefault();
122 126
127 // Set of prerender_contents being observed by this tracker. Can only access
128 // on UI thread.
129 std::set<prerender::PrerenderContents*> observing_set_;
130
123 // |final_status_map_lock_| protects access to |final_status_map_|. 131 // |final_status_map_lock_| protects access to |final_status_map_|.
124 mutable base::Lock final_status_map_lock_; 132 mutable base::Lock final_status_map_lock_;
125 // Map containing child/route id pairs and their final statuses. Must only be 133 // 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 134 // accessed while the lock is held. Values are always accurate and up to
127 // date. 135 // date.
128 FinalStatusMap final_status_map_; 136 FinalStatusMap final_status_map_;
129 137
130 // Superset of child/route id pairs that are prerendering. Can only access on 138 // 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 139 // the IO thread. May contain entries that have since been displayed. Only
132 // used to prevent locking when not needed. 140 // used to prevent locking when not needed.
133 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_; 141 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_;
134 142
135 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); 143 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker);
136 }; 144 };
137 145
138 } // namespace prerender 146 } // namespace prerender
139 147
140 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ 148 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698