Remove support for GICE in CRD host and client
[chromium-blink-merge.git] / components / sessions / serialized_navigation_entry.h
blob44135f489d99e6bb116ae7df9800cee336f0fda5
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 namespace base {
21 class Pickle;
22 class PickleIterator;
25 namespace sync_pb {
26 class TabNavigation;
29 namespace sessions {
31 class SerializedNavigationEntryTestHelper;
33 // The key used to store search terms data in the NavigationEntry.
34 SESSIONS_EXPORT extern const char kSearchTermsKey[];
36 // SerializedNavigationEntry is a "freeze-dried" version of NavigationEntry. It
37 // contains the data needed to restore a NavigationEntry during session restore
38 // and tab restore, and it can also be pickled and unpickled. It is also
39 // convertible to a sync protocol buffer for session syncing.
41 // Default copy constructor and assignment operator welcome.
42 class SESSIONS_EXPORT SerializedNavigationEntry {
43 public:
44 enum BlockedState {
45 STATE_INVALID = 0,
46 STATE_ALLOWED = 1,
47 STATE_BLOCKED = 2,
50 // Creates an invalid (index < 0) SerializedNavigationEntry.
51 SerializedNavigationEntry();
52 ~SerializedNavigationEntry();
54 // Construct a SerializedNavigationEntry for a particular index from a sync
55 // protocol buffer. Note that the sync protocol buffer doesn't contain all
56 // SerializedNavigationEntry fields. Also, the timestamp of the returned
57 // SerializedNavigationEntry is nulled out, as we assume that the protocol
58 // buffer is from a foreign session.
59 static SerializedNavigationEntry FromSyncData(
60 int index,
61 const sync_pb::TabNavigation& sync_data);
63 // Note that not all SerializedNavigationEntry fields are preserved.
64 // |max_size| is the max number of bytes to write.
65 void WriteToPickle(int max_size, base::Pickle* pickle) const;
66 bool ReadFromPickle(base::PickleIterator* iterator);
68 // Convert this navigation into its sync protocol buffer equivalent. Note
69 // that the protocol buffer doesn't contain all SerializedNavigationEntry
70 // fields.
71 sync_pb::TabNavigation ToSyncData() const;
73 // The index in the NavigationController. This SerializedNavigationEntry is
74 // valid only when the index is non-negative.
75 int index() const { return index_; }
76 void set_index(int index) { index_ = index; }
78 // Accessors for some fields taken from NavigationEntry.
79 int unique_id() const { return unique_id_; }
80 const GURL& virtual_url() const { return virtual_url_; }
81 const base::string16& title() const { return title_; }
82 const std::string& encoded_page_state() const { return encoded_page_state_; }
83 const base::string16& search_terms() const { return search_terms_; }
84 const GURL& favicon_url() const { return favicon_url_; }
85 int http_status_code() const { return http_status_code_; }
86 const GURL& referrer_url() const { return referrer_url_; }
87 int referrer_policy() const { return referrer_policy_; }
88 ui::PageTransition transition_type() const {
89 return transition_type_;
91 bool has_post_data() const { return has_post_data_; }
92 int64 post_id() const { return post_id_; }
93 const GURL& original_request_url() const { return original_request_url_; }
94 bool is_overriding_user_agent() const { return is_overriding_user_agent_; }
95 base::Time timestamp() const { return timestamp_; }
97 BlockedState blocked_state() { return blocked_state_; }
98 void set_blocked_state(BlockedState blocked_state) {
99 blocked_state_ = blocked_state;
101 std::set<std::string> content_pack_categories() {
102 return content_pack_categories_;
104 void set_content_pack_categories(
105 const std::set<std::string>& content_pack_categories) {
106 content_pack_categories_ = content_pack_categories;
108 const std::vector<GURL>& redirect_chain() const { return redirect_chain_; }
110 private:
111 friend class ContentSerializedNavigationBuilder;
112 friend class ContentSerializedNavigationDriver;
113 friend class SerializedNavigationEntryTestHelper;
114 friend class IOSSerializedNavigationBuilder;
115 friend class IOSSerializedNavigationDriver;
117 // Index in the NavigationController.
118 int index_;
120 // Member variables corresponding to NavigationEntry fields.
121 int unique_id_;
122 GURL referrer_url_;
123 int referrer_policy_;
124 GURL virtual_url_;
125 base::string16 title_;
126 std::string encoded_page_state_;
127 ui::PageTransition transition_type_;
128 bool has_post_data_;
129 int64 post_id_;
130 GURL original_request_url_;
131 bool is_overriding_user_agent_;
132 base::Time timestamp_;
133 base::string16 search_terms_;
134 GURL favicon_url_;
135 int http_status_code_;
136 bool is_restored_; // Not persisted.
137 std::vector<GURL> redirect_chain_; // Not persisted.
139 // Additional information.
140 BlockedState blocked_state_;
141 std::set<std::string> content_pack_categories_;
144 } // namespace sessions
146 #endif // COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_