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 <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 | 17 |
18 class PrerenderContents; | 18 class PrerenderContents; |
19 class Profile; | 19 class Profile; |
20 class TabContents; | 20 class TabContents; |
21 | 21 |
22 // PrerenderManager is responsible for initiating and keeping prerendered | 22 // PrerenderManager is responsible for initiating and keeping prerendered |
23 // views of webpages. | 23 // views of webpages. |
24 class PrerenderManager : public base::RefCounted<PrerenderManager>, | 24 class PrerenderManager : public base::RefCounted<PrerenderManager>, |
25 private base::NonThreadSafe { | 25 private base::NonThreadSafe { |
26 public: | 26 public: |
| 27 enum PrerenderManagerMode { |
| 28 PRERENDER_MODE_DISABLED, |
| 29 PRERENDER_MODE_ENABLED, |
| 30 PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP, |
| 31 PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP |
| 32 }; |
| 33 |
27 // Owned by a Profile object for the lifetime of the profile. | 34 // Owned by a Profile object for the lifetime of the profile. |
28 explicit PrerenderManager(Profile* profile); | 35 explicit PrerenderManager(Profile* profile); |
29 | 36 |
30 // Preloads the URL supplied. alias_urls indicates URLs that redirect | 37 // Preloads the URL supplied. alias_urls indicates URLs that redirect |
31 // to the same URL to be preloaded. | 38 // to the same URL to be preloaded. |
32 void AddPreload(const GURL& url, const std::vector<GURL>& alias_urls); | 39 void AddPreload(const GURL& url, const std::vector<GURL>& alias_urls); |
33 | 40 |
34 // For a given TabContents that wants to navigate to the URL supplied, | 41 // For a given TabContents that wants to navigate to the URL supplied, |
35 // determines whether a preloaded version of the URL can be used, | 42 // determines whether a preloaded version of the URL can be used, |
36 // and substitutes the prerendered RVH into the TabContents. Returns | 43 // and substitutes the prerendered RVH into the TabContents. Returns |
37 // whether or not a prerendered RVH could be used or not. | 44 // whether or not a prerendered RVH could be used or not. |
38 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); | 45 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); |
39 | 46 |
40 // Allows PrerenderContents to remove itself when prerendering should | 47 // Allows PrerenderContents to remove itself when prerendering should |
41 // be cancelled. Also deletes the entry. | 48 // be cancelled. Also deletes the entry. |
42 void RemoveEntry(PrerenderContents* entry); | 49 void RemoveEntry(PrerenderContents* entry); |
43 | 50 |
44 // Retrieves the PrerenderContents object for the specified URL, if it | 51 // Retrieves the PrerenderContents object for the specified URL, if it |
45 // has been prerendered. The caller will then have ownership of the | 52 // has been prerendered. The caller will then have ownership of the |
46 // PrerenderContents object and is responsible for freeing it. | 53 // PrerenderContents object and is responsible for freeing it. |
47 // Returns NULL if the specified URL has not been prerendered. | 54 // Returns NULL if the specified URL has not been prerendered. |
48 PrerenderContents* GetEntry(const GURL& url); | 55 PrerenderContents* GetEntry(const GURL& url); |
49 | 56 |
| 57 void RecordPerceivedPageLoadTime(base::TimeDelta pplt); |
| 58 |
50 base::TimeDelta max_prerender_age() const { return max_prerender_age_; } | 59 base::TimeDelta max_prerender_age() const { return max_prerender_age_; } |
51 void set_max_prerender_age(base::TimeDelta td) { max_prerender_age_ = td; } | 60 void set_max_prerender_age(base::TimeDelta td) { max_prerender_age_ = td; } |
52 unsigned int max_elements() const { return max_elements_; } | 61 unsigned int max_elements() const { return max_elements_; } |
53 void set_max_elements(unsigned int num) { max_elements_ = num; } | 62 void set_max_elements(unsigned int num) { max_elements_ = num; } |
54 | 63 |
55 protected: | 64 protected: |
56 virtual ~PrerenderManager(); | 65 virtual ~PrerenderManager(); |
57 | 66 |
58 private: | 67 private: |
59 friend class base::RefCounted<PrerenderManager>; | 68 friend class base::RefCounted<PrerenderManager>; |
(...skipping 13 matching lines...) Expand all Loading... |
73 | 82 |
74 // List of prerendered elements. | 83 // List of prerendered elements. |
75 std::list<PrerenderContentsData> prerender_list_; | 84 std::list<PrerenderContentsData> prerender_list_; |
76 | 85 |
77 // Default maximum permitted elements to prerender. | 86 // Default maximum permitted elements to prerender. |
78 static const unsigned int kDefaultMaxPrerenderElements = 1; | 87 static const unsigned int kDefaultMaxPrerenderElements = 1; |
79 | 88 |
80 // Default maximum age a prerendered element may have, in seconds. | 89 // Default maximum age a prerendered element may have, in seconds. |
81 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 90 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
82 | 91 |
| 92 PrerenderManagerMode mode_; |
| 93 |
83 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 94 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
84 }; | 95 }; |
85 | 96 |
86 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 97 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |