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 // OBSOLETE Superseded by kCommandSetWindowWorkspace2. |
| 46 // static const SessionCommand::id_type kCommandSetWindowWorkspace = 22; |
| 47 static const SessionCommand::id_type kCommandSetWindowWorkspace2 = 23; |
46 | 48 |
47 namespace { | 49 namespace { |
48 | 50 |
49 // Various payload structures. | 51 // Various payload structures. |
50 struct ClosedPayload { | 52 struct ClosedPayload { |
51 SessionID::id_type id; | 53 SessionID::id_type id; |
52 int64_t close_time; | 54 int64_t close_time; |
53 }; | 55 }; |
54 | 56 |
55 struct WindowBoundsPayload2 { | 57 struct WindowBoundsPayload2 { |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 if (!command->GetPayload(&payload, sizeof(payload))) { | 576 if (!command->GetPayload(&payload, sizeof(payload))) { |
575 DVLOG(1) << "Failed reading command " << command->id(); | 577 DVLOG(1) << "Failed reading command " << command->id(); |
576 return true; | 578 return true; |
577 } | 579 } |
578 SessionTab* tab = GetTab(payload.tab_id, tabs); | 580 SessionTab* tab = GetTab(payload.tab_id, tabs); |
579 tab->last_active_time = | 581 tab->last_active_time = |
580 base::TimeTicks::FromInternalValue(payload.last_active_time); | 582 base::TimeTicks::FromInternalValue(payload.last_active_time); |
581 break; | 583 break; |
582 } | 584 } |
583 | 585 |
584 case kCommandSetWindowWorkspace: { | 586 case kCommandSetWindowWorkspace2: { |
585 std::unique_ptr<base::Pickle> pickle(command->PayloadAsPickle()); | 587 std::unique_ptr<base::Pickle> pickle(command->PayloadAsPickle()); |
586 base::PickleIterator it(*pickle); | 588 base::PickleIterator it(*pickle); |
587 const SessionID::id_type* window_id; | 589 SessionID::id_type window_id; |
588 std::string workspace; | 590 std::string workspace; |
589 if (!it.ReadBytes(reinterpret_cast<const char**>(&window_id), | 591 if (!it.ReadInt(&window_id) || !it.ReadString(&workspace)) { |
590 sizeof(*window_id)) || | |
591 !it.ReadString(&workspace)) { | |
592 DVLOG(1) << "Failed reading command " << command->id(); | 592 DVLOG(1) << "Failed reading command " << command->id(); |
593 return true; | 593 return true; |
594 } | 594 } |
595 GetWindow(*window_id, windows)->workspace = workspace; | 595 GetWindow(window_id, windows)->workspace = workspace; |
596 break; | 596 break; |
597 } | 597 } |
598 | 598 |
599 default: | 599 default: |
600 // TODO(skuhne): This might call back into a callback handler to extend | 600 // TODO(skuhne): This might call back into a callback handler to extend |
601 // the command set for specific implementations. | 601 // the command set for specific implementations. |
602 DVLOG(1) << "Failed reading an unknown command " << command->id(); | 602 DVLOG(1) << "Failed reading an unknown command " << command->id(); |
603 return true; | 603 return true; |
604 } | 604 } |
605 } | 605 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 std::unique_ptr<SessionCommand> command( | 752 std::unique_ptr<SessionCommand> command( |
753 new SessionCommand(kCommandLastActiveTime, sizeof(payload))); | 753 new SessionCommand(kCommandLastActiveTime, sizeof(payload))); |
754 memcpy(command->contents(), &payload, sizeof(payload)); | 754 memcpy(command->contents(), &payload, sizeof(payload)); |
755 return command; | 755 return command; |
756 } | 756 } |
757 | 757 |
758 std::unique_ptr<SessionCommand> CreateSetWindowWorkspaceCommand( | 758 std::unique_ptr<SessionCommand> CreateSetWindowWorkspaceCommand( |
759 const SessionID& window_id, | 759 const SessionID& window_id, |
760 const std::string& workspace) { | 760 const std::string& workspace) { |
761 base::Pickle pickle; | 761 base::Pickle pickle; |
762 pickle.WriteBytes(static_cast<const void*>(&window_id), sizeof(window_id)); | 762 pickle.WriteInt(window_id.id()); |
763 pickle.WriteString(workspace); | 763 pickle.WriteString(workspace); |
764 std::unique_ptr<SessionCommand> command( | 764 std::unique_ptr<SessionCommand> command( |
765 new SessionCommand(kCommandSetWindowWorkspace, pickle.size())); | 765 new SessionCommand(kCommandSetWindowWorkspace2, pickle)); |
766 memcpy(command->contents(), pickle.data(), pickle.size()); | |
767 return command; | 766 return command; |
768 } | 767 } |
769 | 768 |
770 std::unique_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand( | 769 std::unique_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand( |
771 const SessionID& tab_id, | 770 const SessionID& tab_id, |
772 int count) { | 771 int count) { |
773 TabNavigationPathPrunedFromBackPayload payload = { 0 }; | 772 TabNavigationPathPrunedFromBackPayload payload = { 0 }; |
774 payload.id = tab_id.id(); | 773 payload.id = tab_id.id(); |
775 payload.index = count; | 774 payload.index = count; |
776 std::unique_ptr<SessionCommand> command(new SessionCommand( | 775 std::unique_ptr<SessionCommand> command(new SessionCommand( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 AddTabsToWindows(&tabs, &windows); | 896 AddTabsToWindows(&tabs, &windows); |
898 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); | 897 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); |
899 UpdateSelectedTabIndex(valid_windows); | 898 UpdateSelectedTabIndex(valid_windows); |
900 } | 899 } |
901 STLDeleteValues(&tabs); | 900 STLDeleteValues(&tabs); |
902 // Don't delete contents of windows, that is done by the caller as all | 901 // Don't delete contents of windows, that is done by the caller as all |
903 // valid windows are added to valid_windows. | 902 // valid windows are added to valid_windows. |
904 } | 903 } |
905 | 904 |
906 } // namespace sessions | 905 } // namespace sessions |
OLD | NEW |