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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/task/cancelable_task_tracker.h"
19 #include "base/threading/non_thread_safe.h"
20 #include "base/time/time.h"
21 #include "base/timer/timer.h"
22 #include "chrome/browser/history/history_service.h"
23 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
24 #include "chrome/browser/predictors/logged_in_predictor_table.h"
25 #include "chrome/browser/prerender/prerender_config.h"
26 #include "chrome/browser/prerender/prerender_contents.h"
27 #include "chrome/browser/prerender/prerender_events.h"
28 #include "chrome/browser/prerender/prerender_final_status.h"
29 #include "chrome/browser/prerender/prerender_histograms.h"
30 #include "chrome/browser/prerender/prerender_origin.h"
31 #include "chrome/browser/prerender/prerender_tracker.h"
32 #include "components/keyed_service/core/keyed_service.h"
33 #include "content/public/browser/notification_observer.h"
34 #include "content/public/browser/notification_registrar.h"
35 #include "content/public/browser/render_process_host_observer.h"
36 #include "content/public/browser/session_storage_namespace.h"
37 #include "content/public/browser/web_contents_observer.h"
38 #include "net/cookies/canonical_cookie.h"
39 #include "net/cookies/cookie_monster.h"
43 class InstantSearchPrerendererTest
;
44 struct ChromeCookieDetails
;
47 class DictionaryValue
;
51 struct NavigateParams
;
63 class URLRequestContextGetter
;
68 class PrerenderCondition
;
69 class PrerenderHandle
;
70 class PrerenderHistory
;
71 class PrerenderLocalPredictor
;
73 // PrerenderManager is responsible for initiating and keeping prerendered
74 // views of web pages. All methods must be called on the UI thread unless
75 // indicated otherwise.
76 class PrerenderManager
: public base::SupportsWeakPtr
<PrerenderManager
>,
77 public base::NonThreadSafe
,
78 public content::NotificationObserver
,
79 public content::RenderProcessHostObserver
,
81 public MediaCaptureDevicesDispatcher::Observer
{
83 // NOTE: New values need to be appended, since they are used in histograms.
84 enum PrerenderManagerMode
{
85 PRERENDER_MODE_DISABLED
= 0,
86 PRERENDER_MODE_ENABLED
= 1,
87 PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP
= 2,
88 PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP
= 3,
89 // Obsolete: PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP = 4,
90 PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP
= 5,
91 PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP
= 6,
92 PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP
= 7,
96 // One or more of these flags must be passed to ClearData() to specify just
97 // what data to clear. See function declaration for more information.
99 CLEAR_PRERENDER_CONTENTS
= 0x1 << 0,
100 CLEAR_PRERENDER_HISTORY
= 0x1 << 1,
104 typedef predictors::LoggedInPredictorTable::LoggedInStateMap LoggedInStateMap
;
106 // ID indicating that no experiment is active.
107 static const uint8 kNoExperiment
= 0;
109 // Owned by a Profile object for the lifetime of the profile.
110 PrerenderManager(Profile
* profile
, PrerenderTracker
* prerender_tracker
);
112 virtual ~PrerenderManager();
114 // From KeyedService:
115 virtual void Shutdown() OVERRIDE
;
117 // Entry points for adding prerenders.
119 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify
120 // the RenderView that the prerender request came from. If |size| is empty, a
121 // default from the PrerenderConfig is used. Returns a caller-owned
122 // PrerenderHandle* if the URL was added, NULL if it was not. If the launching
123 // RenderView is itself prerendering, the prerender is added as a pending
125 PrerenderHandle
* AddPrerenderFromLinkRelPrerender(
130 const content::Referrer
& referrer
,
131 const gfx::Size
& size
);
133 // Adds a prerender for |url| if valid. As the prerender request is coming
134 // from a source without a RenderViewHost (i.e., the omnibox) we don't have a
135 // child or route id, or a referrer. This method uses sensible values for
136 // those. The |session_storage_namespace| matches the namespace of the active
137 // tab at the time the prerender is generated from the omnibox. Returns a
138 // caller-owned PrerenderHandle*, or NULL.
139 PrerenderHandle
* AddPrerenderFromOmnibox(
141 content::SessionStorageNamespace
* session_storage_namespace
,
142 const gfx::Size
& size
);
144 PrerenderHandle
* AddPrerenderFromLocalPredictor(
146 content::SessionStorageNamespace
* session_storage_namespace
,
147 const gfx::Size
& size
);
149 PrerenderHandle
* AddPrerenderFromExternalRequest(
151 const content::Referrer
& referrer
,
152 content::SessionStorageNamespace
* session_storage_namespace
,
153 const gfx::Size
& size
);
155 // Adds a prerender for Instant Search |url| if valid. The
156 // |session_storage_namespace| matches the namespace of the active tab at the
157 // time the prerender is generated. Returns a caller-owned PrerenderHandle* or
159 PrerenderHandle
* AddPrerenderForInstant(
161 content::SessionStorageNamespace
* session_storage_namespace
,
162 const gfx::Size
& size
);
164 // Cancels all active prerenders.
165 void CancelAllPrerenders();
167 // If |url| matches a valid prerendered page and |params| are compatible, try
168 // to swap it and merge browsing histories. Returns |true| and updates
169 // |params->target_contents| if a prerendered page is swapped in, |false|
171 bool MaybeUsePrerenderedPage(const GURL
& url
,
172 chrome::NavigateParams
* params
);
174 // Moves a PrerenderContents to the pending delete list from the list of
175 // active prerenders when prerendering should be cancelled.
176 virtual void MoveEntryToPendingDelete(PrerenderContents
* entry
,
177 FinalStatus final_status
);
179 // Records the page load time for a prerender that wasn't swapped in.
180 void RecordPageLoadTimeNotSwappedIn(Origin origin
,
181 base::TimeDelta page_load_time
,
184 // Records the perceived page load time for a page - effectively the time from
185 // when the user navigates to a page to when it finishes loading. The actual
186 // load may have started prior to navigation due to prerender hints.
187 // This must be called on the UI thread.
188 // |fraction_plt_elapsed_at_swap_in| must either be in [0.0, 1.0], or a value
189 // outside that range indicating that it doesn't apply.
190 void RecordPerceivedPageLoadTime(
192 NavigationType navigation_type
,
193 base::TimeDelta perceived_page_load_time
,
194 double fraction_plt_elapsed_at_swap_in
,
197 // Set whether prerendering is currently enabled for this manager.
198 // Must be called on the UI thread.
199 // If |enabled| is false, existing prerendered pages will still persist until
200 // they time out, but new ones will not be generated.
201 void set_enabled(bool enabled
);
203 static PrerenderManagerMode
GetMode();
204 static void SetMode(PrerenderManagerMode mode
);
205 static const char* GetModeString();
206 static bool IsPrerenderingPossible();
207 static bool ActuallyPrerendering();
208 static bool IsControlGroup(uint8 experiment_id
);
209 static bool IsNoUseGroup();
211 // Query the list of current prerender pages to see if the given web contents
212 // is prerendering a page. The optional parameter |origin| is an output
213 // parameter which, if a prerender is found, is set to the Origin of the
214 // prerender |web_contents|.
215 bool IsWebContentsPrerendering(const content::WebContents
* web_contents
,
216 Origin
* origin
) const;
218 // Whether the PrerenderManager has an active prerender with the given url and
219 // SessionStorageNamespace associated with the given WebContens.
220 bool HasPrerenderedUrl(GURL url
, content::WebContents
* web_contents
) const;
222 // Returns the PrerenderContents object for the given web_contents, otherwise
223 // returns NULL. Note that the PrerenderContents may have been Destroy()ed,
224 // but not yet deleted.
225 PrerenderContents
* GetPrerenderContents(
226 const content::WebContents
* web_contents
) const;
228 // Returns the PrerenderContents object for a given child_id, route_id pair,
229 // otherwise returns NULL. Note that the PrerenderContents may have been
230 // Destroy()ed, but not yet deleted.
231 virtual PrerenderContents
* GetPrerenderContentsForRoute(
232 int child_id
, int route_id
) const;
234 // Returns a list of all WebContents being prerendered.
235 const std::vector
<content::WebContents
*> GetAllPrerenderingContents() const;
237 // Checks whether |url| has been recently navigated to.
238 bool HasRecentlyBeenNavigatedTo(Origin origin
, const GURL
& url
);
240 // Returns true iff the method given is valid for prerendering.
241 static bool IsValidHttpMethod(const std::string
& method
);
243 // Returns true iff the scheme of the URL given is valid for prerendering.
244 static bool DoesURLHaveValidScheme(const GURL
& url
);
246 // Returns true iff the scheme of the subresource URL given is valid for
248 static bool DoesSubresourceURLHaveValidScheme(const GURL
& url
);
250 // Returns a Value object containing the active pages being prerendered, and
251 // a history of pages which were prerendered. The caller is responsible for
252 // deleting the return value.
253 base::DictionaryValue
* GetAsValue() const;
255 // Clears the data indicated by which bits of clear_flags are set.
257 // If the CLEAR_PRERENDER_CONTENTS bit is set, all active prerenders are
258 // cancelled and then deleted, and any WebContents queued for destruction are
259 // destroyed as well.
261 // If the CLEAR_PRERENDER_HISTORY bit is set, the prerender history is
262 // cleared, including any entries newly created by destroying them in
263 // response to the CLEAR_PRERENDER_CONTENTS flag.
265 // Intended to be used when clearing the cache or history.
266 void ClearData(int clear_flags
);
268 // Record a final status of a prerendered page in a histogram.
269 // This variation allows specifying whether prerendering had been started
270 // (necessary to flag MatchComplete dummies).
271 void RecordFinalStatusWithMatchCompleteStatus(
274 PrerenderContents::MatchCompleteStatus mc_status
,
275 FinalStatus final_status
) const;
277 // Record a cookie status histogram (see prerender_histograms.h).
278 void RecordCookieStatus(Origin origin
,
280 int cookie_status
) const;
282 // Record a cookie send type histogram (see prerender_histograms.h).
283 void RecordCookieSendType(Origin origin
,
285 int cookie_send_type
) const;
287 // content::NotificationObserver
288 virtual void Observe(int type
,
289 const content::NotificationSource
& source
,
290 const content::NotificationDetails
& details
) OVERRIDE
;
292 // MediaCaptureDevicesDispatcher::Observer
293 virtual void OnCreatingAudioStream(int render_process_id
,
294 int render_frame_id
) OVERRIDE
;
296 const Config
& config() const { return config_
; }
297 Config
& mutable_config() { return config_
; }
299 PrerenderTracker
* prerender_tracker() { return prerender_tracker_
; }
301 bool cookie_store_loaded() { return cookie_store_loaded_
; }
303 // Adds a condition. This is owned by the PrerenderManager.
304 void AddCondition(const PrerenderCondition
* condition
);
306 // Records that some visible tab navigated (or was redirected) to the
308 void RecordNavigation(const GURL
& url
);
310 // Updates the LoggedInPredictor state to reflect that a login has likely
311 // on the URL provided.
312 void RecordLikelyLoginOnURL(const GURL
& url
);
314 // Checks if the LoggedInPredictor shows that the user is likely logged on
315 // to the site for the URL provided.
316 void CheckIfLikelyLoggedInOnURL(const GURL
& url
,
318 bool* database_was_present
,
319 const base::Closure
& result_cb
);
321 void OnHistoryServiceDidQueryURL(Origin origin
,
324 const history::URLRow
& url_row
,
325 const history::VisitVector
& visits
);
327 Profile
* profile() const { return profile_
; }
329 // Classes which will be tested in prerender unit browser tests should use
330 // these methods to get times for comparison, so that the test framework can
331 // mock advancing/retarding time.
332 virtual base::Time
GetCurrentTime() const;
333 virtual base::TimeTicks
GetCurrentTimeTicks() const;
335 scoped_refptr
<predictors::LoggedInPredictorTable
>
336 logged_in_predictor_table() {
337 return logged_in_predictor_table_
;
340 PrerenderLocalPredictor
* local_predictor() {
341 return local_predictor_
.get();
344 // Notification that a cookie event happened on a render frame. Will record a
345 // cookie event for a given render frame, if it is being prerendered.
346 // If cookies were sent, all cookies must be supplied in |cookie_list|.
347 static void RecordCookieEvent(int process_id
,
350 const GURL
& frame_url
,
351 bool is_for_blocking_resource
,
352 PrerenderContents::CookieEvent event
,
353 const net::CookieList
* cookie_list
);
355 // Arranges for all session storage merges to hang indefinitely. This is used
356 // to reliably test various swap abort cases.
357 static void HangSessionStorageMergesForTesting();
359 // Notification that a prerender has completed and its bytes should be
361 void RecordNetworkBytes(Origin origin
, bool used
, int64 prerender_bytes
);
363 // Returns whether prerendering is currently enabled for this manager.
364 bool IsEnabled() const;
366 // Add to the running tally of bytes transferred over the network for this
367 // profile if prerendering is currently enabled.
368 void AddProfileNetworkBytesIfEnabled(int64 bytes
);
370 // Registers a new ProcessHost performing a prerender. Called by
371 // PrerenderContents.
372 void AddPrerenderProcessHost(content::RenderProcessHost
* process_host
);
374 // Returns whether or not |process_host| may be reused for new navigations
375 // from a prerendering perspective. Currently, if Prerender Cookie Stores are
376 // enabled, prerenders must be in their own processes that may not be shared.
377 bool MayReuseProcessHost(content::RenderProcessHost
* process_host
);
379 // content::RenderProcessHostObserver implementation.
380 virtual void RenderProcessHostDestroyed(
381 content::RenderProcessHost
* host
) OVERRIDE
;
383 // To be called once the cookie store for this profile has been loaded.
384 void OnCookieStoreLoaded();
386 // For testing purposes. Issues a callback once the cookie store has been
388 void set_on_cookie_store_loaded_cb_for_testing(base::Closure cb
) {
389 on_cookie_store_loaded_cb_for_testing_
= cb
;
394 class PrerenderData
: public base::SupportsWeakPtr
<PrerenderData
> {
396 struct OrderByExpiryTime
;
398 PrerenderData(PrerenderManager
* manager
,
399 PrerenderContents
* contents
,
400 base::TimeTicks expiry_time
);
404 // Turn this PrerenderData into a Match Complete replacement for itself,
405 // placing the current prerender contents into |to_delete_prerenders_|.
406 void MakeIntoMatchCompleteReplacement();
408 // A new PrerenderHandle has been created for this PrerenderData.
409 void OnHandleCreated(PrerenderHandle
* prerender_handle
);
411 // The launcher associated with a handle is navigating away from the context
412 // that launched this prerender. If the prerender is active, it may stay
413 // alive briefly though, in case we we going through a redirect chain that
414 // will eventually land at it.
415 void OnHandleNavigatedAway(PrerenderHandle
* prerender_handle
);
417 // The launcher associated with a handle has taken explicit action to cancel
418 // this prerender. We may well destroy the prerender in this case if no
419 // other handles continue to track it.
420 void OnHandleCanceled(PrerenderHandle
* prerender_handle
);
422 PrerenderContents
* contents() { return contents_
.get(); }
424 PrerenderContents
* ReleaseContents();
426 int handle_count() const { return handle_count_
; }
428 base::TimeTicks
abandon_time() const { return abandon_time_
; }
430 base::TimeTicks
expiry_time() const { return expiry_time_
; }
431 void set_expiry_time(base::TimeTicks expiry_time
) {
432 expiry_time_
= expiry_time
;
435 void ClearPendingSwap();
437 PendingSwap
* pending_swap() { return pending_swap_
.get(); }
438 void set_pending_swap(PendingSwap
* pending_swap
) {
439 pending_swap_
.reset(pending_swap
);
443 PrerenderManager
* manager_
;
444 scoped_ptr
<PrerenderContents
> contents_
;
446 // The number of distinct PrerenderHandles created for |this|, including
447 // ones that have called PrerenderData::OnHandleNavigatedAway(), but not
448 // counting the ones that have called PrerenderData::OnHandleCanceled(). For
449 // pending prerenders, this will always be 1, since the PrerenderManager
450 // only merges handles of running prerenders.
453 // The time when OnHandleNavigatedAway was called.
454 base::TimeTicks abandon_time_
;
456 // After this time, this prerender is no longer fresh, and should be
458 base::TimeTicks expiry_time_
;
460 // If a session storage namespace merge is in progress for this object,
461 // we need to keep track of various state associated with it.
462 scoped_ptr
<PendingSwap
> pending_swap_
;
464 DISALLOW_COPY_AND_ASSIGN(PrerenderData
);
467 // When a swap can't happen immediately, due to a sesison storage namespace
468 // merge, there will be a pending swap object while the merge is in
469 // progress. It retains all the data needed to do the merge, maintains
470 // throttles for the navigation in the target WebContents that needs to be
471 // delayed, and handles all conditions which would cancel a pending swap.
472 class PendingSwap
: public content::WebContentsObserver
{
474 PendingSwap(PrerenderManager
* manager
,
475 content::WebContents
* target_contents
,
476 PrerenderData
* prerender_data
,
478 bool should_replace_current_entry
);
479 virtual ~PendingSwap();
481 content::WebContents
* target_contents() const;
482 void set_swap_successful(bool swap_successful
) {
483 swap_successful_
= swap_successful
;
488 // content::WebContentsObserver implementation.
489 virtual void AboutToNavigateRenderView(
490 content::RenderViewHost
* render_view_host
) OVERRIDE
;
491 virtual void ProvisionalChangeToMainFrameUrl(
493 content::RenderFrameHost
* render_frame_host
) OVERRIDE
;
494 virtual void DidCommitProvisionalLoadForFrame(
495 content::RenderFrameHost
* render_frame_host
,
496 const GURL
& validated_url
,
497 content::PageTransition transition_type
) OVERRIDE
;
498 virtual void DidFailProvisionalLoad(
499 content::RenderFrameHost
* render_frame_host
,
500 const GURL
& validated_url
,
502 const base::string16
& error_description
) OVERRIDE
;
503 virtual void WebContentsDestroyed() OVERRIDE
;
506 void RecordEvent(PrerenderEvent event
) const;
508 void OnMergeCompleted(content::SessionStorageNamespace::MergeResult result
);
509 void OnMergeTimeout();
511 // Prerender parameters.
512 PrerenderManager
* manager_
;
513 PrerenderData
* prerender_data_
;
515 bool should_replace_current_entry_
;
517 base::TimeTicks start_time_
;
518 PrerenderTracker::ChildRouteIdPair target_route_id_
;
519 bool seen_target_route_id_
;
520 base::OneShotTimer
<PendingSwap
> merge_timeout_
;
521 bool swap_successful_
;
523 base::WeakPtrFactory
<PendingSwap
> weak_factory_
;
526 void SetPrerenderContentsFactory(
527 PrerenderContents::Factory
* prerender_contents_factory
);
529 // Called by a PrerenderData to signal that the launcher has navigated away
530 // from the context that launched the prerender. A user may have clicked
531 // a link in a page containing a <link rel=prerender> element, or the user
532 // might have committed an omnibox navigation. This is used to possibly
533 // shorten the TTL of the prerendered page.
534 void SourceNavigatedAway(PrerenderData
* prerender_data
);
536 // Gets the request context for the profile.
537 // For unit tests, this will be overriden to return NULL, since it is not
539 virtual net::URLRequestContextGetter
* GetURLRequestContext();
542 friend class ::InstantSearchPrerendererTest
;
543 friend class PrerenderBrowserTest
;
544 friend class PrerenderContents
;
545 friend class PrerenderHandle
;
546 friend class UnitTestPrerenderManager
;
548 class OnCloseWebContentsDeleter
;
549 struct NavigationRecord
;
551 // Time interval before a new prerender is allowed.
552 static const int kMinTimeBetweenPrerendersMs
= 500;
554 // Time window for which we record old navigations, in milliseconds.
555 static const int kNavigationRecordWindowMs
= 5000;
557 void OnCancelPrerenderHandle(PrerenderData
* prerender_data
);
559 // Adds a prerender for |url| from |referrer| initiated from the process
560 // |child_id|. The |origin| specifies how the prerender was added. If |size|
561 // is empty, then PrerenderContents::StartPrerendering will instead use a
562 // default from PrerenderConfig. Returns a PrerenderHandle*, owned by the
564 PrerenderHandle
* AddPrerender(
568 const content::Referrer
& referrer
,
569 const gfx::Size
& size
,
570 content::SessionStorageNamespace
* session_storage_namespace
);
572 void StartSchedulingPeriodicCleanups();
573 void StopSchedulingPeriodicCleanups();
575 void EvictOldestPrerendersIfNecessary();
577 // Deletes stale and cancelled prerendered PrerenderContents, as well as
578 // WebContents that have been replaced by prerendered WebContents.
579 // Also identifies and kills PrerenderContents that use too much
581 void PeriodicCleanup();
583 // Posts a task to call PeriodicCleanup. Results in quicker destruction of
584 // objects. If |this| is deleted before the task is run, the task will
585 // automatically be cancelled.
586 void PostCleanupTask();
588 base::TimeTicks
GetExpiryTimeForNewPrerender(Origin origin
) const;
589 base::TimeTicks
GetExpiryTimeForNavigatedAwayPrerender() const;
591 void DeleteOldEntries();
592 virtual PrerenderContents
* CreatePrerenderContents(
594 const content::Referrer
& referrer
,
596 uint8 experiment_id
);
598 // Insures the |active_prerenders_| are sorted by increasing expiry time. Call
599 // after every mutation of active_prerenders_ that can possibly make it
600 // unsorted (e.g. an insert, or changing an expiry time).
601 void SortActivePrerenders();
603 // Finds the active PrerenderData object for a running prerender matching
604 // |url| and |session_storage_namespace|.
605 PrerenderData
* FindPrerenderData(
607 const content::SessionStorageNamespace
* session_storage_namespace
);
609 // Finds the active PrerenderData object currently in a PendingSwap for
610 // |target_contents|. Otherwise, returns NULL.
611 PrerenderData
* FindPrerenderDataForTargetContents(
612 content::WebContents
* target_contents
);
614 // Given the |prerender_contents|, find the iterator in active_prerenders_
615 // correponding to the given prerender.
616 ScopedVector
<PrerenderData
>::iterator
617 FindIteratorForPrerenderContents(PrerenderContents
* prerender_contents
);
619 bool DoesRateLimitAllowPrerender(Origin origin
) const;
621 // Deletes old WebContents that have been replaced by prerendered ones. This
622 // is needed because they're replaced in a callback from the old WebContents,
623 // so cannot immediately be deleted.
624 void DeleteOldWebContents();
626 // Cleans up old NavigationRecord's.
627 void CleanUpOldNavigations();
629 // Arrange for the given WebContents to be deleted asap. If deleter is not
630 // NULL, deletes that as well.
631 void ScheduleDeleteOldWebContents(content::WebContents
* tab
,
632 OnCloseWebContentsDeleter
* deleter
);
634 // Adds to the history list.
635 void AddToHistory(PrerenderContents
* contents
);
637 // Returns a new Value representing the pages currently being prerendered. The
638 // caller is responsible for delete'ing the return value.
639 base::Value
* GetActivePrerendersAsValue() const;
641 // Destroys all pending prerenders using FinalStatus. Also deletes them as
642 // well as any swapped out WebContents queued for destruction.
643 // Used both on destruction, and when clearing the browsing history.
644 void DestroyAllContents(FinalStatus final_status
);
646 // Helper function to destroy a PrerenderContents with the specified
647 // final_status, while at the same time recording that for the MatchComplete
648 // case, that this prerender would have been used.
649 void DestroyAndMarkMatchCompleteAsUsed(PrerenderContents
* prerender_contents
,
650 FinalStatus final_status
);
652 // Records the final status a prerender in the case that a PrerenderContents
653 // was never created, and also adds a PrerenderHistory entry.
654 // This is a helper function which will ultimately call
655 // RecordFinalStatusWthMatchCompleteStatus, using MATCH_COMPLETE_DEFAULT.
656 void RecordFinalStatusWithoutCreatingPrerenderContents(
657 const GURL
& url
, Origin origin
, uint8 experiment_id
,
658 FinalStatus final_status
) const;
661 void CookieChanged(ChromeCookieDetails
* details
);
662 void CookieChangedAnyCookiesLeftLookupResult(const std::string
& domain_key
,
664 void LoggedInPredictorDataReceived(scoped_ptr
<LoggedInStateMap
> new_map
);
666 void RecordEvent(PrerenderContents
* contents
, PrerenderEvent event
) const;
668 // Swaps a prerender |prerender_data| for |url| into the tab, replacing
669 // |web_contents|. Returns the new WebContents that was swapped in, or NULL
670 // if a swap-in was not possible. If |should_replace_current_entry| is true,
671 // the current history entry in |web_contents| is replaced.
672 content::WebContents
* SwapInternal(const GURL
& url
,
673 content::WebContents
* web_contents
,
674 PrerenderData
* prerender_data
,
675 bool should_replace_current_entry
);
677 // The configuration.
680 // Specifies whether prerendering is currently enabled for this
681 // manager. The value can change dynamically during the lifetime
682 // of the PrerenderManager.
685 // The profile that owns this PrerenderManager.
688 PrerenderTracker
* prerender_tracker_
;
690 // All running prerenders. Sorted by expiry time, in ascending order.
691 ScopedVector
<PrerenderData
> active_prerenders_
;
693 // Prerenders awaiting deletion.
694 ScopedVector
<PrerenderData
> to_delete_prerenders_
;
696 // List of recent navigations in this profile, sorted by ascending
698 std::list
<NavigationRecord
> navigations_
;
700 scoped_ptr
<PrerenderContents::Factory
> prerender_contents_factory_
;
702 static PrerenderManagerMode mode_
;
704 // A count of how many prerenders we do per session. Initialized to 0 then
705 // incremented and emitted to a histogram on each successful prerender.
706 static int prerenders_per_session_count_
;
708 // RepeatingTimer to perform periodic cleanups of pending prerendered
710 base::RepeatingTimer
<PrerenderManager
> repeating_timer_
;
712 // Track time of last prerender to limit prerender spam.
713 base::TimeTicks last_prerender_start_time_
;
715 std::list
<content::WebContents
*> old_web_contents_list_
;
717 ScopedVector
<OnCloseWebContentsDeleter
> on_close_web_contents_deleters_
;
719 scoped_ptr
<PrerenderHistory
> prerender_history_
;
721 std::list
<const PrerenderCondition
*> prerender_conditions_
;
723 scoped_ptr
<PrerenderHistograms
> histograms_
;
725 scoped_ptr
<PrerenderLocalPredictor
> local_predictor_
;
727 scoped_refptr
<predictors::LoggedInPredictorTable
> logged_in_predictor_table_
;
729 // Here, we keep the logged in predictor state, but potentially a superset
730 // of its actual (database-backed) state, since we do not incorporate
731 // browser data deletion. We do not use this for actual lookups, but only
732 // to query cookie data for domains we know there was a login before.
733 // This is required to avoid a large number of cookie lookups on bulk
734 // deletion of cookies.
735 scoped_ptr
<LoggedInStateMap
> logged_in_state_
;
737 content::NotificationRegistrar notification_registrar_
;
739 base::CancelableTaskTracker query_url_tracker_
;
741 // The number of bytes transferred over the network for the profile this
742 // PrerenderManager is attached to.
743 int64 profile_network_bytes_
;
745 // The value of profile_network_bytes_ that was last recorded.
746 int64 last_recorded_profile_network_bytes_
;
748 // Set of process hosts being prerendered.
749 typedef std::set
<content::RenderProcessHost
*> PrerenderProcessSet
;
750 PrerenderProcessSet prerender_process_hosts_
;
752 // Indicates whether the cookie store for this profile has fully loaded yet.
753 bool cookie_store_loaded_
;
755 base::Closure on_cookie_store_loaded_cb_for_testing_
;
757 DISALLOW_COPY_AND_ASSIGN(PrerenderManager
);
760 } // namespace prerender
762 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_