[email protected] | e260204 | 2011-06-15 19:57:29 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HISTORY_H_ |
| 6 | #define CHROME_BROWSER_PRERENDER_PRERENDER_HISTORY_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include <list> |
| 10 | |
| 11 | #include "base/threading/non_thread_safe.h" |
[email protected] | 985702c9 | 2011-06-21 16:32:27 | [diff] [blame] | 12 | #include "base/time.h" |
[email protected] | e260204 | 2011-06-15 19:57:29 | [diff] [blame] | 13 | #include "chrome/browser/prerender/prerender_final_status.h" |
[email protected] | 65341d3 | 2011-06-28 01:56:47 | [diff] [blame^] | 14 | #include "chrome/browser/prerender/prerender_origin.h" |
[email protected] | e260204 | 2011-06-15 19:57:29 | [diff] [blame] | 15 | #include "googleurl/src/gurl.h" |
| 16 | |
| 17 | class Value; |
| 18 | |
| 19 | namespace prerender { |
| 20 | |
| 21 | // PrerenderHistory maintains a per-session history of prerendered pages |
| 22 | // and their final dispositions. It has a fixed maximum capacity, and old |
| 23 | // items in history will be removed when the capacity is reached. |
| 24 | class PrerenderHistory : public base::NonThreadSafe { |
| 25 | public: |
| 26 | // Entry is an individual entry in the history list. It corresponds to a |
| 27 | // specific prerendered page. |
| 28 | struct Entry { |
[email protected] | 65341d3 | 2011-06-28 01:56:47 | [diff] [blame^] | 29 | Entry() : final_status(FINAL_STATUS_MAX), origin(ORIGIN_MAX) {} |
[email protected] | e260204 | 2011-06-15 19:57:29 | [diff] [blame] | 30 | |
[email protected] | 985702c9 | 2011-06-21 16:32:27 | [diff] [blame] | 31 | Entry(const GURL& url_arg, |
| 32 | FinalStatus final_status_arg, |
[email protected] | 65341d3 | 2011-06-28 01:56:47 | [diff] [blame^] | 33 | Origin origin_arg, |
[email protected] | 985702c9 | 2011-06-21 16:32:27 | [diff] [blame] | 34 | base::Time end_time_arg) |
| 35 | : url(url_arg), final_status(final_status_arg), |
[email protected] | 65341d3 | 2011-06-28 01:56:47 | [diff] [blame^] | 36 | origin(origin_arg), |
[email protected] | 985702c9 | 2011-06-21 16:32:27 | [diff] [blame] | 37 | end_time(end_time_arg) { |
[email protected] | e260204 | 2011-06-15 19:57:29 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // The URL which was prerendered. This should be the URL included in the |
| 41 | // <link rel="prerender"> tag, and not any URLs which it may have redirected |
| 42 | // to. |
| 43 | GURL url; |
| 44 | |
| 45 | // The FinalStatus describing whether the prerendered page was used or why |
| 46 | // it was cancelled. |
| 47 | FinalStatus final_status; |
[email protected] | 985702c9 | 2011-06-21 16:32:27 | [diff] [blame] | 48 | |
[email protected] | 65341d3 | 2011-06-28 01:56:47 | [diff] [blame^] | 49 | // The Origin describing where the prerender originated from. |
| 50 | Origin origin; |
| 51 | |
[email protected] | 985702c9 | 2011-06-21 16:32:27 | [diff] [blame] | 52 | // Time the PrerenderContents was destroyed. |
| 53 | base::Time end_time; |
[email protected] | e260204 | 2011-06-15 19:57:29 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | // Creates a history with capacity for |max_items| entries. |
| 57 | explicit PrerenderHistory(size_t max_items); |
| 58 | ~PrerenderHistory(); |
| 59 | |
| 60 | // Adds |entry| to the history. If at capacity, the oldest entry is dropped. |
| 61 | void AddEntry(const Entry& entry); |
| 62 | |
[email protected] | cf5db4c | 2011-06-20 21:02:57 | [diff] [blame] | 63 | // Deletes all history entries. |
| 64 | void Clear(); |
| 65 | |
[email protected] | e260204 | 2011-06-15 19:57:29 | [diff] [blame] | 66 | // Retrieves the entries as a value which can be displayed. |
| 67 | Value* GetEntriesAsValue() const; |
| 68 | |
| 69 | private: |
| 70 | std::list<Entry> entries_; |
| 71 | size_t max_items_; |
| 72 | |
| 73 | DISALLOW_COPY_AND_ASSIGN(PrerenderHistory); |
| 74 | }; |
| 75 | |
| 76 | } |
| 77 | #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTORY_H_ |