Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5644)

Unified Diff: chrome/browser/signin/signin_ui_util.cc

Issue 1301583004: Revert of Delete dead signin code (SigninGlobalError) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/signin/signin_ui_util.h ('k') | chrome/browser/ui/browser_command_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/signin/signin_ui_util.cc
diff --git a/chrome/browser/signin/signin_ui_util.cc b/chrome/browser/signin/signin_ui_util.cc
index 8710548fe0bd501343aea5340de1fa0a1364fb8f..a5ed1122b1c59a704cf6411bc19d223e9a33527b 100644
--- a/chrome/browser/signin/signin_ui_util.cc
+++ b/chrome/browser/signin/signin_ui_util.cc
@@ -10,6 +10,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
+#include "chrome/browser/signin/signin_global_error.h"
+#include "chrome/browser/signin/signin_global_error_factory.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"
@@ -26,7 +28,72 @@
#include "ui/gfx/font_list.h"
#include "ui/gfx/text_elider.h"
+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
+
namespace signin_ui_util {
+
+GlobalError* GetSignedInServiceError(Profile* profile) {
+ std::vector<GlobalError*> errors = GetSignedInServiceErrors(profile);
+ if (errors.empty())
+ return NULL;
+ return errors[0];
+}
+
+std::vector<GlobalError*> GetSignedInServiceErrors(Profile* profile) {
+ std::vector<GlobalError*> errors;
+ // Chrome OS doesn't use SigninGlobalError or SyncGlobalError. Other platforms
+ // may use these services to show auth and sync errors in the toolbar menu.
+#if !defined(OS_CHROMEOS)
+ // Auth errors have the highest priority - after that, individual service
+ // errors.
+ SigninGlobalError* signin_error =
+ SigninGlobalErrorFactory::GetForProfile(profile);
+ if (signin_error && signin_error->HasError())
+ errors.push_back(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->IsSyncAllowed()) {
+ SyncGlobalError* error = SyncGlobalErrorFactory::GetForProfile(profile);
+ if (error && error->HasMenuItem())
+ errors.push_back(error);
+ }
+#endif
+
+ return errors;
+}
+
+base::string16 GetSigninMenuLabel(Profile* profile) {
+ GlobalError* error = signin_ui_util::GetSignedInServiceError(profile);
+ if (error)
+ return error->MenuItemLabel();
+
+ // No errors, so just display the signed in user, if any.
+ ProfileSyncService* service = profile->IsSyncAllowed() ?
+ 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->FirstSetupInProgress()) {
+ std::string username;
+ SigninManagerBase* signin_manager =
+ SigninManagerFactory::GetForProfileIfExists(profile);
+ if (signin_manager)
+ username = signin_manager->GetAuthenticatedUsername();
+ if (!username.empty() && !signin_manager->AuthInProgress()) {
+ const base::string16 elided = gfx::ElideText(base::UTF8ToUTF16(username),
+ gfx::FontList(), kUsernameMaxWidth, gfx::ELIDE_EMAIL);
+ return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_SYNCED_LABEL, elided);
+ }
+ }
+ return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_PRE_SYNCED_LABEL,
+ l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
+}
// Given an authentication state this helper function returns various labels
// that can be used to display information about the state.
« no previous file with comments | « chrome/browser/signin/signin_ui_util.h ('k') | chrome/browser/ui/browser_command_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698