OLD | NEW |
---|---|
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_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 // load may have started prior to navigation due to prerender hints. | 152 // load may have started prior to navigation due to prerender hints. |
153 // This must be called on the UI thread. | 153 // This must be called on the UI thread. |
154 // |fraction_plt_elapsed_at_swap_in| must either be in [0.0, 1.0], or a value | 154 // |fraction_plt_elapsed_at_swap_in| must either be in [0.0, 1.0], or a value |
155 // outside that range indicating that it doesn't apply. | 155 // outside that range indicating that it doesn't apply. |
156 static void RecordPerceivedPageLoadTime( | 156 static void RecordPerceivedPageLoadTime( |
157 base::TimeDelta perceived_page_load_time, | 157 base::TimeDelta perceived_page_load_time, |
158 double fraction_plt_elapsed_at_swap_in, | 158 double fraction_plt_elapsed_at_swap_in, |
159 content::WebContents* web_contents, | 159 content::WebContents* web_contents, |
160 const GURL& url); | 160 const GURL& url); |
161 | 161 |
162 // Records the percentage of pixels of the final page in place at swap-in. | |
163 void RecordFractionPixelsFinalAtSwapin( | |
164 content::WebContents* web_contents, | |
165 double fraction); | |
166 | |
162 // Set whether prerendering is currently enabled for this manager. | 167 // Set whether prerendering is currently enabled for this manager. |
163 // Must be called on the UI thread. | 168 // Must be called on the UI thread. |
164 // If |enabled| is false, existing prerendered pages will still persist until | 169 // If |enabled| is false, existing prerendered pages will still persist until |
165 // they time out, but new ones will not be generated. | 170 // they time out, but new ones will not be generated. |
166 void set_enabled(bool enabled); | 171 void set_enabled(bool enabled); |
167 | 172 |
168 // Controls if we launch or squash prefetch requests as they arrive from | 173 // Controls if we launch or squash prefetch requests as they arrive from |
169 // renderers. | 174 // renderers. |
170 static bool IsPrefetchEnabled(); | 175 static bool IsPrefetchEnabled(); |
171 static void SetIsPrefetchEnabled(bool enabled); | 176 static void SetIsPrefetchEnabled(bool enabled); |
172 | 177 |
173 static PrerenderManagerMode GetMode(); | 178 static PrerenderManagerMode GetMode(); |
174 static void SetMode(PrerenderManagerMode mode); | 179 static void SetMode(PrerenderManagerMode mode); |
175 static const char* GetModeString(); | 180 static const char* GetModeString(); |
176 static bool IsPrerenderingPossible(); | 181 static bool IsPrerenderingPossible(); |
177 static bool ActuallyPrerendering(); | 182 static bool ActuallyPrerendering(); |
178 static bool IsControlGroup(); | 183 static bool IsControlGroup(); |
179 static bool IsNoUseGroup(); | 184 static bool IsNoUseGroup(); |
180 | 185 |
181 // Query the list of current prerender pages to see if the given web contents | 186 // Query the list of current prerender pages to see if the given web contents |
182 // is prerendering a page. | 187 // is prerendering a page. The optional parameter |origin| is an output |
183 bool IsWebContentsPrerendering(content::WebContents* web_contents) const; | 188 // parameter which, if a prerender is found, is set to the Origin of the |
189 // prerender |web_contents|. | |
190 bool IsWebContentsPrerendering(content::WebContents* web_contents, | |
191 Origin* origin) const; | |
184 | 192 |
185 // Returns the PrerenderContents object for the given web_contents if it's | 193 // Returns the PrerenderContents object for the given web_contents if it's |
186 // used for an active prerender page, otherwise returns NULL. | 194 // used for an active prerender page, otherwise returns NULL. |
187 PrerenderContents* GetPrerenderContents( | 195 PrerenderContents* GetPrerenderContents( |
188 content::WebContents* web_contents) const; | 196 content::WebContents* web_contents) const; |
189 | 197 |
190 // Maintaining and querying the set of WebContents belonging to this | 198 // Maintaining and querying the set of WebContents belonging to this |
191 // PrerenderManager that are currently showing prerendered pages. | 199 // PrerenderManager that are currently showing prerendered pages. |
192 void MarkWebContentsAsPrerendered(content::WebContents* web_contents); | 200 void MarkWebContentsAsPrerendered(content::WebContents* web_contents, |
193 void MarkWebContentsAsWouldBePrerendered(content::WebContents* web_contents); | 201 Origin origin); |
202 void MarkWebContentsAsWouldBePrerendered(content::WebContents* web_contents, | |
203 Origin origin); | |
194 void MarkWebContentsAsNotPrerendered(content::WebContents* web_contents); | 204 void MarkWebContentsAsNotPrerendered(content::WebContents* web_contents); |
195 bool IsWebContentsPrerendered(content::WebContents* web_contents) const; | 205 |
196 bool WouldWebContentsBePrerendered(content::WebContents* web_contents) const; | 206 // Returns true if |web_contents| was originally a prerender that has since |
207 // been swapped in. The optional parameter |origin| is an output parameter | |
208 // which, if a prerender is found, is set to the Origin of the prerender of | |
209 // |web_contents|. | |
210 bool IsWebContentsPrerendered(content::WebContents* web_contents, | |
211 Origin* origin) const; | |
212 bool WouldWebContentsBePrerendered(content::WebContents* web_contents, | |
213 Origin* origin) const; | |
197 | 214 |
198 // Checks whether |url| has been recently navigated to. | 215 // Checks whether |url| has been recently navigated to. |
199 bool HasRecentlyBeenNavigatedTo(const GURL& url); | 216 bool HasRecentlyBeenNavigatedTo(Origin origin, const GURL& url); |
200 | 217 |
201 // Returns true if the method given is invalid for prerendering. | 218 // Returns true if the method given is invalid for prerendering. |
202 static bool IsValidHttpMethod(const std::string& method); | 219 static bool IsValidHttpMethod(const std::string& method); |
203 | 220 |
204 // Returns a Value object containing the active pages being prerendered, and | 221 // Returns a Value object containing the active pages being prerendered, and |
205 // a history of pages which were prerendered. The caller is responsible for | 222 // a history of pages which were prerendered. The caller is responsible for |
206 // deleting the return value. | 223 // deleting the return value. |
207 base::DictionaryValue* GetAsValue() const; | 224 base::DictionaryValue* GetAsValue() const; |
208 | 225 |
209 // Clears the data indicated by which bits of clear_flags are set. | 226 // Clears the data indicated by which bits of clear_flags are set. |
(...skipping 25 matching lines...) Expand all Loading... | |
235 | 252 |
236 // Adds a condition. This is owned by the PrerenderManager. | 253 // Adds a condition. This is owned by the PrerenderManager. |
237 void AddCondition(const PrerenderCondition* condition); | 254 void AddCondition(const PrerenderCondition* condition); |
238 | 255 |
239 // Records that some visible tab navigated (or was redirected) to the | 256 // Records that some visible tab navigated (or was redirected) to the |
240 // provided URL. | 257 // provided URL. |
241 void RecordNavigation(const GURL& url); | 258 void RecordNavigation(const GURL& url); |
242 | 259 |
243 Profile* profile() const { return profile_; } | 260 Profile* profile() const { return profile_; } |
244 | 261 |
245 PrerenderHistograms* histograms() const { return histograms_.get(); } | |
246 | |
247 protected: | 262 protected: |
248 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> { | 263 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> { |
249 public: | 264 public: |
250 // Constructor for a pending prerender, which will get its contents later. | 265 // Constructor for a pending prerender, which will get its contents later. |
251 explicit PrerenderData(PrerenderManager* manager); | 266 explicit PrerenderData(PrerenderManager* manager); |
252 | 267 |
253 // Constructor for an active prerender. | 268 // Constructor for an active prerender. |
254 PrerenderData(PrerenderManager* manager, | 269 PrerenderData(PrerenderManager* manager, |
255 PrerenderContents* contents, | 270 PrerenderContents* contents, |
256 base::TimeTicks expiry_time); | 271 base::TimeTicks expiry_time); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 void DoShutdown(); | 342 void DoShutdown(); |
328 | 343 |
329 private: | 344 private: |
330 friend class PrerenderBrowserTest; | 345 friend class PrerenderBrowserTest; |
331 friend class PrerenderContents; | 346 friend class PrerenderContents; |
332 friend class PrerenderHandle; | 347 friend class PrerenderHandle; |
333 friend class UnitTestPrerenderManager; | 348 friend class UnitTestPrerenderManager; |
334 | 349 |
335 class OnCloseTabContentsDeleter; | 350 class OnCloseTabContentsDeleter; |
336 struct NavigationRecord; | 351 struct NavigationRecord; |
352 struct PrerenderedWebContentsData { | |
353 Origin origin; | |
337 | 354 |
338 typedef base::hash_map<content::WebContents*, bool> WouldBePrerenderedMap; | 355 explicit PrerenderedWebContentsData(Origin origin); |
356 }; | |
357 | |
358 struct WouldBePrerenderedWebContentsData { | |
359 enum State { | |
360 WAITING_FOR_PROVISIONAL_LOAD, | |
361 SEEN_PROVISIONAL_LOAD, | |
mmenke
2012/10/12 17:59:03
Think both this struct and this enum are worth com
gavinp
2012/10/13 13:48:09
Done. I mostly copied from the comment later in th
| |
362 }; | |
363 | |
364 static const State INITIAL_STATE = WAITING_FOR_PROVISIONAL_LOAD; | |
mmenke
2012/10/12 17:59:03
What's the reason for this?
gavinp
2012/10/13 13:48:09
I'm just trying to make the state machine more exp
mmenke
2012/10/15 15:28:28
I'd prefer that. As-is, just stands out as being
| |
365 | |
366 Origin origin; | |
367 State state; | |
368 | |
369 explicit WouldBePrerenderedWebContentsData(Origin origin); | |
mmenke
2012/10/12 17:59:03
Constructor (And all methods) should go be all dat
gavinp
2012/10/13 13:48:09
Done.
gavinp
2012/10/13 13:48:09
Done.
| |
370 }; | |
339 | 371 |
340 // Time interval before a new prerender is allowed. | 372 // Time interval before a new prerender is allowed. |
341 static const int kMinTimeBetweenPrerendersMs = 500; | 373 static const int kMinTimeBetweenPrerendersMs = 500; |
342 | 374 |
343 // Time window for which we record old navigations, in milliseconds. | 375 // Time window for which we record old navigations, in milliseconds. |
344 static const int kNavigationRecordWindowMs = 5000; | 376 static const int kNavigationRecordWindowMs = 5000; |
345 | 377 |
346 void OnCancelPrerenderHandle(PrerenderData* prerender_data); | 378 void OnCancelPrerenderHandle(PrerenderData* prerender_data); |
347 | 379 |
348 // Adds a prerender for |url| from |referrer| initiated from the process | 380 // Adds a prerender for |url| from |referrer| initiated from the process |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 // If |child_id| and |route_id| correspond to a RenderView that is an active | 436 // If |child_id| and |route_id| correspond to a RenderView that is an active |
405 // prerender, returns the PrerenderData object for that prerender. Otherwise, | 437 // prerender, returns the PrerenderData object for that prerender. Otherwise, |
406 // returns NULL. | 438 // returns NULL. |
407 PrerenderData* FindPrerenderDataForChildAndRoute(int child_id, int route_id); | 439 PrerenderData* FindPrerenderDataForChildAndRoute(int child_id, int route_id); |
408 | 440 |
409 // Given the |prerender_contents|, find the iterator in active_prerender_list_ | 441 // Given the |prerender_contents|, find the iterator in active_prerender_list_ |
410 // correponding to the given prerender. | 442 // correponding to the given prerender. |
411 std::list<linked_ptr<PrerenderData> >::iterator | 443 std::list<linked_ptr<PrerenderData> >::iterator |
412 FindIteratorForPrerenderContents(PrerenderContents* prerender_contents); | 444 FindIteratorForPrerenderContents(PrerenderContents* prerender_contents); |
413 | 445 |
414 bool DoesRateLimitAllowPrerender() const; | 446 bool DoesRateLimitAllowPrerender(Origin origin) const; |
415 | 447 |
416 // Deletes old WebContents that have been replaced by prerendered ones. This | 448 // Deletes old WebContents that have been replaced by prerendered ones. This |
417 // is needed because they're replaced in a callback from the old WebContents, | 449 // is needed because they're replaced in a callback from the old WebContents, |
418 // so cannot immediately be deleted. | 450 // so cannot immediately be deleted. |
419 void DeleteOldTabContents(); | 451 void DeleteOldTabContents(); |
420 | 452 |
421 // Cleans up old NavigationRecord's. | 453 // Cleans up old NavigationRecord's. |
422 void CleanUpOldNavigations(); | 454 void CleanUpOldNavigations(); |
423 | 455 |
424 // Arrange for the given tab contents to be deleted asap. If deleter is not | 456 // Arrange for the given tab contents to be deleted asap. If deleter is not |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 // List of all pending prerenders. | 509 // List of all pending prerenders. |
478 std::list<linked_ptr<PrerenderData> > pending_prerender_list_; | 510 std::list<linked_ptr<PrerenderData> > pending_prerender_list_; |
479 | 511 |
480 // List of recent navigations in this profile, sorted by ascending | 512 // List of recent navigations in this profile, sorted by ascending |
481 // navigate_time_. | 513 // navigate_time_. |
482 std::list<NavigationRecord> navigations_; | 514 std::list<NavigationRecord> navigations_; |
483 | 515 |
484 // List of prerender elements to be deleted | 516 // List of prerender elements to be deleted |
485 std::list<PrerenderContents*> pending_delete_list_; | 517 std::list<PrerenderContents*> pending_delete_list_; |
486 | 518 |
487 // Set of WebContents which are currently displaying a prerendered page. | 519 // This map is from all WebContents which are currently displaying a |
488 base::hash_set<content::WebContents*> prerendered_tab_contents_set_; | 520 // prerendered page which has already been swapped in to a |
521 // PrerenderedWebContentsData for tracking full lifetime information | |
522 // on prerenders. | |
523 base::hash_map<content::WebContents*, PrerenderedWebContentsData> | |
524 prerendered_web_contents_data_; | |
489 | 525 |
490 // WebContents that would have been swapped out for a prerendered WebContents | 526 // WebContents that would have been swapped out for a prerendered WebContents |
491 // if the user was not part of the control group for measurement. When the | 527 // if the user was not part of the control group for measurement. When the |
492 // WebContents gets a provisional load, the WebContents is removed from | 528 // WebContents gets a provisional load, the WebContents is removed from |
493 // the map since the new navigation would not have swapped in a prerender. | 529 // the map since the new navigation would not have swapped in a prerender. |
494 // However, one complication exists because the first provisional load after | 530 // However, one complication exists because the first provisional load after |
495 // the WebContents is marked as "Would Have Been Prerendered" is actually to | 531 // the WebContents is marked as "Would Have Been Prerendered" is actually to |
496 // the prerendered location. So, we need to keep a boolean around that does | 532 // the prerendered location. So, we need to keep a state around that does |
497 // not clear the item from the map on the first provisional load, but does | 533 // not clear the item from the map on the first provisional load, but does |
498 // for subsequent loads. | 534 // for subsequent loads. |
499 WouldBePrerenderedMap would_be_prerendered_map_; | 535 base::hash_map<content::WebContents*, WouldBePrerenderedWebContentsData> |
536 would_be_prerendered_map_; | |
500 | 537 |
501 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 538 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
502 | 539 |
503 static PrerenderManagerMode mode_; | 540 static PrerenderManagerMode mode_; |
504 | 541 |
505 // A count of how many prerenders we do per session. Initialized to 0 then | 542 // A count of how many prerenders we do per session. Initialized to 0 then |
506 // incremented and emitted to a histogram on each successful prerender. | 543 // incremented and emitted to a histogram on each successful prerender. |
507 static int prerenders_per_session_count_; | 544 static int prerenders_per_session_count_; |
508 | 545 |
509 // RepeatingTimer to perform periodic cleanups of pending prerendered | 546 // RepeatingTimer to perform periodic cleanups of pending prerendered |
(...skipping 20 matching lines...) Expand all Loading... | |
530 | 567 |
531 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 568 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
532 }; | 569 }; |
533 | 570 |
534 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( | 571 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( |
535 int render_process_id); | 572 int render_process_id); |
536 | 573 |
537 } // namespace prerender | 574 } // namespace prerender |
538 | 575 |
539 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 576 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |