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/session_service_commands.h" | 5 #include "components/sessions/session_service_commands.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "components/sessions/base_session_service_commands.h" | 10 #include "components/sessions/base_session_service_commands.h" |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 &tab_id, | 534 &tab_id, |
535 &user_agent_override)) { | 535 &user_agent_override)) { |
536 return true; | 536 return true; |
537 } | 537 } |
538 | 538 |
539 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); | 539 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); |
540 break; | 540 break; |
541 } | 541 } |
542 | 542 |
543 case kCommandSessionStorageAssociated: { | 543 case kCommandSessionStorageAssociated: { |
544 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); | 544 scoped_ptr<base::Pickle> command_pickle(command->PayloadAsPickle()); |
545 SessionID::id_type command_tab_id; | 545 SessionID::id_type command_tab_id; |
546 std::string session_storage_persistent_id; | 546 std::string session_storage_persistent_id; |
547 PickleIterator iter(*command_pickle.get()); | 547 base::PickleIterator iter(*command_pickle.get()); |
548 if (!iter.ReadInt(&command_tab_id) || | 548 if (!iter.ReadInt(&command_tab_id) || |
549 !iter.ReadString(&session_storage_persistent_id)) | 549 !iter.ReadString(&session_storage_persistent_id)) |
550 return true; | 550 return true; |
551 // Associate the session storage back. | 551 // Associate the session storage back. |
552 GetTab(command_tab_id, tabs)->session_storage_persistent_id = | 552 GetTab(command_tab_id, tabs)->session_storage_persistent_id = |
553 session_storage_persistent_id; | 553 session_storage_persistent_id; |
554 break; | 554 break; |
555 } | 555 } |
556 | 556 |
557 case kCommandSetActiveWindow: { | 557 case kCommandSetActiveWindow: { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 payload.pinned_state = is_pinned; | 698 payload.pinned_state = is_pinned; |
699 scoped_ptr<SessionCommand> command( | 699 scoped_ptr<SessionCommand> command( |
700 new SessionCommand(kCommandSetPinnedState, sizeof(payload))); | 700 new SessionCommand(kCommandSetPinnedState, sizeof(payload))); |
701 memcpy(command->contents(), &payload, sizeof(payload)); | 701 memcpy(command->contents(), &payload, sizeof(payload)); |
702 return command; | 702 return command; |
703 } | 703 } |
704 | 704 |
705 scoped_ptr<SessionCommand> CreateSessionStorageAssociatedCommand( | 705 scoped_ptr<SessionCommand> CreateSessionStorageAssociatedCommand( |
706 const SessionID& tab_id, | 706 const SessionID& tab_id, |
707 const std::string& session_storage_persistent_id) { | 707 const std::string& session_storage_persistent_id) { |
708 Pickle pickle; | 708 base::Pickle pickle; |
709 pickle.WriteInt(tab_id.id()); | 709 pickle.WriteInt(tab_id.id()); |
710 pickle.WriteString(session_storage_persistent_id); | 710 pickle.WriteString(session_storage_persistent_id); |
711 return scoped_ptr<SessionCommand>( | 711 return scoped_ptr<SessionCommand>( |
712 new SessionCommand(kCommandSessionStorageAssociated, pickle)); | 712 new SessionCommand(kCommandSessionStorageAssociated, pickle)); |
713 } | 713 } |
714 | 714 |
715 scoped_ptr<SessionCommand> CreateSetActiveWindowCommand( | 715 scoped_ptr<SessionCommand> CreateSetActiveWindowCommand( |
716 const SessionID& window_id) { | 716 const SessionID& window_id) { |
717 ActiveWindowPayload payload = 0; | 717 ActiveWindowPayload payload = 0; |
718 payload = window_id.id(); | 718 payload = window_id.id(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 if ((*command)->id() != kCommandUpdateTabNavigation && | 799 if ((*command)->id() != kCommandUpdateTabNavigation && |
800 (*command)->id() != kCommandSetActiveWindow) { | 800 (*command)->id() != kCommandSetActiveWindow) { |
801 return false; | 801 return false; |
802 } | 802 } |
803 for (ScopedVector<SessionCommand>::const_reverse_iterator i = | 803 for (ScopedVector<SessionCommand>::const_reverse_iterator i = |
804 base_session_service->pending_commands().rbegin(); | 804 base_session_service->pending_commands().rbegin(); |
805 i != base_session_service->pending_commands().rend(); ++i) { | 805 i != base_session_service->pending_commands().rend(); ++i) { |
806 SessionCommand* existing_command = *i; | 806 SessionCommand* existing_command = *i; |
807 if ((*command)->id() == kCommandUpdateTabNavigation && | 807 if ((*command)->id() == kCommandUpdateTabNavigation && |
808 existing_command->id() == kCommandUpdateTabNavigation) { | 808 existing_command->id() == kCommandUpdateTabNavigation) { |
809 scoped_ptr<Pickle> command_pickle((*command)->PayloadAsPickle()); | 809 scoped_ptr<base::Pickle> command_pickle((*command)->PayloadAsPickle()); |
810 PickleIterator iterator(*command_pickle); | 810 base::PickleIterator iterator(*command_pickle); |
811 SessionID::id_type command_tab_id; | 811 SessionID::id_type command_tab_id; |
812 int command_nav_index; | 812 int command_nav_index; |
813 if (!iterator.ReadInt(&command_tab_id) || | 813 if (!iterator.ReadInt(&command_tab_id) || |
814 !iterator.ReadInt(&command_nav_index)) { | 814 !iterator.ReadInt(&command_nav_index)) { |
815 return false; | 815 return false; |
816 } | 816 } |
817 SessionID::id_type existing_tab_id; | 817 SessionID::id_type existing_tab_id; |
818 int existing_nav_index; | 818 int existing_nav_index; |
819 { | 819 { |
820 // Creating a pickle like this means the Pickle references the data from | 820 // Creating a pickle like this means the Pickle references the data from |
821 // the command. Make sure we delete the pickle before the command, else | 821 // the command. Make sure we delete the pickle before the command, else |
822 // the pickle references deleted memory. | 822 // the pickle references deleted memory. |
823 scoped_ptr<Pickle> existing_pickle(existing_command->PayloadAsPickle()); | 823 scoped_ptr<base::Pickle> existing_pickle( |
824 iterator = PickleIterator(*existing_pickle); | 824 existing_command->PayloadAsPickle()); |
| 825 iterator = base::PickleIterator(*existing_pickle); |
825 if (!iterator.ReadInt(&existing_tab_id) || | 826 if (!iterator.ReadInt(&existing_tab_id) || |
826 !iterator.ReadInt(&existing_nav_index)) { | 827 !iterator.ReadInt(&existing_nav_index)) { |
827 return false; | 828 return false; |
828 } | 829 } |
829 } | 830 } |
830 if (existing_tab_id == command_tab_id && | 831 if (existing_tab_id == command_tab_id && |
831 existing_nav_index == command_nav_index) { | 832 existing_nav_index == command_nav_index) { |
832 // existing_command is an update for the same tab/index pair. Replace | 833 // existing_command is an update for the same tab/index pair. Replace |
833 // it with the new one. We need to add to the end of the list just in | 834 // it with the new one. We need to add to the end of the list just in |
834 // case there is a prune command after the update command. | 835 // case there is a prune command after the update command. |
(...skipping 28 matching lines...) Expand all Loading... |
863 AddTabsToWindows(&tabs, &windows); | 864 AddTabsToWindows(&tabs, &windows); |
864 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); | 865 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); |
865 UpdateSelectedTabIndex(valid_windows); | 866 UpdateSelectedTabIndex(valid_windows); |
866 } | 867 } |
867 STLDeleteValues(&tabs); | 868 STLDeleteValues(&tabs); |
868 // Don't delete contents of windows, that is done by the caller as all | 869 // Don't delete contents of windows, that is done by the caller as all |
869 // valid windows are added to valid_windows. | 870 // valid windows are added to valid_windows. |
870 } | 871 } |
871 | 872 |
872 } // namespace sessions | 873 } // namespace sessions |
OLD | NEW |