1 // Copyright 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 COMPONENTS_SESSIONS_SESSION_TYPES_H_
6 #define COMPONENTS_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 "components/sessions/serialized_navigation_entry.h"
16 #include "components/sessions/session_id.h"
17 #include "components/sessions/sessions_export.h"
18 #include "components/variations/variations_associated_data.h"
19 #include "sync/protocol/session_specifics.pb.h"
20 #include "ui/base/ui_base_types.h"
21 #include "ui/gfx/geometry/rect.h"
26 class NavigationEntry
;
31 // SessionTab ----------------------------------------------------------------
33 // SessionTab corresponds to a NavigationController.
34 struct SESSIONS_EXPORT SessionTab
{
38 // Since the current_navigation_index can be larger than the index for number
39 // of navigations in the current sessions (chrome://newtab is not stored), we
40 // must perform bounds checking.
41 // Returns a normalized bounds-checked navigation_index.
42 int normalized_navigation_index() const {
43 return std::max(0, std::min(current_navigation_index
,
44 static_cast<int>(navigations
.size() - 1)));
47 // Set all the fields of this object from the given sync data and
48 // timestamp. Uses SerializedNavigationEntry::FromSyncData to fill
49 // |navigations|. Note that the sync protocol buffer doesn't
50 // contain all SerializedNavigationEntry fields.
51 void SetFromSyncData(const sync_pb::SessionTab
& sync_data
,
52 base::Time timestamp
);
54 // Convert this object into its sync protocol buffer equivalent.
55 // Uses SerializedNavigationEntry::ToSyncData to convert |navigations|. Note
56 // that the protocol buffer doesn't contain all SerializedNavigationEntry
57 // fields, and that the returned protocol buffer doesn't have any
59 sync_pb::SessionTab
ToSyncData() const;
61 // Unique id of the window.
64 // Unique if of the tab.
67 // Visual index of the tab within its window. There may be gaps in these
70 // NOTE: this is really only useful for the SessionService during
71 // restore, others can likely ignore this and use the order of the
72 // tabs in SessionWindow.tabs.
75 // Identifies the index of the current navigation in navigations. For
76 // example, if this is 2 it means the current navigation is navigations[2].
78 // NOTE: when the service is creating SessionTabs, initially this corresponds
79 // to SerializedNavigationEntry.index, not the index in navigations. When done
80 // creating though, this is set to the index in navigations.
82 // NOTE 2: this value can be larger than the size of |navigations|, due to
83 // only valid url's being stored (ie chrome://newtab is not stored). Bounds
84 // checking must be performed before indexing into |navigations|.
85 int current_navigation_index
;
87 // True if the tab is pinned.
90 // If non-empty, this tab is an app tab and this is the id of the extension.
91 std::string extension_app_id
;
93 // If non-empty, this string is used as the user agent whenever the tab's
94 // NavigationEntries need it overridden.
95 std::string user_agent_override
;
97 // Timestamp for when this tab was last modified.
100 std::vector
<sessions::SerializedNavigationEntry
> navigations
;
102 // For reassociating sessionStorage.
103 std::string session_storage_persistent_id
;
105 // Ids of the currently assigned variations which should be sent to sync.
106 std::vector
<variations::VariationID
> variation_ids
;
109 DISALLOW_COPY_AND_ASSIGN(SessionTab
);
112 // SessionWindow -------------------------------------------------------------
114 // Describes a saved window.
115 struct SESSIONS_EXPORT SessionWindow
{
119 // Possible window types which can be stored here. Note that these values will
120 // be written out to disc via session commands.
126 // Convert this object into its sync protocol buffer equivalent. Note that
127 // not all fields are synced here, because they don't all make sense or
128 // translate when restoring a SessionWindow on another device.
129 sync_pb::SessionWindow
ToSyncData() const;
131 // Identifier of the window.
134 // Bounds of the window.
137 // Index of the selected tab in tabs; -1 if no tab is selected. After restore
138 // this value is guaranteed to be a valid index into tabs.
140 // NOTE: when the service is creating SessionWindows, initially this
141 // corresponds to SessionTab.tab_visual_index, not the index in
142 // tabs. When done creating though, this is set to the index in
144 int selected_tab_index
;
146 // Type of the window. Note: This type is used to determine if the window gets
150 // If true, the window is constrained.
152 // Currently SessionService prunes all constrained windows so that session
153 // restore does not attempt to restore them.
156 // Timestamp for when this window was last modified.
157 base::Time timestamp
;
159 // The tabs, ordered by visual order.
160 std::vector
<SessionTab
*> tabs
;
162 // Is the window maximized, minimized, or normal?
163 ui::WindowShowState show_state
;
165 std::string app_name
;
168 DISALLOW_COPY_AND_ASSIGN(SessionWindow
);
171 } // namespace sessions
173 #endif // COMPONENTS_SESSIONS_SESSION_TYPES_H_