Skip to content

Commit 3a833d3

Browse files
motiz88facebook-github-bot
authored andcommitted
Move all Tracing method handling to TracingAgent (#52814)
Summary: Pull Request resolved: #52814 Changelog: [Internal] The handling of `Tracing.start` was needlessly split between `HostAgent` and `TracingAgent` because `TracingAgent` did not have a reference to the session state (which, being an Agent, it's allowed to have). This diff cleans that up. Reviewed By: huntie Differential Revision: D78799899 fbshipit-source-id: b05e6dae2e9b287b8708debe756b19f81d5dae06
1 parent 840fd6c commit 3a833d3

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

packages/react-native/ReactCommon/jsinspector-modern/HostAgent.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class HostAgent::Impl final {
4747
hostMetadata_(std::move(hostMetadata)),
4848
sessionState_(sessionState),
4949
networkIOAgent_(NetworkIOAgent(frontendChannel, std::move(executor))),
50-
tracingAgent_(TracingAgent(frontendChannel)) {}
50+
tracingAgent_(TracingAgent(frontendChannel, sessionState)) {}
5151

5252
~Impl() {
5353
if (isPausedInDebuggerOverlayVisible_) {
@@ -207,26 +207,6 @@ class HostAgent::Impl final {
207207
.shouldSendOKResponse = true,
208208
};
209209
}
210-
if (req.method == "Tracing.start") {
211-
if (sessionState_.isDebuggerDomainEnabled) {
212-
frontendChannel_(cdp::jsonError(
213-
req.id,
214-
cdp::ErrorCode::InternalError,
215-
"Debugger domain is expected to be disabled before starting Tracing"));
216-
217-
return {
218-
.isFinishedHandlingRequest = true,
219-
.shouldSendOKResponse = false,
220-
};
221-
}
222-
223-
// We delegate handling of this request to TracingAgent. If not handled,
224-
// then something unexpected happened - don't send an OK response.
225-
return {
226-
.isFinishedHandlingRequest = false,
227-
.shouldSendOKResponse = false,
228-
};
229-
}
230210

231211
return {
232212
.isFinishedHandlingRequest = false,

packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,23 @@ const uint16_t PROFILE_TRACE_EVENT_CHUNK_SIZE = 1;
3131

3232
} // namespace
3333

34+
TracingAgent::TracingAgent(
35+
FrontendChannel frontendChannel,
36+
const SessionState& sessionState)
37+
: frontendChannel_(std::move(frontendChannel)),
38+
sessionState_(sessionState) {}
39+
3440
bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
3541
if (req.method == "Tracing.start") {
3642
// @cdp Tracing.start support is experimental.
43+
if (sessionState_.isDebuggerDomainEnabled) {
44+
frontendChannel_(cdp::jsonError(
45+
req.id,
46+
cdp::ErrorCode::InternalError,
47+
"Debugger domain is expected to be disabled before starting Tracing"));
48+
49+
return true;
50+
}
3751
if (!instanceAgent_) {
3852
frontendChannel_(cdp::jsonError(
3953
req.id,

packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class TracingAgent {
2525
* \param frontendChannel A channel used to send responses to the
2626
* frontend.
2727
*/
28-
explicit TracingAgent(FrontendChannel frontendChannel)
29-
: frontendChannel_(std::move(frontendChannel)) {}
28+
TracingAgent(
29+
FrontendChannel frontendChannel,
30+
const SessionState& sessionState);
3031

3132
/**
3233
* Handle a CDP request. The response will be sent over the provided
@@ -60,6 +61,8 @@ class TracingAgent {
6061
* in this trace.
6162
*/
6263
HighResTimeStamp instanceTracingStartTimestamp_;
64+
65+
const SessionState& sessionState_;
6366
};
6467

6568
} // namespace facebook::react::jsinspector_modern

0 commit comments

Comments
 (0)