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 "chrome/browser/sessions/session_service_commands.h" | 5 #include "chrome/browser/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 "chrome/browser/sessions/base_session_service_commands.h" | 10 #include "chrome/browser/sessions/base_session_service_commands.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 296 } |
297 } | 297 } |
298 | 298 |
299 // Creates tabs and windows from the commands specified in |data|. The created | 299 // Creates tabs and windows from the commands specified in |data|. The created |
300 // tabs and windows are added to |tabs| and |windows| respectively, with the | 300 // tabs and windows are added to |tabs| and |windows| respectively, with the |
301 // id of the active window set in |active_window_id|. It is up to the caller | 301 // id of the active window set in |active_window_id|. It is up to the caller |
302 // to delete the tabs and windows added to |tabs| and |windows|. | 302 // to delete the tabs and windows added to |tabs| and |windows|. |
303 // | 303 // |
304 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is | 304 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is |
305 // done by AddTabsToWindows. | 305 // done by AddTabsToWindows. |
306 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data, | 306 bool CreateTabsAndWindows(const ScopedVector<SessionCommand>& data, |
307 std::map<int, SessionTab*>* tabs, | 307 std::map<int, SessionTab*>* tabs, |
308 std::map<int, SessionWindow*>* windows, | 308 std::map<int, SessionWindow*>* windows, |
309 SessionID::id_type* active_window_id) { | 309 SessionID::id_type* active_window_id) { |
310 // If the file is corrupt (command with wrong size, or unknown command), we | 310 // If the file is corrupt (command with wrong size, or unknown command), we |
311 // still return true and attempt to restore what we we can. | 311 // still return true and attempt to restore what we we can. |
312 VLOG(1) << "CreateTabsAndWindows"; | 312 VLOG(1) << "CreateTabsAndWindows"; |
313 | 313 |
314 for (std::vector<SessionCommand*>::const_iterator i = data.begin(); | 314 for (std::vector<SessionCommand*>::const_iterator i = data.begin(); |
315 i != data.end(); ++i) { | 315 i != data.end(); ++i) { |
316 const SessionCommand::id_type kCommandSetWindowBounds2 = 10; | 316 const SessionCommand::id_type kCommandSetWindowBounds2 = 10; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 // the command set for specific implementations. | 556 // the command set for specific implementations. |
557 VLOG(1) << "Failed reading an unknown command " << command->id(); | 557 VLOG(1) << "Failed reading an unknown command " << command->id(); |
558 return true; | 558 return true; |
559 } | 559 } |
560 } | 560 } |
561 return true; | 561 return true; |
562 } | 562 } |
563 | 563 |
564 } // namespace | 564 } // namespace |
565 | 565 |
566 SessionCommand* CreateSetSelectedTabInWindowCommand(const SessionID& window_id, | 566 scoped_ptr<SessionCommand> CreateSetSelectedTabInWindowCommand( |
567 int index) { | 567 const SessionID& window_id, |
| 568 int index) { |
568 SelectedTabInIndexPayload payload = { 0 }; | 569 SelectedTabInIndexPayload payload = { 0 }; |
569 payload.id = window_id.id(); | 570 payload.id = window_id.id(); |
570 payload.index = index; | 571 payload.index = index; |
571 SessionCommand* command = new SessionCommand(kCommandSetSelectedTabInIndex, | 572 scoped_ptr<SessionCommand> command( |
572 sizeof(payload)); | 573 new SessionCommand(kCommandSetSelectedTabInIndex, sizeof(payload))); |
573 memcpy(command->contents(), &payload, sizeof(payload)); | 574 memcpy(command->contents(), &payload, sizeof(payload)); |
574 return command; | 575 return command; |
575 } | 576 } |
576 | 577 |
577 SessionCommand* CreateSetTabWindowCommand(const SessionID& window_id, | 578 scoped_ptr<SessionCommand> CreateSetTabWindowCommand(const SessionID& window_id, |
578 const SessionID& tab_id) { | 579 const SessionID& tab_id) { |
579 SessionID::id_type payload[] = { window_id.id(), tab_id.id() }; | 580 SessionID::id_type payload[] = { window_id.id(), tab_id.id() }; |
580 SessionCommand* command = | 581 scoped_ptr<SessionCommand> command( |
581 new SessionCommand(kCommandSetTabWindow, sizeof(payload)); | 582 new SessionCommand(kCommandSetTabWindow, sizeof(payload))); |
582 memcpy(command->contents(), payload, sizeof(payload)); | 583 memcpy(command->contents(), payload, sizeof(payload)); |
583 return command; | 584 return command; |
584 } | 585 } |
585 | 586 |
586 SessionCommand* CreateSetWindowBoundsCommand(const SessionID& window_id, | 587 scoped_ptr<SessionCommand> CreateSetWindowBoundsCommand( |
587 const gfx::Rect& bounds, | 588 const SessionID& window_id, |
588 ui::WindowShowState show_state) { | 589 const gfx::Rect& bounds, |
| 590 ui::WindowShowState show_state) { |
589 WindowBoundsPayload3 payload = { 0 }; | 591 WindowBoundsPayload3 payload = { 0 }; |
590 payload.window_id = window_id.id(); | 592 payload.window_id = window_id.id(); |
591 payload.x = bounds.x(); | 593 payload.x = bounds.x(); |
592 payload.y = bounds.y(); | 594 payload.y = bounds.y(); |
593 payload.w = bounds.width(); | 595 payload.w = bounds.width(); |
594 payload.h = bounds.height(); | 596 payload.h = bounds.height(); |
595 payload.show_state = ShowStateToPersistedShowState(show_state); | 597 payload.show_state = ShowStateToPersistedShowState(show_state); |
596 SessionCommand* command = new SessionCommand(kCommandSetWindowBounds3, | 598 scoped_ptr<SessionCommand> command( |
597 sizeof(payload)); | 599 new SessionCommand(kCommandSetWindowBounds3, sizeof(payload))); |
598 memcpy(command->contents(), &payload, sizeof(payload)); | 600 memcpy(command->contents(), &payload, sizeof(payload)); |
599 return command; | 601 return command; |
600 } | 602 } |
601 | 603 |
602 SessionCommand* CreateSetTabIndexInWindowCommand(const SessionID& tab_id, | 604 scoped_ptr<SessionCommand> CreateSetTabIndexInWindowCommand( |
603 int new_index) { | 605 const SessionID& tab_id, |
| 606 int new_index) { |
604 TabIndexInWindowPayload payload = { 0 }; | 607 TabIndexInWindowPayload payload = { 0 }; |
605 payload.id = tab_id.id(); | 608 payload.id = tab_id.id(); |
606 payload.index = new_index; | 609 payload.index = new_index; |
607 SessionCommand* command = | 610 scoped_ptr<SessionCommand> command( |
608 new SessionCommand(kCommandSetTabIndexInWindow, sizeof(payload)); | 611 new SessionCommand(kCommandSetTabIndexInWindow, sizeof(payload))); |
609 memcpy(command->contents(), &payload, sizeof(payload)); | 612 memcpy(command->contents(), &payload, sizeof(payload)); |
610 return command; | 613 return command; |
611 } | 614 } |
612 | 615 |
613 SessionCommand* CreateTabClosedCommand(const SessionID::id_type tab_id) { | 616 scoped_ptr<SessionCommand> CreateTabClosedCommand( |
| 617 const SessionID::id_type tab_id) { |
614 ClosedPayload payload; | 618 ClosedPayload payload; |
615 // Because of what appears to be a compiler bug setting payload to {0} doesn't | 619 // Because of what appears to be a compiler bug setting payload to {0} doesn't |
616 // set the padding to 0, resulting in Purify reporting an UMR when we write | 620 // set the padding to 0, resulting in Purify reporting an UMR when we write |
617 // the structure to disk. To avoid this we explicitly memset the struct. | 621 // the structure to disk. To avoid this we explicitly memset the struct. |
618 memset(&payload, 0, sizeof(payload)); | 622 memset(&payload, 0, sizeof(payload)); |
619 payload.id = tab_id; | 623 payload.id = tab_id; |
620 payload.close_time = base::Time::Now().ToInternalValue(); | 624 payload.close_time = base::Time::Now().ToInternalValue(); |
621 SessionCommand* command = | 625 scoped_ptr<SessionCommand> command( |
622 new SessionCommand(kCommandTabClosed, sizeof(payload)); | 626 new SessionCommand(kCommandTabClosed, sizeof(payload))); |
623 memcpy(command->contents(), &payload, sizeof(payload)); | 627 memcpy(command->contents(), &payload, sizeof(payload)); |
624 return command; | 628 return command; |
625 } | 629 } |
626 | 630 |
627 SessionCommand* CreateWindowClosedCommand(const SessionID::id_type window_id) { | 631 scoped_ptr<SessionCommand> CreateWindowClosedCommand( |
| 632 const SessionID::id_type window_id) { |
628 ClosedPayload payload; | 633 ClosedPayload payload; |
629 // See comment in CreateTabClosedCommand as to why we do this. | 634 // See comment in CreateTabClosedCommand as to why we do this. |
630 memset(&payload, 0, sizeof(payload)); | 635 memset(&payload, 0, sizeof(payload)); |
631 payload.id = window_id; | 636 payload.id = window_id; |
632 payload.close_time = base::Time::Now().ToInternalValue(); | 637 payload.close_time = base::Time::Now().ToInternalValue(); |
633 SessionCommand* command = | 638 scoped_ptr<SessionCommand> command( |
634 new SessionCommand(kCommandWindowClosed, sizeof(payload)); | 639 new SessionCommand(kCommandWindowClosed, sizeof(payload))); |
635 memcpy(command->contents(), &payload, sizeof(payload)); | 640 memcpy(command->contents(), &payload, sizeof(payload)); |
636 return command; | 641 return command; |
637 } | 642 } |
638 | 643 |
639 SessionCommand* CreateSetSelectedNavigationIndexCommand(const SessionID& tab_id, | 644 scoped_ptr<SessionCommand> CreateSetSelectedNavigationIndexCommand( |
640 int index) { | 645 const SessionID& tab_id, |
| 646 int index) { |
641 SelectedNavigationIndexPayload payload = { 0 }; | 647 SelectedNavigationIndexPayload payload = { 0 }; |
642 payload.id = tab_id.id(); | 648 payload.id = tab_id.id(); |
643 payload.index = index; | 649 payload.index = index; |
644 SessionCommand* command = new SessionCommand( | 650 scoped_ptr<SessionCommand> command( |
645 kCommandSetSelectedNavigationIndex, sizeof(payload)); | 651 new SessionCommand(kCommandSetSelectedNavigationIndex, sizeof(payload))); |
646 memcpy(command->contents(), &payload, sizeof(payload)); | 652 memcpy(command->contents(), &payload, sizeof(payload)); |
647 return command; | 653 return command; |
648 } | 654 } |
649 | 655 |
650 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id, | 656 scoped_ptr<SessionCommand> CreateSetWindowTypeCommand( |
651 SessionWindow::WindowType type) { | 657 const SessionID& window_id, |
| 658 SessionWindow::WindowType type) { |
652 WindowTypePayload payload = { 0 }; | 659 WindowTypePayload payload = { 0 }; |
653 payload.id = window_id.id(); | 660 payload.id = window_id.id(); |
654 payload.index = static_cast<int32>(type); | 661 payload.index = static_cast<int32>(type); |
655 SessionCommand* command = new SessionCommand( | 662 scoped_ptr<SessionCommand> command( |
656 kCommandSetWindowType, sizeof(payload)); | 663 new SessionCommand( kCommandSetWindowType, sizeof(payload))); |
657 memcpy(command->contents(), &payload, sizeof(payload)); | 664 memcpy(command->contents(), &payload, sizeof(payload)); |
658 return command; | 665 return command; |
659 } | 666 } |
660 | 667 |
661 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id, | 668 scoped_ptr<SessionCommand> CreatePinnedStateCommand( |
662 bool is_pinned) { | 669 const SessionID& tab_id, |
| 670 bool is_pinned) { |
663 PinnedStatePayload payload = { 0 }; | 671 PinnedStatePayload payload = { 0 }; |
664 payload.tab_id = tab_id.id(); | 672 payload.tab_id = tab_id.id(); |
665 payload.pinned_state = is_pinned; | 673 payload.pinned_state = is_pinned; |
666 SessionCommand* command = | 674 scoped_ptr<SessionCommand> command( |
667 new SessionCommand(kCommandSetPinnedState, sizeof(payload)); | 675 new SessionCommand(kCommandSetPinnedState, sizeof(payload))); |
668 memcpy(command->contents(), &payload, sizeof(payload)); | 676 memcpy(command->contents(), &payload, sizeof(payload)); |
669 return command; | 677 return command; |
670 } | 678 } |
671 | 679 |
672 SessionCommand* CreateSessionStorageAssociatedCommand( | 680 scoped_ptr<SessionCommand> CreateSessionStorageAssociatedCommand( |
673 const SessionID& tab_id, | 681 const SessionID& tab_id, |
674 const std::string& session_storage_persistent_id) { | 682 const std::string& session_storage_persistent_id) { |
675 Pickle pickle; | 683 Pickle pickle; |
676 pickle.WriteInt(tab_id.id()); | 684 pickle.WriteInt(tab_id.id()); |
677 pickle.WriteString(session_storage_persistent_id); | 685 pickle.WriteString(session_storage_persistent_id); |
678 return new SessionCommand(kCommandSessionStorageAssociated, pickle); | 686 return scoped_ptr<SessionCommand>( |
| 687 new SessionCommand(kCommandSessionStorageAssociated, pickle)); |
679 } | 688 } |
680 | 689 |
681 SessionCommand* CreateSetActiveWindowCommand(const SessionID& window_id) { | 690 scoped_ptr<SessionCommand> CreateSetActiveWindowCommand( |
| 691 const SessionID& window_id) { |
682 ActiveWindowPayload payload = 0; | 692 ActiveWindowPayload payload = 0; |
683 payload = window_id.id(); | 693 payload = window_id.id(); |
684 SessionCommand* command = | 694 scoped_ptr<SessionCommand> command( |
685 new SessionCommand(kCommandSetActiveWindow, sizeof(payload)); | 695 new SessionCommand(kCommandSetActiveWindow, sizeof(payload))); |
686 memcpy(command->contents(), &payload, sizeof(payload)); | 696 memcpy(command->contents(), &payload, sizeof(payload)); |
687 return command; | 697 return command; |
688 } | 698 } |
689 | 699 |
690 SessionCommand* CreateTabNavigationPathPrunedFromBackCommand( | 700 scoped_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand( |
691 const SessionID& tab_id, | 701 const SessionID& tab_id, |
692 int count) { | 702 int count) { |
693 TabNavigationPathPrunedFromBackPayload payload = { 0 }; | 703 TabNavigationPathPrunedFromBackPayload payload = { 0 }; |
694 payload.id = tab_id.id(); | 704 payload.id = tab_id.id(); |
695 payload.index = count; | 705 payload.index = count; |
696 SessionCommand* command = | 706 scoped_ptr<SessionCommand> command( |
697 new SessionCommand(kCommandTabNavigationPathPrunedFromBack, | 707 new SessionCommand(kCommandTabNavigationPathPrunedFromBack, |
698 sizeof(payload)); | 708 sizeof(payload))); |
699 memcpy(command->contents(), &payload, sizeof(payload)); | 709 memcpy(command->contents(), &payload, sizeof(payload)); |
700 return command; | 710 return command; |
701 } | 711 } |
702 | 712 |
703 SessionCommand* CreateTabNavigationPathPrunedFromFrontCommand( | 713 scoped_ptr<SessionCommand> CreateTabNavigationPathPrunedFromFrontCommand( |
704 const SessionID& tab_id, | 714 const SessionID& tab_id, |
705 int count) { | 715 int count) { |
706 TabNavigationPathPrunedFromFrontPayload payload = { 0 }; | 716 TabNavigationPathPrunedFromFrontPayload payload = { 0 }; |
707 payload.id = tab_id.id(); | 717 payload.id = tab_id.id(); |
708 payload.index = count; | 718 payload.index = count; |
709 SessionCommand* command = | 719 scoped_ptr<SessionCommand> command( |
710 new SessionCommand(kCommandTabNavigationPathPrunedFromFront, | 720 new SessionCommand(kCommandTabNavigationPathPrunedFromFront, |
711 sizeof(payload)); | 721 sizeof(payload))); |
712 memcpy(command->contents(), &payload, sizeof(payload)); | 722 memcpy(command->contents(), &payload, sizeof(payload)); |
713 return command; | 723 return command; |
714 } | 724 } |
715 | 725 |
716 SessionCommand* CreateUpdateTabNavigationCommand( | 726 scoped_ptr<SessionCommand> CreateUpdateTabNavigationCommand( |
717 const SessionID& tab_id, | 727 const SessionID& tab_id, |
718 const sessions::SerializedNavigationEntry& navigation) { | 728 const sessions::SerializedNavigationEntry& navigation) { |
719 return ::CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, | 729 return CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, |
720 tab_id.id(), | 730 tab_id.id(), |
721 navigation); | 731 navigation); |
722 } | 732 } |
723 | 733 |
724 SessionCommand* CreateSetTabExtensionAppIDCommand( | 734 scoped_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand( |
725 const SessionID& tab_id, | 735 const SessionID& tab_id, |
726 const std::string& extension_id) { | 736 const std::string& extension_id) { |
727 return ::CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID, | 737 return CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID, |
728 tab_id.id(), | 738 tab_id.id(), |
729 extension_id); | 739 extension_id); |
730 } | 740 } |
731 | 741 |
732 SessionCommand* CreateSetTabUserAgentOverrideCommand( | 742 scoped_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand( |
733 const SessionID& tab_id, | 743 const SessionID& tab_id, |
734 const std::string& user_agent_override) { | 744 const std::string& user_agent_override) { |
735 return ::CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride, | 745 return CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride, |
736 tab_id.id(), | 746 tab_id.id(), |
737 user_agent_override); | 747 user_agent_override); |
738 } | 748 } |
739 | 749 |
740 SessionCommand* CreateSetWindowAppNameCommand( | 750 scoped_ptr<SessionCommand> CreateSetWindowAppNameCommand( |
741 const SessionID& window_id, | 751 const SessionID& window_id, |
742 const std::string& app_name) { | 752 const std::string& app_name) { |
743 return ::CreateSetWindowAppNameCommand(kCommandSetWindowAppName, | 753 return CreateSetWindowAppNameCommand(kCommandSetWindowAppName, |
744 window_id.id(), | 754 window_id.id(), |
745 app_name); | 755 app_name); |
746 } | 756 } |
747 | 757 |
748 bool ReplacePendingCommand(SessionCommand* command, | 758 bool ReplacePendingCommand(ScopedVector<SessionCommand>& pending_commands, |
749 std::vector<SessionCommand*>& pending_commands) { | 759 scoped_ptr<SessionCommand>* command) { |
750 // We optimize page navigations, which can happen quite frequently and | 760 // We optimize page navigations, which can happen quite frequently and |
751 // is expensive. And activation is like Highlander, there can only be one! | 761 // is expensive. And activation is like Highlander, there can only be one! |
752 if (command->id() != kCommandUpdateTabNavigation && | 762 if ((*command)->id() != kCommandUpdateTabNavigation && |
753 command->id() != kCommandSetActiveWindow) { | 763 (*command)->id() != kCommandSetActiveWindow) { |
754 return false; | 764 return false; |
755 } | 765 } |
756 for (std::vector<SessionCommand*>::reverse_iterator i = | 766 for (ScopedVector<SessionCommand>::reverse_iterator i = |
757 pending_commands.rbegin(); i != pending_commands.rend(); ++i) { | 767 pending_commands.rbegin(); i != pending_commands.rend(); ++i) { |
758 SessionCommand* existing_command = *i; | 768 SessionCommand* existing_command = *i; |
759 if (command->id() == kCommandUpdateTabNavigation && | 769 if ((*command)->id() == kCommandUpdateTabNavigation && |
760 existing_command->id() == kCommandUpdateTabNavigation) { | 770 existing_command->id() == kCommandUpdateTabNavigation) { |
761 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); | 771 scoped_ptr<Pickle> command_pickle((*command)->PayloadAsPickle()); |
762 PickleIterator iterator(*command_pickle); | 772 PickleIterator iterator(*command_pickle); |
763 SessionID::id_type command_tab_id; | 773 SessionID::id_type command_tab_id; |
764 int command_nav_index; | 774 int command_nav_index; |
765 if (!command_pickle->ReadInt(&iterator, &command_tab_id) || | 775 if (!command_pickle->ReadInt(&iterator, &command_tab_id) || |
766 !command_pickle->ReadInt(&iterator, &command_nav_index)) { | 776 !command_pickle->ReadInt(&iterator, &command_nav_index)) { |
767 return false; | 777 return false; |
768 } | 778 } |
769 SessionID::id_type existing_tab_id; | 779 SessionID::id_type existing_tab_id; |
770 int existing_nav_index; | 780 int existing_nav_index; |
771 { | 781 { |
772 // Creating a pickle like this means the Pickle references the data from | 782 // Creating a pickle like this means the Pickle references the data from |
773 // the command. Make sure we delete the pickle before the command, else | 783 // the command. Make sure we delete the pickle before the command, else |
774 // the pickle references deleted memory. | 784 // the pickle references deleted memory. |
775 scoped_ptr<Pickle> existing_pickle(existing_command->PayloadAsPickle()); | 785 scoped_ptr<Pickle> existing_pickle(existing_command->PayloadAsPickle()); |
776 iterator = PickleIterator(*existing_pickle); | 786 iterator = PickleIterator(*existing_pickle); |
777 if (!existing_pickle->ReadInt(&iterator, &existing_tab_id) || | 787 if (!existing_pickle->ReadInt(&iterator, &existing_tab_id) || |
778 !existing_pickle->ReadInt(&iterator, &existing_nav_index)) { | 788 !existing_pickle->ReadInt(&iterator, &existing_nav_index)) { |
779 return false; | 789 return false; |
780 } | 790 } |
781 } | 791 } |
782 if (existing_tab_id == command_tab_id && | 792 if (existing_tab_id == command_tab_id && |
783 existing_nav_index == command_nav_index) { | 793 existing_nav_index == command_nav_index) { |
784 // existing_command is an update for the same tab/index pair. Replace | 794 // existing_command is an update for the same tab/index pair. Replace |
785 // it with the new one. We need to add to the end of the list just in | 795 // it with the new one. We need to add to the end of the list just in |
786 // case there is a prune command after the update command. | 796 // case there is a prune command after the update command. |
787 delete existing_command; | 797 // Note: ScopedVector::erase will also delete the element. |
788 pending_commands.erase(i.base() - 1); | 798 pending_commands.erase(i.base() - 1); |
789 pending_commands.push_back(command); | 799 pending_commands.push_back((*command).release()); |
790 return true; | 800 return true; |
791 } | 801 } |
792 return false; | 802 return false; |
793 } | 803 } |
794 if (command->id() == kCommandSetActiveWindow && | 804 if ((*command)->id() == kCommandSetActiveWindow && |
795 existing_command->id() == kCommandSetActiveWindow) { | 805 existing_command->id() == kCommandSetActiveWindow) { |
796 *i = command; | 806 *i = (*command).release(); |
797 delete existing_command; | 807 delete existing_command; |
798 return true; | 808 return true; |
799 } | 809 } |
800 } | 810 } |
801 return false; | 811 return false; |
802 } | 812 } |
803 | 813 |
804 bool IsClosingCommand(SessionCommand* command) { | 814 bool IsClosingCommand(SessionCommand* command) { |
805 return command->id() == kCommandTabClosed || | 815 return command->id() == kCommandTabClosed || |
806 command->id() == kCommandWindowClosed; | 816 command->id() == kCommandWindowClosed; |
807 } | 817 } |
808 | 818 |
809 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands, | 819 void RestoreSessionFromCommands(const ScopedVector<SessionCommand>& commands, |
810 std::vector<SessionWindow*>* valid_windows, | 820 std::vector<SessionWindow*>* valid_windows, |
811 SessionID::id_type* active_window_id) { | 821 SessionID::id_type* active_window_id) { |
812 std::map<int, SessionTab*> tabs; | 822 std::map<int, SessionTab*> tabs; |
813 std::map<int, SessionWindow*> windows; | 823 std::map<int, SessionWindow*> windows; |
814 | 824 |
815 VLOG(1) << "RestoreSessionFromCommands " << commands.size(); | 825 VLOG(1) << "RestoreSessionFromCommands " << commands.size(); |
816 if (CreateTabsAndWindows(commands, &tabs, &windows, active_window_id)) { | 826 if (CreateTabsAndWindows(commands, &tabs, &windows, active_window_id)) { |
817 AddTabsToWindows(&tabs, &windows); | 827 AddTabsToWindows(&tabs, &windows); |
818 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); | 828 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); |
819 UpdateSelectedTabIndex(valid_windows); | 829 UpdateSelectedTabIndex(valid_windows); |
820 } | 830 } |
821 STLDeleteValues(&tabs); | 831 STLDeleteValues(&tabs); |
822 // Don't delete contents of windows, that is done by the caller as all | 832 // Don't delete contents of windows, that is done by the caller as all |
823 // valid windows are added to valid_windows. | 833 // valid windows are added to valid_windows. |
824 } | 834 } |
OLD | NEW |