Chromium Code Reviews| 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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 if (!command->GetPayload(&payload, sizeof(payload))) { | 574 if (!command->GetPayload(&payload, sizeof(payload))) { |
| 574 DVLOG(1) << "Failed reading command " << command->id(); | 575 DVLOG(1) << "Failed reading command " << command->id(); |
| 575 return true; | 576 return true; |
| 576 } | 577 } |
| 577 SessionTab* tab = GetTab(payload.tab_id, tabs); | 578 SessionTab* tab = GetTab(payload.tab_id, tabs); |
| 578 tab->last_active_time = | 579 tab->last_active_time = |
| 579 base::TimeTicks::FromInternalValue(payload.last_active_time); | 580 base::TimeTicks::FromInternalValue(payload.last_active_time); |
| 580 break; | 581 break; |
| 581 } | 582 } |
| 582 | 583 |
| 584 case kCommandSetWindowWorkspace: { | |
| 585 std::unique_ptr<base::Pickle> pickle(command->PayloadAsPickle()); | |
| 586 base::PickleIterator it(*pickle); | |
| 587 const SessionID::id_type* window_id; | |
| 588 std::string workspace; | |
| 589 if (!it.ReadBytes(reinterpret_cast<const char**>(&window_id), | |
| 590 sizeof(*window_id)) || | |
| 591 !it.ReadString(&workspace)) { | |
| 592 DVLOG(1) << "Failed reading command " << command->id(); | |
| 593 return true; | |
| 594 } | |
| 595 GetWindow(*window_id, windows)->workspace = workspace; | |
| 596 break; | |
| 597 } | |
| 598 | |
| 583 default: | 599 default: |
| 584 // 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 |
| 585 // the command set for specific implementations. | 601 // the command set for specific implementations. |
| 586 DVLOG(1) << "Failed reading an unknown command " << command->id(); | 602 DVLOG(1) << "Failed reading an unknown command " << command->id(); |
| 587 return true; | 603 return true; |
| 588 } | 604 } |
| 589 } | 605 } |
| 590 return true; | 606 return true; |
| 591 } | 607 } |
| 592 | 608 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 base::TimeTicks last_active_time) { | 748 base::TimeTicks last_active_time) { |
| 733 LastActiveTimePayload payload = {0}; | 749 LastActiveTimePayload payload = {0}; |
| 734 payload.tab_id = tab_id.id(); | 750 payload.tab_id = tab_id.id(); |
| 735 payload.last_active_time = last_active_time.ToInternalValue(); | 751 payload.last_active_time = last_active_time.ToInternalValue(); |
| 736 std::unique_ptr<SessionCommand> command( | 752 std::unique_ptr<SessionCommand> command( |
| 737 new SessionCommand(kCommandLastActiveTime, sizeof(payload))); | 753 new SessionCommand(kCommandLastActiveTime, sizeof(payload))); |
| 738 memcpy(command->contents(), &payload, sizeof(payload)); | 754 memcpy(command->contents(), &payload, sizeof(payload)); |
| 739 return command; | 755 return command; |
| 740 } | 756 } |
| 741 | 757 |
| 758 std::unique_ptr<SessionCommand> CreateSetWindowWorkspaceCommand( | |
| 759 const SessionID& window_id, | |
| 760 const std::string& workspace) { | |
| 761 base::Pickle pickle; | |
| 762 pickle.WriteBytes(static_cast<const void*>(&window_id), sizeof(window_id)); | |
| 763 pickle.WriteString(workspace); | |
| 764 std::unique_ptr<SessionCommand> command( | |
| 765 new SessionCommand(kCommandSetWindowWorkspace, pickle.size())); | |
|
sky
2016/05/03 17:40:52
Use the constructor that takes a Pickle (see line
| |
| 766 memcpy(command->contents(), pickle.data(), pickle.size()); | |
| 767 return command; | |
| 768 } | |
| 769 | |
| 742 std::unique_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand( | 770 std::unique_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand( |
| 743 const SessionID& tab_id, | 771 const SessionID& tab_id, |
| 744 int count) { | 772 int count) { |
| 745 TabNavigationPathPrunedFromBackPayload payload = { 0 }; | 773 TabNavigationPathPrunedFromBackPayload payload = { 0 }; |
| 746 payload.id = tab_id.id(); | 774 payload.id = tab_id.id(); |
| 747 payload.index = count; | 775 payload.index = count; |
| 748 std::unique_ptr<SessionCommand> command(new SessionCommand( | 776 std::unique_ptr<SessionCommand> command(new SessionCommand( |
| 749 kCommandTabNavigationPathPrunedFromBack, sizeof(payload))); | 777 kCommandTabNavigationPathPrunedFromBack, sizeof(payload))); |
| 750 memcpy(command->contents(), &payload, sizeof(payload)); | 778 memcpy(command->contents(), &payload, sizeof(payload)); |
| 751 return command; | 779 return command; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 AddTabsToWindows(&tabs, &windows); | 897 AddTabsToWindows(&tabs, &windows); |
| 870 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); | 898 SortTabsBasedOnVisualOrderAndPrune(&windows, valid_windows); |
| 871 UpdateSelectedTabIndex(valid_windows); | 899 UpdateSelectedTabIndex(valid_windows); |
| 872 } | 900 } |
| 873 STLDeleteValues(&tabs); | 901 STLDeleteValues(&tabs); |
| 874 // Don't delete contents of windows, that is done by the caller as all | 902 // Don't delete contents of windows, that is done by the caller as all |
| 875 // valid windows are added to valid_windows. | 903 // valid windows are added to valid_windows. |
| 876 } | 904 } |
| 877 | 905 |
| 878 } // namespace sessions | 906 } // namespace sessions |
| OLD | NEW |