OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // been displayed or destroyed is still prerendering. | 58 // been displayed or destroyed is still prerendering. |
59 // TODO(mmenke): Remove external use of this method and make it private. | 59 // TODO(mmenke): Remove external use of this method and make it private. |
60 bool IsPrerenderingOnIOThread(int child_id, int route_id) const; | 60 bool IsPrerenderingOnIOThread(int child_id, int route_id) const; |
61 | 61 |
62 // Gets the FinalStatus of the specified prerendered RenderView. Returns | 62 // Gets the FinalStatus of the specified prerendered RenderView. Returns |
63 // |true| and sets |final_status| to the status of the RenderView if it | 63 // |true| and sets |final_status| to the status of the RenderView if it |
64 // is found, returns false otherwise. | 64 // is found, returns false otherwise. |
65 bool GetFinalStatus(int child_id, int route_id, | 65 bool GetFinalStatus(int child_id, int route_id, |
66 FinalStatus* final_status) const; | 66 FinalStatus* final_status) const; |
67 | 67 |
68 protected: | 68 private: |
| 69 friend struct DefaultSingletonTraits<PrerenderTracker>; |
69 friend class PrerenderContents; | 70 friend class PrerenderContents; |
70 | 71 |
71 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerUsed); | 72 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerUsed); |
72 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelled); | 73 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelled); |
73 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledOnIO); | 74 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledOnIO); |
74 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledFast); | 75 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerCancelledFast); |
75 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple); | 76 FRIEND_TEST_ALL_PREFIXES(PrerenderTrackerTest, PrerenderTrackerMultiple); |
76 | 77 |
| 78 typedef std::pair<int, int> ChildRouteIdPair; |
| 79 |
| 80 // Map of child/route id pairs to final statuses. |
| 81 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap; |
| 82 // Set of child/route id pairs that may be prerendering. |
| 83 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs; |
| 84 |
| 85 PrerenderTracker(); |
| 86 ~PrerenderTracker(); |
| 87 |
77 // Must be called when a RenderView starts prerendering, before the first | 88 // Must be called when a RenderView starts prerendering, before the first |
78 // navigation starts to avoid any races. | 89 // navigation starts to avoid any races. |
79 void OnPrerenderingStarted(int child_id, int route_id, | 90 void OnPrerenderingStarted(int child_id, int route_id, |
80 PrerenderManager* prerender_manager); | 91 PrerenderManager* prerender_manager); |
81 | 92 |
82 // Must be called when a RenderView stops prerendering, either because the | 93 // Must be called when a RenderView stops prerendering, either because the |
83 // RenderView was used or prerendering was cancelled and it is being | 94 // RenderView was used or prerendering was cancelled and it is being |
84 // destroyed. | 95 // destroyed. |
85 void OnPrerenderingFinished(int child_id, int route_id); | 96 void OnPrerenderingFinished(int child_id, int route_id); |
86 | 97 |
87 private: | |
88 friend struct DefaultSingletonTraits<PrerenderTracker>; | |
89 | |
90 typedef std::pair<int, int> ChildRouteIdPair; | |
91 | |
92 // Map of child/route id pairs to final statuses. | |
93 typedef std::map<ChildRouteIdPair, RenderViewInfo> FinalStatusMap; | |
94 // Set of child/route id pairs that may be prerendering. | |
95 typedef std::set<ChildRouteIdPair> PossiblyPrerenderingChildRouteIdPairs; | |
96 | |
97 PrerenderTracker(); | |
98 ~PrerenderTracker(); | |
99 | |
100 // Attempts to set the FinalStatus of the specified RenderView to | 98 // Attempts to set the FinalStatus of the specified RenderView to |
101 // |final_status|. If the FinalStatus of the RenderView has already been | 99 // |desired_final_status|. |
102 // set, does nothing. Returns the resulting FinalStatus of that RenderView, | 100 // |
103 // regardless of success or failure. If the RenderView isn't currently | 101 // If the FinalStatus of the RenderView is successfully set, returns true and |
104 // prerendering, returns FINAL_STATUS_MAX. | 102 // sets |actual_final_status| to |desired_final_status|. |
105 FinalStatus SetFinalStatus(int child_id, int route_id, | 103 // |
106 FinalStatus final_status); | 104 // If the FinalStatus of the RenderView was already set, returns false and |
| 105 // sets |actual_final_status| to the actual FinalStatus of the RenderView. |
| 106 // |
| 107 // If the RenderView is not a prerendering RenderView, returns false and sets |
| 108 // |actual_final_status| to FINAL_STATUS_MAX. |
| 109 bool SetFinalStatus(int child_id, int route_id, |
| 110 FinalStatus desired_final_status, |
| 111 FinalStatus* actual_final_status); |
107 | 112 |
108 // Add/remove the specified pair to |possibly_prerendering_io_thread_set_| on | 113 // Add/remove the specified pair to |possibly_prerendering_io_thread_set_| on |
109 // the IO Thread. | 114 // the IO Thread. |
110 void AddPrerenderOnIOThread(const ChildRouteIdPair& child_route_id_pair); | 115 void AddPrerenderOnIOThread(const ChildRouteIdPair& child_route_id_pair); |
111 void RemovePrerenderOnIOThread(const ChildRouteIdPair& child_route_id_pair); | 116 void RemovePrerenderOnIOThread(const ChildRouteIdPair& child_route_id_pair); |
112 | 117 |
113 // Tasks posted to the IO Thread to call the above functions. | 118 // Tasks posted to the IO Thread to call the above functions. |
114 static void AddPrerenderOnIOThreadTask( | 119 static void AddPrerenderOnIOThreadTask( |
115 const ChildRouteIdPair& child_route_id_pair); | 120 const ChildRouteIdPair& child_route_id_pair); |
116 static void RemovePrerenderOnIOThreadTask( | 121 static void RemovePrerenderOnIOThreadTask( |
(...skipping 10 matching lines...) Expand all Loading... |
127 // the IO thread. May contain entries that have since been displayed. Only | 132 // the IO thread. May contain entries that have since been displayed. Only |
128 // used to prevent locking when not needed. | 133 // used to prevent locking when not needed. |
129 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_; | 134 PossiblyPrerenderingChildRouteIdPairs possibly_prerendering_io_thread_set_; |
130 | 135 |
131 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); | 136 DISALLOW_COPY_AND_ASSIGN(PrerenderTracker); |
132 }; | 137 }; |
133 | 138 |
134 } // namespace prerender | 139 } // namespace prerender |
135 | 140 |
136 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ | 141 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TRACKER_H_ |
OLD | NEW |