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 // SessionType is used in a UMA_HISTOGRAM, so please do not add in the |
| 28 // middle. |
| 29 enum SessionType { |
| 30 PRERENDERING_OFF, |
| 31 PRERENDERING_ON, |
| 32 PRERENDERING_SESSION_TYPE_MAX |
| 33 }; |
| 34 |
27 // Owned by a Profile object for the lifetime of the profile. | 35 // Owned by a Profile object for the lifetime of the profile. |
28 explicit PrerenderManager(Profile* profile); | 36 explicit PrerenderManager(Profile* profile); |
29 | 37 |
30 // Preloads the URL supplied. alias_urls indicates URLs that redirect | 38 // Preloads the URL supplied. alias_urls indicates URLs that redirect |
31 // to the same URL to be preloaded. | 39 // to the same URL to be preloaded. |
32 void AddPreload(const GURL& url, const std::vector<GURL>& alias_urls); | 40 void AddPreload(const GURL& url, const std::vector<GURL>& alias_urls); |
33 | 41 |
34 // For a given TabContents that wants to navigate to the URL supplied, | 42 // For a given TabContents that wants to navigate to the URL supplied, |
35 // determines whether a preloaded version of the URL can be used, | 43 // determines whether a preloaded version of the URL can be used, |
36 // and substitutes the prerendered RVH into the TabContents. Returns | 44 // and substitutes the prerendered RVH into the TabContents. Returns |
37 // whether or not a prerendered RVH could be used or not. | 45 // whether or not a prerendered RVH could be used or not. |
38 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); | 46 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); |
39 | 47 |
40 // Allows PrerenderContents to remove itself when prerendering should | 48 // Allows PrerenderContents to remove itself when prerendering should |
41 // be cancelled. Also deletes the entry. | 49 // be cancelled. Also deletes the entry. |
42 void RemoveEntry(PrerenderContents* entry); | 50 void RemoveEntry(PrerenderContents* entry); |
43 | 51 |
44 // Retrieves the PrerenderContents object for the specified URL, if it | 52 // Retrieves the PrerenderContents object for the specified URL, if it |
45 // has been prerendered. The caller will then have ownership of the | 53 // has been prerendered. The caller will then have ownership of the |
46 // PrerenderContents object and is responsible for freeing it. | 54 // PrerenderContents object and is responsible for freeing it. |
47 // Returns NULL if the specified URL has not been prerendered. | 55 // Returns NULL if the specified URL has not been prerendered. |
48 PrerenderContents* GetEntry(const GURL& url); | 56 PrerenderContents* GetEntry(const GURL& url); |
49 | 57 |
50 base::TimeDelta max_prerender_age() const { return max_prerender_age_; } | 58 base::TimeDelta max_prerender_age() const { return max_prerender_age_; } |
51 void set_max_prerender_age(base::TimeDelta td) { max_prerender_age_ = td; } | 59 void set_max_prerender_age(base::TimeDelta td) { max_prerender_age_ = td; } |
52 unsigned int max_elements() const { return max_elements_; } | 60 unsigned int max_elements() const { return max_elements_; } |
53 void set_max_elements(unsigned int num) { max_elements_ = num; } | 61 void set_max_elements(unsigned int num) { max_elements_ = num; } |
54 | 62 |
| 63 static SessionType GetSessionType(); |
| 64 |
55 protected: | 65 protected: |
56 virtual ~PrerenderManager(); | 66 virtual ~PrerenderManager(); |
57 | 67 |
58 private: | 68 private: |
59 friend class base::RefCounted<PrerenderManager>; | 69 friend class base::RefCounted<PrerenderManager>; |
60 struct PrerenderContentsData; | 70 struct PrerenderContentsData; |
61 | 71 |
62 bool IsPrerenderElementFresh(const base::Time start) const; | 72 bool IsPrerenderElementFresh(const base::Time start) const; |
63 void DeleteOldEntries(); | 73 void DeleteOldEntries(); |
64 virtual base::Time GetCurrentTime() const; | 74 virtual base::Time GetCurrentTime() const; |
(...skipping 12 matching lines...) Expand all Loading... |
77 // Default maximum permitted elements to prerender. | 87 // Default maximum permitted elements to prerender. |
78 static const unsigned int kDefaultMaxPrerenderElements = 1; | 88 static const unsigned int kDefaultMaxPrerenderElements = 1; |
79 | 89 |
80 // Default maximum age a prerendered element may have, in seconds. | 90 // Default maximum age a prerendered element may have, in seconds. |
81 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 91 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
82 | 92 |
83 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 93 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
84 }; | 94 }; |
85 | 95 |
86 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 96 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |