| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
| 13 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 14 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 15 #include "base/time.h" | 16 #include "base/time.h" |
| 16 #include "base/timer.h" | 17 #include "base/timer.h" |
| 17 #include "chrome/browser/prerender/prerender_contents.h" | 18 #include "chrome/browser/prerender/prerender_contents.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 | 20 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 52 |
| 52 // Owned by a Profile object for the lifetime of the profile. | 53 // Owned by a Profile object for the lifetime of the profile. |
| 53 explicit PrerenderManager(Profile* profile); | 54 explicit PrerenderManager(Profile* profile); |
| 54 | 55 |
| 55 // Preloads the URL supplied. alias_urls indicates URLs that redirect | 56 // Preloads the URL supplied. alias_urls indicates URLs that redirect |
| 56 // to the same URL to be preloaded. Returns true if the URL was added, | 57 // to the same URL to be preloaded. Returns true if the URL was added, |
| 57 // false if it was not. | 58 // false if it was not. |
| 58 bool AddPreload(const GURL& url, const std::vector<GURL>& alias_urls, | 59 bool AddPreload(const GURL& url, const std::vector<GURL>& alias_urls, |
| 59 const GURL& referrer); | 60 const GURL& referrer); |
| 60 | 61 |
| 62 void AddPendingPreload(const std::pair<int, int>& child_route_id_pair, |
| 63 const GURL& url, |
| 64 const std::vector<GURL>& alias_urls, |
| 65 const GURL& referrer); |
| 66 |
| 61 // For a given TabContents that wants to navigate to the URL supplied, | 67 // For a given TabContents that wants to navigate to the URL supplied, |
| 62 // determines whether a preloaded version of the URL can be used, | 68 // determines whether a preloaded version of the URL can be used, |
| 63 // and substitutes the prerendered RVH into the TabContents. Returns | 69 // and substitutes the prerendered RVH into the TabContents. Returns |
| 64 // whether or not a prerendered RVH could be used or not. | 70 // whether or not a prerendered RVH could be used or not. |
| 65 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); | 71 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); |
| 66 | 72 |
| 67 // Allows PrerenderContents to remove itself when prerendering should | 73 // Allows PrerenderContents to remove itself when prerendering should |
| 68 // be cancelled. | 74 // be cancelled. |
| 69 void RemoveEntry(PrerenderContents* entry); | 75 void RemoveEntry(PrerenderContents* entry); |
| 70 | 76 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 95 | 101 |
| 96 // Maintaining and querying the set of TabContents belonging to this | 102 // Maintaining and querying the set of TabContents belonging to this |
| 97 // PrerenderManager that are currently showing prerendered pages. | 103 // PrerenderManager that are currently showing prerendered pages. |
| 98 void MarkTabContentsAsPrerendered(TabContents* tc); | 104 void MarkTabContentsAsPrerendered(TabContents* tc); |
| 99 void MarkTabContentsAsWouldBePrerendered(TabContents* tc); | 105 void MarkTabContentsAsWouldBePrerendered(TabContents* tc); |
| 100 void MarkTabContentsAsNotPrerendered(TabContents* tc); | 106 void MarkTabContentsAsNotPrerendered(TabContents* tc); |
| 101 bool IsTabContentsPrerendered(TabContents* tc) const; | 107 bool IsTabContentsPrerendered(TabContents* tc) const; |
| 102 bool WouldTabContentsBePrerendered(TabContents* tc) const; | 108 bool WouldTabContentsBePrerendered(TabContents* tc) const; |
| 103 | 109 |
| 104 protected: | 110 protected: |
| 111 struct PendingContentsData; |
| 112 |
| 105 virtual ~PrerenderManager(); | 113 virtual ~PrerenderManager(); |
| 106 | 114 |
| 107 void SetPrerenderContentsFactory( | 115 void SetPrerenderContentsFactory( |
| 108 PrerenderContents::Factory* prerender_contents_factory); | 116 PrerenderContents::Factory* prerender_contents_factory); |
| 109 | 117 |
| 118 PendingContentsData* FindPendingEntry(const GURL& url); |
| 119 |
| 110 private: | 120 private: |
| 111 // Test that needs needs access to internal functions. | 121 // Test that needs needs access to internal functions. |
| 112 friend class PrerenderBrowserTest; | 122 friend class PrerenderBrowserTest; |
| 113 | 123 |
| 114 friend class base::RefCounted<PrerenderManager>; | 124 friend class base::RefCounted<PrerenderManager>; |
| 115 struct PrerenderContentsData; | 125 struct PrerenderContentsData; |
| 116 | 126 |
| 117 // Starts and stops scheduling periodic cleanups, respectively. | 127 // Starts and stops scheduling periodic cleanups, respectively. |
| 118 void StartSchedulingPeriodicCleanups(); | 128 void StartSchedulingPeriodicCleanups(); |
| 119 void StopSchedulingPeriodicCleanups(); | 129 void StopSchedulingPeriodicCleanups(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 133 | 143 |
| 134 // Finds the specified PrerenderContents and returns it, if it exists. | 144 // Finds the specified PrerenderContents and returns it, if it exists. |
| 135 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 145 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
| 136 // ownership of the PrerenderContents. | 146 // ownership of the PrerenderContents. |
| 137 PrerenderContents* FindEntry(const GURL& url); | 147 PrerenderContents* FindEntry(const GURL& url); |
| 138 | 148 |
| 139 static bool ShouldRecordWindowedPPLT(); | 149 static bool ShouldRecordWindowedPPLT(); |
| 140 | 150 |
| 141 static void RecordPrefetchTagObservedOnUIThread(); | 151 static void RecordPrefetchTagObservedOnUIThread(); |
| 142 | 152 |
| 153 // Called when removing a preload to ensure we clean up any pending preloads |
| 154 // that might remain in the map. |
| 155 void RemovePendingPreload(PrerenderContents* entry); |
| 156 |
| 143 Profile* profile_; | 157 Profile* profile_; |
| 144 | 158 |
| 145 base::TimeDelta max_prerender_age_; | 159 base::TimeDelta max_prerender_age_; |
| 146 unsigned int max_elements_; | 160 unsigned int max_elements_; |
| 147 | 161 |
| 148 // List of prerendered elements. | 162 // List of prerendered elements. |
| 149 std::list<PrerenderContentsData> prerender_list_; | 163 std::list<PrerenderContentsData> prerender_list_; |
| 150 | 164 |
| 151 // Set of TabContents which are currently displaying a prerendered page. | 165 // Set of TabContents which are currently displaying a prerendered page. |
| 152 base::hash_set<TabContents*> prerendered_tc_set_; | 166 base::hash_set<TabContents*> prerendered_tc_set_; |
| 153 | 167 |
| 154 // Set of TabContents which would be displaying a prerendered page | 168 // Set of TabContents which would be displaying a prerendered page |
| 155 // (for the control group). | 169 // (for the control group). |
| 156 base::hash_set<TabContents*> would_be_prerendered_tc_set_; | 170 base::hash_set<TabContents*> would_be_prerendered_tc_set_; |
| 157 | 171 |
| 172 // Map of child/route id pairs to pending prerender data. |
| 173 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > |
| 174 PendingPrerenderList; |
| 175 PendingPrerenderList pending_prerender_list_; |
| 176 |
| 158 // Default maximum permitted elements to prerender. | 177 // Default maximum permitted elements to prerender. |
| 159 static const unsigned int kDefaultMaxPrerenderElements = 1; | 178 static const unsigned int kDefaultMaxPrerenderElements = 1; |
| 160 | 179 |
| 161 // Default maximum age a prerendered element may have, in seconds. | 180 // Default maximum age a prerendered element may have, in seconds. |
| 162 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 181 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
| 163 | 182 |
| 164 // Time window for which we will record windowed PLT's from the last | 183 // Time window for which we will record windowed PLT's from the last |
| 165 // observed link rel=prefetch tag. | 184 // observed link rel=prefetch tag. |
| 166 static const int kWindowedPPLTSeconds = 30; | 185 static const int kWindowedPPLTSeconds = 30; |
| 167 | 186 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 181 // RepeatingTimer to perform periodic cleanups of pending prerendered | 200 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| 182 // pages. | 201 // pages. |
| 183 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 202 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
| 184 | 203 |
| 185 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 204 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 186 }; | 205 }; |
| 187 | 206 |
| 188 } // prerender | 207 } // prerender |
| 189 | 208 |
| 190 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 209 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |