Files
react-native/ReactCommon/react/renderer/mounting/TelemetryController.cpp
T
Oleksandr Melnykov fc1f5bbb92 Ensure correct instance for transaction telemetry
Summary:
Ensures that transaction telemetry modified by transaction controller is the same as sent in the view callbacks.

Changelog: [Internal]

Reviewed By: cortinico, cipolleschi

Differential Revision: D35827347

fbshipit-source-id: 123ae01d4a7fe1a9c97ebccae3ae248f7f2cf654
2022-04-25 04:14:39 -07:00

56 lines
1.4 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "TelemetryController.h"
#include <react/renderer/mounting/MountingCoordinator.h>
namespace facebook {
namespace react {
TelemetryController::TelemetryController(
MountingCoordinator const &mountingCoordinator) noexcept
: mountingCoordinator_(mountingCoordinator) {}
bool TelemetryController::pullTransaction(
MountingTransactionCallback const &willMount,
MountingTransactionCallback const &doMount,
MountingTransactionCallback const &didMount) const {
auto optional = mountingCoordinator_.pullTransaction();
if (!optional.has_value()) {
return false;
}
auto transaction = std::move(*optional);
auto &telemetry = transaction.getTelemetry();
auto numberOfMutations = static_cast<int>(transaction.getMutations().size());
mutex_.lock();
auto compoundTelemetry = compoundTelemetry_;
mutex_.unlock();
willMount(transaction, compoundTelemetry);
telemetry.willMount();
doMount(transaction, compoundTelemetry);
telemetry.didMount();
compoundTelemetry.incorporate(telemetry, numberOfMutations);
didMount(transaction, compoundTelemetry);
mutex_.lock();
compoundTelemetry_ = compoundTelemetry;
mutex_.unlock();
return true;
}
} // namespace react
} // namespace facebook