blob: fd3b6bc44d8508308bae6dcccb6211cfdf81c481 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2022 The Chromium Authors
Alexander Timin074cd182022-03-23 18:11:222// 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
10namespace content {
11
12void 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-Chapleau344221a2024-12-05 14:51:1118base::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
29std::optional<GlobalRenderFrameHostToken>
30GlobalRenderFrameHostToken::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 Timin074cd182022-03-23 18:11:2254} // namespace content