OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ | 5 #ifndef COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ |
6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ | 6 #define COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/sessions/core/tab_restore_service.h" | 14 #include "components/sessions/core/tab_restore_service.h" |
15 #include "components/sessions/session_id.h" | 15 #include "components/sessions/session_id.h" |
16 #include "components/sessions/session_types.h" | 16 #include "components/sessions/session_types.h" |
17 #include "components/sessions/sessions_export.h" | 17 #include "components/sessions/sessions_export.h" |
18 | 18 |
| 19 namespace sessions { |
| 20 |
19 class TabRestoreService; | 21 class TabRestoreService; |
| 22 class TabRestoreServiceClient; |
20 class TabRestoreServiceDelegate; | 23 class TabRestoreServiceDelegate; |
21 class TabRestoreServiceObserver; | 24 class TabRestoreServiceObserver; |
22 class TimeFactory; | 25 class TimeFactory; |
23 | 26 |
24 namespace sessions { | |
25 class TabRestoreServiceClient; | |
26 } | |
27 | |
28 // Helper class used to implement InMemoryTabRestoreService and | 27 // Helper class used to implement InMemoryTabRestoreService and |
29 // PersistentTabRestoreService. See tab_restore_service.h for method-level | 28 // PersistentTabRestoreService. See tab_restore_service.h for method-level |
30 // comments. | 29 // comments. |
31 class SESSIONS_EXPORT TabRestoreServiceHelper { | 30 class SESSIONS_EXPORT TabRestoreServiceHelper { |
32 public: | 31 public: |
33 typedef TabRestoreService::Entries Entries; | 32 typedef TabRestoreService::Entries Entries; |
34 typedef TabRestoreService::Entry Entry; | 33 typedef TabRestoreService::Entry Entry; |
35 typedef TabRestoreService::Tab Tab; | 34 typedef TabRestoreService::Tab Tab; |
36 typedef TabRestoreService::TimeFactory TimeFactory; | 35 typedef TabRestoreService::TimeFactory TimeFactory; |
37 typedef TabRestoreService::Window Window; | 36 typedef TabRestoreService::Window Window; |
(...skipping 20 matching lines...) Expand all Loading... |
58 enum { | 57 enum { |
59 // Max number of entries we'll keep around. | 58 // Max number of entries we'll keep around. |
60 kMaxEntries = 25, | 59 kMaxEntries = 25, |
61 }; | 60 }; |
62 | 61 |
63 // Creates a new TabRestoreServiceHelper and provides an object that provides | 62 // Creates a new TabRestoreServiceHelper and provides an object that provides |
64 // the current time. The TabRestoreServiceHelper does not take ownership of | 63 // the current time. The TabRestoreServiceHelper does not take ownership of |
65 // |time_factory| and |observer|. Note that |observer| can also be NULL. | 64 // |time_factory| and |observer|. Note that |observer| can also be NULL. |
66 TabRestoreServiceHelper(TabRestoreService* tab_restore_service, | 65 TabRestoreServiceHelper(TabRestoreService* tab_restore_service, |
67 Observer* observer, | 66 Observer* observer, |
68 sessions::TabRestoreServiceClient* client, | 67 TabRestoreServiceClient* client, |
69 TimeFactory* time_factory); | 68 TimeFactory* time_factory); |
70 | 69 |
71 ~TabRestoreServiceHelper(); | 70 ~TabRestoreServiceHelper(); |
72 | 71 |
73 // Helper methods used to implement TabRestoreService. | 72 // Helper methods used to implement TabRestoreService. |
74 void AddObserver(TabRestoreServiceObserver* observer); | 73 void AddObserver(TabRestoreServiceObserver* observer); |
75 void RemoveObserver(TabRestoreServiceObserver* observer); | 74 void RemoveObserver(TabRestoreServiceObserver* observer); |
76 void CreateHistoricalTab(sessions::LiveTab* live_tab, int index); | 75 void CreateHistoricalTab(LiveTab* live_tab, int index); |
77 void BrowserClosing(TabRestoreServiceDelegate* delegate); | 76 void BrowserClosing(TabRestoreServiceDelegate* delegate); |
78 void BrowserClosed(TabRestoreServiceDelegate* delegate); | 77 void BrowserClosed(TabRestoreServiceDelegate* delegate); |
79 void ClearEntries(); | 78 void ClearEntries(); |
80 const Entries& entries() const; | 79 const Entries& entries() const; |
81 std::vector<sessions::LiveTab*> RestoreMostRecentEntry( | 80 std::vector<LiveTab*> RestoreMostRecentEntry( |
82 TabRestoreServiceDelegate* delegate, | 81 TabRestoreServiceDelegate* delegate, |
83 int host_desktop_type); | 82 int host_desktop_type); |
84 Tab* RemoveTabEntryById(SessionID::id_type id); | 83 Tab* RemoveTabEntryById(SessionID::id_type id); |
85 std::vector<sessions::LiveTab*> RestoreEntryById( | 84 std::vector<LiveTab*> RestoreEntryById(TabRestoreServiceDelegate* delegate, |
86 TabRestoreServiceDelegate* delegate, | 85 SessionID::id_type id, |
87 SessionID::id_type id, | 86 int host_desktop_type, |
88 int host_desktop_type, | 87 WindowOpenDisposition disposition); |
89 WindowOpenDisposition disposition); | |
90 | 88 |
91 // Notifies observers the tabs have changed. | 89 // Notifies observers the tabs have changed. |
92 void NotifyTabsChanged(); | 90 void NotifyTabsChanged(); |
93 | 91 |
94 // Notifies observers the service has loaded. | 92 // Notifies observers the service has loaded. |
95 void NotifyLoaded(); | 93 void NotifyLoaded(); |
96 | 94 |
97 // Adds |entry| to the list of entries and takes ownership. If |prune| is true | 95 // Adds |entry| to the list of entries and takes ownership. If |prune| is true |
98 // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to | 96 // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to |
99 // the front, otherwise the back. Normal closes go to the front, but | 97 // the front, otherwise the back. Normal closes go to the front, but |
(...skipping 14 matching lines...) Expand all Loading... |
114 static bool ValidateEntry(Entry* entry); | 112 static bool ValidateEntry(Entry* entry); |
115 | 113 |
116 private: | 114 private: |
117 friend class PersistentTabRestoreService; | 115 friend class PersistentTabRestoreService; |
118 | 116 |
119 // Populates the tab's navigations from the LiveTab, and its browser_id and | 117 // Populates the tab's navigations from the LiveTab, and its browser_id and |
120 // pinned state from the delegate. | 118 // pinned state from the delegate. |
121 void PopulateTab(Tab* tab, | 119 void PopulateTab(Tab* tab, |
122 int index, | 120 int index, |
123 TabRestoreServiceDelegate* delegate, | 121 TabRestoreServiceDelegate* delegate, |
124 sessions::LiveTab* live_tab); | 122 LiveTab* live_tab); |
125 | 123 |
126 // This is a helper function for RestoreEntryById() for restoring a single | 124 // This is a helper function for RestoreEntryById() for restoring a single |
127 // tab. If |delegate| is NULL, this creates a new window for the entry. This | 125 // tab. If |delegate| is NULL, this creates a new window for the entry. This |
128 // returns the TabRestoreServiceDelegate into which the tab was restored. | 126 // returns the TabRestoreServiceDelegate into which the tab was restored. |
129 // |disposition| will be respected, but if it is UNKNOWN then the tab's | 127 // |disposition| will be respected, but if it is UNKNOWN then the tab's |
130 // original attributes will be respected instead. If a new | 128 // original attributes will be respected instead. If a new |
131 // TabRestoreServiceDelegate needs to be created for this tab, | 129 // TabRestoreServiceDelegate needs to be created for this tab, |
132 // |host_desktop_type| will be passed to | 130 // |host_desktop_type| will be passed to |
133 // TabRestoreServiceClient::CreateTabRestoreServiceDelegate(). If present, | 131 // TabRestoreServiceClient::CreateTabRestoreServiceDelegate(). If present, |
134 // |live_tab| will be populated with the LiveTab of the restored tab. | 132 // |live_tab| will be populated with the LiveTab of the restored tab. |
135 TabRestoreServiceDelegate* RestoreTab(const Tab& tab, | 133 TabRestoreServiceDelegate* RestoreTab(const Tab& tab, |
136 TabRestoreServiceDelegate* delegate, | 134 TabRestoreServiceDelegate* delegate, |
137 int host_desktop_type, | 135 int host_desktop_type, |
138 WindowOpenDisposition disposition, | 136 WindowOpenDisposition disposition, |
139 sessions::LiveTab** live_tab); | 137 LiveTab** live_tab); |
140 | 138 |
141 // Returns true if |tab| has more than one navigation. If |tab| has more | 139 // Returns true if |tab| has more than one navigation. If |tab| has more |
142 // than one navigation |tab->current_navigation_index| is constrained based | 140 // than one navigation |tab->current_navigation_index| is constrained based |
143 // on the number of navigations. | 141 // on the number of navigations. |
144 static bool ValidateTab(Tab* tab); | 142 static bool ValidateTab(Tab* tab); |
145 | 143 |
146 // Validates all the tabs in a window, plus the window's active tab index. | 144 // Validates all the tabs in a window, plus the window's active tab index. |
147 static bool ValidateWindow(Window* window); | 145 static bool ValidateWindow(Window* window); |
148 | 146 |
149 // Returns true if |tab| is one we care about restoring. | 147 // Returns true if |tab| is one we care about restoring. |
(...skipping 10 matching lines...) Expand all Loading... |
160 void UpdateTabBrowserIDs(SessionID::id_type old_id, | 158 void UpdateTabBrowserIDs(SessionID::id_type old_id, |
161 SessionID::id_type new_id); | 159 SessionID::id_type new_id); |
162 | 160 |
163 // Gets the current time. This uses the time_factory_ if there is one. | 161 // Gets the current time. This uses the time_factory_ if there is one. |
164 base::Time TimeNow() const; | 162 base::Time TimeNow() const; |
165 | 163 |
166 TabRestoreService* const tab_restore_service_; | 164 TabRestoreService* const tab_restore_service_; |
167 | 165 |
168 Observer* const observer_; | 166 Observer* const observer_; |
169 | 167 |
170 sessions::TabRestoreServiceClient* client_; | 168 TabRestoreServiceClient* client_; |
171 | 169 |
172 // Set of entries. They are ordered from most to least recent. | 170 // Set of entries. They are ordered from most to least recent. |
173 Entries entries_; | 171 Entries entries_; |
174 | 172 |
175 // Are we restoring a tab? If this is true we ignore requests to create a | 173 // Are we restoring a tab? If this is true we ignore requests to create a |
176 // historical tab. | 174 // historical tab. |
177 bool restoring_; | 175 bool restoring_; |
178 | 176 |
179 base::ObserverList<TabRestoreServiceObserver> observer_list_; | 177 base::ObserverList<TabRestoreServiceObserver> observer_list_; |
180 | 178 |
181 // Set of delegates that we've received a BrowserClosing method for but no | 179 // Set of delegates that we've received a BrowserClosing method for but no |
182 // corresponding BrowserClosed. We cache the set of delegates closing to | 180 // corresponding BrowserClosed. We cache the set of delegates closing to |
183 // avoid creating historical tabs for them. | 181 // avoid creating historical tabs for them. |
184 std::set<TabRestoreServiceDelegate*> closing_delegates_; | 182 std::set<TabRestoreServiceDelegate*> closing_delegates_; |
185 | 183 |
186 TimeFactory* const time_factory_; | 184 TimeFactory* const time_factory_; |
187 | 185 |
188 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); | 186 DISALLOW_COPY_AND_ASSIGN(TabRestoreServiceHelper); |
189 }; | 187 }; |
190 | 188 |
| 189 } // namespace sessions |
| 190 |
191 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ | 191 #endif // COMPONENTS_SESSIONS_CORE_TAB_RESTORE_SERVICE_HELPER_H_ |
OLD | NEW |