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/base_session_service_commands.h" | 5 #include "components/sessions/core/base_session_service_commands.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "components/sessions/core/session_backend.h" | 10 #include "components/sessions/core/session_backend.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 if (*bytes_written + num_bytes < max_bytes) { | 24 if (*bytes_written + num_bytes < max_bytes) { |
25 *bytes_written += num_bytes; | 25 *bytes_written += num_bytes; |
26 pickle.WriteString(str); | 26 pickle.WriteString(str); |
27 } else { | 27 } else { |
28 pickle.WriteString(std::string()); | 28 pickle.WriteString(std::string()); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 scoped_ptr<SessionCommand> CreateUpdateTabNavigationCommand( | 34 std::unique_ptr<SessionCommand> CreateUpdateTabNavigationCommand( |
35 SessionID::id_type command_id, | 35 SessionID::id_type command_id, |
36 SessionID::id_type tab_id, | 36 SessionID::id_type tab_id, |
37 const sessions::SerializedNavigationEntry& navigation) { | 37 const sessions::SerializedNavigationEntry& navigation) { |
38 // Use pickle to handle marshalling. | 38 // Use pickle to handle marshalling. |
39 base::Pickle pickle; | 39 base::Pickle pickle; |
40 pickle.WriteInt(tab_id); | 40 pickle.WriteInt(tab_id); |
41 // We only allow navigations up to 63k (which should be completely | 41 // We only allow navigations up to 63k (which should be completely |
42 // reasonable). | 42 // reasonable). |
43 static const size_t max_state_size = | 43 static const size_t max_state_size = |
44 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | 44 std::numeric_limits<SessionCommand::size_type>::max() - 1024; |
45 navigation.WriteToPickle(max_state_size, &pickle); | 45 navigation.WriteToPickle(max_state_size, &pickle); |
46 return scoped_ptr<SessionCommand>(new SessionCommand(command_id, pickle)); | 46 return std::unique_ptr<SessionCommand>( |
| 47 new SessionCommand(command_id, pickle)); |
47 } | 48 } |
48 | 49 |
49 scoped_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand( | 50 std::unique_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand( |
50 SessionID::id_type command_id, | 51 SessionID::id_type command_id, |
51 SessionID::id_type tab_id, | 52 SessionID::id_type tab_id, |
52 const std::string& extension_id) { | 53 const std::string& extension_id) { |
53 // Use pickle to handle marshalling. | 54 // Use pickle to handle marshalling. |
54 base::Pickle pickle; | 55 base::Pickle pickle; |
55 pickle.WriteInt(tab_id); | 56 pickle.WriteInt(tab_id); |
56 | 57 |
57 // Enforce a max for ids. They should never be anywhere near this size. | 58 // Enforce a max for ids. They should never be anywhere near this size. |
58 static const SessionCommand::size_type max_id_size = | 59 static const SessionCommand::size_type max_id_size = |
59 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | 60 std::numeric_limits<SessionCommand::size_type>::max() - 1024; |
60 | 61 |
61 int bytes_written = 0; | 62 int bytes_written = 0; |
62 | 63 |
63 WriteStringToPickle(pickle, &bytes_written, max_id_size, extension_id); | 64 WriteStringToPickle(pickle, &bytes_written, max_id_size, extension_id); |
64 | 65 |
65 return scoped_ptr<SessionCommand>(new SessionCommand(command_id, pickle)); | 66 return std::unique_ptr<SessionCommand>( |
| 67 new SessionCommand(command_id, pickle)); |
66 } | 68 } |
67 | 69 |
68 scoped_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand( | 70 std::unique_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand( |
69 SessionID::id_type command_id, | 71 SessionID::id_type command_id, |
70 SessionID::id_type tab_id, | 72 SessionID::id_type tab_id, |
71 const std::string& user_agent_override) { | 73 const std::string& user_agent_override) { |
72 // Use pickle to handle marshalling. | 74 // Use pickle to handle marshalling. |
73 base::Pickle pickle; | 75 base::Pickle pickle; |
74 pickle.WriteInt(tab_id); | 76 pickle.WriteInt(tab_id); |
75 | 77 |
76 // Enforce a max for the user agent length. They should never be anywhere | 78 // Enforce a max for the user agent length. They should never be anywhere |
77 // near this size. | 79 // near this size. |
78 static const SessionCommand::size_type max_user_agent_size = | 80 static const SessionCommand::size_type max_user_agent_size = |
79 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | 81 std::numeric_limits<SessionCommand::size_type>::max() - 1024; |
80 | 82 |
81 int bytes_written = 0; | 83 int bytes_written = 0; |
82 | 84 |
83 WriteStringToPickle(pickle, &bytes_written, max_user_agent_size, | 85 WriteStringToPickle(pickle, &bytes_written, max_user_agent_size, |
84 user_agent_override); | 86 user_agent_override); |
85 | 87 |
86 return scoped_ptr<SessionCommand>(new SessionCommand(command_id, pickle)); | 88 return std::unique_ptr<SessionCommand>( |
| 89 new SessionCommand(command_id, pickle)); |
87 } | 90 } |
88 | 91 |
89 scoped_ptr<SessionCommand> CreateSetWindowAppNameCommand( | 92 std::unique_ptr<SessionCommand> CreateSetWindowAppNameCommand( |
90 SessionID::id_type command_id, | 93 SessionID::id_type command_id, |
91 SessionID::id_type window_id, | 94 SessionID::id_type window_id, |
92 const std::string& app_name) { | 95 const std::string& app_name) { |
93 // Use pickle to handle marshalling. | 96 // Use pickle to handle marshalling. |
94 base::Pickle pickle; | 97 base::Pickle pickle; |
95 pickle.WriteInt(window_id); | 98 pickle.WriteInt(window_id); |
96 | 99 |
97 // Enforce a max for ids. They should never be anywhere near this size. | 100 // Enforce a max for ids. They should never be anywhere near this size. |
98 static const SessionCommand::size_type max_id_size = | 101 static const SessionCommand::size_type max_id_size = |
99 std::numeric_limits<SessionCommand::size_type>::max() - 1024; | 102 std::numeric_limits<SessionCommand::size_type>::max() - 1024; |
100 | 103 |
101 int bytes_written = 0; | 104 int bytes_written = 0; |
102 | 105 |
103 WriteStringToPickle(pickle, &bytes_written, max_id_size, app_name); | 106 WriteStringToPickle(pickle, &bytes_written, max_id_size, app_name); |
104 | 107 |
105 return scoped_ptr<SessionCommand>(new SessionCommand(command_id, pickle)); | 108 return std::unique_ptr<SessionCommand>( |
| 109 new SessionCommand(command_id, pickle)); |
106 } | 110 } |
107 | 111 |
108 bool RestoreUpdateTabNavigationCommand( | 112 bool RestoreUpdateTabNavigationCommand( |
109 const SessionCommand& command, | 113 const SessionCommand& command, |
110 sessions::SerializedNavigationEntry* navigation, | 114 sessions::SerializedNavigationEntry* navigation, |
111 SessionID::id_type* tab_id) { | 115 SessionID::id_type* tab_id) { |
112 scoped_ptr<base::Pickle> pickle(command.PayloadAsPickle()); | 116 std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle()); |
113 if (!pickle.get()) | 117 if (!pickle.get()) |
114 return false; | 118 return false; |
115 base::PickleIterator iterator(*pickle); | 119 base::PickleIterator iterator(*pickle); |
116 return iterator.ReadInt(tab_id) && navigation->ReadFromPickle(&iterator); | 120 return iterator.ReadInt(tab_id) && navigation->ReadFromPickle(&iterator); |
117 } | 121 } |
118 | 122 |
119 bool RestoreSetTabExtensionAppIDCommand(const SessionCommand& command, | 123 bool RestoreSetTabExtensionAppIDCommand(const SessionCommand& command, |
120 SessionID::id_type* tab_id, | 124 SessionID::id_type* tab_id, |
121 std::string* extension_app_id) { | 125 std::string* extension_app_id) { |
122 scoped_ptr<base::Pickle> pickle(command.PayloadAsPickle()); | 126 std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle()); |
123 if (!pickle.get()) | 127 if (!pickle.get()) |
124 return false; | 128 return false; |
125 | 129 |
126 base::PickleIterator iterator(*pickle); | 130 base::PickleIterator iterator(*pickle); |
127 return iterator.ReadInt(tab_id) && iterator.ReadString(extension_app_id); | 131 return iterator.ReadInt(tab_id) && iterator.ReadString(extension_app_id); |
128 } | 132 } |
129 | 133 |
130 bool RestoreSetTabUserAgentOverrideCommand(const SessionCommand& command, | 134 bool RestoreSetTabUserAgentOverrideCommand(const SessionCommand& command, |
131 SessionID::id_type* tab_id, | 135 SessionID::id_type* tab_id, |
132 std::string* user_agent_override) { | 136 std::string* user_agent_override) { |
133 scoped_ptr<base::Pickle> pickle(command.PayloadAsPickle()); | 137 std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle()); |
134 if (!pickle.get()) | 138 if (!pickle.get()) |
135 return false; | 139 return false; |
136 | 140 |
137 base::PickleIterator iterator(*pickle); | 141 base::PickleIterator iterator(*pickle); |
138 return iterator.ReadInt(tab_id) && iterator.ReadString(user_agent_override); | 142 return iterator.ReadInt(tab_id) && iterator.ReadString(user_agent_override); |
139 } | 143 } |
140 | 144 |
141 bool RestoreSetWindowAppNameCommand(const SessionCommand& command, | 145 bool RestoreSetWindowAppNameCommand(const SessionCommand& command, |
142 SessionID::id_type* window_id, | 146 SessionID::id_type* window_id, |
143 std::string* app_name) { | 147 std::string* app_name) { |
144 scoped_ptr<base::Pickle> pickle(command.PayloadAsPickle()); | 148 std::unique_ptr<base::Pickle> pickle(command.PayloadAsPickle()); |
145 if (!pickle.get()) | 149 if (!pickle.get()) |
146 return false; | 150 return false; |
147 | 151 |
148 base::PickleIterator iterator(*pickle); | 152 base::PickleIterator iterator(*pickle); |
149 return iterator.ReadInt(window_id) && iterator.ReadString(app_name); | 153 return iterator.ReadInt(window_id) && iterator.ReadString(app_name); |
150 } | 154 } |
151 | 155 |
152 } // namespace sessions | 156 } // namespace sessions |
OLD | NEW |