blob: f969557c78ed11ec796d99e6875eabd6e2fd8492 [file] [log] [blame]
[email protected]e2602042011-06-15 19:57:291// 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]985702c92011-06-21 16:32:2712#include "base/time.h"
[email protected]e2602042011-06-15 19:57:2913#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]65341d32011-06-28 01:56:4714#include "chrome/browser/prerender/prerender_origin.h"
[email protected]e2602042011-06-15 19:57:2915#include "googleurl/src/gurl.h"
16
17class Value;
18
19namespace 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.
24class 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]65341d32011-06-28 01:56:4729 Entry() : final_status(FINAL_STATUS_MAX), origin(ORIGIN_MAX) {}
[email protected]e2602042011-06-15 19:57:2930
[email protected]985702c92011-06-21 16:32:2731 Entry(const GURL& url_arg,
32 FinalStatus final_status_arg,
[email protected]65341d32011-06-28 01:56:4733 Origin origin_arg,
[email protected]985702c92011-06-21 16:32:2734 base::Time end_time_arg)
35 : url(url_arg), final_status(final_status_arg),
[email protected]65341d32011-06-28 01:56:4736 origin(origin_arg),
[email protected]985702c92011-06-21 16:32:2737 end_time(end_time_arg) {
[email protected]e2602042011-06-15 19:57:2938 }
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]985702c92011-06-21 16:32:2748
[email protected]65341d32011-06-28 01:56:4749 // The Origin describing where the prerender originated from.
50 Origin origin;
51
[email protected]985702c92011-06-21 16:32:2752 // Time the PrerenderContents was destroyed.
53 base::Time end_time;
[email protected]e2602042011-06-15 19:57:2954 };
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]cf5db4c2011-06-20 21:02:5763 // Deletes all history entries.
64 void Clear();
65
[email protected]e2602042011-06-15 19:57:2966 // 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_