• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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"
21 
22 namespace content {
23 class BrowserContext;
24 class NavigationEntry;
25 }
26 
27 // SessionTab ----------------------------------------------------------------
28 
29 // SessionTab corresponds to a NavigationController.
30 struct SessionTab {
31   SessionTab();
32   ~SessionTab();
33 
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.
normalized_navigation_indexSessionTab38   int normalized_navigation_index() const {
39     return std::max(0, std::min(current_navigation_index,
40                                 static_cast<int>(navigations.size() - 1)));
41   }
42 
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);
49 
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;
56 
57   // Unique id of the window.
58   SessionID window_id;
59 
60   // Unique if of the tab.
61   SessionID tab_id;
62 
63   // Visual index of the tab within its window. There may be gaps in these
64   // values.
65   //
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;
70 
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].
73   //
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.
77   //
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;
82 
83   // True if the tab is pinned.
84   bool pinned;
85 
86   // If non-empty, this tab is an app tab and this is the id of the extension.
87   std::string extension_app_id;
88 
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;
92 
93   // Timestamp for when this tab was last modified.
94   base::Time timestamp;
95 
96   std::vector<sessions::SerializedNavigationEntry> navigations;
97 
98   // For reassociating sessionStorage.
99   std::string session_storage_persistent_id;
100 
101  private:
102   DISALLOW_COPY_AND_ASSIGN(SessionTab);
103 };
104 
105 // SessionWindow -------------------------------------------------------------
106 
107 // Describes a saved window.
108 struct SessionWindow {
109   SessionWindow();
110   ~SessionWindow();
111 
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;
116 
117   // Identifier of the window.
118   SessionID window_id;
119 
120   // Bounds of the window.
121   gfx::Rect bounds;
122 
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.
125   //
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;
131 
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;
136 
137   // If true, the window is constrained.
138   //
139   // Currently SessionService prunes all constrained windows so that session
140   // restore does not attempt to restore them.
141   bool is_constrained;
142 
143   // Timestamp for when this window was last modified.
144   base::Time timestamp;
145 
146   // The tabs, ordered by visual order.
147   std::vector<SessionTab*> tabs;
148 
149   // Is the window maximized, minimized, or normal?
150   ui::WindowShowState show_state;
151 
152   std::string app_name;
153 
154  private:
155   DISALLOW_COPY_AND_ASSIGN(SessionWindow);
156 };
157 
158 #endif  // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_
159