Update mojo sdk to rev 8563c3d4162bd74e96783e823e076e99869d7385
[chromium-blink-merge.git] / components / sessions / session_types.h
bloba7f035891ba5c6e2db6bb70eb0c4f1f238886393
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_
8 #include <algorithm>
9 #include <string>
10 #include <vector>
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"
22 #include "url/gurl.h"
24 namespace content {
25 class BrowserContext;
26 class NavigationEntry;
29 namespace sessions {
31 // SessionTab ----------------------------------------------------------------
33 // SessionTab corresponds to a NavigationController.
34 struct SESSIONS_EXPORT SessionTab {
35 SessionTab();
36 ~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
58 // favicon data.
59 sync_pb::SessionTab ToSyncData() const;
61 // Unique id of the window.
62 SessionID window_id;
64 // Unique if of the tab.
65 SessionID tab_id;
67 // Visual index of the tab within its window. There may be gaps in these
68 // values.
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.
73 int tab_visual_index;
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.
88 bool 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.
98 base::Time timestamp;
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;
108 private:
109 DISALLOW_COPY_AND_ASSIGN(SessionTab);
112 // SessionWindow -------------------------------------------------------------
114 // Describes a saved window.
115 struct SESSIONS_EXPORT SessionWindow {
116 SessionWindow();
117 ~SessionWindow();
119 // Possible window types which can be stored here. Note that these values will
120 // be written out to disc via session commands.
121 enum WindowType {
122 TYPE_TABBED = 0,
123 TYPE_POPUP = 1
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.
132 SessionID window_id;
134 // Bounds of the window.
135 gfx::Rect bounds;
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
143 // tabs.
144 int selected_tab_index;
146 // Type of the window. Note: This type is used to determine if the window gets
147 // saved or not.
148 WindowType type;
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.
154 bool is_constrained;
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;
167 private:
168 DISALLOW_COPY_AND_ASSIGN(SessionWindow);
171 } // namespace sessions
173 #endif // COMPONENTS_SESSIONS_SESSION_TYPES_H_