Index: chrome/browser/ui/toolbar/wrench_menu_model.cc |
diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc |
index d77e397df17835465623ec7ab4667a5f135197b4..9eb883ff857d14c4e79918121db1dc66c50218b0 100644 |
--- a/chrome/browser/ui/toolbar/wrench_menu_model.cc |
+++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc |
@@ -18,12 +18,7 @@ |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_manager.h" |
-#include "chrome/browser/signin/signin_global_error.h" |
-#include "chrome/browser/signin/signin_manager.h" |
-#include "chrome/browser/signin/signin_manager_factory.h" |
-#include "chrome/browser/sync/profile_sync_service.h" |
-#include "chrome/browser/sync/profile_sync_service_factory.h" |
-#include "chrome/browser/sync/sync_global_error.h" |
+#include "chrome/browser/signin/signin_ui_util.h" |
#include "chrome/browser/task_manager/task_manager.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_commands.h" |
@@ -56,8 +51,6 @@ |
#include "ui/base/layout.h" |
#include "ui/base/models/button_menu_item_model.h" |
#include "ui/base/resource/resource_bundle.h" |
-#include "ui/base/text/text_elider.h" |
-#include "ui/gfx/font.h" |
#include "ui/gfx/image/image.h" |
#include "ui/gfx/image/image_skia.h" |
@@ -77,12 +70,6 @@ using content::HostZoomMap; |
using content::UserMetricsAction; |
using content::WebContents; |
-namespace { |
-// Maximum width of a username - we trim emails that are wider than this so |
-// the wrench menu doesn't get ridiculously wide. |
-const int kUsernameMaxWidth = 200; |
-} // namespace |
- |
//////////////////////////////////////////////////////////////////////////////// |
// EncodingMenuModel |
@@ -293,33 +280,9 @@ string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { |
} |
case IDC_UPGRADE_DIALOG: |
return l10n_util::GetStringUTF16(IDS_UPDATE_NOW); |
- case IDC_SHOW_SIGNIN: { |
- GlobalError* error = GetActiveSignedInServiceError(); |
- if (error) |
- return error->MenuItemLabel(); |
- |
- // No errors, so just display the signed in user, if any. |
- Profile* profile = browser_->profile()->GetOriginalProfile(); |
- ProfileSyncService* service = profile->IsSyncAccessible() ? |
- ProfileSyncServiceFactory::GetForProfile(profile) : NULL; |
- |
- // Even if the user is signed in, don't display the "signed in as..." |
- // label if we're still setting up sync. |
- if (!service || service->HasSyncSetupCompleted()) { |
- SigninManager* signin_manager = |
- SigninManagerFactory::GetForProfile(profile); |
- std::string username = signin_manager->GetAuthenticatedUsername(); |
- if (!username.empty() && !signin_manager->AuthInProgress()) { |
- string16 elided_username = ui::ElideEmail(UTF8ToUTF16(username), |
- gfx::Font(), |
- kUsernameMaxWidth); |
- return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_SYNCED_LABEL, |
- elided_username); |
- } |
- } |
- return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_PRE_SYNCED_LABEL, |
- l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
- } |
+ case IDC_SHOW_SIGNIN: |
+ return signin_ui_util::GetSigninMenuLabel( |
+ browser_->profile()->GetOriginalProfile()); |
default: |
NOTREACHED(); |
return string16(); |
@@ -340,7 +303,8 @@ bool WrenchMenuModel::GetIconForCommandId(int command_id, |
return false; |
} |
case IDC_SHOW_SIGNIN: { |
- GlobalError* error = GetActiveSignedInServiceError(); |
+ GlobalError* error = signin_ui_util::GetSignedInServiceError( |
+ browser_->profile()->GetOriginalProfile()); |
if (error) { |
int icon_id = error->MenuItemIconResourceID(); |
if (icon_id) { |
@@ -365,8 +329,9 @@ void WrenchMenuModel::ExecuteCommand(int command_id) { |
} |
if (command_id == IDC_SHOW_SIGNIN) { |
- // If a custom error message is being shown, display it. |
- GlobalError* error = GetActiveSignedInServiceError(); |
+ // If a custom error message is being shown, handle it. |
+ GlobalError* error = signin_ui_util::GetSignedInServiceError( |
+ browser_->profile()->GetOriginalProfile()); |
if (error) { |
error->ExecuteMenuItem(browser_); |
return; |
@@ -569,16 +534,14 @@ void WrenchMenuModel::Build(bool is_new_menu, bool supports_new_separators) { |
AddItemWithStringId(IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS); |
AddSeparator(ui::NORMAL_SEPARATOR); |
- // TODO(atwilson): Remove call to IsSyncAccessible() once we fully support |
- // signin while sync is disabled. |
- if (browser_defaults::kShowSigninMenuItem && |
- browser_->profile()->GetOriginalProfile()->IsSyncAccessible()) { |
- const string16 short_product_name = |
- l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
- AddItem(IDC_SHOW_SYNC_SETUP, l10n_util::GetStringFUTF16( |
- IDS_SYNC_MENU_PRE_SYNCED_LABEL, short_product_name)); |
- AddSeparator(ui::NORMAL_SEPARATOR); |
- } |
+#if !defined(OS_CHROMEOS) |
+ // No "Sign in to Chromium..." menu item on ChromeOS. |
+ const string16 short_product_name = |
+ l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
+ AddItem(IDC_SHOW_SYNC_SETUP, l10n_util::GetStringFUTF16( |
+ IDS_SYNC_MENU_PRE_SYNCED_LABEL, short_product_name)); |
+ AddSeparator(ui::NORMAL_SEPARATOR); |
+#endif |
AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); |
@@ -734,25 +697,3 @@ void WrenchMenuModel::UpdateZoomControls() { |
zoom_label_ = l10n_util::GetStringFUTF16( |
IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
} |
- |
-GlobalError* WrenchMenuModel::GetActiveSignedInServiceError() const { |
- Profile* profile = browser_->profile()->GetOriginalProfile(); |
- // Auth errors have the highest priority - after that, individual service |
- // errors. |
- SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); |
- SigninGlobalError* signin_error = signin_manager->signin_global_error(); |
- if (signin_error && signin_error->HasBadge()) |
- return signin_error; |
- |
- // No auth error - now try other services. Currently the list is just hard- |
- // coded but in the future if we add more we can create some kind of |
- // registration framework. |
- if (profile->IsSyncAccessible()) { |
- ProfileSyncService* service = |
- ProfileSyncServiceFactory::GetForProfile(profile); |
- SyncGlobalError* error = service->sync_global_error(); |
- if (error && error->HasBadge()) |
- return error; |
- } |
- return NULL; |
-} |