| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 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 CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ |
| 7 | 7 |
| 8 #include <algorithm> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string16.h" | 13 #include "base/string16.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "chrome/browser/sessions/session_id.h" | 15 #include "chrome/browser/sessions/session_id.h" |
| 15 #include "content/public/common/page_transition_types.h" | 16 #include "content/public/common/page_transition_types.h" |
| 16 #include "content/public/common/referrer.h" | 17 #include "content/public/common/referrer.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 static TabNavigation FromNavigationEntry( | 52 static TabNavigation FromNavigationEntry( |
| 52 int index, | 53 int index, |
| 53 const content::NavigationEntry& entry, | 54 const content::NavigationEntry& entry, |
| 54 base::Time timestamp); | 55 base::Time timestamp); |
| 55 | 56 |
| 56 // Construct a TabNavigation for a particular index from a sync | 57 // Construct a TabNavigation for a particular index from a sync |
| 57 // protocol buffer. Note that the sync protocol buffer doesn't | 58 // protocol buffer. Note that the sync protocol buffer doesn't |
| 58 // contain all TabNavigation fields. | 59 // contain all TabNavigation fields. |
| 59 static TabNavigation FromSyncData( | 60 static TabNavigation FromSyncData( |
| 60 int index, | 61 int index, |
| 61 const sync_pb::TabNavigation& specifics); | 62 const sync_pb::TabNavigation& sync_data); |
| 62 | 63 |
| 63 // Note that not all TabNavigation fields are preserved. | 64 // Note that not all TabNavigation fields are preserved. |
| 64 void WriteToPickle(Pickle* pickle) const; | 65 void WriteToPickle(Pickle* pickle) const; |
| 65 bool ReadFromPickle(PickleIterator* iterator); | 66 bool ReadFromPickle(PickleIterator* iterator); |
| 66 | 67 |
| 67 // Convert this TabNavigation into a NavigationEntry with the given | 68 // Convert this TabNavigation into a NavigationEntry with the given |
| 68 // page ID and context. The NavigationEntry will have a transition | 69 // page ID and context. The NavigationEntry will have a transition |
| 69 // type of PAGE_TRANSITION_RELOAD and a new unique ID. | 70 // type of PAGE_TRANSITION_RELOAD and a new unique ID. |
| 70 scoped_ptr<content::NavigationEntry> ToNavigationEntry( | 71 scoped_ptr<content::NavigationEntry> ToNavigationEntry( |
| 71 int page_id, | 72 int page_id, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // | 124 // |
| 124 // TODO(akalin): Add a timestamp field to NavigationEntry. | 125 // TODO(akalin): Add a timestamp field to NavigationEntry. |
| 125 base::Time timestamp_; | 126 base::Time timestamp_; |
| 126 }; | 127 }; |
| 127 | 128 |
| 128 // SessionTab ---------------------------------------------------------------- | 129 // SessionTab ---------------------------------------------------------------- |
| 129 | 130 |
| 130 // SessionTab corresponds to a NavigationController. | 131 // SessionTab corresponds to a NavigationController. |
| 131 struct SessionTab { | 132 struct SessionTab { |
| 132 SessionTab(); | 133 SessionTab(); |
| 133 virtual ~SessionTab(); | 134 ~SessionTab(); |
| 134 | 135 |
| 135 // Since the current_navigation_index can be larger than the index for number | 136 // Since the current_navigation_index can be larger than the index for number |
| 136 // of navigations in the current sessions (chrome://newtab is not stored), we | 137 // of navigations in the current sessions (chrome://newtab is not stored), we |
| 137 // must perform bounds checking. | 138 // must perform bounds checking. |
| 138 // Returns a normalized bounds-checked navigation_index. | 139 // Returns a normalized bounds-checked navigation_index. |
| 139 int normalized_navigation_index() const { | 140 int normalized_navigation_index() const { |
| 140 return std::max(0, std::min(current_navigation_index, | 141 return std::max(0, std::min(current_navigation_index, |
| 141 static_cast<int>(navigations.size() - 1))); | 142 static_cast<int>(navigations.size() - 1))); |
| 142 } | 143 } |
| 143 | 144 |
| 145 // Set all the fields of this object from the given sync data and |
| 146 // timestamp. Uses TabNavigation::FromSyncData to fill |
| 147 // |navigations|. Note that the sync protocol buffer doesn't |
| 148 // contain all TabNavigation fields. |
| 149 void SetFromSyncData(const sync_pb::SessionTab& sync_data, |
| 150 base::Time timestamp); |
| 151 |
| 152 // Convert this object into its sync protocol buffer equivalent. |
| 153 // Uses TabNavigation::ToSyncData to convert |navigations|. Note |
| 154 // that the protocol buffer doesn't contain all TabNavigation |
| 155 // fields, and that the returned protocol buffer doesn't have any |
| 156 // favicon data. |
| 157 sync_pb::SessionTab ToSyncData() const; |
| 158 |
| 144 // Unique id of the window. | 159 // Unique id of the window. |
| 145 SessionID window_id; | 160 SessionID window_id; |
| 146 | 161 |
| 147 // Unique if of the tab. | 162 // Unique if of the tab. |
| 148 SessionID tab_id; | 163 SessionID tab_id; |
| 149 | 164 |
| 150 // Visual index of the tab within its window. There may be gaps in these | 165 // Visual index of the tab within its window. There may be gaps in these |
| 151 // values. | 166 // values. |
| 152 // | 167 // |
| 153 // NOTE: this is really only useful for the SessionService during | 168 // NOTE: this is really only useful for the SessionService during |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Is the window maximized, minimized, or normal? | 246 // Is the window maximized, minimized, or normal? |
| 232 ui::WindowShowState show_state; | 247 ui::WindowShowState show_state; |
| 233 | 248 |
| 234 std::string app_name; | 249 std::string app_name; |
| 235 | 250 |
| 236 private: | 251 private: |
| 237 DISALLOW_COPY_AND_ASSIGN(SessionWindow); | 252 DISALLOW_COPY_AND_ASSIGN(SessionWindow); |
| 238 }; | 253 }; |
| 239 | 254 |
| 240 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ | 255 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ |
| OLD | NEW |