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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/cancelable_callback.h" | |
15 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
16 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
19 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
20 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
21 #include "base/time/time.h" | 20 #include "base/time/time.h" |
22 #include "base/timer/timer.h" | 21 #include "base/timer/timer.h" |
23 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 22 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
24 #include "chrome/browser/predictors/logged_in_predictor_table.h" | 23 #include "chrome/browser/predictors/logged_in_predictor_table.h" |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 DISALLOW_COPY_AND_ASSIGN(PrerenderData); | 421 DISALLOW_COPY_AND_ASSIGN(PrerenderData); |
423 }; | 422 }; |
424 | 423 |
425 // When a swap can't happen immediately, due to a sesison storage namespace | 424 // When a swap can't happen immediately, due to a sesison storage namespace |
426 // merge, there will be a pending swap object while the merge is in | 425 // merge, there will be a pending swap object while the merge is in |
427 // progress. It retains all the data needed to do the merge, maintains | 426 // progress. It retains all the data needed to do the merge, maintains |
428 // throttles for the navigation in the target WebContents that needs to be | 427 // throttles for the navigation in the target WebContents that needs to be |
429 // delayed, and handles all conditions which would cancel a pending swap. | 428 // delayed, and handles all conditions which would cancel a pending swap. |
430 class PendingSwap : public content::WebContentsObserver { | 429 class PendingSwap : public content::WebContentsObserver { |
431 public: | 430 public: |
432 PendingSwap(PrerenderTracker* prerender_tracker, | 431 PendingSwap(PrerenderManager* manager, |
433 content::WebContents* target_contents, | 432 content::WebContents* target_contents, |
434 PrerenderData* prerender_data, | 433 PrerenderData* prerender_data, |
435 const GURL& url, | 434 const GURL& url); |
436 const base::Closure& timeout_cb, | |
437 const content::SessionStorageNamespace::MergeResultCallback& | |
438 merge_result_cb); | |
439 virtual ~PendingSwap(); | 435 virtual ~PendingSwap(); |
440 const base::Closure& GetTimeoutCallback(); | 436 |
441 const content::SessionStorageNamespace::MergeResultCallback& | 437 void BeginSwap(); |
442 GetMergeResultCallback(); | |
443 | 438 |
444 // content::WebContentsObserver implementation. | 439 // content::WebContentsObserver implementation. |
445 virtual void ProvisionalChangeToMainFrameUrl( | 440 virtual void ProvisionalChangeToMainFrameUrl( |
446 const GURL& url, | 441 const GURL& url, |
447 content::RenderViewHost* render_view_host) OVERRIDE; | 442 content::RenderViewHost* render_view_host) OVERRIDE; |
448 virtual void DidCommitProvisionalLoadForFrame( | 443 virtual void DidCommitProvisionalLoadForFrame( |
449 int64 frame_id, | 444 int64 frame_id, |
450 const string16& frame_unique_name, | 445 const string16& frame_unique_name, |
451 bool is_main_frame, | 446 bool is_main_frame, |
452 const GURL& validated_url, | 447 const GURL& validated_url, |
453 content::PageTransition transition_type, | 448 content::PageTransition transition_type, |
454 content::RenderViewHost* render_view_host) OVERRIDE; | 449 content::RenderViewHost* render_view_host) OVERRIDE; |
455 virtual void RenderViewCreated( | 450 virtual void RenderViewCreated( |
456 content::RenderViewHost* render_view_host) OVERRIDE; | 451 content::RenderViewHost* render_view_host) OVERRIDE; |
457 virtual void DidFailProvisionalLoad( | 452 virtual void DidFailProvisionalLoad( |
458 int64 frame_id, | 453 int64 frame_id, |
459 const string16& frame_unique_name, | 454 const string16& frame_unique_name, |
460 bool is_main_frame, | 455 bool is_main_frame, |
461 const GURL& validated_url, | 456 const GURL& validated_url, |
462 int error_code, | 457 int error_code, |
463 const string16& error_description, | 458 const string16& error_description, |
464 content::RenderViewHost* render_view_host) OVERRIDE; | 459 content::RenderViewHost* render_view_host) OVERRIDE; |
465 virtual void WebContentsDestroyed(content::WebContents* web_contents) | 460 virtual void WebContentsDestroyed(content::WebContents* web_contents) |
466 OVERRIDE; | 461 OVERRIDE; |
467 | 462 |
468 base::TimeDelta GetElapsedTime(); | |
469 void SwapSuccessful(); | 463 void SwapSuccessful(); |
470 const GURL& url() const { return url_; } | |
471 content::WebContents* target_contents() const { return target_contents_; } | |
472 | 464 |
473 private: | 465 private: |
474 PrerenderTracker* prerender_tracker_; | 466 void RecordEvent(PrerenderEvent event) const; |
| 467 |
| 468 void OnMergeCompleted(content::SessionStorageNamespace::MergeResult result); |
| 469 void OnMergeTimeout(); |
| 470 |
| 471 PrerenderManager* manager_; |
475 content::WebContents* target_contents_; | 472 content::WebContents* target_contents_; |
476 PrerenderData* prerender_data_; | 473 PrerenderData* prerender_data_; |
477 GURL url_; | 474 GURL url_; |
478 base::CancelableClosure timeout_cb_; | |
479 base::CancelableCallback< | |
480 void(content::SessionStorageNamespace::MergeResult)> merge_result_cb_; | |
481 base::TimeTicks start_time_; | 475 base::TimeTicks start_time_; |
482 std::vector<PrerenderTracker::ChildRouteIdPair> rvh_ids_; | 476 std::vector<PrerenderTracker::ChildRouteIdPair> rvh_ids_; |
| 477 base::OneShotTimer<PendingSwap> merge_timeout_; |
| 478 |
| 479 base::WeakPtrFactory<PendingSwap> weak_factory_; |
483 }; | 480 }; |
484 | 481 |
485 void SetPrerenderContentsFactory( | 482 void SetPrerenderContentsFactory( |
486 PrerenderContents::Factory* prerender_contents_factory); | 483 PrerenderContents::Factory* prerender_contents_factory); |
487 | 484 |
488 // Adds prerenders from the pending Prerenders, called by | 485 // Adds prerenders from the pending Prerenders, called by |
489 // PrerenderContents::StartPendingPrerenders. | 486 // PrerenderContents::StartPendingPrerenders. |
490 void StartPendingPrerenders( | 487 void StartPendingPrerenders( |
491 int process_id, | 488 int process_id, |
492 ScopedVector<PrerenderContents::PendingPrerenderInfo>* pending_prerenders, | 489 ScopedVector<PrerenderContents::PendingPrerenderInfo>* pending_prerenders, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 646 |
650 // Returns whether prerendering is currently enabled for this manager. | 647 // Returns whether prerendering is currently enabled for this manager. |
651 // Must be called on the UI thread. | 648 // Must be called on the UI thread. |
652 bool IsEnabled() const; | 649 bool IsEnabled() const; |
653 | 650 |
654 void CookieChanged(ChromeCookieDetails* details); | 651 void CookieChanged(ChromeCookieDetails* details); |
655 void CookieChangedAnyCookiesLeftLookupResult(const std::string& domain_key, | 652 void CookieChangedAnyCookiesLeftLookupResult(const std::string& domain_key, |
656 bool cookies_exist); | 653 bool cookies_exist); |
657 void LoggedInPredictorDataReceived(scoped_ptr<LoggedInStateMap> new_map); | 654 void LoggedInPredictorDataReceived(scoped_ptr<LoggedInStateMap> new_map); |
658 | 655 |
659 void ProcessMergeResult(PrerenderData* prerender_data, | |
660 bool timed_out, | |
661 content::SessionStorageNamespace::MergeResult result); | |
662 | |
663 void RecordEvent(PrerenderContents* contents, PrerenderEvent event) const; | 656 void RecordEvent(PrerenderContents* contents, PrerenderEvent event) const; |
664 | 657 |
665 // Swaps a prerender for |url| into the tab, replacing |web_contents|. | 658 // Swaps a prerender |prerender_data| for |url| into the tab, replacing |
666 // Returns the new WebContents that was swapped in, or NULL if a swap-in | 659 // |web_contents|. Returns the new WebContents that was swapped in, or NULL |
667 // was not possible. Optionally, a |swap_candidate| can be specified. | 660 // if a swap-in was not possible. |
668 // Must be supplied if a merge has completed and we retry swap. | |
669 // That's because we must skip the check whether a PrerenderData object that | |
670 // could be swapped in is used for a pending merge, if the PrerenderData | |
671 // object being considered is the one for which the merge has just completed | |
672 // and which is intended to be swapped in. | |
673 content::WebContents* SwapInternal(const GURL& url, | 661 content::WebContents* SwapInternal(const GURL& url, |
674 content::WebContents* web_contents, | 662 content::WebContents* web_contents, |
675 PrerenderData* swap_candidate); | 663 PrerenderData* prerender_data); |
676 | 664 |
677 // The configuration. | 665 // The configuration. |
678 Config config_; | 666 Config config_; |
679 | 667 |
680 // Specifies whether prerendering is currently enabled for this | 668 // Specifies whether prerendering is currently enabled for this |
681 // manager. The value can change dynamically during the lifetime | 669 // manager. The value can change dynamically during the lifetime |
682 // of the PrerenderManager. | 670 // of the PrerenderManager. |
683 bool enabled_; | 671 bool enabled_; |
684 | 672 |
685 static bool is_prefetch_enabled_; | 673 static bool is_prefetch_enabled_; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 747 |
760 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 748 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
761 }; | 749 }; |
762 | 750 |
763 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( | 751 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( |
764 int render_process_id); | 752 int render_process_id); |
765 | 753 |
766 } // namespace prerender | 754 } // namespace prerender |
767 | 755 |
768 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 756 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |