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 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 24 matching lines...) Expand all Loading... |
35 static const SessionCommand::id_type kCommandSetPinnedState = 12; | 35 static const SessionCommand::id_type kCommandSetPinnedState = 12; |
36 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; | 36 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; |
37 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; | 37 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; |
38 static const SessionCommand::id_type kCommandSetWindowAppName = 15; | 38 static const SessionCommand::id_type kCommandSetWindowAppName = 15; |
39 static const SessionCommand::id_type kCommandTabClosed = 16; | 39 static const SessionCommand::id_type kCommandTabClosed = 16; |
40 static const SessionCommand::id_type kCommandWindowClosed = 17; | 40 static const SessionCommand::id_type kCommandWindowClosed = 17; |
41 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 18; | 41 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 18; |
42 static const SessionCommand::id_type kCommandSessionStorageAssociated = 19; | 42 static const SessionCommand::id_type kCommandSessionStorageAssociated = 19; |
43 static const SessionCommand::id_type kCommandSetActiveWindow = 20; | 43 static const SessionCommand::id_type kCommandSetActiveWindow = 20; |
44 static const SessionCommand::id_type kCommandLastActiveTime = 21; | 44 static const SessionCommand::id_type kCommandLastActiveTime = 21; |
| 45 static const SessionCommand::id_type kCommandSetWindowWorkspace = 22; |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
48 // Various payload structures. | 49 // Various payload structures. |
49 struct ClosedPayload { | 50 struct ClosedPayload { |
50 SessionID::id_type id; | 51 SessionID::id_type id; |
51 int64_t close_time; | 52 int64_t close_time; |
52 }; | 53 }; |
53 | 54 |
54 struct WindowBoundsPayload2 { | 55 struct WindowBoundsPayload2 { |
(...skipping 26 matching lines...) Expand all Loading... |
81 typedef IDAndIndexPayload TabNavigationPathPrunedFromBackPayload; | 82 typedef IDAndIndexPayload TabNavigationPathPrunedFromBackPayload; |
82 | 83 |
83 typedef IDAndIndexPayload SelectedNavigationIndexPayload; | 84 typedef IDAndIndexPayload SelectedNavigationIndexPayload; |
84 | 85 |
85 typedef IDAndIndexPayload SelectedTabInIndexPayload; | 86 typedef IDAndIndexPayload SelectedTabInIndexPayload; |
86 | 87 |
87 typedef IDAndIndexPayload WindowTypePayload; | 88 typedef IDAndIndexPayload WindowTypePayload; |
88 | 89 |
89 typedef IDAndIndexPayload TabNavigationPathPrunedFromFrontPayload; | 90 typedef IDAndIndexPayload TabNavigationPathPrunedFromFrontPayload; |
90 | 91 |
| 92 typedef IDAndIndexPayload SetWindowWorkspacePayload; |
| 93 |
91 struct PinnedStatePayload { | 94 struct PinnedStatePayload { |
92 SessionID::id_type tab_id; | 95 SessionID::id_type tab_id; |
93 bool pinned_state; | 96 bool pinned_state; |
94 }; | 97 }; |
95 | 98 |
96 struct LastActiveTimePayload { | 99 struct LastActiveTimePayload { |
97 SessionID::id_type tab_id; | 100 SessionID::id_type tab_id; |
98 int64_t last_active_time; | 101 int64_t last_active_time; |
99 }; | 102 }; |
100 | 103 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 if (!command->GetPayload(&payload, sizeof(payload))) { | 576 if (!command->GetPayload(&payload, sizeof(payload))) { |
574 DVLOG(1) << "Failed reading command " << command->id(); | 577 DVLOG(1) << "Failed reading command " << command->id(); |
575 return true; | 578 return true; |
576 } | 579 } |
577 SessionTab* tab = GetTab(payload.tab_id, tabs); | 580 SessionTab* tab = GetTab(payload.tab_id, tabs); |
578 tab->last_active_time = | 581 tab->last_active_time = |
579 base::TimeTicks::FromInternalValue(payload.last_active_time); | 582 base::TimeTicks::FromInternalValue(payload.last_active_time); |
580 break; | 583 break; |
581 } | 584 } |
582 | 585 |
| 586 case kCommandSetWindowWorkspace: { |
| 587 SetWindowWorkspacePayload payload; |
| 588 if (!command->GetPayload(&payload, sizeof(payload))) { |
| 589 DVLOG(1) << "Failed reading command " << command->id(); |
| 590 return true; |
| 591 } |
| 592 GetWindow(payload.id, windows)->workspace_id = payload.index; |
| 593 break; |
| 594 } |
| 595 |
583 default: | 596 default: |
584 // TODO(skuhne): This might call back into a callback handler to extend | 597 // TODO(skuhne): This might call back into a callback handler to extend |
585 // the command set for specific implementations. | 598 // the command set for specific implementations. |
586 DVLOG(1) << "Failed reading an unknown command " << command->id(); | 599 DVLOG(1) << "Failed reading an unknown command " << command->id(); |
587 return true; | 600 return true; |
588 } | 601 } |
589 } | 602 } |
590 return true; | 603 return true; |
591 } | 604 } |
592 | 605 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 base::TimeTicks last_active_time) { | 745 base::TimeTicks last_active_time) { |
733 LastActiveTimePayload payload = {0}; | 746 LastActiveTimePayload payload = {0}; |
734 payload.tab_id = tab_id.id(); | 747 payload.tab_id = tab_id.id(); |
735 payload.last_active_time = last_active_time.ToInternalValue(); | 748 payload.last_active_time = last_active_time.ToInternalValue(); |
736 std::unique_ptr<SessionCommand> command( | 749 std::unique_ptr<SessionCommand> command( |
737 new SessionCommand(kCommandLastActiveTime, sizeof(payload))); | 750 new SessionCommand(kCommandLastActiveTime, sizeof(payload))); |
738 memcpy(command->contents(), &payload, sizeof(payload)); | 751 memcpy(command->contents(), &payload, sizeof(payload)); |
739 return command; | 752 return command; |
740 } | 753 } |
741 | 754 |
| 755 std::unique_ptr<SessionCommand> CreateSetWindowWorkspaceCommand( |
| 756 const SessionID& window_id, |
| 757 int current_desktop) { |
| 758 SetWindowWorkspacePayload payload = {0}; |
| 759 payload.id = window_id.id(); |
| 760 payload.index = current_desktop; |
| 761 std::unique_ptr<SessionCommand> command( |
| 762 new SessionCommand(kCommandSetWindowWorkspace, sizeof(payload))); |
| 763 memcpy(command->contents(), &payload, sizeof(payload)); |
| 764 return command; |
| 765 } |
| 766 |
742 std::unique_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand( | 767 std::unique_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand( |
743 const SessionID& tab_id, | 768 const SessionID& tab_id, |
744 int count) { | 769 int count) { |
745 TabNavigationPathPrunedFromBackPayload payload = { 0 }; | 770 TabNavigationPathPrunedFromBackPayload payload = { 0 }; |
746 payload.id = tab_id.id(); | 771 payload.id = tab_id.id(); |
747 payload.index = count; | 772 payload.index = count; |
748 std::unique_ptr<SessionCommand> command(new SessionCommand( | 773 std::unique_ptr<SessionCommand> command(new SessionCommand( |
749 kCommandTabNavigationPathPrunedFromBack, sizeof(payload))); | 774 kCommandTabNavigationPathPrunedFromBack, sizeof(payload))); |
750 memcpy(command->contents(), &payload, sizeof(payload)); | 775 memcpy(command->contents(), &payload, sizeof(payload)); |
751 return command; | 776 return command; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 AddTabsToWindows(&tabs, &windows); | 894 AddTabsToWindows(&tabs, &windows); |
870 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); | 895 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); |
871 UpdateSelectedTabIndex(valid_windows); | 896 UpdateSelectedTabIndex(valid_windows); |
872 } | 897 } |
873 STLDeleteValues(&tabs); | 898 STLDeleteValues(&tabs); |
874 // Don't delete contents of windows, that is done by the caller as all | 899 // Don't delete contents of windows, that is done by the caller as all |
875 // valid windows are added to valid_windows. | 900 // valid windows are added to valid_windows. |
876 } | 901 } |
877 | 902 |
878 } // namespace sessions | 903 } // namespace sessions |
OLD | NEW |