2/6 Track image request metadata in ImageTelemetry, to be passed from ImageShadowNode into RCTImageComponentView

Summary:
* Create `ImageTelemetry` as a property of ImageRequest to pass image metadata from the ImageShadowNode into RCTImageComponentView
  * ImageRequest is a object in the ImageShadowNode::ConcreteState

Reviewed By: fkgozali

Differential Revision: D23239664

fbshipit-source-id: db0f08bb889af8ce63fbe1abe88744edddb86150
This commit is contained in:
Paige Sun authored and Facebook GitHub Bot committed 2020-09-11 15:09:11 -07:00
1 parent fcfa4309f7
commit d4e1202b4e
13 files changed
+97 -20

No files matched your search

@@ -47,10 +47,7 @@ rn_xplat_cxx_library(
tests = [":tests"],
visibility = ["PUBLIC"],
deps = [
"//third-party/glog:glog",
"//xplat/fbsystrace:fbsystrace",
"//xplat/folly:headers_only",
"//xplat/folly:memory",
"//xplat/folly:molly",
YOGA_CXX_TARGET,
react_native_xplat_target("react/renderer/debug:debug"),
@@ -46,7 +46,7 @@ class ImageShadowNode final : public ConcreteViewShadowNode<
ShadowNodeFamilyFragment const &familyFragment,
ComponentDescriptor const &componentDescriptor) {
auto imageSource = ImageSource{ImageSource::Type::Invalid};
return {imageSource, {imageSource, nullptr}, 0};
return {imageSource, {imageSource, nullptr, nullptr}, 0};
}
#pragma mark - LayoutableShadowNode
@@ -80,10 +80,7 @@ rn_xplat_cxx_library(
],
visibility = ["PUBLIC"],
deps = [
"//third-party/glog:glog",
"//xplat/fbsystrace:fbsystrace",
"//xplat/folly:headers_only",
"//xplat/folly:memory",
"//xplat/folly:molly",
YOGA_CXX_TARGET,
react_native_xplat_target("react/renderer/debug:debug"),
@@ -44,13 +44,13 @@ class SliderShadowNode final : public ConcreteViewShadowNode<
ComponentDescriptor const &componentDescriptor) {
auto imageSource = ImageSource{ImageSource::Type::Invalid};
return {imageSource,
{imageSource, nullptr},
{imageSource, nullptr, nullptr},
imageSource,
{imageSource, nullptr},
{imageSource, nullptr, nullptr},
imageSource,
{imageSource, nullptr},
{imageSource, nullptr, nullptr},
imageSource,
{imageSource, nullptr}};
{imageSource, nullptr, nullptr}};
}
#pragma mark - LayoutableShadowNode
@@ -103,10 +103,7 @@ rn_xplat_cxx_library(
tests = [":tests"],
visibility = ["PUBLIC"],
deps = [
"//third-party/glog:glog",
"//xplat/fbsystrace:fbsystrace",
"//xplat/folly:headers_only",
"//xplat/folly:memory",
"//xplat/folly:molly",
YOGA_CXX_TARGET,
react_native_xplat_target("react/renderer/core:core"),
@@ -11,6 +11,7 @@
#include <react/renderer/imagemanager/ImageResponse.h>
#include <react/renderer/imagemanager/ImageResponseObserver.h>
#include <react/renderer/imagemanager/ImageResponseObserverCoordinator.h>
#include <react/renderer/imagemanager/ImageTelemetry.h>
#include <react/renderer/imagemanager/primitives.h>
namespace facebook {
@@ -30,6 +31,7 @@ class ImageRequest final {
*/
ImageRequest(
const ImageSource &imageSource,
std::shared_ptr<const ImageTelemetry> telemetry,
std::shared_ptr<const ImageInstrumentation> instrumentation);
/*
@@ -63,6 +65,12 @@ class ImageRequest final {
*/
const ImageResponseObserverCoordinator &getObserverCoordinator() const;
/*
* Returns stored image telemetry object as a shared pointer.
* Retain this *or* `ImageRequest` to ensure a correct lifetime of the object.
*/
const std::shared_ptr<const ImageTelemetry> &getSharedTelemetry() const;
/*
* Returns stored image instrumentation object as a shared pointer.
* Retain this *or* `ImageRequest` to ensure a correct lifetime of the object.
@@ -83,6 +91,11 @@ class ImageRequest final {
*/
ImageSource imageSource_;
/*
* Image telemetry associated with the request.
*/
std::shared_ptr<const ImageTelemetry> telemetry_{};
/*
* Event coordinator associated with the reqest.
*/
@@ -0,0 +1,26 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ImageTelemetry.h"
namespace facebook {
namespace react {
SurfaceId ImageTelemetry::getSurfaceId() const {
return surfaceId_;
}
std::string ImageTelemetry::getLoaderModuleName() const {
return loaderModuleName_;
}
void ImageTelemetry::setLoaderModuleName(std::string const &loaderModuleName) {
loaderModuleName_ = loaderModuleName;
}
} // namespace react
} // namespace facebook
@@ -0,0 +1,30 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <react/renderer/core/ReactPrimitives.h>
namespace facebook {
namespace react {
/*
* Represents telemetry data associated with a image request
*/
class ImageTelemetry final {
public:
ImageTelemetry(SurfaceId const surfaceId) : surfaceId_(surfaceId) {}
SurfaceId getSurfaceId() const;
std::string getLoaderModuleName() const;
void setLoaderModuleName(std::string const &loaderModuleName);
private:
const SurfaceId surfaceId_;
std::string loaderModuleName_{""};
};
} // namespace react
} // namespace facebook
@@ -24,7 +24,7 @@ ImageRequest ImageManager::requestImage(
const ImageSource &imageSource,
SurfaceId surfaceId) const {
// Not implemented.
return ImageRequest(imageSource, nullptr);
return ImageRequest(imageSource, nullptr, nullptr);
}
} // namespace react
@@ -12,14 +12,19 @@ namespace react {
ImageRequest::ImageRequest(
const ImageSource &imageSource,
std::shared_ptr<const ImageTelemetry> telemetry,
std::shared_ptr<const ImageInstrumentation> instrumentation)
: imageSource_(imageSource), instrumentation_(instrumentation) {
: imageSource_(imageSource),
telemetry_(telemetry),
instrumentation_(instrumentation) {
// Not implemented.
}
ImageRequest::ImageRequest(ImageRequest &&other) noexcept
: imageSource_(std::move(other.imageSource_)),
coordinator_(std::move(other.coordinator_)) {
telemetry_(std::move(other.telemetry_)),
coordinator_(std::move(other.coordinator_)),
instrumentation_(std::move(other.instrumentation_)) {
// Not implemented.
}
@@ -12,18 +12,23 @@ namespace react {
ImageRequest::ImageRequest(
const ImageSource &imageSource,
std::shared_ptr<const ImageTelemetry> telemetry,
std::shared_ptr<const ImageInstrumentation> instrumentation)
: imageSource_(imageSource), instrumentation_(instrumentation) {
: imageSource_(imageSource),
telemetry_(telemetry),
instrumentation_(instrumentation) {
coordinator_ = std::make_shared<ImageResponseObserverCoordinator>();
}
ImageRequest::ImageRequest(ImageRequest &&other) noexcept
: imageSource_(std::move(other.imageSource_)),
telemetry_(std::move(other.telemetry_)),
coordinator_(std::move(other.coordinator_)),
instrumentation_(std::move(other.instrumentation_)) {
other.moved_ = true;
other.coordinator_ = nullptr;
other.cancelRequest_ = nullptr;
other.telemetry_ = nullptr;
other.instrumentation_ = nullptr;
}
@@ -38,6 +43,11 @@ void ImageRequest::setCancelationFunction(
cancelRequest_ = cancelationFunction;
}
const std::shared_ptr<const ImageTelemetry> &ImageRequest::getSharedTelemetry()
const {
return telemetry_;
}
const ImageResponseObserverCoordinator &ImageRequest::getObserverCoordinator()
const {
return *coordinator_;
@@ -42,7 +42,8 @@ using namespace facebook::react;
SystraceSection s("RCTImageManager::requestImage");
auto imageInstrumentation = std::make_shared<RCTImageInstrumentationProxy>(_imageLoader);
auto imageRequest = ImageRequest(imageSource, imageInstrumentation);
auto telemetry = std::make_shared<ImageTelemetry>(surfaceId);
auto imageRequest = ImageRequest(imageSource, telemetry, imageInstrumentation);
auto weakObserverCoordinator =
(std::weak_ptr<const ImageResponseObserverCoordinator>)imageRequest.getSharedObserverCoordinator();
@@ -36,7 +36,8 @@ using namespace facebook::react;
- (ImageRequest)requestImage:(ImageSource)imageSource surfaceId:(SurfaceId)surfaceId
{
auto imageRequest = ImageRequest(imageSource, nullptr);
auto telemetry = std::make_shared<ImageTelemetry>(surfaceId);
auto imageRequest = ImageRequest(imageSource, telemetry, nullptr);
auto weakObserverCoordinator =
(std::weak_ptr<const ImageResponseObserverCoordinator>)imageRequest.getSharedObserverCoordinator();