Home | History | Annotate | Download | only in sessions
      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   // Identifier of the window.
    114   SessionID window_id;
    115 
    116   // Bounds of the window.
    117   gfx::Rect bounds;
    118 
    119   // Index of the selected tab in tabs; -1 if no tab is selected. After restore
    120   // this value is guaranteed to be a valid index into tabs.
    121   //
    122   // NOTE: when the service is creating SessionWindows, initially this
    123   // corresponds to SessionTab.tab_visual_index, not the index in
    124   // tabs. When done creating though, this is set to the index in
    125   // tabs.
    126   int selected_tab_index;
    127 
    128   // Type of the browser. Currently we only store browsers of type
    129   // TYPE_TABBED and TYPE_POPUP.
    130   // This would be Browser::Type, but that would cause a circular dependency.
    131   int type;
    132 
    133   // If true, the window is constrained.
    134   //
    135   // Currently SessionService prunes all constrained windows so that session
    136   // restore does not attempt to restore them.
    137   bool is_constrained;
    138 
    139   // Timestamp for when this window was last modified.
    140   base::Time timestamp;
    141 
    142   // The tabs, ordered by visual order.
    143   std::vector<SessionTab*> tabs;
    144 
    145   // Is the window maximized, minimized, or normal?
    146   ui::WindowShowState show_state;
    147 
    148   std::string app_name;
    149 
    150  private:
    151   DISALLOW_COPY_AND_ASSIGN(SessionWindow);
    152 };
    153 
    154 #endif  // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_
    155