Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / signin_ui_util.cc
index 8842076..8316747 100644 (file)
@@ -4,9 +4,11 @@
 
 #include "chrome/browser/signin/signin_ui_util.h"
 
+#include "base/prefs/pref_service.h"
 #include "base/strings/sys_string_conversions.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/account_tracker_service_factory.h"
 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
 #include "chrome/browser/signin/signin_global_error.h"
 #include "chrome/browser/signin/signin_global_error_factory.h"
 #include "chrome/browser/sync/profile_sync_service_factory.h"
 #include "chrome/browser/sync/sync_global_error.h"
 #include "chrome/browser/sync/sync_global_error_factory.h"
+#include "chrome/browser/ui/browser_navigator.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/signin/core/browser/account_tracker_service.h"
 #include "components/signin/core/browser/profile_oauth2_token_service.h"
 #include "components/signin/core/browser/signin_manager.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
+#include "components/signin/core/common/profile_management_switches.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/gfx/font_list.h"
 #include "ui/gfx/text_elider.h"
@@ -47,7 +53,7 @@ std::vector<GlobalError*> GetSignedInServiceErrors(Profile* profile) {
   // errors.
   SigninGlobalError* signin_error =
       SigninGlobalErrorFactory::GetForProfile(profile);
-  if (signin_error && signin_error->HasMenuItem())
+  if (signin_error && signin_error->HasError())
     errors.push_back(signin_error);
 
   // No auth error - now try other services. Currently the list is just hard-
@@ -81,10 +87,9 @@ base::string16 GetSigninMenuLabel(Profile* profile) {
     if (signin_manager)
       username = signin_manager->GetAuthenticatedUsername();
     if (!username.empty() && !signin_manager->AuthInProgress()) {
-      base::string16 elided_username = gfx::ElideEmail(
-          base::UTF8ToUTF16(username), gfx::FontList(), kUsernameMaxWidth);
-      return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_SYNCED_LABEL,
-                                        elided_username);
+      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,
@@ -97,8 +102,6 @@ void GetStatusLabelsForAuthError(Profile* profile,
                                  const SigninManagerBase& signin_manager,
                                  base::string16* status_label,
                                  base::string16* link_label) {
-  base::string16 username =
-      base::UTF8ToUTF16(signin_manager.GetAuthenticatedUsername());
   base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
   if (link_label)
     link_label->assign(l10n_util::GetStringUTF16(IDS_SYNC_RELOGIN_LINK_LABEL));
@@ -113,7 +116,7 @@ void GetStatusLabelsForAuthError(Profile* profile,
     case GoogleServiceAuthError::ACCOUNT_DISABLED:
       // If the user name is empty then the first login failed, otherwise the
       // credentials are out-of-date.
-      if (username.empty()) {
+      if (!signin_manager.IsAuthenticated()) {
         if (status_label) {
           status_label->assign(
               l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS));
@@ -154,4 +157,33 @@ void GetStatusLabelsForAuthError(Profile* profile,
   }
 }
 
+void InitializePrefsForProfile(Profile* profile) {
+  // Suppresses the upgrade tutorial for a new profile.
+  if (profile->IsNewProfile() && switches::IsNewAvatarMenu()) {
+    profile->GetPrefs()->SetInteger(
+        prefs::kProfileAvatarTutorialShown, kUpgradeWelcomeTutorialShowMax + 1);
+  }
+}
+
+void ShowSigninErrorLearnMorePage(Profile* profile) {
+  static const char kSigninErrorLearnMoreUrl[] =
+      "https://support.google.com/chrome/answer/1181420?";
+  chrome::NavigateParams params(
+      profile, GURL(kSigninErrorLearnMoreUrl), ui::PAGE_TRANSITION_LINK);
+  params.disposition = NEW_FOREGROUND_TAB;
+  chrome::Navigate(&params);
+}
+
+std::string GetDisplayEmail(Profile* profile, const std::string& account_id) {
+  AccountTrackerService* account_tracker =
+      AccountTrackerServiceFactory::GetForProfile(profile);
+  std::string email = account_tracker->GetAccountInfo(account_id).email;
+  if (email.empty()) {
+    DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED,
+              account_tracker->GetMigrationState());
+    return account_id;
+  }
+  return email;
+}
+
 }  // namespace signin_ui_util