Chromium Code Reviews| 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 | |
|
sky
2014/10/20 22:27:32
Add a comment here indicating 3/4 were deprecated
| |
| 64 // MigrateClosedPayload for details on why they were replaced. | |
| 65 static const SessionCommand::id_type kCommandTabClosedObsolete = 3; | |
| 66 static const SessionCommand::id_type kCommandWindowClosedObsolete = 4; | |
| 67 static const SessionCommand::id_type | 63 static const SessionCommand::id_type |
| 68 kCommandTabNavigationPathPrunedFromBack = 5; | 64 kCommandTabNavigationPathPrunedFromBack = 5; |
| 69 static const SessionCommand::id_type kCommandUpdateTabNavigation = 6; | 65 static const SessionCommand::id_type kCommandUpdateTabNavigation = 6; |
| 70 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; | 66 static const SessionCommand::id_type kCommandSetSelectedNavigationIndex = 7; |
| 71 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; | 67 static const SessionCommand::id_type kCommandSetSelectedTabInIndex = 8; |
| 72 static const SessionCommand::id_type kCommandSetWindowType = 9; | 68 static const SessionCommand::id_type kCommandSetWindowType = 9; |
| 73 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. | 69 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. |
| 74 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; | 70 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; |
| 75 static const SessionCommand::id_type | 71 static const SessionCommand::id_type |
| 76 kCommandTabNavigationPathPrunedFromFront = 11; | 72 kCommandTabNavigationPathPrunedFromFront = 11; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 return ui::SHOW_STATE_MAXIMIZED; | 187 return ui::SHOW_STATE_MAXIMIZED; |
| 192 case PERSISTED_SHOW_STATE_FULLSCREEN: | 188 case PERSISTED_SHOW_STATE_FULLSCREEN: |
| 193 return ui::SHOW_STATE_FULLSCREEN; | 189 return ui::SHOW_STATE_FULLSCREEN; |
| 194 case PERSISTED_SHOW_STATE_DETACHED_DEPRECATED: | 190 case PERSISTED_SHOW_STATE_DETACHED_DEPRECATED: |
| 195 return ui::SHOW_STATE_NORMAL; | 191 return ui::SHOW_STATE_NORMAL; |
| 196 } | 192 } |
| 197 NOTREACHED(); | 193 NOTREACHED(); |
| 198 return ui::SHOW_STATE_NORMAL; | 194 return ui::SHOW_STATE_NORMAL; |
| 199 } | 195 } |
| 200 | 196 |
| 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 | 197 } // namespace |
| 227 | 198 |
| 228 // SessionService ------------------------------------------------------------- | 199 // SessionService ------------------------------------------------------------- |
| 229 | 200 |
| 230 SessionService::SessionService(Profile* profile) | 201 SessionService::SessionService(Profile* profile) |
| 231 : BaseSessionService(SESSION_RESTORE, profile, base::FilePath()), | 202 : BaseSessionService(SESSION_RESTORE, profile, base::FilePath()), |
| 232 has_open_trackable_browsers_(false), | 203 has_open_trackable_browsers_(false), |
| 233 move_on_new_browser_(false), | 204 move_on_new_browser_(false), |
| 234 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), | 205 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), |
| 235 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), | 206 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 case kCommandSetTabIndexInWindow: { | 1107 case kCommandSetTabIndexInWindow: { |
| 1137 TabIndexInWindowPayload payload; | 1108 TabIndexInWindowPayload payload; |
| 1138 if (!command->GetPayload(&payload, sizeof(payload))) { | 1109 if (!command->GetPayload(&payload, sizeof(payload))) { |
| 1139 VLOG(1) << "Failed reading command " << command->id(); | 1110 VLOG(1) << "Failed reading command " << command->id(); |
| 1140 return true; | 1111 return true; |
| 1141 } | 1112 } |
| 1142 GetTab(payload.id, tabs)->tab_visual_index = payload.index; | 1113 GetTab(payload.id, tabs)->tab_visual_index = payload.index; |
| 1143 break; | 1114 break; |
| 1144 } | 1115 } |
| 1145 | 1116 |
| 1146 case kCommandTabClosedObsolete: | |
| 1147 case kCommandWindowClosedObsolete: | |
| 1148 case kCommandTabClosed: | 1117 case kCommandTabClosed: |
| 1149 case kCommandWindowClosed: { | 1118 case kCommandWindowClosed: { |
| 1150 ClosedPayload payload; | 1119 ClosedPayload payload; |
| 1151 if (!command->GetPayload(&payload, sizeof(payload)) && | 1120 if (!command->GetPayload(&payload, sizeof(payload))) { |
| 1152 !MigrateClosedPayload(*command, &payload)) { | |
| 1153 VLOG(1) << "Failed reading command " << command->id(); | 1121 VLOG(1) << "Failed reading command " << command->id(); |
| 1154 return true; | 1122 return true; |
| 1155 } | 1123 } |
| 1156 if (command->id() == kCommandTabClosed || | 1124 if (command->id() == kCommandTabClosed) { |
| 1157 command->id() == kCommandTabClosedObsolete) { | |
| 1158 delete GetTab(payload.id, tabs); | 1125 delete GetTab(payload.id, tabs); |
| 1159 tabs->erase(payload.id); | 1126 tabs->erase(payload.id); |
| 1160 } else { | 1127 } else { |
| 1161 delete GetWindow(payload.id, windows); | 1128 delete GetWindow(payload.id, windows); |
| 1162 windows->erase(payload.id); | 1129 windows->erase(payload.id); |
| 1163 } | 1130 } |
| 1164 break; | 1131 break; |
| 1165 } | 1132 } |
| 1166 | 1133 |
| 1167 case kCommandTabNavigationPathPrunedFromBack: { | 1134 case kCommandTabNavigationPathPrunedFromBack: { |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1849 return; | 1816 return; |
| 1850 } | 1817 } |
| 1851 | 1818 |
| 1852 // Check for any open windows for the current profile that we aren't tracking. | 1819 // Check for any open windows for the current profile that we aren't tracking. |
| 1853 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 1820 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 1854 if ((*it)->profile() == profile()) | 1821 if ((*it)->profile() == profile()) |
| 1855 return; | 1822 return; |
| 1856 } | 1823 } |
| 1857 DeleteSessionOnlyData(profile()); | 1824 DeleteSessionOnlyData(profile()); |
| 1858 } | 1825 } |
| OLD | NEW |