Minor fixes for the snap package:

 - use the correct icon for the desktop file for all channels
 - special case the desktop file name when running as a snap

Change-Id: I9e4d03a96754bd51d798a13d6476210b9f6a8ce2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137328
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758904}
diff --git a/chrome/common/channel_info_posix.cc b/chrome/common/channel_info_posix.cc
index 1632dce..88b20489 100644
--- a/chrome/common/channel_info_posix.cc
+++ b/chrome/common/channel_info_posix.cc
@@ -70,6 +70,13 @@
 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
 std::string GetDesktopName(base::Environment* env) {
 #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
+  // Google Chrome packaged as a snap is a special case: the application name
+  // is always "google-chrome", regardless of the channel (channels are built
+  // in to snapd, switching between them or doing parallel installs does not
+  // require distinct application names).
+  std::string snap_name;
+  if (env->GetVar("SNAP_NAME", &snap_name) && snap_name == "google-chrome")
+    return "google-chrome.desktop";
   version_info::Channel product_channel(GetChannel());
   switch (product_channel) {
     case version_info::Channel::DEV:
diff --git a/chrome/installer/linux/snap/build.sh b/chrome/installer/linux/snap/build.sh
index f811aac..ce37c98 100755
--- a/chrome/installer/linux/snap/build.sh
+++ b/chrome/installer/linux/snap/build.sh
@@ -53,6 +53,14 @@
 process_template "${SCRIPTDIR}/chrome.launcher.in" "${LAUNCHER_SCRIPT}"
 chmod +x "${LAUNCHER_SCRIPT}"
 process_template "${SCRIPTDIR}/snapcraft.yaml.in" "${TMPFILEDIR}/snapcraft.yaml"
+if [ "$SNAPNAME" = "google-chrome" ]; then
+  LOGO="product_logo_256"
+  if [ "$CHANNEL" = "beta" ]; then
+    sed -i -e "s:$LOGO.png:$LOGO_beta.png:" "${TMPFILEDIR}/snapcraft.yaml"
+  elif [ "$CHANNEL" = "unstable" ]; then
+    sed -i -e "s:$LOGO.png:$LOGO_dev.png:" "${TMPFILEDIR}/snapcraft.yaml"
+  fi
+fi
 
 cd "${TMPFILEDIR}"