Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / sessions / session_types.h
blob35b4d29bae78060651e76b8044c5596f7692b997
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_
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 "sync/protocol/session_specifics.pb.h"
18 #include "ui/base/ui_base_types.h"
19 #include "ui/gfx/rect.h"
20 #include "url/gurl.h"
22 namespace content {
23 class BrowserContext;
24 class NavigationEntry;
27 // SessionTab ----------------------------------------------------------------
29 // SessionTab corresponds to a NavigationController.
30 struct SessionTab {
31 SessionTab();
32 ~SessionTab();
34 // Since the current_navigation_index can be larger than the index for number
35 // of navigations in the current sessions (chrome://newtab is not stored), we
36 // must perform bounds checking.
37 // Returns a normalized bounds-checked navigation_index.
38 int normalized_navigation_index() const {
39 return std::max(0, std::min(current_navigation_index,
40 static_cast<int>(navigations.size() - 1)));
43 // Set all the fields of this object from the given sync data and
44 // timestamp. Uses SerializedNavigationEntry::FromSyncData to fill
45 // |navigations|. Note that the sync protocol buffer doesn't
46 // contain all SerializedNavigationEntry fields.
47 void SetFromSyncData(const sync_pb::SessionTab& sync_data,
48 base::Time timestamp);
50 // Convert this object into its sync protocol buffer equivalent.
51 // Uses SerializedNavigationEntry::ToSyncData to convert |navigations|. Note
52 // that the protocol buffer doesn't contain all SerializedNavigationEntry
53 // fields, and that the returned protocol buffer doesn't have any
54 // favicon data.
55 sync_pb::SessionTab ToSyncData() const;
57 // Unique id of the window.
58 SessionID window_id;
60 // Unique if of the tab.
61 SessionID tab_id;
63 // Visual index of the tab within its window. There may be gaps in these
64 // values.
66 // NOTE: this is really only useful for the SessionService during
67 // restore, others can likely ignore this and use the order of the
68 // tabs in SessionWindow.tabs.
69 int tab_visual_index;
71 // Identifies the index of the current navigation in navigations. For
72 // example, if this is 2 it means the current navigation is navigations[2].
74 // NOTE: when the service is creating SessionTabs, initially this corresponds
75 // to SerializedNavigationEntry.index, not the index in navigations. When done
76 // creating though, this is set to the index in navigations.
78 // NOTE 2: this value can be larger than the size of |navigations|, due to
79 // only valid url's being stored (ie chrome://newtab is not stored). Bounds
80 // checking must be performed before indexing into |navigations|.
81 int current_navigation_index;
83 // True if the tab is pinned.
84 bool pinned;
86 // If non-empty, this tab is an app tab and this is the id of the extension.
87 std::string extension_app_id;
89 // If non-empty, this string is used as the user agent whenever the tab's
90 // NavigationEntries need it overridden.
91 std::string user_agent_override;
93 // Timestamp for when this tab was last modified.
94 base::Time timestamp;
96 std::vector<sessions::SerializedNavigationEntry> navigations;
98 // For reassociating sessionStorage.
99 std::string session_storage_persistent_id;
101 private:
102 DISALLOW_COPY_AND_ASSIGN(SessionTab);
105 // SessionWindow -------------------------------------------------------------
107 // Describes a saved window.
108 struct SessionWindow {
109 SessionWindow();
110 ~SessionWindow();
112 // Convert this object into its sync protocol buffer equivalent. Note that
113 // not all fields are synced here, because they don't all make sense or
114 // translate when restoring a SessionWindow on another device.
115 sync_pb::SessionWindow ToSyncData() const;
117 // Identifier of the window.
118 SessionID window_id;
120 // Bounds of the window.
121 gfx::Rect bounds;
123 // Index of the selected tab in tabs; -1 if no tab is selected. After restore
124 // this value is guaranteed to be a valid index into tabs.
126 // NOTE: when the service is creating SessionWindows, initially this
127 // corresponds to SessionTab.tab_visual_index, not the index in
128 // tabs. When done creating though, this is set to the index in
129 // tabs.
130 int selected_tab_index;
132 // Type of the browser. Currently we only store browsers of type
133 // TYPE_TABBED and TYPE_POPUP.
134 // This would be Browser::Type, but that would cause a circular dependency.
135 int type;
137 // If true, the window is constrained.
139 // Currently SessionService prunes all constrained windows so that session
140 // restore does not attempt to restore them.
141 bool is_constrained;
143 // Timestamp for when this window was last modified.
144 base::Time timestamp;
146 // The tabs, ordered by visual order.
147 std::vector<SessionTab*> tabs;
149 // Is the window maximized, minimized, or normal?
150 ui::WindowShowState show_state;
152 std::string app_name;
154 private:
155 DISALLOW_COPY_AND_ASSIGN(SessionWindow);
158 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_