[cc/metrics] Gracefully handle shared-memory allocation failure.

If shared-memory allocation for smoothness-ukm data fails, then
handle that error gracefully, rather than crashing out.

BUG=1134659

(cherry picked from commit 4adfc23bee93a3d33752e3e242068e71d00eccbc)

Change-Id: I309e478ce112d9e0303d7aea6619260abac0cfe1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446929
Reviewed-by: Daniel Cheng <[email protected]>
Auto-Submit: Sadrul Chowdhury <[email protected]>
Commit-Queue: Sadrul Chowdhury <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#813405}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2468638
Reviewed-by: Sadrul Chowdhury <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#334}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc
index 357c793b..fc369d7 100644
--- a/cc/trees/layer_tree_host.cc
+++ b/cc/trees/layer_tree_host.cc
@@ -1865,7 +1865,8 @@
 LayerTreeHost::CreateSharedMemoryForSmoothnessUkm() {
   const auto size = sizeof(UkmSmoothnessDataShared);
   ukm_smoothness_mapping_ = base::ReadOnlySharedMemoryRegion::Create(size);
-  DCHECK(ukm_smoothness_mapping_.IsValid());
+  if (!ukm_smoothness_mapping_.IsValid())
+    return {};
   proxy_->SetUkmSmoothnessDestination(
       ukm_smoothness_mapping_.mapping.GetMemoryAs<UkmSmoothnessDataShared>());
   return std::move(ukm_smoothness_mapping_.region);
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index c1518a7..c10e26f9 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -739,8 +739,10 @@
   DCHECK(for_frame());
   RenderFrameImpl* render_frame =
       RenderFrameImpl::FromWebFrame(GetFrameWidget()->LocalRoot());
-  render_frame->SetUpSharedMemoryForSmoothness(
-      layer_tree_host_->CreateSharedMemoryForSmoothnessUkm());
+  auto shmem = layer_tree_host_->CreateSharedMemoryForSmoothnessUkm();
+  if (shmem.IsValid()) {
+    render_frame->SetUpSharedMemoryForSmoothness(std::move(shmem));
+  }
 }
 
 blink::WebInputMethodController* RenderWidget::GetInputMethodController()