Support full-screen and single-profile avatar bubbles.

Enable IDC_SHOW_AVATAR_MENU for normal browser windows.
(full-screen and single-profile windows are now allowed)
(non-tabbed and incognito windows are still disallowed)

Nix BrowserCommandController's use of ProfileManager.
(no commands rely on the profile count anymore)
Cleanup some BrowserCommandController code.

Inline AvatarMenuButton::ShowAvatarBubble in BrowserView.
(ShowAvatarBubbleFromAvatarButton needs to set an anchor)
(single-profile windows have no avatar icon; use hotdogs)
Anchor to the Chrome menu button in Mac single-profile too.

Take an ArrowPaintType in AvatarMenuBubbleView::ShowBubble.
(lets fullscreen hide the arrow, there's no visible anchor)
(this corresponds with fullscreen bookmark bubble behavior)

Remove a stale Windows Valgrind DrMemory test exclusion entry.
(test name was changed, but the exclusion wasn't; isn't needed)

BUG=255452,167014
TEST=The avatar menu shows for Ctrl+Shift+M even in fullscreen and even for single-profile Chrome windows. Test with and without the experimental --new-profile-management, and in LTR and RTL Chrome UI modes.
[email protected], [email protected]

Review URL: https://codereview.chromium.org/264303006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270126 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc
index 354932e..d6bccf4 100644
--- a/chrome/browser/ui/browser_command_controller.cc
+++ b/chrome/browser/ui/browser_command_controller.cc
@@ -13,9 +13,7 @@
 #include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/lifetime/application_lifetime.h"
 #include "chrome/browser/prefs/incognito_mode_prefs.h"
-#include "chrome/browser/profiles/avatar_menu.h"
 #include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
 #include "chrome/browser/sessions/tab_restore_service.h"
 #include "chrome/browser/sessions/tab_restore_service_factory.h"
 #include "chrome/browser/shell_integration.h"
@@ -183,17 +181,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // BrowserCommandController, public:
 
-BrowserCommandController::BrowserCommandController(
-    Browser* browser,
-    ProfileManager* profile_manager)
+BrowserCommandController::BrowserCommandController(Browser* browser)
     : browser_(browser),
-      profile_manager_(profile_manager),
       command_updater_(this),
       block_command_execution_(false),
       last_blocked_command_id_(-1),
       last_blocked_command_disposition_(CURRENT_TAB) {
-  if (profile_manager_)
-    profile_manager_->GetProfileInfoCache().AddObserver(this);
   browser_->tab_strip_model()->AddObserver(this);
   PrefService* local_state = g_browser_process->local_state();
   if (local_state) {
@@ -259,8 +252,6 @@
   profile_pref_registrar_.RemoveAll();
   local_pref_registrar_.RemoveAll();
   browser_->tab_strip_model()->RemoveObserver(this);
-  if (profile_manager_)
-    profile_manager_->GetProfileInfoCache().RemoveObserver(this);
 }
 
 bool BrowserCommandController::IsReservedCommandOrKey(
@@ -782,20 +773,6 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-// BrowserCommandController, ProfileInfoCacheObserver implementation:
-
-void BrowserCommandController::OnProfileAdded(
-    const base::FilePath& profile_path) {
-  UpdateCommandsForMultipleProfiles();
-}
-
-void BrowserCommandController::OnProfileWasRemoved(
-    const base::FilePath& profile_path,
-    const base::string16& profile_name) {
-  UpdateCommandsForMultipleProfiles();
-}
-
-////////////////////////////////////////////////////////////////////////////////
 // BrowserCommandController, SigninPrefObserver implementation:
 
 void BrowserCommandController::OnSigninAllowedPrefChange() {
@@ -969,29 +946,31 @@
   command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
 
   // Show various bits of UI
+  const bool guest_session = profile()->IsGuestSession();
+  const bool normal_window = browser_->is_type_tabbed();
   UpdateOpenFileState(&command_updater_);
   command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
   UpdateCommandsForDevTools();
   command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
-  command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY,
-                                        !profile()->IsGuestSession());
+  command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
   command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
   command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
   command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
-  command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU,
-                                        !profile()->IsGuestSession());
+  command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
   command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
-                                        !profile()->IsGuestSession() &&
+                                        !guest_session &&
                                         !profile()->IsOffTheRecord());
+  command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
 #if defined(OS_CHROMEOS)
   command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
+#else
+  // Chrome OS uses the system tray menu to handle multi-profiles.
+  if (normal_window && (guest_session || !profile()->IsOffTheRecord()))
+    command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
 #endif
 
   UpdateShowSyncState(true);
 
-  // Initialize other commands based on the window type.
-  bool normal_window = browser_->is_type_tabbed();
-
   // Navigation commands
   command_updater_.UpdateCommandEnabled(
       IDC_HOME,
@@ -1015,39 +994,24 @@
   command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
   command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
 #if defined(OS_WIN)
-#if !defined(USE_AURA)
-  const bool metro_mode = base::win::IsMetroProcess();
-#else
-  const bool metro_mode =
-     browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
-         true : false;
-#endif
-  command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro_mode);
-  command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro_mode);
-  int restart_mode = metro_mode ?
-      IDC_WIN8_DESKTOP_RESTART : IDC_WIN8_METRO_RESTART;
+  bool metro = browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH;
+  command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro);
+  command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro);
+  int restart_mode = metro ? IDC_WIN8_DESKTOP_RESTART : IDC_WIN8_METRO_RESTART;
   command_updater_.UpdateCommandEnabled(restart_mode, normal_window);
 #endif
 
-  // Show various bits of UI
-  command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
-
-  // The upgrade entry and the view incompatibility entry should always be
-  // enabled. Whether they are visible is a separate matter determined on menu
-  // show.
+  // These are always enabled; the menu determines their menu item visibility.
   command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
   command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
 
   // Toggle speech input
   command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true);
 
-  // Initialize other commands whose state changes based on fullscreen mode.
+  // Initialize other commands whose state changes based on various conditions.
   UpdateCommandsForFullscreenMode();
-
   UpdateCommandsForContentRestrictionState();
-
   UpdateCommandsForBookmarkEditing();
-
   UpdateCommandsForIncognitoAvailability();
 }
 
@@ -1279,18 +1243,6 @@
                                         fullscreen_enabled);
 
   UpdateCommandsForBookmarkBar();
-  UpdateCommandsForMultipleProfiles();
-}
-
-void BrowserCommandController::UpdateCommandsForMultipleProfiles() {
-  bool is_regular_or_guest_session =
-      profile()->IsGuestSession() || !profile()->IsOffTheRecord();
-  bool enable = IsShowingMainUI() &&
-      is_regular_or_guest_session &&
-      profile_manager_ &&
-      AvatarMenu::ShouldShowAvatarMenu();
-  command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU,
-                                        enable);
 }
 
 void BrowserCommandController::UpdatePrintingState() {