[WebAPKs] Do not start second install while first install has not finished

This CL blocks installs for a WebAPK if an install for the WebAPK is already in
progress. This CL does this by introducing the singleton WebApkService which
keeps track of in-progress installs

BUG=636016
TEST=None

Review-Url: https://codereview.chromium.org/2596483002
Cr-Commit-Position: refs/heads/master@{#442254}
diff --git a/chrome/browser/android/shortcut_helper.cc b/chrome/browser/android/shortcut_helper.cc
index ac08fd22..1536a9ad 100644
--- a/chrome/browser/android/shortcut_helper.cc
+++ b/chrome/browser/android/shortcut_helper.cc
@@ -15,7 +15,7 @@
 #include "base/strings/string16.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/browser/android/webapk/chrome_webapk_host.h"
-#include "chrome/browser/android/webapk/webapk_installer.h"
+#include "chrome/browser/android/webapk/webapk_install_service.h"
 #include "chrome/browser/manifest/manifest_icon_downloader.h"
 #include "chrome/common/chrome_switches.h"
 #include "content/public/browser/browser_thread.h"
@@ -85,9 +85,8 @@
     const ShortcutInfo& info,
     const SkBitmap& icon_bitmap,
     const WebApkInstaller::FinishCallback& callback) {
-  // WebApkInstaller destroys itself when it is done.
-  WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap);
-  installer->InstallAsync(browser_context, callback);
+  WebApkInstallService::Get(browser_context)
+      ->InstallAsync(info, icon_bitmap, callback);
 }
 
 // static
@@ -146,6 +145,11 @@
                                   info.source);
 }
 
+void ShortcutHelper::ShowWebApkInstallInProgressToast() {
+  Java_ShortcutHelper_showWebApkInstallInProgressToast(
+      base::android::AttachCurrentThread());
+}
+
 int ShortcutHelper::GetIdealHomescreenIconSizeInPx() {
   if (kIdealHomescreenIconSize == -1)
     GetHomescreenIconAndSplashImageSizes();
@@ -260,8 +264,13 @@
 }
 
 // static
-bool ShortcutHelper::IsWebApkInstalled(const GURL& url) {
-  return !QueryWebApkPackage(url).empty();
+bool ShortcutHelper::IsWebApkInstalled(
+    content::BrowserContext* browser_context,
+    const GURL& start_url,
+    const GURL& manifest_url) {
+  return !QueryWebApkPackage(start_url).empty() ||
+      WebApkInstallService::Get(browser_context)
+      ->IsInstallInProgress(manifest_url);
 }
 
 GURL ShortcutHelper::GetScopeFromURL(const GURL& url) {