#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
+#include "base/task/cancelable_task_tracker.h"
#include "base/threading/non_thread_safe.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/session_storage_namespace.h"
#include "content/public/browser/web_contents_observer.h"
#include "net/cookies/canonical_cookie.h"
namespace prerender {
-class PrerenderCondition;
class PrerenderHandle;
class PrerenderHistory;
class PrerenderLocalPredictor;
class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
public base::NonThreadSafe,
public content::NotificationObserver,
+ public content::RenderProcessHostObserver,
public KeyedService,
public MediaCaptureDevicesDispatcher::Observer {
public:
PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP = 5,
PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP = 6,
PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP = 7,
+ PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP = 8,
PRERENDER_MODE_MAX
};
double fraction_plt_elapsed_at_swap_in,
const GURL& url);
- // Set whether prerendering is currently enabled for this manager.
- // Must be called on the UI thread.
- // If |enabled| is false, existing prerendered pages will still persist until
- // they time out, but new ones will not be generated.
- void set_enabled(bool enabled);
-
static PrerenderManagerMode GetMode();
static void SetMode(PrerenderManagerMode mode);
static const char* GetModeString();
PrerenderTracker* prerender_tracker() { return prerender_tracker_; }
- // Adds a condition. This is owned by the PrerenderManager.
- void AddCondition(const PrerenderCondition* condition);
+ bool cookie_store_loaded() { return cookie_store_loaded_; }
// Records that some visible tab navigated (or was redirected) to the
// provided URL.
void OnHistoryServiceDidQueryURL(Origin origin,
uint8 experiment_id,
- CancelableRequestProvider::Handle handle,
bool success,
- const history::URLRow* url_row,
- history::VisitVector* visits);
+ const history::URLRow& url_row,
+ const history::VisitVector& visits);
Profile* profile() const { return profile_; }
// Notification that a prerender has completed and its bytes should be
// recorded.
- void RecordNetworkBytes(bool used, int64 prerender_bytes);
+ void RecordNetworkBytes(Origin origin, bool used, int64 prerender_bytes);
+
+ // Returns whether prerendering is currently enabled for this manager.
+ bool IsEnabled() const;
// Add to the running tally of bytes transferred over the network for this
// profile if prerendering is currently enabled.
void AddProfileNetworkBytesIfEnabled(int64 bytes);
+ // Registers a new ProcessHost performing a prerender. Called by
+ // PrerenderContents.
+ void AddPrerenderProcessHost(content::RenderProcessHost* process_host);
+
+ // Returns whether or not |process_host| may be reused for new navigations
+ // from a prerendering perspective. Currently, if Prerender Cookie Stores are
+ // enabled, prerenders must be in their own processes that may not be shared.
+ bool MayReuseProcessHost(content::RenderProcessHost* process_host);
+
+ // content::RenderProcessHostObserver implementation.
+ virtual void RenderProcessHostDestroyed(
+ content::RenderProcessHost* host) OVERRIDE;
+
+ // To be called once the cookie store for this profile has been loaded.
+ void OnCookieStoreLoaded();
+
+ // For testing purposes. Issues a callback once the cookie store has been
+ // loaded.
+ void set_on_cookie_store_loaded_cb_for_testing(base::Closure cb) {
+ on_cookie_store_loaded_cb_for_testing_ = cb;
+ }
+
protected:
class PendingSwap;
class PrerenderData : public base::SupportsWeakPtr<PrerenderData> {
bool should_replace_current_entry);
virtual ~PendingSwap();
- content::WebContents* target_contents() const;
void set_swap_successful(bool swap_successful) {
swap_successful_ = swap_successful;
}
// content::WebContentsObserver implementation.
virtual void AboutToNavigateRenderView(
content::RenderViewHost* render_view_host) OVERRIDE;
- virtual void ProvisionalChangeToMainFrameUrl(
- const GURL& url,
- content::RenderFrameHost* render_frame_host) OVERRIDE;
+ virtual void DidStartProvisionalLoadForFrame(
+ content::RenderFrameHost* render_frame_host,
+ const GURL& validated_url,
+ bool is_error_page,
+ bool is_iframe_srcdoc) OVERRIDE;
virtual void DidCommitProvisionalLoadForFrame(
- int64 frame_id,
- const base::string16& frame_unique_name,
- bool is_main_frame,
+ content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
- content::PageTransition transition_type,
- content::RenderViewHost* render_view_host) OVERRIDE;
+ ui::PageTransition transition_type) OVERRIDE;
virtual void DidFailProvisionalLoad(
- int64 frame_id,
- const base::string16& frame_unique_name,
- bool is_main_frame,
+ content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
- const base::string16& error_description,
- content::RenderViewHost* render_view_host) OVERRIDE;
- virtual void WebContentsDestroyed(content::WebContents* web_contents)
- OVERRIDE;
+ const base::string16& error_description) OVERRIDE;
+ virtual void WebContentsDestroyed() OVERRIDE;
private:
void RecordEvent(PrerenderEvent event) const;
// shorten the TTL of the prerendered page.
void SourceNavigatedAway(PrerenderData* prerender_data);
+ // Gets the request context for the profile.
+ // For unit tests, this will be overriden to return NULL, since it is not
+ // needed.
+ virtual net::URLRequestContextGetter* GetURLRequestContext();
+
private:
friend class ::InstantSearchPrerendererTest;
friend class PrerenderBrowserTest;
void DestroyAndMarkMatchCompleteAsUsed(PrerenderContents* prerender_contents,
FinalStatus final_status);
- // Record a final status of a prerendered page in a histogram.
+ // Records the final status a prerender in the case that a PrerenderContents
+ // was never created, and also adds a PrerenderHistory entry.
// This is a helper function which will ultimately call
// RecordFinalStatusWthMatchCompleteStatus, using MATCH_COMPLETE_DEFAULT.
- void RecordFinalStatus(Origin origin,
- uint8 experiment_id,
- FinalStatus final_status) const;
+ void RecordFinalStatusWithoutCreatingPrerenderContents(
+ const GURL& url, Origin origin, uint8 experiment_id,
+ FinalStatus final_status) const;
- // Returns whether prerendering is currently enabled for this manager.
- // Must be called on the UI thread.
- bool IsEnabled() const;
void CookieChanged(ChromeCookieDetails* details);
void CookieChangedAnyCookiesLeftLookupResult(const std::string& domain_key,
// The configuration.
Config config_;
- // Specifies whether prerendering is currently enabled for this
- // manager. The value can change dynamically during the lifetime
- // of the PrerenderManager.
- bool enabled_;
-
// The profile that owns this PrerenderManager.
Profile* profile_;
scoped_ptr<PrerenderHistory> prerender_history_;
- std::list<const PrerenderCondition*> prerender_conditions_;
-
scoped_ptr<PrerenderHistograms> histograms_;
scoped_ptr<PrerenderLocalPredictor> local_predictor_;
content::NotificationRegistrar notification_registrar_;
- CancelableRequestConsumer query_url_consumer_;
+ base::CancelableTaskTracker query_url_tracker_;
// The number of bytes transferred over the network for the profile this
// PrerenderManager is attached to.
// The value of profile_network_bytes_ that was last recorded.
int64 last_recorded_profile_network_bytes_;
+ // Set of process hosts being prerendered.
+ typedef std::set<content::RenderProcessHost*> PrerenderProcessSet;
+ PrerenderProcessSet prerender_process_hosts_;
+
+ // Indicates whether the cookie store for this profile has fully loaded yet.
+ bool cookie_store_loaded_;
+
+ base::Closure on_cookie_store_loaded_cb_for_testing_;
+
DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
};