[merge to 124] bento_button: Fix a crash when calculating preferred size of desk button

This fixes a crash when calculating the preferred size of the desk
button if Desk Profiles feature is not enabled.

(cherry picked from commit bb570a7a7af65067ccb08ff1560b4c42f89dd745)

Bug: b/333984207
Test: Manual
Change-Id: If7e2caba0991f06de24fb08436a9d8db341daa1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5449436
Commit-Queue: Yongshun Liu <yongshun@chromium.org>
Reviewed-by: Daniel Andersson <dandersson@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1286623}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5449837
Cr-Commit-Position: refs/branch-heads/6367@{#873}
Cr-Branched-From: d158c6dc6e3604e6f899041972edf26087a49740-refs/heads/main@{#1274542}
diff --git a/ash/wm/desks/desk_button/desk_button.cc b/ash/wm/desks/desk_button/desk_button.cc
index 7942012..45b36c0 100644
--- a/ash/wm/desks/desk_button/desk_button.cc
+++ b/ash/wm/desks/desk_button/desk_button.cc
@@ -71,7 +71,7 @@
   int width =
       GetButtonInsets().width() + desk_name_label_->GetPreferredSize().width();
   if (desk_button_container_->ShouldShowDeskProfilesUi()) {
-    width += desk_avatar_view_->GetPreferredSize().width() +
+    width += kDeskButtonAvatarSize.width() +
              kDeskButtonChildSpacingHorizontalExpanded;
     width = std::clamp(width, kDeskButtonWidthHorizontalZeroWithAvatar,
                        kDeskButtonWidthHorizontalExpandedWithAvatar);
diff --git a/ash/wm/desks/desk_button/desk_button_container.cc b/ash/wm/desks/desk_button/desk_button_container.cc
index 988da75b..257db53 100644
--- a/ash/wm/desks/desk_button/desk_button_container.cc
+++ b/ash/wm/desks/desk_button/desk_button_container.cc
@@ -17,6 +17,7 @@
 #include "ash/wm/desks/desks_controller.h"
 #include "base/i18n/rtl.h"
 #include "base/notreached.h"
+#include "chromeos/constants/chromeos_features.h"
 #include "ui/base/metadata/metadata_impl_macros.h"
 #include "ui/chromeos/styles/cros_tokens_color_mappings.h"
 #include "ui/compositor/layer.h"
@@ -32,10 +33,15 @@
 
 // static
 bool DeskButtonContainer::ShouldShowDeskProfilesUi() {
-  if (auto* desk_profiles_delegate = Shell::Get()->GetDeskProfilesDelegate()) {
-    return desk_profiles_delegate->GetProfilesSnapshot().size() > 1u;
+  if (!chromeos::features::IsDeskProfilesEnabled()) {
+    return false;
   }
-  return false;
+  auto* desk_profiles_delegate = Shell::Get()->GetDeskProfilesDelegate();
+  if (!desk_profiles_delegate ||
+      desk_profiles_delegate->GetProfilesSnapshot().size() < 2u) {
+    return false;
+  }
+  return true;
 }
 
 // static