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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "base/time/time.h"
15 #include "chrome/browser/sessions/session_id.h"
16 #include "components/sessions/serialized_navigation_entry.h"
17 #include "content/public/common/page_transition_types.h"
18 #include "sync/protocol/session_specifics.pb.h"
19 #include "ui/base/ui_base_types.h"
20 #include "ui/gfx/rect.h"
25 class NavigationEntry
;
28 // SessionTab ----------------------------------------------------------------
30 // SessionTab corresponds to a NavigationController.
35 // Since the current_navigation_index can be larger than the index for number
36 // of navigations in the current sessions (chrome://newtab is not stored), we
37 // must perform bounds checking.
38 // Returns a normalized bounds-checked navigation_index.
39 int normalized_navigation_index() const {
40 return std::max(0, std::min(current_navigation_index
,
41 static_cast<int>(navigations
.size() - 1)));
44 // Set all the fields of this object from the given sync data and
45 // timestamp. Uses SerializedNavigationEntry::FromSyncData to fill
46 // |navigations|. Note that the sync protocol buffer doesn't
47 // contain all SerializedNavigationEntry fields.
48 void SetFromSyncData(const sync_pb::SessionTab
& sync_data
,
49 base::Time timestamp
);
51 // Convert this object into its sync protocol buffer equivalent.
52 // Uses SerializedNavigationEntry::ToSyncData to convert |navigations|. Note
53 // that the protocol buffer doesn't contain all SerializedNavigationEntry
54 // fields, and that the returned protocol buffer doesn't have any
56 sync_pb::SessionTab
ToSyncData() const;
58 // Unique id of the window.
61 // Unique if of the tab.
64 // Visual index of the tab within its window. There may be gaps in these
67 // NOTE: this is really only useful for the SessionService during
68 // restore, others can likely ignore this and use the order of the
69 // tabs in SessionWindow.tabs.
72 // Identifies the index of the current navigation in navigations. For
73 // example, if this is 2 it means the current navigation is navigations[2].
75 // NOTE: when the service is creating SessionTabs, initially this corresponds
76 // to SerializedNavigationEntry.index, not the index in navigations. When done
77 // creating though, this is set to the index in navigations.
79 // NOTE 2: this value can be larger than the size of |navigations|, due to
80 // only valid url's being stored (ie chrome://newtab is not stored). Bounds
81 // checking must be performed before indexing into |navigations|.
82 int current_navigation_index
;
84 // True if the tab is pinned.
87 // If non-empty, this tab is an app tab and this is the id of the extension.
88 std::string extension_app_id
;
90 // If non-empty, this string is used as the user agent whenever the tab's
91 // NavigationEntries need it overridden.
92 std::string user_agent_override
;
94 // Timestamp for when this tab was last modified.
97 std::vector
<sessions::SerializedNavigationEntry
> navigations
;
99 // For reassociating sessionStorage.
100 std::string session_storage_persistent_id
;
103 DISALLOW_COPY_AND_ASSIGN(SessionTab
);
106 // SessionWindow -------------------------------------------------------------
108 // Describes a saved window.
109 struct SessionWindow
{
113 // Convert this object into its sync protocol buffer equivalent. Note that
114 // not all fields are synced here, because they don't all make sense or
115 // translate when restoring a SessionWindow on another device.
116 sync_pb::SessionWindow
ToSyncData() const;
118 // Identifier of the window.
121 // Bounds of the window.
124 // Index of the selected tab in tabs; -1 if no tab is selected. After restore
125 // this value is guaranteed to be a valid index into tabs.
127 // NOTE: when the service is creating SessionWindows, initially this
128 // corresponds to SessionTab.tab_visual_index, not the index in
129 // tabs. When done creating though, this is set to the index in
131 int selected_tab_index
;
133 // Type of the browser. Currently we only store browsers of type
134 // TYPE_TABBED and TYPE_POPUP.
135 // This would be Browser::Type, but that would cause a circular dependency.
138 // If true, the window is constrained.
140 // Currently SessionService prunes all constrained windows so that session
141 // restore does not attempt to restore them.
144 // Timestamp for when this window was last modified.
145 base::Time timestamp
;
147 // The tabs, ordered by visual order.
148 std::vector
<SessionTab
*> tabs
;
150 // Is the window maximized, minimized, or normal?
151 ui::WindowShowState show_state
;
153 std::string app_name
;
156 DISALLOW_COPY_AND_ASSIGN(SessionWindow
);
159 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_