Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / components / sessions / session_types.h
blobf26eaea4934e16b7dca1ddc24670d0b4c79fc5bd
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 "sync/protocol/session_specifics.pb.h"
19 #include "ui/base/ui_base_types.h"
20 #include "ui/gfx/rect.h"
21 #include "url/gurl.h"
23 namespace content {
24 class BrowserContext;
25 class NavigationEntry;
28 namespace sessions {
30 // SessionTab ----------------------------------------------------------------
32 // SessionTab corresponds to a NavigationController.
33 struct SESSIONS_EXPORT SessionTab {
34 SessionTab();
35 ~SessionTab();
37 // Since the current_navigation_index can be larger than the index for number
38 // of navigations in the current sessions (chrome://newtab is not stored), we
39 // must perform bounds checking.
40 // Returns a normalized bounds-checked navigation_index.
41 int normalized_navigation_index() const {
42 return std::max(0, std::min(current_navigation_index,
43 static_cast<int>(navigations.size() - 1)));
46 // Set all the fields of this object from the given sync data and
47 // timestamp. Uses SerializedNavigationEntry::FromSyncData to fill
48 // |navigations|. Note that the sync protocol buffer doesn't
49 // contain all SerializedNavigationEntry fields.
50 void SetFromSyncData(const sync_pb::SessionTab& sync_data,
51 base::Time timestamp);
53 // Convert this object into its sync protocol buffer equivalent.
54 // Uses SerializedNavigationEntry::ToSyncData to convert |navigations|. Note
55 // that the protocol buffer doesn't contain all SerializedNavigationEntry
56 // fields, and that the returned protocol buffer doesn't have any
57 // favicon data.
58 sync_pb::SessionTab ToSyncData() const;
60 // Unique id of the window.
61 SessionID window_id;
63 // Unique if of the tab.
64 SessionID tab_id;
66 // Visual index of the tab within its window. There may be gaps in these
67 // values.
69 // NOTE: this is really only useful for the SessionService during
70 // restore, others can likely ignore this and use the order of the
71 // tabs in SessionWindow.tabs.
72 int tab_visual_index;
74 // Identifies the index of the current navigation in navigations. For
75 // example, if this is 2 it means the current navigation is navigations[2].
77 // NOTE: when the service is creating SessionTabs, initially this corresponds
78 // to SerializedNavigationEntry.index, not the index in navigations. When done
79 // creating though, this is set to the index in navigations.
81 // NOTE 2: this value can be larger than the size of |navigations|, due to
82 // only valid url's being stored (ie chrome://newtab is not stored). Bounds
83 // checking must be performed before indexing into |navigations|.
84 int current_navigation_index;
86 // True if the tab is pinned.
87 bool pinned;
89 // If non-empty, this tab is an app tab and this is the id of the extension.
90 std::string extension_app_id;
92 // If non-empty, this string is used as the user agent whenever the tab's
93 // NavigationEntries need it overridden.
94 std::string user_agent_override;
96 // Timestamp for when this tab was last modified.
97 base::Time timestamp;
99 std::vector<sessions::SerializedNavigationEntry> navigations;
101 // For reassociating sessionStorage.
102 std::string session_storage_persistent_id;
104 private:
105 DISALLOW_COPY_AND_ASSIGN(SessionTab);
108 // SessionWindow -------------------------------------------------------------
110 // Describes a saved window.
111 struct SESSIONS_EXPORT SessionWindow {
112 SessionWindow();
113 ~SessionWindow();
115 // Possible window types which can be stored here. Note that these values will
116 // be written out to disc via session commands.
117 enum WindowType {
118 TYPE_TABBED = 0,
119 TYPE_POPUP = 1
122 // Convert this object into its sync protocol buffer equivalent. Note that
123 // not all fields are synced here, because they don't all make sense or
124 // translate when restoring a SessionWindow on another device.
125 sync_pb::SessionWindow ToSyncData() const;
127 // Identifier of the window.
128 SessionID window_id;
130 // Bounds of the window.
131 gfx::Rect bounds;
133 // Index of the selected tab in tabs; -1 if no tab is selected. After restore
134 // this value is guaranteed to be a valid index into tabs.
136 // NOTE: when the service is creating SessionWindows, initially this
137 // corresponds to SessionTab.tab_visual_index, not the index in
138 // tabs. When done creating though, this is set to the index in
139 // tabs.
140 int selected_tab_index;
142 // Type of the window. Note: This type is used to determine if the window gets
143 // saved or not.
144 WindowType type;
146 // If true, the window is constrained.
148 // Currently SessionService prunes all constrained windows so that session
149 // restore does not attempt to restore them.
150 bool is_constrained;
152 // Timestamp for when this window was last modified.
153 base::Time timestamp;
155 // The tabs, ordered by visual order.
156 std::vector<SessionTab*> tabs;
158 // Is the window maximized, minimized, or normal?
159 ui::WindowShowState show_state;
161 std::string app_name;
163 private:
164 DISALLOW_COPY_AND_ASSIGN(SessionWindow);
167 } // namespace sessions
169 #endif // COMPONENTS_SESSIONS_SESSION_TYPES_H_