[Merge M73][NTP] Fix console error if no suggestions are available

If no suggestions are available run the callback with a string setting
search_suggestions.suggestionHtml to an empty string rather than nullptr.
This fixes the console error:
'search-suggestions.js:1 Failed to load resource: net::ERR_FAILED'.

Bug: 904565
Change-Id: I9671c2e39297bf10802f1d2feacff6fab2e6d06b
Reviewed-on: https://chromium-review.googlesource.com/c/1446789
Reviewed-by: Ramya Nagarajan <ramyan@chromium.org>
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#627691}(cherry picked from commit 0e82675707acbcafd5cba04efdbe04efabfd5cfd)
Reviewed-on: https://chromium-review.googlesource.com/c/1450302
Reviewed-by: Kyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/branch-heads/3683@{#122}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/chrome/browser/search/local_ntp_source.cc b/chrome/browser/search/local_ntp_source.cc
index 1a8cce7..5440ced 100644
--- a/chrome/browser/search/local_ntp_source.cc
+++ b/chrome/browser/search/local_ntp_source.cc
@@ -430,10 +430,14 @@
 }
 
 std::unique_ptr<base::DictionaryValue> ConvertSearchSuggestDataToDict(
-    const SearchSuggestData& data) {
+    const base::Optional<SearchSuggestData>& data) {
   auto result = std::make_unique<base::DictionaryValue>();
-  result->SetString("suggestionsHtml", data.suggestions_html);
-  result->SetString("suggestionsEndOfBodyScript", data.end_of_body_script);
+  if (data.has_value()) {
+    result->SetString("suggestionsHtml", data->suggestions_html);
+    result->SetString("suggestionsEndOfBodyScript", data->end_of_body_script);
+  } else {
+    result->SetString("suggestionsHtml", std::string());
+  }
   return result;
 }
 
@@ -1306,16 +1310,11 @@
     const content::URLDataSource::GotDataCallback& callback) {
   base::Optional<SearchSuggestData> data =
       search_suggest_service_->search_suggest_data();
-  if (!data.has_value()) {
-    callback.Run(nullptr);
-    return;
-  }
 
-  SearchSuggestData suggest_data = *data;
   search_suggest_service_->SuggestionsDisplayed();
   scoped_refptr<base::RefCountedString> result;
   std::string js;
-  base::JSONWriter::Write(*ConvertSearchSuggestDataToDict(suggest_data), &js);
+  base::JSONWriter::Write(*ConvertSearchSuggestDataToDict(data), &js);
   js = "var search_suggestions  = " + js + ";";
   result = base::RefCountedString::TakeString(&js);
   callback.Run(result);