Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / browser_command_controller.cc
index 354932e..f5f622c 100644 (file)
@@ -11,9 +11,9 @@
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/defaults.h"
 #include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_util.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"
@@ -41,6 +41,7 @@
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_contents_observer.h"
 #include "content/public/common/url_constants.h"
+#include "extensions/browser/extension_system.h"
 #include "ui/events/keycodes/keyboard_codes.h"
 
 #if defined(OS_MACOSX)
@@ -135,7 +136,7 @@ class SwitchToMetroUIHandler
 
  private:
   virtual void SetDefaultWebClientUIState(
-      ShellIntegration::DefaultWebClientUIState state) OVERRIDE {
+      ShellIntegration::DefaultWebClientUIState state) override {
     switch (state) {
       case ShellIntegration::STATE_PROCESSING:
         return;
@@ -156,7 +157,7 @@ class SwitchToMetroUIHandler
     delete this;
   }
 
-  virtual void OnSetAsDefaultConcluded(bool success)  OVERRIDE {
+  virtual void OnSetAsDefaultConcluded(bool success)  override {
     if (!success) {
       delete this;
       return;
@@ -165,7 +166,7 @@ class SwitchToMetroUIHandler
     default_browser_worker_->StartCheckIsDefault();
   }
 
-  virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE {
+  virtual bool IsInteractiveSetDefaultPermitted() override {
     return true;
   }
 
@@ -183,17 +184,12 @@ namespace chrome {
 ///////////////////////////////////////////////////////////////////////////////
 // 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) {
@@ -211,11 +207,11 @@ BrowserCommandController::BrowserCommandController(
       base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
                  base::Unretained(this)));
   profile_pref_registrar_.Add(
-      prefs::kEditBookmarksEnabled,
+      bookmarks::prefs::kEditBookmarksEnabled,
       base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
                  base::Unretained(this)));
   profile_pref_registrar_.Add(
-      prefs::kShowBookmarkBar,
+      bookmarks::prefs::kShowBookmarkBar,
       base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
                  base::Unretained(this)));
   profile_pref_registrar_.Add(
@@ -259,8 +255,6 @@ BrowserCommandController::~BrowserCommandController() {
   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(
@@ -326,6 +320,10 @@ void BrowserCommandController::TabStateChanged() {
   UpdateCommandsForTabState();
 }
 
+void BrowserCommandController::ZoomStateChanged() {
+  UpdateCommandsForZoomState();
+}
+
 void BrowserCommandController::ContentRestrictionsChanged() {
   UpdateCommandsForContentRestrictionState();
 }
@@ -464,19 +462,6 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
 #endif
       break;
 
-#if defined(USE_ASH)
-    case IDC_TOGGLE_ASH_DESKTOP:
-      chrome::ToggleAshDesktop();
-      break;
-    case IDC_MINIMIZE_WINDOW:
-      content::RecordAction(
-          base::UserMetricsAction("Accel_Toggle_Minimized_M"));
-      ash::accelerators::ToggleMinimized();
-      break;
-    // If Ash needs many more commands here we should implement a general
-    // mechanism to pass accelerators back into Ash. http://crbug.com/285308
-#endif
-
 #if defined(OS_CHROMEOS)
     case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
     case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
@@ -501,20 +486,32 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
     case IDC_METRO_SNAP_DISABLE:
       browser_->SetMetroSnapMode(false);
       break;
-    case IDC_WIN8_DESKTOP_RESTART:
-      if (!VerifyMetroSwitchForApps(window()->GetNativeWindow(), id))
+    case IDC_WIN_DESKTOP_RESTART:
+      if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id))
         break;
 
       chrome::AttemptRestartToDesktopMode();
-      content::RecordAction(base::UserMetricsAction("Win8DesktopRestart"));
+      if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
+        content::RecordAction(base::UserMetricsAction("Win8DesktopRestart"));
+      } else {
+        content::RecordAction(base::UserMetricsAction("Win7DesktopRestart"));
+      }
       break;
     case IDC_WIN8_METRO_RESTART:
-      if (!VerifyMetroSwitchForApps(window()->GetNativeWindow(), id))
+    case IDC_WIN_CHROMEOS_RESTART:
+      if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id))
         break;
-
-      // SwitchToMetroUIHandler deletes itself.
-      new SwitchToMetroUIHandler;
-      content::RecordAction(base::UserMetricsAction("Win8MetroRestart"));
+      if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
+        // SwitchToMetroUIHandler deletes itself.
+        new SwitchToMetroUIHandler;
+        content::RecordAction(base::UserMetricsAction("Win8MetroRestart"));
+      } else {
+        content::RecordAction(base::UserMetricsAction("Win7ASHRestart"));
+        chrome::AttemptRestartToMetroMode();
+      }
+      break;
+    case IDC_PIN_TO_START_SCREEN:
+      TogglePagePinnedToStartScreen(browser_);
       break;
 #endif
 
@@ -534,9 +531,6 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
     case IDC_BOOKMARK_PAGE:
       BookmarkCurrentPage(browser_);
       break;
-    case IDC_PIN_TO_START_SCREEN:
-      TogglePagePinnedToStartScreen(browser_);
-      break;
     case IDC_BOOKMARK_ALL_TABS:
       BookmarkAllTabs(browser_);
       break;
@@ -549,13 +543,12 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
     case IDC_PRINT:
       Print(browser_);
       break;
-    case IDC_ADVANCED_PRINT:
+#if defined(ENABLE_BASIC_PRINTING)
+    case IDC_BASIC_PRINT:
       content::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
-      AdvancedPrint(browser_);
-      break;
-    case IDC_PRINT_TO_DESTINATION:
-      PrintToDestination(browser_);
+      BasicPrint(browser_);
       break;
+#endif  // ENABLE_BASIC_PRINTING
     case IDC_TRANSLATE_PAGE:
       Translate(browser_);
       break;
@@ -569,7 +562,6 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
       break;
     case IDC_ENCODING_UTF8:
     case IDC_ENCODING_UTF16LE:
-    case IDC_ENCODING_ISO88591:
     case IDC_ENCODING_WINDOWS1252:
     case IDC_ENCODING_GBK:
     case IDC_ENCODING_GB18030:
@@ -774,6 +766,14 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
     case IDC_TOGGLE_SPEECH_INPUT:
       ToggleSpeechInput(browser_);
       break;
+    case IDC_DISTILL_PAGE:
+      DistillCurrentPage(browser_);
+      break;
+#if defined(OS_CHROMEOS)
+    case IDC_TOUCH_HUD_PROJECTION_TOGGLE:
+      ash::accelerators::ToggleTouchHudProjection();
+      break;
+#endif
 
     default:
       LOG(WARNING) << "Received Unimplemented Command: " << id;
@@ -782,20 +782,6 @@ void BrowserCommandController::ExecuteCommandWithDisposition(
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-// 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() {
@@ -838,9 +824,7 @@ void BrowserCommandController::TabBlockedStateChanged(
 
 void BrowserCommandController::TabRestoreServiceChanged(
     TabRestoreService* service) {
-  command_updater_.UpdateCommandEnabled(
-      IDC_RESTORE_TAB,
-      GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE);
+  UpdateTabRestoreCommandState();
 }
 
 void BrowserCommandController::TabRestoreServiceDestroyed(
@@ -848,6 +832,11 @@ void BrowserCommandController::TabRestoreServiceDestroyed(
   service->RemoveObserver(this);
 }
 
+void BrowserCommandController::TabRestoreServiceLoaded(
+    TabRestoreService* service) {
+  UpdateTabRestoreCommandState();
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // BrowserCommandController, private:
 
@@ -860,13 +849,11 @@ class BrowserCommandController::InterstitialObserver
         controller_(controller) {
   }
 
-  using content::WebContentsObserver::web_contents;
-
-  virtual void DidAttachInterstitialPage() OVERRIDE {
+  void DidAttachInterstitialPage() override {
     controller_->UpdateCommandsForTabState();
   }
 
-  virtual void DidDetachInterstitialPage() OVERRIDE {
+  void DidDetachInterstitialPage() override {
     controller_->UpdateCommandsForTabState();
   }
 
@@ -896,7 +883,7 @@ void BrowserCommandController::InitCommandState() {
   command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
   command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
   command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
-  command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false);
+  UpdateTabRestoreCommandState();
 #if defined(OS_WIN) && defined(USE_ASH)
   if (browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH)
     command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
@@ -904,11 +891,6 @@ void BrowserCommandController::InitCommandState() {
   command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
 #endif
   command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
-#if defined(OS_WIN) && defined(USE_ASH) && !defined(NDEBUG)
-  if (base::win::GetVersion() < base::win::VERSION_WIN8 &&
-      chrome::HOST_DESKTOP_TYPE_NATIVE != chrome::HOST_DESKTOP_TYPE_ASH)
-    command_updater_.UpdateCommandEnabled(IDC_TOGGLE_ASH_DESKTOP, true);
-#endif
 #if defined(USE_ASH)
   command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
 #endif
@@ -926,7 +908,6 @@ void BrowserCommandController::InitCommandState() {
   command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
   command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true);
   command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true);
-  command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88591, true);
   command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true);
   command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true);
   command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true);
@@ -965,38 +946,41 @@ void BrowserCommandController::InitCommandState() {
   // Zoom
   command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
   command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
-  command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true);
+  command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
   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_MENU, 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);
+  command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, 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,
-      normal_window || (CommandLine::ForCurrentProcess()->HasSwitch(
-                            switches::kEnableStreamlinedHostedApps) &&
+      normal_window || (extensions::util::IsStreamlinedHostedAppsEnabled() &&
                         browser_->is_app()));
 
   // Window management commands
@@ -1015,39 +999,32 @@ void BrowserCommandController::InitCommandState() {
   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_WIN_DESKTOP_RESTART :
+      (base::win::GetVersion() >= base::win::VERSION_WIN8 ?
+          IDC_WIN8_METRO_RESTART : IDC_WIN_CHROMEOS_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.
-  UpdateCommandsForFullscreenMode();
+  // Distill current page.
+  command_updater_.UpdateCommandEnabled(
+      IDC_DISTILL_PAGE,
+      CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kEnableDomDistiller));
 
+  // Initialize other commands whose state changes based on various conditions.
+  UpdateCommandsForFullscreenMode();
   UpdateCommandsForContentRestrictionState();
-
   UpdateCommandsForBookmarkEditing();
-
   UpdateCommandsForIncognitoAvailability();
 }
 
@@ -1055,6 +1032,8 @@ void BrowserCommandController::InitCommandState() {
 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
     CommandUpdater* command_updater,
     Profile* profile) {
+  const bool guest_session = profile->IsGuestSession();
+  // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
   IncognitoModePrefs::Availability incognito_availability =
       IncognitoModePrefs::GetAvailability(profile->GetPrefs());
   command_updater->UpdateCommandEnabled(
@@ -1062,16 +1041,16 @@ void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
       incognito_availability != IncognitoModePrefs::FORCED);
   command_updater->UpdateCommandEnabled(
       IDC_NEW_INCOGNITO_WINDOW,
-      incognito_availability != IncognitoModePrefs::DISABLED);
+      incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
 
-  const bool guest_session = profile->IsGuestSession();
   const bool forced_incognito =
       incognito_availability == IncognitoModePrefs::FORCED ||
       guest_session;  // Guest always runs in Incognito mode.
   command_updater->UpdateCommandEnabled(
       IDC_SHOW_BOOKMARK_MANAGER,
       browser_defaults::bookmarks_enabled && !forced_incognito);
-  ExtensionService* extension_service = profile->GetExtensionService();
+  ExtensionService* extension_service =
+      extensions::ExtensionSystem::Get(profile)->extension_service();
   const bool enable_extensions =
       extension_service && extension_service->extensions_enabled();
 
@@ -1127,7 +1106,7 @@ void BrowserCommandController::UpdateCommandsForTabState() {
 
   // Changing the encoding is not possible on Chrome-internal webpages.
   NavigationController& nc = current_web_contents->GetController();
-  bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) ||
+  bool is_chrome_internal = HasInternalURL(nc.GetLastCommittedEntry()) ||
       current_web_contents->ShowingInterstitialPage();
   command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
       !is_chrome_internal && current_web_contents->IsSavable());
@@ -1150,6 +1129,18 @@ void BrowserCommandController::UpdateCommandsForTabState() {
   UpdateCommandsForContentRestrictionState();
   UpdateCommandsForBookmarkEditing();
   UpdateCommandsForFind();
+  // Update the zoom commands when an active tab is selected.
+  UpdateCommandsForZoomState();
+}
+
+void BrowserCommandController::UpdateCommandsForZoomState() {
+  WebContents* contents =
+      browser_->tab_strip_model()->GetActiveWebContents();
+  if (!contents)
+    return;
+  command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
+  command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, ActualSize(contents));
+  command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
 }
 
 void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
@@ -1185,16 +1176,18 @@ void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
                                         CanBookmarkCurrentPage(browser_));
   command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
                                         CanBookmarkAllTabs(browser_));
-  command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN,
-                                        true);
+#if defined(OS_WIN)
+  command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
+#endif
 }
 
 void BrowserCommandController::UpdateCommandsForBookmarkBar() {
-  command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR,
-      browser_defaults::bookmarks_enabled &&
-      !profile()->IsGuestSession() &&
-      !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) &&
-      IsShowingMainUI());
+  command_updater_.UpdateCommandEnabled(
+      IDC_SHOW_BOOKMARK_BAR,
+      browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
+          !profile()->GetPrefs()->IsManagedPreference(
+              bookmarks::prefs::kShowBookmarkBar) &&
+          IsShowingMainUI());
 }
 
 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
@@ -1279,38 +1272,15 @@ void BrowserCommandController::UpdateCommandsForFullscreenMode() {
                                         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() {
   bool print_enabled = CanPrint(browser_);
   command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
-  command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT,
-                                        CanAdvancedPrint(browser_));
-  command_updater_.UpdateCommandEnabled(IDC_PRINT_TO_DESTINATION,
-                                        print_enabled);
-#if defined(OS_WIN)
-  HMODULE metro_module = base::win::GetMetroModule();
-  if (metro_module != NULL) {
-    typedef void (*MetroEnablePrinting)(BOOL);
-    MetroEnablePrinting metro_enable_printing =
-        reinterpret_cast<MetroEnablePrinting>(
-            ::GetProcAddress(metro_module, "MetroEnablePrinting"));
-    if (metro_enable_printing)
-      metro_enable_printing(print_enabled);
-  }
-#endif
+#if defined(ENABLE_BASIC_PRINTING)
+  command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
+                                        CanBasicPrint(browser_));
+#endif  // ENABLE_BASIC_PRINTING
 }
 
 void BrowserCommandController::UpdateSaveAsState() {
@@ -1339,6 +1309,18 @@ void BrowserCommandController::UpdateReloadStopState(bool is_loading,
   command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
 }
 
+void BrowserCommandController::UpdateTabRestoreCommandState() {
+  TabRestoreService* tab_restore_service =
+      TabRestoreServiceFactory::GetForProfile(profile());
+  // The command is enabled if the service hasn't loaded yet to trigger loading.
+  // The command is updated once the load completes.
+  command_updater_.UpdateCommandEnabled(
+      IDC_RESTORE_TAB,
+      tab_restore_service &&
+      (!tab_restore_service->IsLoaded() ||
+       GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
+}
+
 void BrowserCommandController::UpdateCommandsForFind() {
   TabStripModel* model = browser_->tab_strip_model();
   bool enabled = !model->IsTabBlocked(model->active_index()) &&