| Index: chrome/browser/ui/toolbar/wrench_menu_model.cc
|
| ===================================================================
|
| --- chrome/browser/ui/toolbar/wrench_menu_model.cc (revision 177205)
|
| +++ chrome/browser/ui/toolbar/wrench_menu_model.cc (working copy)
|
| @@ -18,12 +18,12 @@
|
| #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/sync/sync_ui_util.h"
|
| #include "chrome/browser/task_manager/task_manager.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_commands.h"
|
| @@ -57,8 +57,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"
|
|
|
| @@ -78,12 +76,6 @@
|
| 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
|
|
|
| @@ -257,7 +249,7 @@
|
| #endif
|
| command_id == IDC_VIEW_BACKGROUND_PAGES ||
|
| command_id == IDC_UPGRADE_DIALOG ||
|
| - command_id == IDC_SHOW_SIGNIN;
|
| + command_id == IDC_SHOW_SYNC_SETUP;
|
| }
|
|
|
| string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const {
|
| @@ -292,28 +284,19 @@
|
| }
|
| case IDC_UPGRADE_DIALOG:
|
| return l10n_util::GetStringUTF16(IDS_UPDATE_NOW);
|
| - case IDC_SHOW_SIGNIN: {
|
| - GlobalError* error = GetActiveSignedInServiceError();
|
| - if (error)
|
| + case IDC_SHOW_SYNC_SETUP: {
|
| + ProfileSyncService* service =
|
| + ProfileSyncServiceFactory::GetInstance()->GetForProfile(
|
| + browser_->profile()->GetOriginalProfile());
|
| + SyncGlobalError* error = service->sync_global_error();
|
| + if (error && error->HasCustomizedSyncMenuItem())
|
| 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);
|
| + if (service->HasSyncSetupCompleted()) {
|
| + std::string username = browser_->profile()->GetPrefs()->GetString(
|
| + prefs::kGoogleServicesUsername);
|
| + if (!username.empty()) {
|
| return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_SYNCED_LABEL,
|
| - elided_username);
|
| + UTF8ToUTF16(username));
|
| }
|
| }
|
| return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_PRE_SYNCED_LABEL,
|
| @@ -338,9 +321,12 @@
|
| }
|
| return false;
|
| }
|
| - case IDC_SHOW_SIGNIN: {
|
| - GlobalError* error = GetActiveSignedInServiceError();
|
| - if (error) {
|
| + case IDC_SHOW_SYNC_SETUP: {
|
| + ProfileSyncService* service =
|
| + ProfileSyncServiceFactory::GetInstance()->GetForProfile(
|
| + browser_->profile()->GetOriginalProfile());
|
| + SyncGlobalError* error = service->sync_global_error();
|
| + if (error && error->HasCustomizedSyncMenuItem()) {
|
| int icon_id = error->MenuItemIconResourceID();
|
| if (icon_id) {
|
| *icon = rb.GetNativeImageNamed(icon_id);
|
| @@ -363,10 +349,12 @@
|
| return;
|
| }
|
|
|
| - if (command_id == IDC_SHOW_SIGNIN) {
|
| - // If a custom error message is being shown, display it.
|
| - GlobalError* error = GetActiveSignedInServiceError();
|
| - if (error) {
|
| + if (command_id == IDC_SHOW_SYNC_SETUP) {
|
| + ProfileSyncService* service =
|
| + ProfileSyncServiceFactory::GetInstance()->GetForProfile(
|
| + browser_->profile()->GetOriginalProfile());
|
| + SyncGlobalError* error = service->sync_global_error();
|
| + if (error && error->HasCustomizedSyncMenuItem()) {
|
| error->ExecuteMenuItem(browser_);
|
| return;
|
| }
|
| @@ -568,9 +556,7 @@
|
| 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 &&
|
| + if (browser_defaults::kShowSyncSetupMenuItem &&
|
| browser_->profile()->GetOriginalProfile()->IsSyncAccessible()) {
|
| const string16 short_product_name =
|
| l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
|
| @@ -733,24 +719,9 @@
|
| IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent));
|
| }
|
|
|
| -GlobalError* WrenchMenuModel::GetActiveSignedInServiceError() const {
|
| +string16 WrenchMenuModel::GetSyncMenuLabel() 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;
|
| + return sync_ui_util::GetSyncMenuLabel(
|
| + ProfileSyncServiceFactory::GetForProfile(profile),
|
| + *SigninManagerFactory::GetForProfile(profile));
|
| }
|
|
|