[Extensions] Rework inline installation observation

Instead of observing through the WebstoreAPI, observe directly in the TabHelper.
This is a great deal less code, more direct, and also fixes a lifetime issue
with the TabHelper being deleted before the inline installation completes.

BUG=613949

Review-Url: https://codereview.chromium.org/2103663002
Cr-Commit-Position: refs/heads/master@{#403188}
diff --git a/chrome/browser/extensions/webstore_standalone_installer.cc b/chrome/browser/extensions/webstore_standalone_installer.cc
index 33c164f..ac7f2f22 100644
--- a/chrome/browser/extensions/webstore_standalone_installer.cc
+++ b/chrome/browser/extensions/webstore_standalone_installer.cc
@@ -29,15 +29,6 @@
 
 namespace extensions {
 
-const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID";
-const char kWebstoreRequestError[] =
-    "Could not fetch data from the Chrome Web Store";
-const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse";
-const char kInvalidManifestError[] = "Invalid manifest";
-const char kUserCancelledError[] = "User cancelled install";
-const char kExtensionIsBlacklisted[] = "Extension is blacklisted";
-const char kInstallInProgressError[] = "An install is already in progress";
-
 WebstoreStandaloneInstaller::WebstoreStandaloneInstaller(
     const std::string& webstore_item_id,
     Profile* profile,
@@ -58,7 +49,8 @@
   AddRef();
 
   if (!crx_file::id_util::IdIsValid(id_)) {
-    CompleteInstall(webstore_install::INVALID_ID, kInvalidWebstoreItemId);
+    CompleteInstall(webstore_install::INVALID_ID,
+                    webstore_install::kInvalidWebstoreItemId);
     return;
   }
 
@@ -113,7 +105,7 @@
       tracker->GetActiveInstall(id_);
   if (existing_install_data) {
     *reason = webstore_install::INSTALL_IN_PROGRESS;
-    *error = kInstallInProgressError;
+    *error = webstore_install::kInstallInProgressError;
     return false;
   }
 
@@ -192,7 +184,8 @@
 void WebstoreStandaloneInstaller::OnInstallPromptDone(
     ExtensionInstallPrompt::Result result) {
   if (result == ExtensionInstallPrompt::Result::USER_CANCELED) {
-    CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError);
+    CompleteInstall(webstore_install::USER_CANCELLED,
+                    webstore_install::kUserCancelledError);
     return;
   }
 
@@ -218,7 +211,7 @@
     if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) {
       // Don't install a blacklisted extension.
       install_result = webstore_install::BLACKLISTED;
-      install_message = kExtensionIsBlacklisted;
+      install_message = webstore_install::kExtensionIsBlacklisted;
     } else if (!extension_service->IsExtensionEnabled(id_)) {
       // If the extension is installed but disabled, and not blacklisted,
       // enable it.
@@ -240,7 +233,7 @@
 void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() {
   OnWebStoreDataFetcherDone();
   CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR,
-                  kWebstoreRequestError);
+                  webstore_install::kWebstoreRequestError);
 }
 
 void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess(
@@ -271,7 +264,7 @@
       !webstore_data->GetDouble(kAverageRatingKey, &average_rating_) ||
       !webstore_data->GetInteger(kRatingCountKey, &rating_count_)) {
     CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE,
-                    kInvalidWebstoreResponseError);
+                    webstore_install::kInvalidWebstoreResponseError);
     return;
   }
 
@@ -282,7 +275,7 @@
   if (average_rating_ < ExtensionInstallPrompt::kMinExtensionRating ||
       average_rating_ > ExtensionInstallPrompt::kMaxExtensionRating) {
     CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE,
-                    kInvalidWebstoreResponseError);
+                    webstore_install::kInvalidWebstoreResponseError);
     return;
   }
 
@@ -293,7 +286,7 @@
       !webstore_data->GetString(
           kLocalizedDescriptionKey, &localized_description_))) {
     CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE,
-                    kInvalidWebstoreResponseError);
+                    webstore_install::kInvalidWebstoreResponseError);
     return;
   }
 
@@ -303,14 +296,14 @@
     std::string icon_url_string;
     if (!webstore_data->GetString(kIconUrlKey, &icon_url_string)) {
       CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE,
-                      kInvalidWebstoreResponseError);
+                      webstore_install::kInvalidWebstoreResponseError);
       return;
     }
     icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve(
         icon_url_string);
     if (!icon_url.is_valid()) {
       CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE,
-                      kInvalidWebstoreResponseError);
+                      webstore_install::kInvalidWebstoreResponseError);
       return;
     }
   }
@@ -403,7 +396,8 @@
   scoped_refptr<const Extension> localized_extension =
       GetLocalizedExtensionForDisplay();
   if (!localized_extension.get()) {
-    CompleteInstall(webstore_install::INVALID_MANIFEST, kInvalidManifestError);
+    CompleteInstall(webstore_install::INVALID_MANIFEST,
+                    webstore_install::kInvalidManifestError);
     return;
   }