OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/sessions/session_service.h" | 5 #include "chrome/browser/sessions/session_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 using base::Time; | 53 using base::Time; |
54 using content::NavigationEntry; | 54 using content::NavigationEntry; |
55 using content::WebContents; | 55 using content::WebContents; |
56 using sessions::SerializedNavigationEntry; | 56 using sessions::SerializedNavigationEntry; |
57 | 57 |
58 // Identifier for commands written to file. | 58 // Identifier for commands written to file. |
59 static const SessionCommand::id_type kCommandSetTabWindow = 0; | 59 static const SessionCommand::id_type kCommandSetTabWindow = 0; |
60 // OBSOLETE Superseded by kCommandSetWindowBounds3. | 60 // OBSOLETE Superseded by kCommandSetWindowBounds3. |
61 // static const SessionCommand::id_type kCommandSetWindowBounds = 1; | 61 // static const SessionCommand::id_type kCommandSetWindowBounds = 1; |
62 static const SessionCommand::id_type kCommandSetTabIndexInWindow = 2; | 62 static const SessionCommand::id_type kCommandSetTabIndexInWindow = 2; |
63 // Original kCommandTabClosed/kCommandWindowClosed. See comment in | 63 // OBSOLETE Superseded kCommandTabClosed/kCommandWindowClosed commands. |
64 // MigrateClosedPayload for details on why they were replaced. | 64 // static const SessionCommand::id_type kCommandTabClosedObsolete = 3; |
65 static const SessionCommand::id_type kCommandTabClosedObsolete = 3; | 65 // static const SessionCommand::id_type kCommandWindowClosedObsolete = 4; |
66 static const SessionCommand::id_type kCommandWindowClosedObsolete = 4; | |
67 static const SessionCommand::id_type | 66 static const SessionCommand::id_type |
68 kCommandTabNavigationPathPrunedFromBack = 5; | 67 kCommandTabNavigationPathPrunedFromBack = 5; |
69 static const SessionCommand::id_type kCommandUpdateTabNavigation = 6; | 68 static const SessionCommand::id_type kCommandUpdateTabNavigation = 6; |
70 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; | 69 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; |
71 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; | 70 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; |
72 static const SessionCommand::id_type kCommandSetWindowType = 9; | 71 static const SessionCommand::id_type kCommandSetWindowType = 9; |
73 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. | 72 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. |
74 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; | 73 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; |
75 static const SessionCommand::id_type | 74 static const SessionCommand::id_type |
76 kCommandTabNavigationPathPrunedFromFront = 11; | 75 kCommandTabNavigationPathPrunedFromFront = 11; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return ui::SHOW_STATE_MAXIMIZED; | 190 return ui::SHOW_STATE_MAXIMIZED; |
192 case PERSISTED_SHOW_STATE_FULLSCREEN: | 191 case PERSISTED_SHOW_STATE_FULLSCREEN: |
193 return ui::SHOW_STATE_FULLSCREEN; | 192 return ui::SHOW_STATE_FULLSCREEN; |
194 case PERSISTED_SHOW_STATE_DETACHED_DEPRECATED: | 193 case PERSISTED_SHOW_STATE_DETACHED_DEPRECATED: |
195 return ui::SHOW_STATE_NORMAL; | 194 return ui::SHOW_STATE_NORMAL; |
196 } | 195 } |
197 NOTREACHED(); | 196 NOTREACHED(); |
198 return ui::SHOW_STATE_NORMAL; | 197 return ui::SHOW_STATE_NORMAL; |
199 } | 198 } |
200 | 199 |
201 // Migrates a |ClosedPayload|, returning true on success (migration was | |
202 // necessary and happened), or false (migration was not necessary or was not | |
203 // successful). | |
204 bool MigrateClosedPayload(const SessionCommand& command, | |
205 ClosedPayload* payload) { | |
206 #if defined(OS_CHROMEOS) | |
207 // Pre M17 versions of chromeos were 32bit. Post M17 is 64 bit. Apparently the | |
208 // 32 bit versions of chrome on pre M17 resulted in a sizeof 12 for the | |
209 // ClosedPayload, where as post M17 64-bit gives a sizeof 16 (presumably the | |
210 // struct is padded). | |
211 if ((command.id() == kCommandWindowClosedObsolete || | |
212 command.id() == kCommandTabClosedObsolete) && | |
213 command.size() == 12 && sizeof(payload->id) == 4 && | |
214 sizeof(payload->close_time) == 8) { | |
215 memcpy(&payload->id, command.contents(), 4); | |
216 memcpy(&payload->close_time, command.contents() + 4, 8); | |
217 return true; | |
218 } else { | |
219 return false; | |
220 } | |
221 #else | |
222 return false; | |
223 #endif | |
224 } | |
225 | |
226 } // namespace | 200 } // namespace |
227 | 201 |
228 // SessionService ------------------------------------------------------------- | 202 // SessionService ------------------------------------------------------------- |
229 | 203 |
230 SessionService::SessionService(Profile* profile) | 204 SessionService::SessionService(Profile* profile) |
231 : BaseSessionService(SESSION_RESTORE, profile, base::FilePath()), | 205 : BaseSessionService(SESSION_RESTORE, profile, base::FilePath()), |
232 has_open_trackable_browsers_(false), | 206 has_open_trackable_browsers_(false), |
233 move_on_new_browser_(false), | 207 move_on_new_browser_(false), |
234 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 208 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
235 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 209 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 case kCommandSetTabIndexInWindow: { | 1110 case kCommandSetTabIndexInWindow: { |
1137 TabIndexInWindowPayload payload; | 1111 TabIndexInWindowPayload payload; |
1138 if (!command->GetPayload(&payload, sizeof(payload))) { | 1112 if (!command->GetPayload(&payload, sizeof(payload))) { |
1139 VLOG(1) << "Failed reading command " << command->id(); | 1113 VLOG(1) << "Failed reading command " << command->id(); |
1140 return true; | 1114 return true; |
1141 } | 1115 } |
1142 GetTab(payload.id, tabs)->tab_visual_index = payload.index; | 1116 GetTab(payload.id, tabs)->tab_visual_index = payload.index; |
1143 break; | 1117 break; |
1144 } | 1118 } |
1145 | 1119 |
1146 case kCommandTabClosedObsolete: | |
1147 case kCommandWindowClosedObsolete: | |
1148 case kCommandTabClosed: | 1120 case kCommandTabClosed: |
1149 case kCommandWindowClosed: { | 1121 case kCommandWindowClosed: { |
1150 ClosedPayload payload; | 1122 ClosedPayload payload; |
1151 if (!command->GetPayload(&payload, sizeof(payload)) && | 1123 if (!command->GetPayload(&payload, sizeof(payload))) { |
1152 !MigrateClosedPayload(*command, &payload)) { | |
1153 VLOG(1) << "Failed reading command " << command->id(); | 1124 VLOG(1) << "Failed reading command " << command->id(); |
1154 return true; | 1125 return true; |
1155 } | 1126 } |
1156 if (command->id() == kCommandTabClosed || | 1127 if (command->id() == kCommandTabClosed) { |
1157 command->id() == kCommandTabClosedObsolete) { | |
1158 delete GetTab(payload.id, tabs); | 1128 delete GetTab(payload.id, tabs); |
1159 tabs->erase(payload.id); | 1129 tabs->erase(payload.id); |
1160 } else { | 1130 } else { |
1161 delete GetWindow(payload.id, windows); | 1131 delete GetWindow(payload.id, windows); |
1162 windows->erase(payload.id); | 1132 windows->erase(payload.id); |
1163 } | 1133 } |
1164 break; | 1134 break; |
1165 } | 1135 } |
1166 | 1136 |
1167 case kCommandTabNavigationPathPrunedFromBack: { | 1137 case kCommandTabNavigationPathPrunedFromBack: { |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 return; | 1819 return; |
1850 } | 1820 } |
1851 | 1821 |
1852 // Check for any open windows for the current profile that we aren't tracking. | 1822 // Check for any open windows for the current profile that we aren't tracking. |
1853 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 1823 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
1854 if ((*it)->profile() == profile()) | 1824 if ((*it)->profile() == profile()) |
1855 return; | 1825 return; |
1856 } | 1826 } |
1857 DeleteSessionOnlyData(profile()); | 1827 DeleteSessionOnlyData(profile()); |
1858 } | 1828 } |
OLD | NEW |