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. 4 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 6 #define CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 7 8 #include <algorithm> 9 #include <string> 10 #include <vector> 11 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" 21 #include "url/gurl.h" 22 23 namespace content { 24 class BrowserContext; 25 class NavigationEntry; 26 } 27 28 // SessionTab ---------------------------------------------------------------- 29 30 // SessionTab corresponds to a NavigationController. 31 struct SessionTab { 32 SessionTab(); 33 ~SessionTab(); 34 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))); 42 } 43 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); 50 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 55 // favicon data. 56 sync_pb::SessionTab ToSyncData() const; 57 58 // Unique id of the window. 59 SessionID window_id; 60 61 // Unique if of the tab. 62 SessionID tab_id; 63 64 // Visual index of the tab within its window. There may be gaps in these 65 // values. 66 // 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. 70 int tab_visual_index; 71 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]. 74 // 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. 78 // 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; 83 84 // True if the tab is pinned. 85 bool pinned; 86 87 // If non-empty, this tab is an app tab and this is the id of the extension. 88 std::string extension_app_id; 89 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; 93 94 // Timestamp for when this tab was last modified. 95 base::Time timestamp; 96 97 std::vector<sessions::SerializedNavigationEntry> navigations; 98 99 // For reassociating sessionStorage. 100 std::string session_storage_persistent_id; 101 102 private: 103 DISALLOW_COPY_AND_ASSIGN(SessionTab); 104 }; 105 106 // SessionWindow ------------------------------------------------------------- 107 108 // Describes a saved window. 109 struct SessionWindow { 110 SessionWindow(); 111 ~SessionWindow(); 112 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; 117 118 // Identifier of the window. 119 SessionID window_id; 120 121 // Bounds of the window. 122 gfx::Rect bounds; 123 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. 126 // 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 130 // tabs. 131 int selected_tab_index; 132 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. 136 int type; 137 138 // If true, the window is constrained. 139 // 140 // Currently SessionService prunes all constrained windows so that session 141 // restore does not attempt to restore them. 142 bool is_constrained; 143 144 // Timestamp for when this window was last modified. 145 base::Time timestamp; 146 147 // The tabs, ordered by visual order. 148 std::vector<SessionTab*> tabs; 149 150 // Is the window maximized, minimized, or normal? 151 ui::WindowShowState show_state; 152 153 std::string app_name; 154 155 private: 156 DISALLOW_COPY_AND_ASSIGN(SessionWindow); 157 }; 158 159 #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ 160