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/containers/hash_tables.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/scoped_vector.h"
18 #include "base/memory/weak_ptr.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/media/media_capture_devices_dispatcher.h"
23 #include "chrome/browser/predictors/logged_in_predictor_table.h"
24 #include "chrome/browser/prerender/prerender_config.h"
25 #include "chrome/browser/prerender/prerender_contents.h"
26 #include "chrome/browser/prerender/prerender_events.h"
27 #include "chrome/browser/prerender/prerender_final_status.h"
28 #include "chrome/browser/prerender/prerender_origin.h"
29 #include "chrome/browser/prerender/prerender_tracker.h"
30 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
31 #include "content/public/browser/notification_observer.h"
32 #include "content/public/browser/notification_registrar.h"
33 #include "content/public/browser/session_storage_namespace.h"
34 #include "content/public/browser/web_contents_observer.h"
35 #include "net/cookies/canonical_cookie.h"
36 #include "net/cookies/cookie_monster.h"
40 class InstantSearchPrerendererTest
;
41 struct ChromeCookieDetails
;
44 class DictionaryValue
;
48 struct NavigateParams
;
60 class URLRequestContextGetter
;
63 #if defined(COMPILER_GCC)
65 namespace BASE_HASH_NAMESPACE
{
67 struct hash
<content::WebContents
*> {
68 std::size_t operator()(content::WebContents
* value
) const {
69 return reinterpret_cast<std::size_t>(value
);
73 } // namespace BASE_HASH_NAMESPACE
79 class PrerenderCondition
;
80 class PrerenderHandle
;
81 class PrerenderHistograms
;
82 class PrerenderHistory
;
83 class PrerenderLocalPredictor
;
85 // PrerenderManager is responsible for initiating and keeping prerendered
86 // views of web pages. All methods must be called on the UI thread unless
87 // indicated otherwise.
88 class PrerenderManager
: public base::SupportsWeakPtr
<PrerenderManager
>,
89 public base::NonThreadSafe
,
90 public content::NotificationObserver
,
91 public BrowserContextKeyedService
,
92 public MediaCaptureDevicesDispatcher::Observer
{
94 // NOTE: New values need to be appended, since they are used in histograms.
95 enum PrerenderManagerMode
{
96 PRERENDER_MODE_DISABLED
= 0,
97 PRERENDER_MODE_ENABLED
= 1,
98 PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP
= 2,
99 PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP
= 3,
100 // Obsolete: PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP = 4,
101 PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP
= 5,
102 PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP
= 6,
103 PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP
= 7,
107 // One or more of these flags must be passed to ClearData() to specify just
108 // what data to clear. See function declaration for more information.
110 CLEAR_PRERENDER_CONTENTS
= 0x1 << 0,
111 CLEAR_PRERENDER_HISTORY
= 0x1 << 1,
115 typedef predictors::LoggedInPredictorTable::LoggedInStateMap LoggedInStateMap
;
117 // ID indicating that no experiment is active.
118 static const uint8 kNoExperiment
= 0;
120 // Owned by a Profile object for the lifetime of the profile.
121 PrerenderManager(Profile
* profile
, PrerenderTracker
* prerender_tracker
);
123 virtual ~PrerenderManager();
125 // From BrowserContextKeyedService:
126 virtual void Shutdown() OVERRIDE
;
128 // Entry points for adding prerenders.
130 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify
131 // the RenderView that the prerender request came from. If |size| is empty, a
132 // default from the PrerenderConfig is used. Returns a caller-owned
133 // PrerenderHandle* if the URL was added, NULL if it was not. If the launching
134 // RenderView is itself prerendering, the prerender is added as a pending
136 PrerenderHandle
* AddPrerenderFromLinkRelPrerender(
140 const content::Referrer
& referrer
,
141 const gfx::Size
& size
);
143 // Adds a prerender for |url| if valid. As the prerender request is coming
144 // from a source without a RenderViewHost (i.e., the omnibox) we don't have a
145 // child or route id, or a referrer. This method uses sensible values for
146 // those. The |session_storage_namespace| matches the namespace of the active
147 // tab at the time the prerender is generated from the omnibox. Returns a
148 // caller-owned PrerenderHandle*, or NULL.
149 PrerenderHandle
* AddPrerenderFromOmnibox(
151 content::SessionStorageNamespace
* session_storage_namespace
,
152 const gfx::Size
& size
);
154 PrerenderHandle
* AddPrerenderFromLocalPredictor(
156 content::SessionStorageNamespace
* session_storage_namespace
,
157 const gfx::Size
& size
);
159 PrerenderHandle
* AddPrerenderFromExternalRequest(
161 const content::Referrer
& referrer
,
162 content::SessionStorageNamespace
* session_storage_namespace
,
163 const gfx::Size
& size
);
165 // Adds a prerender for Instant Search |url| if valid. The
166 // |session_storage_namespace| matches the namespace of the active tab at the
167 // time the prerender is generated. Returns a caller-owned PrerenderHandle* or
169 PrerenderHandle
* AddPrerenderForInstant(
171 content::SessionStorageNamespace
* session_storage_namespace
,
172 const gfx::Size
& size
);
174 // Cancels all active prerenders.
175 void CancelAllPrerenders();
177 // If |url| matches a valid prerendered page and |params| are compatible, try
178 // to swap it and merge browsing histories. Returns |true| and updates
179 // |params->target_contents| if a prerendered page is swapped in, |false|
181 bool MaybeUsePrerenderedPage(const GURL
& url
,
182 chrome::NavigateParams
* params
);
184 // Moves a PrerenderContents to the pending delete list from the list of
185 // active prerenders when prerendering should be cancelled.
186 virtual void MoveEntryToPendingDelete(PrerenderContents
* entry
,
187 FinalStatus final_status
);
189 // Records the perceived page load time for a page - effectively the time from
190 // when the user navigates to a page to when it finishes loading. The actual
191 // load may have started prior to navigation due to prerender hints.
192 // This must be called on the UI thread.
193 // |fraction_plt_elapsed_at_swap_in| must either be in [0.0, 1.0], or a value
194 // outside that range indicating that it doesn't apply.
195 static void RecordPerceivedPageLoadTime(
196 base::TimeDelta perceived_page_load_time
,
197 double fraction_plt_elapsed_at_swap_in
,
198 content::WebContents
* web_contents
,
201 // Set whether prerendering is currently enabled for this manager.
202 // Must be called on the UI thread.
203 // If |enabled| is false, existing prerendered pages will still persist until
204 // they time out, but new ones will not be generated.
205 void set_enabled(bool enabled
);
207 static PrerenderManagerMode
GetMode();
208 static void SetMode(PrerenderManagerMode mode
);
209 static const char* GetModeString();
210 static bool IsPrerenderingPossible();
211 static bool ActuallyPrerendering();
212 static bool IsControlGroup(uint8 experiment_id
);
213 static bool IsNoUseGroup();
215 // Query the list of current prerender pages to see if the given web contents
216 // is prerendering a page. The optional parameter |origin| is an output
217 // parameter which, if a prerender is found, is set to the Origin of the
218 // prerender |web_contents|.
219 bool IsWebContentsPrerendering(const content::WebContents
* web_contents
,
220 Origin
* origin
) const;
222 // Whether the PrerenderManager has an active prerender with the given url and
223 // SessionStorageNamespace associated with the given WebContens.
224 bool HasPrerenderedUrl(GURL url
, content::WebContents
* web_contents
) const;
226 // Returns the PrerenderContents object for the given web_contents, otherwise
227 // returns NULL. Note that the PrerenderContents may have been Destroy()ed,
228 // but not yet deleted.
229 PrerenderContents
* GetPrerenderContents(
230 const content::WebContents
* web_contents
) const;
232 // Returns a list of all WebContents being prerendered.
233 const std::vector
<content::WebContents
*> GetAllPrerenderingContents() const;
235 // Maintaining and querying the set of WebContents belonging to this
236 // PrerenderManager that are currently showing prerendered pages.
237 void MarkWebContentsAsPrerendered(content::WebContents
* web_contents
,
239 void MarkWebContentsAsWouldBePrerendered(content::WebContents
* web_contents
,
241 void MarkWebContentsAsNotPrerendered(content::WebContents
* web_contents
);
243 // Returns true if |web_contents| was originally a prerender that has since
244 // been swapped in. The optional parameter |origin| is an output parameter
245 // which, if a prerender is found, is set to the Origin of the prerender of
247 bool IsWebContentsPrerendered(content::WebContents
* web_contents
,
248 Origin
* origin
) const;
249 bool WouldWebContentsBePrerendered(content::WebContents
* web_contents
,
250 Origin
* origin
) const;
252 // Checks whether |url| has been recently navigated to.
253 bool HasRecentlyBeenNavigatedTo(Origin origin
, const GURL
& url
);
255 // Returns true iff the method given is valid for prerendering.
256 static bool IsValidHttpMethod(const std::string
& method
);
258 // Returns true iff the scheme of the URL given is valid for prerendering.
259 static bool DoesURLHaveValidScheme(const GURL
& url
);
261 // Returns true iff the scheme of the subresource URL given is valid for
263 static bool DoesSubresourceURLHaveValidScheme(const GURL
& url
);
265 // Returns a Value object containing the active pages being prerendered, and
266 // a history of pages which were prerendered. The caller is responsible for
267 // deleting the return value.
268 base::DictionaryValue
* GetAsValue() const;
270 // Clears the data indicated by which bits of clear_flags are set.
272 // If the CLEAR_PRERENDER_CONTENTS bit is set, all active prerenders are
273 // cancelled and then deleted, and any WebContents queued for destruction are
274 // destroyed as well.
276 // If the CLEAR_PRERENDER_HISTORY bit is set, the prerender history is
277 // cleared, including any entries newly created by destroying them in
278 // response to the CLEAR_PRERENDER_CONTENTS flag.
280 // Intended to be used when clearing the cache or history.
281 void ClearData(int clear_flags
);
283 // Record a final status of a prerendered page in a histogram.
284 // This variation allows specifying whether prerendering had been started
285 // (necessary to flag MatchComplete dummies).
286 void RecordFinalStatusWithMatchCompleteStatus(
289 PrerenderContents::MatchCompleteStatus mc_status
,
290 FinalStatus final_status
) const;
292 // Record a cookie status histogram (see prerender_histograms.h).
293 void RecordCookieStatus(Origin origin
,
295 int cookie_status
) const;
297 // content::NotificationObserver
298 virtual void Observe(int type
,
299 const content::NotificationSource
& source
,
300 const content::NotificationDetails
& details
) OVERRIDE
;
302 // MediaCaptureDevicesDispatcher::Observer
303 virtual void OnCreatingAudioStream(int render_process_id
,
304 int render_view_id
) OVERRIDE
;
306 const Config
& config() const { return config_
; }
307 Config
& mutable_config() { return config_
; }
309 PrerenderTracker
* prerender_tracker() { return prerender_tracker_
; }
311 // Adds a condition. This is owned by the PrerenderManager.
312 void AddCondition(const PrerenderCondition
* condition
);
314 // Records that some visible tab navigated (or was redirected) to the
316 void RecordNavigation(const GURL
& url
);
318 // Updates the LoggedInPredictor state to reflect that a login has likely
319 // on the URL provided.
320 void RecordLikelyLoginOnURL(const GURL
& url
);
322 // Checks if the LoggedInPredictor shows that the user is likely logged on
323 // to the site for the URL provided.
324 void CheckIfLikelyLoggedInOnURL(const GURL
& url
,
326 bool* database_was_present
,
327 const base::Closure
& result_cb
);
329 Profile
* profile() const { return profile_
; }
331 // Classes which will be tested in prerender unit browser tests should use
332 // these methods to get times for comparison, so that the test framework can
333 // mock advancing/retarding time.
334 virtual base::Time
GetCurrentTime() const;
335 virtual base::TimeTicks
GetCurrentTimeTicks() const;
337 scoped_refptr
<predictors::LoggedInPredictorTable
>
338 logged_in_predictor_table() {
339 return logged_in_predictor_table_
;
342 PrerenderLocalPredictor
* local_predictor() {
343 return local_predictor_
.get();
346 // Notification that a cookie event happened on a render frame. Will record a
347 // cookie event for a given render frame, if it is being prerendered.
348 // If cookies were sent, all cookies must be supplied in |cookie_list|.
349 static void RecordCookieEvent(int process_id
,
352 const GURL
& frame_url
,
353 PrerenderContents::CookieEvent event
,
354 const net::CookieList
* cookie_list
);
358 class PrerenderData
: public base::SupportsWeakPtr
<PrerenderData
> {
360 struct OrderByExpiryTime
;
362 PrerenderData(PrerenderManager
* manager
,
363 PrerenderContents
* contents
,
364 base::TimeTicks expiry_time
);
368 // Turn this PrerenderData into a Match Complete replacement for itself,
369 // placing the current prerender contents into |to_delete_prerenders_|.
370 void MakeIntoMatchCompleteReplacement();
372 // A new PrerenderHandle has been created for this PrerenderData.
373 void OnHandleCreated(PrerenderHandle
* prerender_handle
);
375 // The launcher associated with a handle is navigating away from the context
376 // that launched this prerender. If the prerender is active, it may stay
377 // alive briefly though, in case we we going through a redirect chain that
378 // will eventually land at it.
379 void OnHandleNavigatedAway(PrerenderHandle
* prerender_handle
);
381 // The launcher associated with a handle has taken explicit action to cancel
382 // this prerender. We may well destroy the prerender in this case if no
383 // other handles continue to track it.
384 void OnHandleCanceled(PrerenderHandle
* prerender_handle
);
386 PrerenderContents
* contents() { return contents_
.get(); }
388 PrerenderContents
* ReleaseContents();
390 int handle_count() const { return handle_count_
; }
392 base::TimeTicks
expiry_time() const { return expiry_time_
; }
393 void set_expiry_time(base::TimeTicks expiry_time
) {
394 expiry_time_
= expiry_time
;
397 void ClearPendingSwap();
399 PendingSwap
* pending_swap() { return pending_swap_
.get(); }
400 void set_pending_swap(PendingSwap
* pending_swap
) {
401 pending_swap_
.reset(pending_swap
);
405 PrerenderManager
* manager_
;
406 scoped_ptr
<PrerenderContents
> contents_
;
408 // The number of distinct PrerenderHandles created for |this|, including
409 // ones that have called PrerenderData::OnHandleNavigatedAway(), but not
410 // counting the ones that have called PrerenderData::OnHandleCanceled(). For
411 // pending prerenders, this will always be 1, since the PrerenderManager
412 // only merges handles of running prerenders.
415 // After this time, this prerender is no longer fresh, and should be
417 base::TimeTicks expiry_time_
;
419 // If a session storage namespace merge is in progress for this object,
420 // we need to keep track of various state associated with it.
421 scoped_ptr
<PendingSwap
> pending_swap_
;
423 DISALLOW_COPY_AND_ASSIGN(PrerenderData
);
426 // When a swap can't happen immediately, due to a sesison storage namespace
427 // merge, there will be a pending swap object while the merge is in
428 // progress. It retains all the data needed to do the merge, maintains
429 // throttles for the navigation in the target WebContents that needs to be
430 // delayed, and handles all conditions which would cancel a pending swap.
431 class PendingSwap
: public content::WebContentsObserver
{
433 PendingSwap(PrerenderManager
* manager
,
434 content::WebContents
* target_contents
,
435 PrerenderData
* prerender_data
,
437 bool should_replace_current_entry
);
438 virtual ~PendingSwap();
440 void set_swap_successful(bool swap_successful
) {
441 swap_successful_
= swap_successful
;
446 // content::WebContentsObserver implementation.
447 virtual void ProvisionalChangeToMainFrameUrl(
449 content::RenderFrameHost
* render_frame_host
) OVERRIDE
;
450 virtual void DidCommitProvisionalLoadForFrame(
452 const base::string16
& frame_unique_name
,
454 const GURL
& validated_url
,
455 content::PageTransition transition_type
,
456 content::RenderViewHost
* render_view_host
) OVERRIDE
;
457 virtual void RenderViewCreated(
458 content::RenderViewHost
* render_view_host
) OVERRIDE
;
459 virtual void DidFailProvisionalLoad(
461 const base::string16
& frame_unique_name
,
463 const GURL
& validated_url
,
465 const base::string16
& error_description
,
466 content::RenderViewHost
* render_view_host
) OVERRIDE
;
467 virtual void WebContentsDestroyed(content::WebContents
* web_contents
)
471 void RecordEvent(PrerenderEvent event
) const;
473 void OnMergeCompleted(content::SessionStorageNamespace::MergeResult result
);
474 void OnMergeTimeout();
476 // Prerender parameters.
477 PrerenderManager
* manager_
;
478 content::WebContents
* target_contents_
;
479 PrerenderData
* prerender_data_
;
481 bool should_replace_current_entry_
;
483 base::TimeTicks start_time_
;
484 std::vector
<PrerenderTracker::ChildRouteIdPair
> main_rfh_ids_
;
485 base::OneShotTimer
<PendingSwap
> merge_timeout_
;
486 bool swap_successful_
;
488 base::WeakPtrFactory
<PendingSwap
> weak_factory_
;
491 void SetPrerenderContentsFactory(
492 PrerenderContents::Factory
* prerender_contents_factory
);
494 // Adds prerenders from the pending Prerenders, called by
495 // PrerenderContents::StartPendingPrerenders.
496 void StartPendingPrerenders(
498 ScopedVector
<PrerenderContents::PendingPrerenderInfo
>* pending_prerenders
,
499 content::SessionStorageNamespace
* session_storage_namespace
);
501 // Called by a PrerenderData to signal that the launcher has navigated away
502 // from the context that launched the prerender. A user may have clicked
503 // a link in a page containing a <link rel=prerender> element, or the user
504 // might have committed an omnibox navigation. This is used to possibly
505 // shorten the TTL of the prerendered page.
506 void SourceNavigatedAway(PrerenderData
* prerender_data
);
509 friend class ::InstantSearchPrerendererTest
;
510 friend class PrerenderBrowserTest
;
511 friend class PrerenderContents
;
512 friend class PrerenderHandle
;
513 friend class UnitTestPrerenderManager
;
515 class OnCloseWebContentsDeleter
;
516 struct NavigationRecord
;
518 // For each WebContents that is swapped in, we store a
519 // PrerenderedWebContentsData so that we can track the origin of the
521 struct PrerenderedWebContentsData
{
522 explicit PrerenderedWebContentsData(Origin origin
);
527 // In the control group experimental group for each WebContents "not swapped
528 // in" we create a WouldBePrerenderedWebContentsData to the origin of the
529 // "prerender" we did not launch. We also track a state machine to ensure
530 // the histogram reporting tracks what histograms would have done.
531 struct WouldBePrerenderedWebContentsData
{
532 // When the WebContents gets a provisional load, we'd like to remove the
533 // WebContents from the map since the new navigation would not have swapped
534 // in a prerender. But the first provisional load after the control
535 // prerender is not "swapped in" is actually to the prerendered location! So
536 // we don't remove the item from the map on the first provisional load, but
537 // we do for subsequent loads.
539 WAITING_FOR_PROVISIONAL_LOAD
,
540 SEEN_PROVISIONAL_LOAD
,
543 explicit WouldBePrerenderedWebContentsData(Origin origin
);
549 // Time interval before a new prerender is allowed.
550 static const int kMinTimeBetweenPrerendersMs
= 500;
552 // Time window for which we record old navigations, in milliseconds.
553 static const int kNavigationRecordWindowMs
= 5000;
555 void OnCancelPrerenderHandle(PrerenderData
* prerender_data
);
557 // Adds a prerender for |url| from |referrer| initiated from the process
558 // |child_id|. The |origin| specifies how the prerender was added. If |size|
559 // is empty, then PrerenderContents::StartPrerendering will instead use a
560 // default from PrerenderConfig. Returns a PrerenderHandle*, owned by the
562 PrerenderHandle
* AddPrerender(
566 const content::Referrer
& referrer
,
567 const gfx::Size
& size
,
568 content::SessionStorageNamespace
* session_storage_namespace
);
570 void StartSchedulingPeriodicCleanups();
571 void StopSchedulingPeriodicCleanups();
573 void EvictOldestPrerendersIfNecessary();
575 // Deletes stale and cancelled prerendered PrerenderContents, as well as
576 // WebContents that have been replaced by prerendered WebContents.
577 // Also identifies and kills PrerenderContents that use too much
579 void PeriodicCleanup();
581 // Posts a task to call PeriodicCleanup. Results in quicker destruction of
582 // objects. If |this| is deleted before the task is run, the task will
583 // automatically be cancelled.
584 void PostCleanupTask();
586 base::TimeTicks
GetExpiryTimeForNewPrerender(Origin origin
) const;
587 base::TimeTicks
GetExpiryTimeForNavigatedAwayPrerender() const;
589 void DeleteOldEntries();
590 virtual PrerenderContents
* CreatePrerenderContents(
592 const content::Referrer
& referrer
,
594 uint8 experiment_id
);
596 // Insures the |active_prerenders_| are sorted by increasing expiry time. Call
597 // after every mutation of active_prerenders_ that can possibly make it
598 // unsorted (e.g. an insert, or changing an expiry time).
599 void SortActivePrerenders();
601 // Finds the active PrerenderData object for a running prerender matching
602 // |url| and |session_storage_namespace|.
603 PrerenderData
* FindPrerenderData(
605 const content::SessionStorageNamespace
* session_storage_namespace
);
607 // If |child_id| and |route_id| correspond to a RenderView that is an active
608 // prerender, returns the PrerenderData object for that prerender. Otherwise,
610 PrerenderData
* FindPrerenderDataForChildAndRoute(int child_id
, int route_id
);
612 // Given the |prerender_contents|, find the iterator in active_prerenders_
613 // correponding to the given prerender.
614 ScopedVector
<PrerenderData
>::iterator
615 FindIteratorForPrerenderContents(PrerenderContents
* prerender_contents
);
617 bool DoesRateLimitAllowPrerender(Origin origin
) const;
619 // Deletes old WebContents that have been replaced by prerendered ones. This
620 // is needed because they're replaced in a callback from the old WebContents,
621 // so cannot immediately be deleted.
622 void DeleteOldWebContents();
624 // Cleans up old NavigationRecord's.
625 void CleanUpOldNavigations();
627 // Arrange for the given WebContents to be deleted asap. If deleter is not
628 // NULL, deletes that as well.
629 void ScheduleDeleteOldWebContents(content::WebContents
* tab
,
630 OnCloseWebContentsDeleter
* deleter
);
632 // Adds to the history list.
633 void AddToHistory(PrerenderContents
* contents
);
635 // Returns a new Value representing the pages currently being prerendered. The
636 // caller is responsible for delete'ing the return value.
637 base::Value
* GetActivePrerendersAsValue() const;
639 // Destroys all pending prerenders using FinalStatus. Also deletes them as
640 // well as any swapped out WebContents queued for destruction.
641 // Used both on destruction, and when clearing the browsing history.
642 void DestroyAllContents(FinalStatus final_status
);
644 // Helper function to destroy a PrerenderContents with the specified
645 // final_status, while at the same time recording that for the MatchComplete
646 // case, that this prerender would have been used.
647 void DestroyAndMarkMatchCompleteAsUsed(PrerenderContents
* prerender_contents
,
648 FinalStatus final_status
);
650 // Record a final status of a prerendered page in a histogram.
651 // This is a helper function which will ultimately call
652 // RecordFinalStatusWthMatchCompleteStatus, using MATCH_COMPLETE_DEFAULT.
653 void RecordFinalStatus(Origin origin
,
655 FinalStatus final_status
) const;
657 // Returns whether prerendering is currently enabled for this manager.
658 // Must be called on the UI thread.
659 bool IsEnabled() 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 // This map is from all WebContents which are currently displaying a
701 // prerendered page which has already been swapped in to a
702 // PrerenderedWebContentsData for tracking full lifetime information
704 base::hash_map
<content::WebContents
*, PrerenderedWebContentsData
>
705 prerendered_web_contents_data_
;
707 // WebContents that would have been swapped out for a prerendered WebContents
708 // if the user was not part of the control group for measurement. When the
709 // WebContents gets a provisional load, the WebContents is removed from
710 // the map since the new navigation would not have swapped in a prerender.
711 // However, one complication exists because the first provisional load after
712 // the WebContents is marked as "Would Have Been Prerendered" is actually to
713 // the prerendered location. So, we need to keep a state around that does
714 // not clear the item from the map on the first provisional load, but does
715 // for subsequent loads.
716 base::hash_map
<content::WebContents
*, WouldBePrerenderedWebContentsData
>
717 would_be_prerendered_map_
;
719 scoped_ptr
<PrerenderContents::Factory
> prerender_contents_factory_
;
721 static PrerenderManagerMode mode_
;
723 // A count of how many prerenders we do per session. Initialized to 0 then
724 // incremented and emitted to a histogram on each successful prerender.
725 static int prerenders_per_session_count_
;
727 // RepeatingTimer to perform periodic cleanups of pending prerendered
729 base::RepeatingTimer
<PrerenderManager
> repeating_timer_
;
731 // Track time of last prerender to limit prerender spam.
732 base::TimeTicks last_prerender_start_time_
;
734 std::list
<content::WebContents
*> old_web_contents_list_
;
736 ScopedVector
<OnCloseWebContentsDeleter
> on_close_web_contents_deleters_
;
738 scoped_ptr
<PrerenderHistory
> prerender_history_
;
740 std::list
<const PrerenderCondition
*> prerender_conditions_
;
742 scoped_ptr
<PrerenderHistograms
> histograms_
;
744 scoped_ptr
<PrerenderLocalPredictor
> local_predictor_
;
746 scoped_refptr
<predictors::LoggedInPredictorTable
> logged_in_predictor_table_
;
748 // Here, we keep the logged in predictor state, but potentially a superset
749 // of its actual (database-backed) state, since we do not incorporate
750 // browser data deletion. We do not use this for actual lookups, but only
751 // to query cookie data for domains we know there was a login before.
752 // This is required to avoid a large number of cookie lookups on bulk
753 // deletion of cookies.
754 scoped_ptr
<LoggedInStateMap
> logged_in_state_
;
756 content::NotificationRegistrar notification_registrar_
;
758 DISALLOW_COPY_AND_ASSIGN(PrerenderManager
);
761 PrerenderManager
* FindPrerenderManagerUsingRenderProcessId(
762 int render_process_id
);
764 } // namespace prerender
766 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_