| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_SESSIONS_SESSION_TYPES_H_ | |
| 6 #define COMPONENTS_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 "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" | |
| 23 | |
| 24 namespace content { | |
| 25 class BrowserContext; | |
| 26 class NavigationEntry; | |
| 27 } | |
| 28 | |
| 29 namespace sessions { | |
| 30 | |
| 31 // SessionTab ---------------------------------------------------------------- | |
| 32 | |
| 33 // SessionTab corresponds to a NavigationController. | |
| 34 struct SESSIONS_EXPORT SessionTab { | |
| 35 SessionTab(); | |
| 36 ~SessionTab(); | |
| 37 | |
| 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))); | |
| 45 } | |
| 46 | |
| 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); | |
| 53 | |
| 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; | |
| 60 | |
| 61 // Unique id of the window. | |
| 62 SessionID window_id; | |
| 63 | |
| 64 // Unique if of the tab. | |
| 65 SessionID tab_id; | |
| 66 | |
| 67 // Visual index of the tab within its window. There may be gaps in these | |
| 68 // values. | |
| 69 // | |
| 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; | |
| 74 | |
| 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]. | |
| 77 // | |
| 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. | |
| 81 // | |
| 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; | |
| 86 | |
| 87 // True if the tab is pinned. | |
| 88 bool pinned; | |
| 89 | |
| 90 // If non-empty, this tab is an app tab and this is the id of the extension. | |
| 91 std::string extension_app_id; | |
| 92 | |
| 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; | |
| 96 | |
| 97 // Timestamp for when this tab was last modified. | |
| 98 base::Time timestamp; | |
| 99 | |
| 100 // Timestamp for when this tab was last activated. As these use TimeTicks, | |
| 101 // they should not be compared with one another, unless it's within the same | |
| 102 // chrome session. | |
| 103 base::TimeTicks last_active_time; | |
| 104 | |
| 105 std::vector<sessions::SerializedNavigationEntry> navigations; | |
| 106 | |
| 107 // For reassociating sessionStorage. | |
| 108 std::string session_storage_persistent_id; | |
| 109 | |
| 110 // Ids of the currently assigned variations which should be sent to sync. | |
| 111 std::vector<variations::VariationID> variation_ids; | |
| 112 | |
| 113 private: | |
| 114 DISALLOW_COPY_AND_ASSIGN(SessionTab); | |
| 115 }; | |
| 116 | |
| 117 // SessionWindow ------------------------------------------------------------- | |
| 118 | |
| 119 // Describes a saved window. | |
| 120 struct SESSIONS_EXPORT SessionWindow { | |
| 121 SessionWindow(); | |
| 122 ~SessionWindow(); | |
| 123 | |
| 124 // Possible window types which can be stored here. Note that these values will | |
| 125 // be written out to disc via session commands. | |
| 126 enum WindowType { | |
| 127 TYPE_TABBED = 0, | |
| 128 TYPE_POPUP = 1 | |
| 129 }; | |
| 130 | |
| 131 // Convert this object into its sync protocol buffer equivalent. Note that | |
| 132 // not all fields are synced here, because they don't all make sense or | |
| 133 // translate when restoring a SessionWindow on another device. | |
| 134 sync_pb::SessionWindow ToSyncData() const; | |
| 135 | |
| 136 // Identifier of the window. | |
| 137 SessionID window_id; | |
| 138 | |
| 139 // Bounds of the window. | |
| 140 gfx::Rect bounds; | |
| 141 | |
| 142 // Index of the selected tab in tabs; -1 if no tab is selected. After restore | |
| 143 // this value is guaranteed to be a valid index into tabs. | |
| 144 // | |
| 145 // NOTE: when the service is creating SessionWindows, initially this | |
| 146 // corresponds to SessionTab.tab_visual_index, not the index in | |
| 147 // tabs. When done creating though, this is set to the index in | |
| 148 // tabs. | |
| 149 int selected_tab_index; | |
| 150 | |
| 151 // Type of the window. Note: This type is used to determine if the window gets | |
| 152 // saved or not. | |
| 153 WindowType type; | |
| 154 | |
| 155 // If true, the window is constrained. | |
| 156 // | |
| 157 // Currently SessionService prunes all constrained windows so that session | |
| 158 // restore does not attempt to restore them. | |
| 159 bool is_constrained; | |
| 160 | |
| 161 // Timestamp for when this window was last modified. | |
| 162 base::Time timestamp; | |
| 163 | |
| 164 // The tabs, ordered by visual order. | |
| 165 std::vector<SessionTab*> tabs; | |
| 166 | |
| 167 // Is the window maximized, minimized, or normal? | |
| 168 ui::WindowShowState show_state; | |
| 169 | |
| 170 std::string app_name; | |
| 171 | |
| 172 private: | |
| 173 DISALLOW_COPY_AND_ASSIGN(SessionWindow); | |
| 174 }; | |
| 175 | |
| 176 } // namespace sessions | |
| 177 | |
| 178 #endif // COMPONENTS_SESSIONS_SESSION_TYPES_H_ | |
| OLD | NEW |