[omnibox] Connect PedalProvider to AutocompleteClientProvider

Some Pedals need to be filtered by application state regardless
of whether a query suggestion triggers the Pedal suggestion, and
to do this requires a context that can inform the Pedal system
during autocomplete time (as opposed to the later execution time).
AutocompleteClientProvider is the abstract base class for this purpose,
and works well, so it is used by this CL for the first instance
of Pedal filtering: the UpdateChrome Pedal is filtered when no
update is ready.

Bug: 893183
Change-Id: I3344b26600188c0c952ea81dba1e90a6b4133318
Reviewed-on: https://chromium-review.googlesource.com/c/1297587
Commit-Queue: Orin Jaworski <[email protected]>
Reviewed-by: Greg Thompson <[email protected]>
Reviewed-by: Justin Donnelly <[email protected]>
Cr-Commit-Position: refs/heads/master@{#606701}
diff --git a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
index 8709f2b8..cfab194 100644
--- a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
+++ b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
@@ -54,6 +54,10 @@
 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h"
 #endif
 
+#if !defined(OS_ANDROID)
+#include "chrome/browser/upgrade_detector/upgrade_detector.h"
+#endif
+
 namespace {
 
 #if !defined(OS_ANDROID)
@@ -100,7 +104,7 @@
       storage_partition_(nullptr) {
   if (OmniboxFieldTrial::GetPedalSuggestionMode() !=
       OmniboxFieldTrial::PedalSuggestionMode::NONE)
-    pedal_provider_ = std::make_unique<OmniboxPedalProvider>();
+    pedal_provider_ = std::make_unique<OmniboxPedalProvider>(*this);
 }
 
 ChromeAutocompleteProviderClient::~ChromeAutocompleteProviderClient() {
@@ -431,6 +435,14 @@
   return false;
 }
 
+bool ChromeAutocompleteProviderClient::IsBrowserUpdateAvailable() const {
+#if defined(OS_ANDROID)
+  return false;
+#else
+  return UpgradeDetector::GetInstance()->is_upgrade_available();
+#endif
+}
+
 bool ChromeAutocompleteProviderClient::StrippedURLsAreEqual(
     const GURL& url1,
     const GURL& url2,
diff --git a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h
index 23e917a..847f36551 100644
--- a/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h
+++ b/chrome/browser/autocomplete/chrome_autocomplete_provider_client.h
@@ -74,6 +74,7 @@
       AutocompleteController* controller) override;
   bool IsTabOpenWithURL(const GURL& url,
                         const AutocompleteInput* input) override;
+  bool IsBrowserUpdateAvailable() const override;
 
   // For testing.
   void set_storage_partition(content::StoragePartition* storage_partition) {
diff --git a/chrome/browser/upgrade_detector/upgrade_detector.h b/chrome/browser/upgrade_detector/upgrade_detector.h
index 5369ad0..f9d009e 100644
--- a/chrome/browser/upgrade_detector/upgrade_detector.h
+++ b/chrome/browser/upgrade_detector/upgrade_detector.h
@@ -77,6 +77,13 @@
     return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU;
   }
 
+  // Returns true if the detector has found that a newer version of Chrome is
+  // installed and a relaunch would complete the update.
+  bool is_upgrade_available() const {
+    return upgrade_available_ == UPGRADE_AVAILABLE_REGULAR ||
+           upgrade_available_ == UPGRADE_AVAILABLE_CRITICAL;
+  }
+
   // Notify this object that the user has acknowledged the critical update so we
   // don't need to complain about it for now.
   void acknowledge_critical_update() { critical_update_acknowledged_ = true; }