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

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

Issue 98373010: Refactor prerender pending swap logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: I can order correctly words Created 7 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_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
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 set_swap_successful(bool swap_successful) {
442 GetMergeResultCallback(); 438 swap_successful_ = swap_successful;
439 }
440
441 void BeginSwap();
443 442
444 // content::WebContentsObserver implementation. 443 // content::WebContentsObserver implementation.
445 virtual void ProvisionalChangeToMainFrameUrl( 444 virtual void ProvisionalChangeToMainFrameUrl(
446 const GURL& url, 445 const GURL& url,
447 content::RenderViewHost* render_view_host) OVERRIDE; 446 content::RenderViewHost* render_view_host) OVERRIDE;
448 virtual void DidCommitProvisionalLoadForFrame( 447 virtual void DidCommitProvisionalLoadForFrame(
449 int64 frame_id, 448 int64 frame_id,
450 const string16& frame_unique_name, 449 const string16& frame_unique_name,
451 bool is_main_frame, 450 bool is_main_frame,
452 const GURL& validated_url, 451 const GURL& validated_url,
453 content::PageTransition transition_type, 452 content::PageTransition transition_type,
454 content::RenderViewHost* render_view_host) OVERRIDE; 453 content::RenderViewHost* render_view_host) OVERRIDE;
455 virtual void RenderViewCreated( 454 virtual void RenderViewCreated(
456 content::RenderViewHost* render_view_host) OVERRIDE; 455 content::RenderViewHost* render_view_host) OVERRIDE;
457 virtual void DidFailProvisionalLoad( 456 virtual void DidFailProvisionalLoad(
458 int64 frame_id, 457 int64 frame_id,
459 const string16& frame_unique_name, 458 const string16& frame_unique_name,
460 bool is_main_frame, 459 bool is_main_frame,
461 const GURL& validated_url, 460 const GURL& validated_url,
462 int error_code, 461 int error_code,
463 const string16& error_description, 462 const string16& error_description,
464 content::RenderViewHost* render_view_host) OVERRIDE; 463 content::RenderViewHost* render_view_host) OVERRIDE;
465 virtual void WebContentsDestroyed(content::WebContents* web_contents) 464 virtual void WebContentsDestroyed(content::WebContents* web_contents)
466 OVERRIDE; 465 OVERRIDE;
467 466
468 base::TimeDelta GetElapsedTime(); 467 private:
469 void SwapSuccessful(); 468 void RecordEvent(PrerenderEvent event) const;
470 const GURL& url() const { return url_; }
471 content::WebContents* target_contents() const { return target_contents_; }
472 469
473 private: 470 void OnMergeCompleted(content::SessionStorageNamespace::MergeResult result);
474 PrerenderTracker* prerender_tracker_; 471 void OnMergeTimeout();
472
473 PrerenderManager* manager_;
475 content::WebContents* target_contents_; 474 content::WebContents* target_contents_;
476 PrerenderData* prerender_data_; 475 PrerenderData* prerender_data_;
477 GURL url_; 476 GURL url_;
478 base::CancelableClosure timeout_cb_;
479 base::CancelableCallback<
480 void(content::SessionStorageNamespace::MergeResult)> merge_result_cb_;
481 base::TimeTicks start_time_; 477 base::TimeTicks start_time_;
482 std::vector<PrerenderTracker::ChildRouteIdPair> rvh_ids_; 478 std::vector<PrerenderTracker::ChildRouteIdPair> rvh_ids_;
479 base::OneShotTimer<PendingSwap> merge_timeout_;
480 bool swap_successful_;
481
482 base::WeakPtrFactory<PendingSwap> weak_factory_;
483 }; 483 };
484 484
485 void SetPrerenderContentsFactory( 485 void SetPrerenderContentsFactory(
486 PrerenderContents::Factory* prerender_contents_factory); 486 PrerenderContents::Factory* prerender_contents_factory);
487 487
488 // Adds prerenders from the pending Prerenders, called by 488 // Adds prerenders from the pending Prerenders, called by
489 // PrerenderContents::StartPendingPrerenders. 489 // PrerenderContents::StartPendingPrerenders.
490 void StartPendingPrerenders( 490 void StartPendingPrerenders(
491 int process_id, 491 int process_id,
492 ScopedVector<PrerenderContents::PendingPrerenderInfo>* pending_prerenders, 492 ScopedVector<PrerenderContents::PendingPrerenderInfo>* pending_prerenders,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 649
650 // Returns whether prerendering is currently enabled for this manager. 650 // Returns whether prerendering is currently enabled for this manager.
651 // Must be called on the UI thread. 651 // Must be called on the UI thread.
652 bool IsEnabled() const; 652 bool IsEnabled() const;
653 653
654 void CookieChanged(ChromeCookieDetails* details); 654 void CookieChanged(ChromeCookieDetails* details);
655 void CookieChangedAnyCookiesLeftLookupResult(const std::string& domain_key, 655 void CookieChangedAnyCookiesLeftLookupResult(const std::string& domain_key,
656 bool cookies_exist); 656 bool cookies_exist);
657 void LoggedInPredictorDataReceived(scoped_ptr<LoggedInStateMap> new_map); 657 void LoggedInPredictorDataReceived(scoped_ptr<LoggedInStateMap> new_map);
658 658
659 void ProcessMergeResult(PrerenderData* prerender_data,
660 bool timed_out,
661 content::SessionStorageNamespace::MergeResult result);
662
663 void RecordEvent(PrerenderContents* contents, PrerenderEvent event) const; 659 void RecordEvent(PrerenderContents* contents, PrerenderEvent event) const;
664 660
665 // Swaps a prerender for |url| into the tab, replacing |web_contents|. 661 // 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 662 // |web_contents|. Returns the new WebContents that was swapped in, or NULL
667 // was not possible. Optionally, a |swap_candidate| can be specified. 663 // 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, 664 content::WebContents* SwapInternal(const GURL& url,
674 content::WebContents* web_contents, 665 content::WebContents* web_contents,
675 PrerenderData* swap_candidate); 666 PrerenderData* prerender_data);
676 667
677 // The configuration. 668 // The configuration.
678 Config config_; 669 Config config_;
679 670
680 // Specifies whether prerendering is currently enabled for this 671 // Specifies whether prerendering is currently enabled for this
681 // manager. The value can change dynamically during the lifetime 672 // manager. The value can change dynamically during the lifetime
682 // of the PrerenderManager. 673 // of the PrerenderManager.
683 bool enabled_; 674 bool enabled_;
684 675
685 static bool is_prefetch_enabled_; 676 static bool is_prefetch_enabled_;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 750
760 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 751 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
761 }; 752 };
762 753
763 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( 754 PrerenderManager* FindPrerenderManagerUsingRenderProcessId(
764 int render_process_id); 755 int render_process_id);
765 756
766 } // namespace prerender 757 } // namespace prerender
767 758
768 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 759 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_events.h ('k') | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698