Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / profiles / avatar_menu.cc
index 5bd91cd..992a2aa 100644 (file)
 #include "chrome/browser/ui/browser_dialogs.h"
 #include "chrome/browser/ui/host_desktop.h"
 #include "chrome/browser/ui/startup/startup_browser_creator.h"
+#include "chrome/browser/ui/user_manager.h"
 #include "chrome/common/chrome_switches.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/signin/core/common/profile_management_switches.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/notification_service.h"
-#include "grit/generated_resources.h"
 #include "grit/theme_resources.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/resource/resource_bundle.h"
 
 #if defined(ENABLE_MANAGED_USERS)
-#include "chrome/browser/managed_mode/managed_user_service.h"
-#include "chrome/browser/managed_mode/managed_user_service_factory.h"
+#include "chrome/browser/supervised_user/supervised_user_service.h"
+#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
 #endif
 
 using content::BrowserThread;
@@ -51,6 +53,9 @@ AvatarMenu::AvatarMenu(ProfileInfoInterface* profile_cache,
                        Browser* browser)
     : profile_list_(ProfileList::Create(profile_cache)),
       menu_actions_(AvatarMenuActions::Create()),
+#if defined(ENABLE_MANAGED_USERS)
+      supervised_user_observer_(this),
+#endif
       profile_info_(profile_cache),
       observer_(observer),
       browser_(browser) {
@@ -62,6 +67,15 @@ AvatarMenu::AvatarMenu(ProfileInfoInterface* profile_cache,
   // Register this as an observer of the info cache.
   registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
       content::NotificationService::AllSources());
+
+#if defined(ENABLE_MANAGED_USERS)
+  // Register this as an observer of the SupervisedUserService to be notified
+  // of changes to the custodian info.
+  if (browser_) {
+    supervised_user_observer_.Add(
+        SupervisedUserServiceFactory::GetForProfile(browser_->profile()));
+  }
+#endif
 }
 
 AvatarMenu::~AvatarMenu() {
@@ -95,13 +109,10 @@ bool AvatarMenu::ShouldShowAvatarMenu() {
   // implementations.
   if (profiles::IsMultipleProfilesEnabled()) {
 #if defined(OS_CHROMEOS)
-    // On ChromeOS the menu will be shown in M-31 mode when it is possible to
-    // have two users logged in at the same time.
-    return ash::switches::UseFullMultiProfileMode() &&
-           ChromeShellDelegate::instance() &&
-           ChromeShellDelegate::instance()->IsMultiProfilesEnabled();
+    // On ChromeOS the menu will not be shown.
+    return false;
 #else
-    return profiles::IsNewProfileManagementEnabled() ||
+    return switches::IsNewAvatarMenu() ||
            (g_browser_process->profile_manager() &&
             g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
 #endif
@@ -114,15 +125,19 @@ bool AvatarMenu::CompareItems(const Item* item1, const Item* item2) {
       base::i18n::ToLower(item2->name)) < 0;
 }
 
-void AvatarMenu::SwitchToProfile(size_t index, bool always_create) {
+void AvatarMenu::SwitchToProfile(size_t index,
+                                 bool always_create,
+                                 ProfileMetrics::ProfileOpen metric) {
   DCHECK(profiles::IsMultipleProfilesEnabled() ||
          index == GetActiveProfileIndex());
   const Item& item = GetItemAt(index);
 
-  if (profiles::IsNewProfileManagementEnabled()) {
+  if (switches::IsNewAvatarMenu()) {
     // Don't open a browser window for signed-out profiles.
     if (item.signin_required) {
-      chrome::ShowUserManager(item.profile_path);
+      UserManager::Show(item.profile_path,
+                        profiles::USER_MANAGER_NO_TUTORIAL,
+                        profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
       return;
     }
   }
@@ -135,8 +150,8 @@ void AvatarMenu::SwitchToProfile(size_t index, bool always_create) {
     desktop_type = browser_->host_desktop_type();
 
   profiles::SwitchToProfile(path, desktop_type, always_create,
-                            profiles::ProfileSwitchingDoneCallback());
-  ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON);
+                            ProfileManager::CreateCallback(),
+                            metric);
 }
 
 void AvatarMenu::AddNewProfile(ProfileMetrics::ProfileAdd type) {
@@ -185,22 +200,23 @@ size_t AvatarMenu::GetActiveProfileIndex() {
   return index;
 }
 
-base::string16 AvatarMenu::GetManagedUserInformation() const {
+base::string16 AvatarMenu::GetSupervisedUserInformation() const {
   // |browser_| can be NULL in unit_tests.
-  if (browser_ && browser_->profile()->IsManaged()) {
+  if (browser_ && browser_->profile()->IsSupervised()) {
 #if defined(ENABLE_MANAGED_USERS)
-    ManagedUserService* service = ManagedUserServiceFactory::GetForProfile(
-        browser_->profile());
-    base::string16 custodian = UTF8ToUTF16(service->GetCustodianEmailAddress());
-    return l10n_util::GetStringFUTF16(IDS_MANAGED_USER_INFO, custodian);
+    SupervisedUserService* service =
+        SupervisedUserServiceFactory::GetForProfile(browser_->profile());
+    base::string16 custodian =
+        base::UTF8ToUTF16(service->GetCustodianEmailAddress());
+    return l10n_util::GetStringFUTF16(IDS_SUPERVISED_USER_INFO, custodian);
 #endif
   }
   return base::string16();
 }
 
-const gfx::Image& AvatarMenu::GetManagedUserIcon() const {
+const gfx::Image& AvatarMenu::GetSupervisedUserIcon() const {
   return ResourceBundle::GetSharedInstance().GetNativeImageNamed(
-      IDR_MANAGED_USER_ICON);
+      IDR_SUPERVISED_USER_ICON);
 }
 
 void AvatarMenu::ActiveBrowserChanged(Browser* browser) {
@@ -231,10 +247,10 @@ void AvatarMenu::Observe(int type,
     observer_->OnAvatarMenuChanged(this);
 }
 
-content::WebContents* AvatarMenu::BeginSignOut() {
-  return menu_actions_->BeginSignOut();
-}
-
-void AvatarMenu::SetLogoutURL(const std::string& logout_url) {
-  menu_actions_->SetLogoutURL(logout_url);
+#if defined(ENABLE_MANAGED_USERS)
+void AvatarMenu::OnCustodianInfoChanged() {
+  RebuildMenu();
+  if (observer_)
+    observer_->OnAvatarMenuChanged(this);
 }
+#endif