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