mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Configure prod version of NetworkReporter (#50286)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50286 Configures a thinner version of `NetworkReporter.cpp` (the entry point to `jsinspector_network`) in production builds (i.e. dev or profiling build, as gated by `REACT_NATIVE_DEBUGGER_ENABLED`). Even though enabling the CDP Network domain isn't reachable in prod, this will reduce the compiled code footprint of `jsinspector_network`. We also don't need `glog` here any more — remove dep. **Implementation notes** The reason to gate the logic within each method, with inline `#ifdefs`, rather than swapping between complete implementation files, is because each `report*` function will also have load-bearing logic (for the Performance API) in all prod builds. Therefore, this will reduce duplication (and file switching) down the line — and can be understood at a glance with this pattern. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D71636694 fbshipit-source-id: 50e7c008bb6fd128fe1248d767832b36ccb0219b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c91cafae32
commit
4a055e4812
@@ -23,6 +23,5 @@ target_include_directories(jsinspector_network PUBLIC ${REACT_COMMON_DIR})
|
||||
|
||||
target_link_libraries(jsinspector_network
|
||||
folly_runtime
|
||||
glog
|
||||
jsinspector_cdp
|
||||
)
|
||||
|
||||
@@ -7,16 +7,23 @@
|
||||
|
||||
#include "NetworkReporter.h"
|
||||
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
#include "CdpNetwork.h"
|
||||
#endif
|
||||
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
#include <folly/dynamic.h>
|
||||
#include <jsinspector-modern/cdp/CdpJson.h>
|
||||
#endif
|
||||
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
#include <chrono>
|
||||
#endif
|
||||
#include <stdexcept>
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
namespace {
|
||||
|
||||
/**
|
||||
@@ -34,6 +41,7 @@ double getCurrentUnixTimestampSeconds() {
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
NetworkReporter& NetworkReporter::getInstance() {
|
||||
static NetworkReporter instance;
|
||||
@@ -67,6 +75,8 @@ void NetworkReporter::reportRequestStart(
|
||||
const RequestInfo& requestInfo,
|
||||
int encodedDataLength,
|
||||
const std::optional<ResponseInfo>& redirectResponse) const {
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
// Debug build: CDP event handling
|
||||
if (!isDebuggingEnabledNoSync()) {
|
||||
return;
|
||||
}
|
||||
@@ -94,32 +104,41 @@ void NetworkReporter::reportRequestStart(
|
||||
|
||||
frontendChannel_(
|
||||
cdp::jsonNotification("Network.requestWillBeSent", params.toDynamic()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetworkReporter::reportConnectionTiming(
|
||||
const std::string& /*requestId*/) const {
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
// Debug build: CDP event handling
|
||||
if (!isDebuggingEnabledNoSync()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(T218236597)
|
||||
throw std::runtime_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetworkReporter::reportRequestFailed(
|
||||
const std::string& /*requestId*/) const {
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
// Debug build: CDP event handling
|
||||
if (!isDebuggingEnabledNoSync()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(T218236855)
|
||||
throw std::runtime_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetworkReporter::reportResponseStart(
|
||||
const std::string& requestId,
|
||||
const ResponseInfo& responseInfo,
|
||||
int encodedDataLength) const {
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
// Debug build: CDP event handling
|
||||
if (!isDebuggingEnabledNoSync()) {
|
||||
return;
|
||||
}
|
||||
@@ -137,21 +156,27 @@ void NetworkReporter::reportResponseStart(
|
||||
|
||||
frontendChannel_(
|
||||
cdp::jsonNotification("Network.responseReceived", params.toDynamic()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetworkReporter::reportDataReceived(
|
||||
const std::string& /*requestId*/) const {
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
// Debug build: CDP event handling
|
||||
if (!isDebuggingEnabledNoSync()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(T218236266)
|
||||
throw std::runtime_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetworkReporter::reportResponseEnd(
|
||||
const std::string& requestId,
|
||||
int encodedDataLength) const {
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
// Debug build: CDP event handling
|
||||
if (!isDebuggingEnabledNoSync()) {
|
||||
return;
|
||||
}
|
||||
@@ -164,6 +189,7 @@ void NetworkReporter::reportResponseEnd(
|
||||
|
||||
frontendChannel_(
|
||||
cdp::jsonNotification("Network.loadingFinished", params.toDynamic()));
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
|
||||
@@ -25,6 +25,8 @@ using FrontendChannel = std::function<void(std::string_view messageJson)>;
|
||||
/**
|
||||
* [Experimental] An interface for reporting network events to the modern
|
||||
* debugger server and Web Performance APIs.
|
||||
*
|
||||
* In a production (non dev or profiling) build, CDP reporting is disabled.
|
||||
*/
|
||||
class NetworkReporter {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user