| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/sessions/core/session_service_commands.h" | 5 #include "components/sessions/core/session_service_commands.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 13 #include "components/sessions/core/base_session_service_commands.h" | 13 #include "components/sessions/core/base_session_service_commands.h" |
| 14 #include "components/sessions/core/base_session_service_delegate.h" | 14 #include "components/sessions/core/base_session_service_delegate.h" |
| 15 #include "components/sessions/core/session_command.h" | 15 #include "components/sessions/core/session_command.h" |
| 16 #include "components/sessions/core/session_types.h" | 16 #include "components/sessions/core/session_types.h" |
| 17 | 17 |
| 18 namespace sessions { | 18 namespace sessions { |
| 19 | 19 |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 !iterator.ReadInt(&existing_nav_index)) { | 830 !iterator.ReadInt(&existing_nav_index)) { |
| 831 return false; | 831 return false; |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 if (existing_tab_id == command_tab_id && | 834 if (existing_tab_id == command_tab_id && |
| 835 existing_nav_index == command_nav_index) { | 835 existing_nav_index == command_nav_index) { |
| 836 // existing_command is an update for the same tab/index pair. Replace | 836 // existing_command is an update for the same tab/index pair. Replace |
| 837 // it with the new one. We need to add to the end of the list just in | 837 // it with the new one. We need to add to the end of the list just in |
| 838 // case there is a prune command after the update command. | 838 // case there is a prune command after the update command. |
| 839 base_session_service->EraseCommand(*(i.base() - 1)); | 839 base_session_service->EraseCommand(*(i.base() - 1)); |
| 840 base_session_service->AppendRebuildCommand((*command).Pass()); | 840 base_session_service->AppendRebuildCommand((std::move(*command))); |
| 841 return true; | 841 return true; |
| 842 } | 842 } |
| 843 return false; | 843 return false; |
| 844 } | 844 } |
| 845 if ((*command)->id() == kCommandSetActiveWindow && | 845 if ((*command)->id() == kCommandSetActiveWindow && |
| 846 existing_command->id() == kCommandSetActiveWindow) { | 846 existing_command->id() == kCommandSetActiveWindow) { |
| 847 base_session_service->SwapCommand(existing_command, (*command).Pass()); | 847 base_session_service->SwapCommand(existing_command, |
| 848 (std::move(*command))); |
| 848 return true; | 849 return true; |
| 849 } | 850 } |
| 850 } | 851 } |
| 851 return false; | 852 return false; |
| 852 } | 853 } |
| 853 | 854 |
| 854 bool IsClosingCommand(SessionCommand* command) { | 855 bool IsClosingCommand(SessionCommand* command) { |
| 855 return command->id() == kCommandTabClosed || | 856 return command->id() == kCommandTabClosed || |
| 856 command->id() == kCommandWindowClosed; | 857 command->id() == kCommandWindowClosed; |
| 857 } | 858 } |
| 858 | 859 |
| 859 void RestoreSessionFromCommands(const ScopedVector<SessionCommand>& commands, | 860 void RestoreSessionFromCommands(const ScopedVector<SessionCommand>& commands, |
| 860 std::vector<SessionWindow*>* valid_windows, | 861 std::vector<SessionWindow*>* valid_windows, |
| 861 SessionID::id_type* active_window_id) { | 862 SessionID::id_type* active_window_id) { |
| 862 std::map<int, SessionTab*> tabs; | 863 std::map<int, SessionTab*> tabs; |
| 863 std::map<int, SessionWindow*> windows; | 864 std::map<int, SessionWindow*> windows; |
| 864 | 865 |
| 865 DVLOG(1) << "RestoreSessionFromCommands " << commands.size(); | 866 DVLOG(1) << "RestoreSessionFromCommands " << commands.size(); |
| 866 if (CreateTabsAndWindows(commands, &tabs, &windows, active_window_id)) { | 867 if (CreateTabsAndWindows(commands, &tabs, &windows, active_window_id)) { |
| 867 AddTabsToWindows(&tabs, &windows); | 868 AddTabsToWindows(&tabs, &windows); |
| 868 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); | 869 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); |
| 869 UpdateSelectedTabIndex(valid_windows); | 870 UpdateSelectedTabIndex(valid_windows); |
| 870 } | 871 } |
| 871 STLDeleteValues(&tabs); | 872 STLDeleteValues(&tabs); |
| 872 // Don't delete contents of windows, that is done by the caller as all | 873 // Don't delete contents of windows, that is done by the caller as all |
| 873 // valid windows are added to valid_windows. | 874 // valid windows are added to valid_windows. |
| 874 } | 875 } |
| 875 | 876 |
| 876 } // namespace sessions | 877 } // namespace sessions |
| OLD | NEW |