Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/public/browser/global_routing_id.h" |
| 6 | |
| 7 | #include "base/trace_event/typed_macros.h" |
| 8 | #include "base/tracing/protos/chrome_track_event.pbzero.h" |
| 9 | |
| 10 | namespace content { |
| 11 | |
| 12 | void GlobalRenderFrameHostId::WriteIntoTrace( |
| 13 | perfetto::TracedProto<TraceProto> proto) const { |
| 14 | proto->set_process_id(child_id); |
| 15 | proto->set_routing_id(frame_routing_id); |
| 16 | } |
| 17 | |
Dominique Fauteux-Chapleau | 344221a | 2024-12-05 14:51:11 | [diff] [blame] | 18 | base::Pickle GlobalRenderFrameHostToken::ToPickle() { |
| 19 | base::Pickle pickle; |
| 20 | |
| 21 | pickle.WriteInt(child_id); |
| 22 | pickle.WriteUInt64(frame_token.value().GetHighForSerialization()); |
| 23 | pickle.WriteUInt64(frame_token.value().GetLowForSerialization()); |
| 24 | |
| 25 | return pickle; |
| 26 | } |
| 27 | |
| 28 | // static |
| 29 | std::optional<GlobalRenderFrameHostToken> |
| 30 | GlobalRenderFrameHostToken::FromPickle(const base::Pickle& pickle) { |
| 31 | base::PickleIterator iterator(pickle); |
| 32 | int child_id = 0; |
| 33 | uint64_t high = 0; |
| 34 | uint64_t low = 0; |
| 35 | if (!iterator.ReadInt(&child_id) || !iterator.ReadUInt64(&high) || |
| 36 | !iterator.ReadUInt64(&low)) { |
| 37 | return std::nullopt; |
| 38 | } |
| 39 | |
| 40 | auto deserialized_frame_token = |
| 41 | base::UnguessableToken::Deserialize(high, low); |
| 42 | if (!deserialized_frame_token) { |
| 43 | return std::nullopt; |
| 44 | } |
| 45 | |
| 46 | GlobalRenderFrameHostToken token; |
| 47 | |
| 48 | token.child_id = child_id; |
| 49 | token.frame_token = blink::LocalFrameToken(*deserialized_frame_token); |
| 50 | |
| 51 | return token; |
| 52 | } |
| 53 | |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 54 | } // namespace content |