Port Android relocation packer to chromium build
[chromium-blink-merge.git] / components / sessions / serialized_navigation_entry.h
blob49ae3dd1a27d13d71892a5e3e281aa213aaa8d8b
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_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "base/time/time.h"
16 #include "components/sessions/sessions_export.h"
17 #include "ui/base/page_transition_types.h"
18 #include "url/gurl.h"
20 class Pickle;
21 class PickleIterator;
23 namespace sync_pb {
24 class TabNavigation;
27 namespace sessions {
29 class SerializedNavigationEntryTestHelper;
31 // The key used to store search terms data in the NavigationEntry.
32 SESSIONS_EXPORT extern const char kSearchTermsKey[];
34 // SerializedNavigationEntry is a "freeze-dried" version of NavigationEntry. It
35 // contains the data needed to restore a NavigationEntry during session restore
36 // and tab restore, and it can also be pickled and unpickled. It is also
37 // convertible to a sync protocol buffer for session syncing.
39 // Default copy constructor and assignment operator welcome.
40 class SESSIONS_EXPORT SerializedNavigationEntry {
41 public:
42 enum BlockedState {
43 STATE_INVALID = 0,
44 STATE_ALLOWED = 1,
45 STATE_BLOCKED = 2,
48 // Creates an invalid (index < 0) SerializedNavigationEntry.
49 SerializedNavigationEntry();
50 ~SerializedNavigationEntry();
52 // Construct a SerializedNavigationEntry for a particular index from a sync
53 // protocol buffer. Note that the sync protocol buffer doesn't contain all
54 // SerializedNavigationEntry fields. Also, the timestamp of the returned
55 // SerializedNavigationEntry is nulled out, as we assume that the protocol
56 // buffer is from a foreign session.
57 static SerializedNavigationEntry FromSyncData(
58 int index,
59 const sync_pb::TabNavigation& sync_data);
61 // Note that not all SerializedNavigationEntry fields are preserved.
62 // |max_size| is the max number of bytes to write.
63 void WriteToPickle(int max_size, Pickle* pickle) const;
64 bool ReadFromPickle(PickleIterator* iterator);
66 // Convert this navigation into its sync protocol buffer equivalent. Note
67 // that the protocol buffer doesn't contain all SerializedNavigationEntry
68 // fields.
69 sync_pb::TabNavigation ToSyncData() const;
71 // The index in the NavigationController. This SerializedNavigationEntry is
72 // valid only when the index is non-negative.
73 int index() const { return index_; }
74 void set_index(int index) { index_ = index; }
76 // Accessors for some fields taken from NavigationEntry.
77 int unique_id() const { return unique_id_; }
78 const GURL& virtual_url() const { return virtual_url_; }
79 const base::string16& title() const { return title_; }
80 const std::string& encoded_page_state() const { return encoded_page_state_; }
81 const base::string16& search_terms() const { return search_terms_; }
82 const GURL& favicon_url() const { return favicon_url_; }
83 int http_status_code() const { return http_status_code_; }
84 const GURL& referrer_url() const { return referrer_url_; }
85 int referrer_policy() const { return referrer_policy_; }
86 ui::PageTransition transition_type() const {
87 return transition_type_;
89 bool has_post_data() const { return has_post_data_; }
90 int64 post_id() const { return post_id_; }
91 const GURL& original_request_url() const { return original_request_url_; }
92 bool is_overriding_user_agent() const { return is_overriding_user_agent_; }
93 base::Time timestamp() const { return timestamp_; }
95 BlockedState blocked_state() { return blocked_state_; }
96 void set_blocked_state(BlockedState blocked_state) {
97 blocked_state_ = blocked_state;
99 std::set<std::string> content_pack_categories() {
100 return content_pack_categories_;
102 void set_content_pack_categories(
103 const std::set<std::string>& content_pack_categories) {
104 content_pack_categories_ = content_pack_categories;
106 const std::vector<GURL>& redirect_chain() const { return redirect_chain_; }
108 private:
109 friend class ContentSerializedNavigationBuilder;
110 friend class ContentSerializedNavigationDriver;
111 friend class SerializedNavigationEntryTestHelper;
112 friend class IOSSerializedNavigationBuilder;
113 friend class IOSSerializedNavigationDriver;
115 // Index in the NavigationController.
116 int index_;
118 // Member variables corresponding to NavigationEntry fields.
119 int unique_id_;
120 GURL referrer_url_;
121 int referrer_policy_;
122 GURL virtual_url_;
123 base::string16 title_;
124 std::string encoded_page_state_;
125 ui::PageTransition transition_type_;
126 bool has_post_data_;
127 int64 post_id_;
128 GURL original_request_url_;
129 bool is_overriding_user_agent_;
130 base::Time timestamp_;
131 base::string16 search_terms_;
132 GURL favicon_url_;
133 int http_status_code_;
134 bool is_restored_; // Not persisted.
135 std::vector<GURL> redirect_chain_; // Not persisted.
137 // Additional information.
138 BlockedState blocked_state_;
139 std::set<std::string> content_pack_categories_;
142 } // namespace sessions
144 #endif // COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_