Add OptionalOrNullptr helper for converting base::Optional<T> to T*

A common pattern for converting base::Optional<T> to T* is:
  optional ? &*optional : nullptr
This patch adds a helper to make the pattern simpler: OptionalOrNullptr.
This expression is relatively common, in part, because the styleguide
recommends T* parameters over Optional<T>:
https://chromium.googlesource.com/chromium/src/+/master/docs/optional.md#When-not-to-use

This patch also updates callsites in third_party/WebKit/* and cc/*.

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I2c8b31b52480ad69228123df951486634edec006
Reviewed-on: https://chromium-review.googlesource.com/950226
Commit-Queue: Philip Rogers <[email protected]>
Reviewed-by: danakj <[email protected]>
Cr-Commit-Position: refs/heads/master@{#541993}
diff --git a/base/stl_util.h b/base/stl_util.h
index 186bf12b..6d47bc3a 100644
--- a/base/stl_util.h
+++ b/base/stl_util.h
@@ -21,6 +21,7 @@
 #include <vector>
 
 #include "base/logging.h"
+#include "base/optional.h"
 
 namespace base {
 
@@ -336,6 +337,17 @@
   const typename Collection::const_iterator end_;
 };
 
+// Helper for returning the optional value's address, or nullptr.
+template <class T>
+T* OptionalOrNullptr(base::Optional<T>& optional) {
+  return optional.has_value() ? &optional.value() : nullptr;
+}
+
+template <class T>
+const T* OptionalOrNullptr(const base::Optional<T>& optional) {
+  return optional.has_value() ? &optional.value() : nullptr;
+}
+
 }  // namespace base
 
 #endif  // BASE_STL_UTIL_H_