Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
|
Jói
2013/04/26 21:55:47
2013 since it is essentially a new file?
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 5 #ifndef COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 6 #define COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_ |
| 7 | 7 |
| 8 #include <algorithm> | |
| 9 #include <string> | 8 #include <string> |
| 10 #include <vector> | |
| 11 | 9 |
| 10 #include "base/basictypes.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/string16.h" | 12 #include "base/string16.h" |
| 14 #include "base/time.h" | 13 #include "base/time.h" |
| 15 #include "chrome/browser/sessions/session_id.h" | 14 #include "components/sessions/sessions_export.h" |
| 16 #include "content/public/common/page_transition_types.h" | 15 #include "content/public/common/page_transition_types.h" |
| 17 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
| 18 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 19 #include "sync/protocol/session_specifics.pb.h" | 18 #include "sync/protocol/session_specifics.pb.h" |
| 20 #include "ui/base/ui_base_types.h" | |
| 21 #include "ui/gfx/rect.h" | |
| 22 | 19 |
| 23 class Pickle; | 20 class Pickle; |
| 24 class PickleIterator; | 21 class PickleIterator; |
| 25 | 22 |
| 26 namespace content { | 23 namespace content { |
| 27 class BrowserContext; | 24 class BrowserContext; |
| 28 class NavigationEntry; | 25 class NavigationEntry; |
| 29 } | 26 } |
| 30 | 27 |
| 31 // TabNavigation ------------------------------------------------------------- | 28 namespace components { |
|
Jói
2013/04/26 21:55:47
Here and elsewhere, the namespace should actually
| |
| 32 | 29 |
| 33 // TabNavigation is a "freeze-dried" version of NavigationEntry. It | 30 class SerializedNavigationEntryTestHelper; |
| 34 // contains the data needed to restore a NavigationEntry during | 31 |
| 35 // session restore and tab restore, and it can also be pickled and | 32 // The key used to store search terms data in the NavigationEntry. |
| 36 // unpickled. It is also convertible to a sync protocol buffer for | 33 SESSIONS_EXPORT extern const char kSearchTermsKey[]; |
| 37 // session syncing. | 34 |
| 35 // SerializedNavigationEntry is a "freeze-dried" version of NavigationEntry. It | |
| 36 // contains the data needed to restore a NavigationEntry during session restore | |
| 37 // and tab restore, and it can also be pickled and unpickled. It is also | |
| 38 // convertible to a sync protocol buffer for session syncing. | |
| 38 // | 39 // |
| 39 // Default copy constructor and assignment operator welcome. | 40 // Default copy constructor and assignment operator welcome. |
| 40 class TabNavigation { | 41 class SESSIONS_EXPORT SerializedNavigationEntry { |
| 41 public: | 42 public: |
| 42 // Creates an invalid (index < 0) TabNavigation. | 43 // Creates an invalid (index < 0) SerializedNavigationEntry. |
| 43 TabNavigation(); | 44 SerializedNavigationEntry(); |
| 44 ~TabNavigation(); | 45 ~SerializedNavigationEntry(); |
| 45 | 46 |
| 46 // Construct a TabNavigation for a particular index from the given | 47 // Construct a SerializedNavigationEntry for a particular index from the given |
| 47 // NavigationEntry. | 48 // NavigationEntry. |
| 48 static TabNavigation FromNavigationEntry( | 49 static SerializedNavigationEntry FromNavigationEntry( |
| 49 int index, | 50 int index, |
| 50 const content::NavigationEntry& entry); | 51 const content::NavigationEntry& entry); |
| 51 | 52 |
| 52 // Construct a TabNavigation for a particular index from a sync | 53 // Construct a SerializedNavigationEntry for a particular index from a sync |
| 53 // protocol buffer. Note that the sync protocol buffer doesn't | 54 // protocol buffer. Note that the sync protocol buffer doesn't contain all |
| 54 // contain all TabNavigation fields. Also, the timestamp of the | 55 // SerializedNavigationEntry fields. Also, the timestamp of the returned |
| 55 // returned TabNavigation is nulled out, as we assume that the | 56 // SerializedNavigationEntry is nulled out, as we assume that the protocol |
| 56 // protocol buffer is from a foreign session. | 57 // buffer is from a foreign session. |
| 57 static TabNavigation FromSyncData( | 58 static SerializedNavigationEntry FromSyncData( |
| 58 int index, | 59 int index, |
| 59 const sync_pb::TabNavigation& sync_data); | 60 const sync_pb::TabNavigation& sync_data); |
| 60 | 61 |
| 61 // Note that not all TabNavigation fields are preserved. | 62 // Note that not all SerializedNavigationEntry fields are preserved. |
| 62 void WriteToPickle(Pickle* pickle) const; | 63 // |max_size| is the max number of bytes to write. |
| 64 void WriteToPickle(int max_size, Pickle* pickle) const; | |
|
Jói
2013/04/26 21:55:47
The change to add a max-size parameter should perh
| |
| 63 bool ReadFromPickle(PickleIterator* iterator); | 65 bool ReadFromPickle(PickleIterator* iterator); |
| 64 | 66 |
| 65 // Convert this TabNavigation into a NavigationEntry with the given | 67 // Convert this SerializedNavigationEntry into a NavigationEntry with the |
| 66 // page ID and context. The NavigationEntry will have a transition | 68 // given page ID and context. The NavigationEntry will have a transition type |
| 67 // type of PAGE_TRANSITION_RELOAD and a new unique ID. | 69 // of PAGE_TRANSITION_RELOAD and a new unique ID. |
| 68 scoped_ptr<content::NavigationEntry> ToNavigationEntry( | 70 scoped_ptr<content::NavigationEntry> ToNavigationEntry( |
| 69 int page_id, | 71 int page_id, |
| 70 content::BrowserContext* browser_context) const; | 72 content::BrowserContext* browser_context) const; |
| 71 | 73 |
| 72 // Convert this navigation into its sync protocol buffer equivalent. | 74 // Convert this navigation into its sync protocol buffer equivalent. Note |
| 73 // Note that the protocol buffer doesn't contain all TabNavigation | 75 // that the protocol buffer doesn't contain all SerializedNavigationEntry |
| 74 // fields. | 76 // fields. |
| 75 sync_pb::TabNavigation ToSyncData() const; | 77 sync_pb::TabNavigation ToSyncData() const; |
| 76 | 78 |
| 77 // The index in the NavigationController. This TabNavigation is | 79 // The index in the NavigationController. This SerializedNavigationEntry is |
| 78 // valid only when the index is non-negative. | 80 // valid only when the index is non-negative. |
| 79 // | |
| 80 // This is used when determining the selected TabNavigation and only | |
| 81 // used by SessionService. | |
| 82 int index() const { return index_; } | 81 int index() const { return index_; } |
| 83 void set_index(int index) { index_ = index; } | 82 void set_index(int index) { index_ = index; } |
| 84 | 83 |
| 85 // Accessors for some fields taken from NavigationEntry. | 84 // Accessors for some fields taken from NavigationEntry. |
| 86 int unique_id() const { return unique_id_; } | 85 int unique_id() const { return unique_id_; } |
| 87 const GURL& virtual_url() const { return virtual_url_; } | 86 const GURL& virtual_url() const { return virtual_url_; } |
| 88 const string16& title() const { return title_; } | 87 const string16& title() const { return title_; } |
| 89 const std::string& content_state() const { return content_state_; } | 88 const std::string& content_state() const { return content_state_; } |
| 90 const string16& search_terms() const { return search_terms_; } | 89 const string16& search_terms() const { return search_terms_; } |
| 91 const GURL& favicon_url() const { return favicon_url_; } | 90 const GURL& favicon_url() const { return favicon_url_; } |
| 91 const content::Referrer& referrer() const { return referrer_; } | |
|
Jói
2013/04/26 21:55:47
Likewise for these, may want to mention that you a
| |
| 92 content::PageTransition transition_type() const { | |
| 93 return transition_type_; | |
| 94 } | |
| 95 bool has_post_data() const { return has_post_data_; } | |
| 96 int64 post_id() const { return post_id_; } | |
| 97 const GURL& original_request_url() const { return original_request_url_; } | |
| 98 bool is_overriding_user_agent() const { return is_overriding_user_agent_; } | |
| 99 base::Time timestamp() const { return timestamp_; } | |
| 92 | 100 |
| 93 // Converts a set of TabNavigations into a list of NavigationEntrys | 101 // Converts a set of SerializedNavigationEntrys into a list of |
| 94 // with sequential page IDs and the given context. The caller owns | 102 // NavigationEntrys with sequential page IDs and the given context. The caller |
| 95 // the returned NavigationEntrys. | 103 // owns the returned NavigationEntrys. |
| 96 static std::vector<content::NavigationEntry*> | 104 static std::vector<content::NavigationEntry*> ToNavigationEntries( |
| 97 CreateNavigationEntriesFromTabNavigations( | 105 const std::vector<SerializedNavigationEntry>& navigations, |
| 98 const std::vector<TabNavigation>& navigations, | |
| 99 content::BrowserContext* browser_context); | 106 content::BrowserContext* browser_context); |
| 100 | 107 |
| 101 private: | 108 private: |
| 102 friend struct SessionTypesTestHelper; | 109 friend class SerializedNavigationEntryTestHelper; |
| 103 | 110 |
| 104 // Index in the NavigationController. | 111 // Index in the NavigationController. |
| 105 int index_; | 112 int index_; |
| 106 | 113 |
| 107 // Member variables corresponding to NavigationEntry fields. | 114 // Member variables corresponding to NavigationEntry fields. |
| 108 int unique_id_; | 115 int unique_id_; |
| 109 content::Referrer referrer_; | 116 content::Referrer referrer_; |
| 110 GURL virtual_url_; | 117 GURL virtual_url_; |
| 111 string16 title_; | 118 string16 title_; |
| 112 std::string content_state_; | 119 std::string content_state_; |
| 113 content::PageTransition transition_type_; | 120 content::PageTransition transition_type_; |
| 114 bool has_post_data_; | 121 bool has_post_data_; |
| 115 int64 post_id_; | 122 int64 post_id_; |
| 116 GURL original_request_url_; | 123 GURL original_request_url_; |
| 117 bool is_overriding_user_agent_; | 124 bool is_overriding_user_agent_; |
| 118 base::Time timestamp_; | 125 base::Time timestamp_; |
| 119 string16 search_terms_; | 126 string16 search_terms_; |
| 120 GURL favicon_url_; | 127 GURL favicon_url_; |
| 121 }; | 128 }; |
| 122 | 129 |
| 123 // SessionTab ---------------------------------------------------------------- | 130 } // namespace components |
| 124 | 131 |
| 125 // SessionTab corresponds to a NavigationController. | 132 #endif // COMPONENTS_SESSIONS_SERIALIZED_NAVIGATION_ENTRY_H_ |
| 126 struct SessionTab { | |
| 127 SessionTab(); | |
| 128 ~SessionTab(); | |
| 129 | |
| 130 // Since the current_navigation_index can be larger than the index for number | |
| 131 // of navigations in the current sessions (chrome://newtab is not stored), we | |
| 132 // must perform bounds checking. | |
| 133 // Returns a normalized bounds-checked navigation_index. | |
| 134 int normalized_navigation_index() const { | |
| 135 return std::max(0, std::min(current_navigation_index, | |
| 136 static_cast<int>(navigations.size() - 1))); | |
| 137 } | |
| 138 | |
| 139 // Set all the fields of this object from the given sync data and | |
| 140 // timestamp. Uses TabNavigation::FromSyncData to fill | |
| 141 // |navigations|. Note that the sync protocol buffer doesn't | |
| 142 // contain all TabNavigation fields. | |
| 143 void SetFromSyncData(const sync_pb::SessionTab& sync_data, | |
| 144 base::Time timestamp); | |
| 145 | |
| 146 // Convert this object into its sync protocol buffer equivalent. | |
| 147 // Uses TabNavigation::ToSyncData to convert |navigations|. Note | |
| 148 // that the protocol buffer doesn't contain all TabNavigation | |
| 149 // fields, and that the returned protocol buffer doesn't have any | |
| 150 // favicon data. | |
| 151 sync_pb::SessionTab ToSyncData() const; | |
| 152 | |
| 153 // Unique id of the window. | |
| 154 SessionID window_id; | |
| 155 | |
| 156 // Unique if of the tab. | |
| 157 SessionID tab_id; | |
| 158 | |
| 159 // Visual index of the tab within its window. There may be gaps in these | |
| 160 // values. | |
| 161 // | |
| 162 // NOTE: this is really only useful for the SessionService during | |
| 163 // restore, others can likely ignore this and use the order of the | |
| 164 // tabs in SessionWindow.tabs. | |
| 165 int tab_visual_index; | |
| 166 | |
| 167 // Identifies the index of the current navigation in navigations. For | |
| 168 // example, if this is 2 it means the current navigation is navigations[2]. | |
| 169 // | |
| 170 // NOTE: when the service is creating SessionTabs, initially this | |
| 171 // corresponds to TabNavigation.index, not the index in navigations. When done | |
| 172 // creating though, this is set to the index in navigations. | |
| 173 // | |
| 174 // NOTE 2: this value can be larger than the size of |navigations|, due to | |
| 175 // only valid url's being stored (ie chrome://newtab is not stored). Bounds | |
| 176 // checking must be performed before indexing into |navigations|. | |
| 177 int current_navigation_index; | |
| 178 | |
| 179 // True if the tab is pinned. | |
| 180 bool pinned; | |
| 181 | |
| 182 // If non-empty, this tab is an app tab and this is the id of the extension. | |
| 183 std::string extension_app_id; | |
| 184 | |
| 185 // If non-empty, this string is used as the user agent whenever the tab's | |
| 186 // NavigationEntries need it overridden. | |
| 187 std::string user_agent_override; | |
| 188 | |
| 189 // Timestamp for when this tab was last modified. | |
| 190 base::Time timestamp; | |
| 191 | |
| 192 std::vector<TabNavigation> navigations; | |
| 193 | |
| 194 // For reassociating sessionStorage. | |
| 195 std::string session_storage_persistent_id; | |
| 196 | |
| 197 private: | |
| 198 DISALLOW_COPY_AND_ASSIGN(SessionTab); | |
| 199 }; | |
| 200 | |
| 201 // SessionWindow ------------------------------------------------------------- | |
| 202 | |
| 203 // Describes a saved window. | |
| 204 struct SessionWindow { | |
| 205 SessionWindow(); | |
| 206 ~SessionWindow(); | |
| 207 | |
| 208 // Identifier of the window. | |
| 209 SessionID window_id; | |
| 210 | |
| 211 // Bounds of the window. | |
| 212 gfx::Rect bounds; | |
| 213 | |
| 214 // Index of the selected tab in tabs; -1 if no tab is selected. After restore | |
| 215 // this value is guaranteed to be a valid index into tabs. | |
| 216 // | |
| 217 // NOTE: when the service is creating SessionWindows, initially this | |
| 218 // corresponds to SessionTab.tab_visual_index, not the index in | |
| 219 // tabs. When done creating though, this is set to the index in | |
| 220 // tabs. | |
| 221 int selected_tab_index; | |
| 222 | |
| 223 // Type of the browser. Currently we only store browsers of type | |
| 224 // TYPE_TABBED and TYPE_POPUP. | |
| 225 // This would be Browser::Type, but that would cause a circular dependency. | |
| 226 int type; | |
| 227 | |
| 228 // If true, the window is constrained. | |
| 229 // | |
| 230 // Currently SessionService prunes all constrained windows so that session | |
| 231 // restore does not attempt to restore them. | |
| 232 bool is_constrained; | |
| 233 | |
| 234 // Timestamp for when this window was last modified. | |
| 235 base::Time timestamp; | |
| 236 | |
| 237 // The tabs, ordered by visual order. | |
| 238 std::vector<SessionTab*> tabs; | |
| 239 | |
| 240 // Is the window maximized, minimized, or normal? | |
| 241 ui::WindowShowState show_state; | |
| 242 | |
| 243 std::string app_name; | |
| 244 | |
| 245 private: | |
| 246 DISALLOW_COPY_AND_ASSIGN(SessionWindow); | |
| 247 }; | |
| 248 | |
| 249 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | |
| OLD | NEW |