Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 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: |
| 105 virtual ~PrerenderManager(); | 111 virtual ~PrerenderManager(); |
| 106 | 112 |
| 107 void SetPrerenderContentsFactory( | 113 void SetPrerenderContentsFactory( |
| 108 PrerenderContents::Factory* prerender_contents_factory); | 114 PrerenderContents::Factory* prerender_contents_factory); |
| 109 | 115 |
| 116 struct PendingContentsData; | |
|
cbentzel
2011/03/21 19:46:04
the struct declaration should go at top of protect
dominich
2011/03/21 20:25:51
Done.
| |
| 117 PendingContentsData* FindPendingEntry(const GURL& url); | |
| 118 | |
| 110 private: | 119 private: |
| 111 // Test that needs needs access to internal functions. | 120 // Test that needs needs access to internal functions. |
| 112 friend class PrerenderBrowserTest; | 121 friend class PrerenderBrowserTest; |
| 113 | 122 |
| 114 friend class base::RefCounted<PrerenderManager>; | 123 friend class base::RefCounted<PrerenderManager>; |
| 115 struct PrerenderContentsData; | 124 struct PrerenderContentsData; |
| 116 | 125 |
| 117 // Starts and stops scheduling periodic cleanups, respectively. | 126 // Starts and stops scheduling periodic cleanups, respectively. |
| 118 void StartSchedulingPeriodicCleanups(); | 127 void StartSchedulingPeriodicCleanups(); |
| 119 void StopSchedulingPeriodicCleanups(); | 128 void StopSchedulingPeriodicCleanups(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 133 | 142 |
| 134 // Finds the specified PrerenderContents and returns it, if it exists. | 143 // Finds the specified PrerenderContents and returns it, if it exists. |
| 135 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 144 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
| 136 // ownership of the PrerenderContents. | 145 // ownership of the PrerenderContents. |
| 137 PrerenderContents* FindEntry(const GURL& url); | 146 PrerenderContents* FindEntry(const GURL& url); |
| 138 | 147 |
| 139 static bool ShouldRecordWindowedPPLT(); | 148 static bool ShouldRecordWindowedPPLT(); |
| 140 | 149 |
| 141 static void RecordPrefetchTagObservedOnUIThread(); | 150 static void RecordPrefetchTagObservedOnUIThread(); |
| 142 | 151 |
| 152 // Called when removing a preload to ensure we clean up any pending preloads | |
| 153 // that might remain in the map. | |
| 154 void RemovePendingPreload(PrerenderContents* entry); | |
| 155 | |
| 143 Profile* profile_; | 156 Profile* profile_; |
| 144 | 157 |
| 145 base::TimeDelta max_prerender_age_; | 158 base::TimeDelta max_prerender_age_; |
| 146 unsigned int max_elements_; | 159 unsigned int max_elements_; |
| 147 | 160 |
| 148 // List of prerendered elements. | 161 // List of prerendered elements. |
| 149 std::list<PrerenderContentsData> prerender_list_; | 162 std::list<PrerenderContentsData> prerender_list_; |
| 150 | 163 |
| 151 // Set of TabContents which are currently displaying a prerendered page. | 164 // Set of TabContents which are currently displaying a prerendered page. |
| 152 base::hash_set<TabContents*> prerendered_tc_set_; | 165 base::hash_set<TabContents*> prerendered_tc_set_; |
| 153 | 166 |
| 154 // Set of TabContents which would be displaying a prerendered page | 167 // Set of TabContents which would be displaying a prerendered page |
| 155 // (for the control group). | 168 // (for the control group). |
| 156 base::hash_set<TabContents*> would_be_prerendered_tc_set_; | 169 base::hash_set<TabContents*> would_be_prerendered_tc_set_; |
| 157 | 170 |
| 171 // Map of child/route id pairs to pending prerender data. | |
| 172 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > | |
| 173 PendingPrerenderList; | |
| 174 PendingPrerenderList pending_prerender_list_; | |
| 175 | |
| 158 // Default maximum permitted elements to prerender. | 176 // Default maximum permitted elements to prerender. |
| 159 static const unsigned int kDefaultMaxPrerenderElements = 1; | 177 static const unsigned int kDefaultMaxPrerenderElements = 1; |
| 160 | 178 |
| 161 // Default maximum age a prerendered element may have, in seconds. | 179 // Default maximum age a prerendered element may have, in seconds. |
| 162 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 180 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
| 163 | 181 |
| 164 // Time window for which we will record windowed PLT's from the last | 182 // Time window for which we will record windowed PLT's from the last |
| 165 // observed link rel=prefetch tag. | 183 // observed link rel=prefetch tag. |
| 166 static const int kWindowedPPLTSeconds = 30; | 184 static const int kWindowedPPLTSeconds = 30; |
| 167 | 185 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 181 // RepeatingTimer to perform periodic cleanups of pending prerendered | 199 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| 182 // pages. | 200 // pages. |
| 183 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 201 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
| 184 | 202 |
| 185 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 203 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 186 }; | 204 }; |
| 187 | 205 |
| 188 } // prerender | 206 } // prerender |
| 189 | 207 |
| 190 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 208 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |