1 // Copyright 2013 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.
5 #ifndef COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_
6 #define COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h"
14 #include "base/time.h"
15 #include "components/sessions/sessions_export.h"
16 #include "content/public/common/page_transition_types.h"
17 #include "content/public/common/referrer.h"
18 #include "googleurl/src/gurl.h"
25 class NavigationEntry
;
34 class SerializedNavigationEntryTestHelper
;
36 // The key used to store search terms data in the NavigationEntry.
37 SESSIONS_EXPORT
extern const char kSearchTermsKey
[];
39 // SerializedNavigationEntry is a "freeze-dried" version of NavigationEntry. It
40 // contains the data needed to restore a NavigationEntry during session restore
41 // and tab restore, and it can also be pickled and unpickled. It is also
42 // convertible to a sync protocol buffer for session syncing.
44 // Default copy constructor and assignment operator welcome.
45 class SESSIONS_EXPORT SerializedNavigationEntry
{
47 // Creates an invalid (index < 0) SerializedNavigationEntry.
48 SerializedNavigationEntry();
49 ~SerializedNavigationEntry();
51 // Construct a SerializedNavigationEntry for a particular index from the given
53 static SerializedNavigationEntry
FromNavigationEntry(
55 const content::NavigationEntry
& entry
);
57 // Construct a SerializedNavigationEntry for a particular index from a sync
58 // protocol buffer. Note that the sync protocol buffer doesn't contain all
59 // SerializedNavigationEntry fields. Also, the timestamp of the returned
60 // SerializedNavigationEntry is nulled out, as we assume that the protocol
61 // buffer is from a foreign session.
62 static SerializedNavigationEntry
FromSyncData(
64 const sync_pb::TabNavigation
& sync_data
);
66 // Note that not all SerializedNavigationEntry fields are preserved.
67 // |max_size| is the max number of bytes to write.
68 void WriteToPickle(int max_size
, Pickle
* pickle
) const;
69 bool ReadFromPickle(PickleIterator
* iterator
);
71 // Convert this SerializedNavigationEntry into a NavigationEntry with the
72 // given page ID and context. The NavigationEntry will have a transition type
73 // of PAGE_TRANSITION_RELOAD and a new unique ID.
74 scoped_ptr
<content::NavigationEntry
> ToNavigationEntry(
76 content::BrowserContext
* browser_context
) const;
78 // Convert this navigation into its sync protocol buffer equivalent. Note
79 // that the protocol buffer doesn't contain all SerializedNavigationEntry
81 sync_pb::TabNavigation
ToSyncData() const;
83 // The index in the NavigationController. This SerializedNavigationEntry is
84 // valid only when the index is non-negative.
85 int index() const { return index_
; }
86 void set_index(int index
) { index_
= index
; }
88 // Accessors for some fields taken from NavigationEntry.
89 int unique_id() const { return unique_id_
; }
90 const GURL
& virtual_url() const { return virtual_url_
; }
91 const string16
& title() const { return title_
; }
92 const std::string
& content_state() const { return content_state_
; }
93 const string16
& search_terms() const { return search_terms_
; }
94 const GURL
& favicon_url() const { return favicon_url_
; }
95 const content::Referrer
& referrer() const { return referrer_
; }
96 content::PageTransition
transition_type() const {
97 return transition_type_
;
99 bool has_post_data() const { return has_post_data_
; }
100 int64
post_id() const { return post_id_
; }
101 const GURL
& original_request_url() const { return original_request_url_
; }
102 bool is_overriding_user_agent() const { return is_overriding_user_agent_
; }
103 base::Time
timestamp() const { return timestamp_
; }
105 // Converts a set of SerializedNavigationEntrys into a list of
106 // NavigationEntrys with sequential page IDs and the given context. The caller
107 // owns the returned NavigationEntrys.
108 static std::vector
<content::NavigationEntry
*> ToNavigationEntries(
109 const std::vector
<SerializedNavigationEntry
>& navigations
,
110 content::BrowserContext
* browser_context
);
113 friend class SerializedNavigationEntryTestHelper
;
115 // Index in the NavigationController.
118 // Member variables corresponding to NavigationEntry fields.
120 content::Referrer referrer_
;
123 std::string content_state_
;
124 content::PageTransition transition_type_
;
127 GURL original_request_url_
;
128 bool is_overriding_user_agent_
;
129 base::Time timestamp_
;
130 string16 search_terms_
;
134 } // namespace sessions
136 #endif // COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_