summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorben <ben@chromium.org>2015-10-05 12:14:32 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-05 19:15:37 +0000
commit9307244929dc1676f0a1f4699fb2c9b3539b9545 (patch)
treef0d53ddbdd5938147d3105b09586f72060700069 /ash
parent9061e0756c36fbf65b90c652fdb1ccc4c832ac62 (diff)
downloadchromium_src-9307244929dc1676f0a1f4699fb2c9b3539b9545.zip
chromium_src-9307244929dc1676f0a1f4699fb2c9b3539b9545.tar.gz
chromium_src-9307244929dc1676f0a1f4699fb2c9b3539b9545.tar.bz2
Extract content-specific aspects of SessionStateDelegate onto ShellContentState.
R=sky@chromium.org http://crbug.com/332504 Review URL: https://codereview.chromium.org/1377343003 Cr-Commit-Position: refs/heads/master@{#352381}
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp2
-rw-r--r--ash/content/shell_content_state.cc4
-rw-r--r--ash/content/shell_content_state.h20
-rw-r--r--ash/frame/custom_frame_view_ash.cc5
-rw-r--r--ash/frame/frame_util.cc38
-rw-r--r--ash/frame/frame_util.h28
-rw-r--r--ash/media_delegate.h9
-rw-r--r--ash/session/session_state_delegate.h51
-rw-r--r--ash/session/session_types.h16
-rw-r--r--ash/shell/content/shell_content_state_impl.cc16
-rw-r--r--ash/shell/content/shell_content_state_impl.h5
-rw-r--r--ash/shell/shell_delegate_impl.cc26
-rw-r--r--ash/system/tray/media_security/multi_profile_media_tray_item.cc10
-rw-r--r--ash/system/user/tray_user.cc21
-rw-r--r--ash/system/user/tray_user.h12
-rw-r--r--ash/system/user/user_card_view.cc43
-rw-r--r--ash/system/user/user_card_view.h9
-rw-r--r--ash/system/user/user_view.cc28
-rw-r--r--ash/system/user/user_view.h4
-rw-r--r--ash/test/ash_test_helper.cc8
-rw-r--r--ash/test/ash_test_helper.h6
-rw-r--r--ash/test/content/test_shell_content_state.cc16
-rw-r--r--ash/test/content/test_shell_content_state.h5
-rw-r--r--ash/test/test_session_state_delegate.cc29
-rw-r--r--ash/test/test_session_state_delegate.h11
-rw-r--r--ash/test/test_shell_delegate.cc3
26 files changed, 176 insertions, 249 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index 7b01a91..b3e1ac0 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -137,8 +137,6 @@
'frame/default_header_painter.h',
'frame/frame_border_hit_test_controller.cc',
'frame/frame_border_hit_test_controller.h',
- 'frame/frame_util.cc',
- 'frame/frame_util.h',
'frame/header_painter.h',
'frame/header_painter_util.cc',
'frame/header_painter_util.h',
diff --git a/ash/content/shell_content_state.cc b/ash/content/shell_content_state.cc
index 55edb6f..d40ba6d 100644
--- a/ash/content/shell_content_state.cc
+++ b/ash/content/shell_content_state.cc
@@ -30,10 +30,6 @@ void ShellContentState::DestroyInstance() {
instance_ = nullptr;
}
-content::BrowserContext* ShellContentState::GetActiveBrowserContext() {
- return nullptr;
-}
-
ShellContentState::ShellContentState() {}
ShellContentState::~ShellContentState() {}
diff --git a/ash/content/shell_content_state.h b/ash/content/shell_content_state.h
index bce240a..a9a6f8a 100644
--- a/ash/content/shell_content_state.h
+++ b/ash/content/shell_content_state.h
@@ -6,8 +6,13 @@
#define ASH_CONTENT_SHELL_CONTENT_STATE_H_
#include "ash/content/ash_with_content_export.h"
+#include "ash/session/session_types.h"
#include "base/macros.h"
+namespace aura {
+class Window;
+}
+
namespace content {
class BrowserContext;
}
@@ -22,7 +27,20 @@ class ASH_WITH_CONTENT_EXPORT ShellContentState {
// Provides the embedder a way to return an active browser context for the
// current user scenario. Default implementation here returns nullptr.
- virtual content::BrowserContext* GetActiveBrowserContext();
+ virtual content::BrowserContext* GetActiveBrowserContext() = 0;
+
+ // Returns the browser context for the user given by |index|.
+ virtual content::BrowserContext* GetBrowserContextByIndex(
+ UserIndex index) = 0;
+
+ // Returns the browser context associated with the window.
+ virtual content::BrowserContext* GetBrowserContextForWindow(
+ aura::Window* window) = 0;
+
+ // Returns the browser context on which the window is currently shown. NULL
+ // means the window will be shown for every user.
+ virtual content::BrowserContext* GetUserPresentingBrowserContextForWindow(
+ aura::Window* window) = 0;
protected:
ShellContentState();
diff --git a/ash/frame/custom_frame_view_ash.cc b/ash/frame/custom_frame_view_ash.cc
index d519653..90d5c6a 100644
--- a/ash/frame/custom_frame_view_ash.cc
+++ b/ash/frame/custom_frame_view_ash.cc
@@ -11,7 +11,6 @@
#include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/frame/default_header_painter.h"
#include "ash/frame/frame_border_hit_test_controller.h"
-#include "ash/frame/frame_util.h"
#include "ash/frame/header_painter.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
@@ -252,9 +251,7 @@ void CustomFrameViewAsh::HeaderView::UpdateAvatarIcon() {
delete avatar_icon_;
avatar_icon_ = NULL;
} else {
- gfx::ImageSkia image = GetAvatarImageForContext(
- delegate->GetBrowserContextForWindow(window)).AsImageSkia();
- DCHECK(!image.isNull());
+ gfx::ImageSkia image = delegate->GetAvatarImageForWindow(window);
DCHECK_EQ(image.width(), image.height());
if (!avatar_icon_) {
avatar_icon_ = new views::ImageView();
diff --git a/ash/frame/frame_util.cc b/ash/frame/frame_util.cc
deleted file mode 100644
index c4b1be9..0000000
--- a/ash/frame/frame_util.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ash/frame/frame_util.h"
-
-#include "ash/session/session_state_delegate.h"
-#include "ash/shell.h"
-#include "components/user_manager/user_info.h"
-#include "grit/ash_resources.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/image/image_skia.h"
-#include "ui/gfx/image/image_skia_operations.h"
-
-namespace ash {
-
-gfx::Image GetAvatarImageForContext(content::BrowserContext* context) {
- static const gfx::ImageSkia* holder =
- ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_AVATAR_HOLDER);
- static const gfx::ImageSkia* holder_mask =
- ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_AVATAR_HOLDER_MASK);
- gfx::ImageSkia user_image = Shell::GetInstance()
- ->session_state_delegate()
- ->GetUserInfo(context)
- ->GetImage();
- gfx::ImageSkia resized = gfx::ImageSkiaOperations::CreateResizedImage(
- user_image, skia::ImageOperations::RESIZE_BEST, holder->size());
- gfx::ImageSkia masked =
- gfx::ImageSkiaOperations::CreateMaskedImage(resized, *holder_mask);
- gfx::ImageSkia result =
- gfx::ImageSkiaOperations::CreateSuperimposedImage(*holder, masked);
- return gfx::Image(result);
-}
-
-} // namespace ash
-
diff --git a/ash/frame/frame_util.h b/ash/frame/frame_util.h
deleted file mode 100644
index ef8e0c4..0000000
--- a/ash/frame/frame_util.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ASH_FRAME_FRAME_UTIL_H_
-#define ASH_FRAME_FRAME_UTIL_H_
-
-#include "ash/ash_export.h"
-
-namespace content {
-class BrowserContext;
-}
-
-namespace gfx {
-class Image;
-}
-
-namespace ash {
-
-// Returns the avatar image to be used in the title bar
-// for the user associated witht the |context|.
-ASH_EXPORT gfx::Image GetAvatarImageForContext(
- content::BrowserContext* context);
-
-} // namespace ash
-
-#endif // ASH_FRAME_FRAME_UTIL_H_
-
diff --git a/ash/media_delegate.h b/ash/media_delegate.h
index 4ea9a17..1b79078 100644
--- a/ash/media_delegate.h
+++ b/ash/media_delegate.h
@@ -5,6 +5,8 @@
#ifndef ASH_MEDIA_DELEGATE_H_
#define ASH_MEDIA_DELEGATE_H_
+#include "ash/session/session_types.h"
+
namespace content {
class BrowserContext;
}
@@ -32,10 +34,9 @@ class MediaDelegate {
// Handles the Previous Track Media shortcut key.
virtual void HandleMediaPrevTrack() = 0;
- // Returns the current media recording state of web contents
- // that belongs to the |context|.
- virtual MediaCaptureState GetMediaCaptureState(
- content::BrowserContext* context) = 0;
+ // Returns the current media recording state of web contents that belongs to
+ // the the user @ |index|. See session_types.h for a description of UserIndex.
+ virtual MediaCaptureState GetMediaCaptureState(UserIndex index) = 0;
};
} // namespace ash
diff --git a/ash/session/session_state_delegate.h b/ash/session/session_state_delegate.h
index 5e73e58..ef88a24 100644
--- a/ash/session/session_state_delegate.h
+++ b/ash/session/session_state_delegate.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,41 +6,27 @@
#define ASH_SESSION_SESSION_STATE_DELEGATE_H_
#include <string>
-#include <vector>
#include "ash/ash_export.h"
-#include "base/strings/string16.h"
+#include "ash/session/session_types.h"
namespace aura {
class Window;
-} // namespace aura
-
-namespace content {
-class BrowserContext;
}
namespace gfx {
class ImageSkia;
-} // namespace gfx
+}
namespace user_manager {
class UserInfo;
-} // namespace user_manager
+}
namespace ash {
class SessionStateObserver;
-// The index for the multi-profile item to use. The list is always LRU sorted
-// So that the index #0 is the currently active user.
-typedef int MultiProfileIndex;
-
-// A list of user_id.
-typedef std::vector<std::string> UserIdList;
-
// Delegate for checking and modifying the session state.
-// TODO(oshima): Replace MultiProfileIndex with BrowsreContext, bacause
-// GetUserXXX are useful for non multi profile scenario in ash_shell.
class ASH_EXPORT SessionStateDelegate {
public:
// Defines the cycle direction for |CycleActiveUser|.
@@ -73,19 +59,6 @@ class ASH_EXPORT SessionStateDelegate {
virtual ~SessionStateDelegate() {};
- // Returns the browser context for the user given by |index|.
- virtual content::BrowserContext* GetBrowserContextByIndex(
- MultiProfileIndex index) = 0;
-
- // Returns the browser context associated with the window.
- virtual content::BrowserContext* GetBrowserContextForWindow(
- aura::Window* window) = 0;
-
- // Returns the browser context on which the window is currently shown. NULL
- // means the window will be shown for every user.
- virtual content::BrowserContext* GetUserPresentingBrowserContextForWindow(
- aura::Window* window) = 0;
-
// Returns the maximum possible number of logged in users.
virtual int GetMaximumNumberOfLoggedInUsers() const = 0;
@@ -128,20 +101,18 @@ class ASH_EXPORT SessionStateDelegate {
// Returns current session state.
virtual SessionState GetSessionState() const = 0;
- // TODO(oshima): consolidate these two GetUserInfo.
-
- // Gets the user info for the user with the given |index|.
+ // Gets the user info for the user with the given |index|. See session_types.h
+ // for a description of UserIndex.
// Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|.
- virtual const user_manager::UserInfo* GetUserInfo(
- MultiProfileIndex index) const = 0;
-
- // Gets the avatar image for the user associated with the |context|.
- virtual const user_manager::UserInfo* GetUserInfo(
- content::BrowserContext* context) const = 0;
+ virtual const user_manager::UserInfo* GetUserInfo(UserIndex index) const = 0;
// Whether or not the window's title should show the avatar.
virtual bool ShouldShowAvatar(aura::Window* window) const = 0;
+ // Returns the avatar image for the specified window.
+ virtual gfx::ImageSkia GetAvatarImageForWindow(
+ aura::Window* window) const = 0;
+
// Switches to another active user with |user_id|
// (if that user has already signed in).
virtual void SwitchActiveUser(const std::string& user_id) = 0;
diff --git a/ash/session/session_types.h b/ash/session/session_types.h
new file mode 100644
index 0000000..c04a0109
--- /dev/null
+++ b/ash/session/session_types.h
@@ -0,0 +1,16 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SESSION_SESSION_TYPES_H_
+#define ASH_SESSION_SESSION_TYPES_H_
+
+namespace ash {
+
+// The index of the user profile to use. The list is always LRU sorted so that
+// index 0 is the currently active user.
+using UserIndex = int;
+
+} // namespace ash
+
+#endif // ASH_SESSION_SESSION_TYPES_H_
diff --git a/ash/shell/content/shell_content_state_impl.cc b/ash/shell/content/shell_content_state_impl.cc
index f1566e4..fa40503 100644
--- a/ash/shell/content/shell_content_state_impl.cc
+++ b/ash/shell/content/shell_content_state_impl.cc
@@ -16,4 +16,20 @@ content::BrowserContext* ShellContentStateImpl::GetActiveBrowserContext() {
return browser_context_;
}
+content::BrowserContext* ShellContentStateImpl::GetBrowserContextByIndex(
+ UserIndex index) {
+ return browser_context_;
+}
+
+content::BrowserContext* ShellContentStateImpl::GetBrowserContextForWindow(
+ aura::Window* window) {
+ return browser_context_;
+}
+
+content::BrowserContext*
+ShellContentStateImpl::GetUserPresentingBrowserContextForWindow(
+ aura::Window* window) {
+ return browser_context_;
+}
+
} // namespace ash
diff --git a/ash/shell/content/shell_content_state_impl.h b/ash/shell/content/shell_content_state_impl.h
index 645e7e3..eba8578 100644
--- a/ash/shell/content/shell_content_state_impl.h
+++ b/ash/shell/content/shell_content_state_impl.h
@@ -18,6 +18,11 @@ class ShellContentStateImpl : public ShellContentState {
// Overridden from ShellContentState:
content::BrowserContext* GetActiveBrowserContext() override;
+ content::BrowserContext* GetBrowserContextByIndex(UserIndex index) override;
+ content::BrowserContext* GetBrowserContextForWindow(
+ aura::Window* window) override;
+ content::BrowserContext* GetUserPresentingBrowserContextForWindow(
+ aura::Window* window) override;
content::BrowserContext* browser_context_;
diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc
index a72452fe..db062e0 100644
--- a/ash/shell/shell_delegate_impl.cc
+++ b/ash/shell/shell_delegate_impl.cc
@@ -26,6 +26,7 @@
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/aura/window.h"
#include "ui/gfx/image/image.h"
+#include "ui/gfx/image/image_skia.h"
namespace ash {
namespace shell {
@@ -65,8 +66,7 @@ class MediaDelegateImpl : public MediaDelegate {
void HandleMediaNextTrack() override {}
void HandleMediaPlayPause() override {}
void HandleMediaPrevTrack() override {}
- MediaCaptureState GetMediaCaptureState(
- content::BrowserContext* context) override {
+ MediaCaptureState GetMediaCaptureState(UserIndex index) override {
return MEDIA_CAPTURE_VIDEO;
}
@@ -82,18 +82,6 @@ class SessionStateDelegateImpl : public SessionStateDelegate {
~SessionStateDelegateImpl() override {}
// SessionStateDelegate:
- content::BrowserContext* GetBrowserContextByIndex(
- MultiProfileIndex index) override {
- return ShellContentState::GetInstance()->GetActiveBrowserContext();
- }
- content::BrowserContext* GetBrowserContextForWindow(
- aura::Window* window) override {
- return ShellContentState::GetInstance()->GetActiveBrowserContext();
- }
- content::BrowserContext* GetUserPresentingBrowserContextForWindow(
- aura::Window* window) override {
- return NULL;
- }
int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
int NumberOfLoggedInUsers() const override {
// ash_shell has 2 users.
@@ -120,17 +108,15 @@ class SessionStateDelegateImpl : public SessionStateDelegate {
return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
: SESSION_STATE_LOGIN_PRIMARY;
}
- const user_manager::UserInfo* GetUserInfo(
- MultiProfileIndex index) const override {
- return user_info_.get();
- }
- const user_manager::UserInfo* GetUserInfo(
- content::BrowserContext* context) const override {
+ const user_manager::UserInfo* GetUserInfo(UserIndex index) const override {
return user_info_.get();
}
bool ShouldShowAvatar(aura::Window* window) const override {
return !user_info_->GetImage().isNull();
}
+ gfx::ImageSkia GetAvatarImageForWindow(aura::Window* window) const override {
+ return gfx::ImageSkia();
+ }
void SwitchActiveUser(const std::string& user_id) override {}
void CycleActiveUser(CycleUser cycle_user) override {}
bool IsMultiProfileAllowedByPrimaryUserPolicy() const override {
diff --git a/ash/system/tray/media_security/multi_profile_media_tray_item.cc b/ash/system/tray/media_security/multi_profile_media_tray_item.cc
index 870d4cd..468aa64 100644
--- a/ash/system/tray/media_security/multi_profile_media_tray_item.cc
+++ b/ash/system/tray/media_security/multi_profile_media_tray_item.cc
@@ -5,6 +5,7 @@
#include "ash/system/tray/media_security/multi_profile_media_tray_item.h"
#include "ash/ash_view_ids.h"
+#include "ash/content/shell_content_state.h"
#include "ash/media_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
@@ -46,12 +47,9 @@ class MultiProfileMediaTrayView : public TrayItemView,
SessionStateDelegate* session_state_delegate =
Shell::GetInstance()->session_state_delegate();
// The user at 0 is the current desktop user.
- for (MultiProfileIndex index = 1;
- index < session_state_delegate->NumberOfLoggedInUsers();
- ++index) {
- content::BrowserContext* context =
- session_state_delegate->GetBrowserContextByIndex(index);
- if (media_delegate->GetMediaCaptureState(context) != MEDIA_CAPTURE_NONE) {
+ for (UserIndex index = 1;
+ index < session_state_delegate->NumberOfLoggedInUsers(); ++index) {
+ if (media_delegate->GetMediaCaptureState(index) != MEDIA_CAPTURE_NONE) {
SetVisible(true);
return;
}
diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc
index 83ab7e7..fd101e7 100644
--- a/ash/system/user/tray_user.cc
+++ b/ash/system/user/tray_user.cc
@@ -39,9 +39,9 @@ const int kUserLabelToIconPadding = 5;
namespace ash {
-TrayUser::TrayUser(SystemTray* system_tray, MultiProfileIndex index)
+TrayUser::TrayUser(SystemTray* system_tray, UserIndex index)
: SystemTrayItem(system_tray),
- multiprofile_index_(index),
+ user_index_(index),
user_(nullptr),
layout_view_(nullptr),
avatar_(nullptr),
@@ -95,9 +95,8 @@ views::View* TrayUser::CreateDefaultView(user::LoginStatus status) {
// If the screen is locked or a system modal dialog box is shown, show only
// the currently active user.
- if (multiprofile_index_ &&
- (session_state_delegate->IsUserSessionBlocked() ||
- Shell::GetInstance()->IsSystemModalWindowOpen()))
+ if (user_index_ && (session_state_delegate->IsUserSessionBlocked() ||
+ Shell::GetInstance()->IsSystemModalWindowOpen()))
return nullptr;
CHECK(user_ == nullptr);
@@ -105,10 +104,10 @@ views::View* TrayUser::CreateDefaultView(user::LoginStatus status) {
int logged_in_users = session_state_delegate->NumberOfLoggedInUsers();
// Do not show more UserView's then there are logged in users.
- if (multiprofile_index_ >= logged_in_users)
+ if (user_index_ >= logged_in_users)
return nullptr;
- user_ = new tray::UserView(this, status, multiprofile_index_, false);
+ user_ = new tray::UserView(this, status, user_index_, false);
return user_;
}
@@ -142,7 +141,7 @@ void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) {
// Only the active user is represented in the tray.
if (!layout_view_)
return;
- if (multiprofile_index_ > 0)
+ if (user_index_ > 0)
return;
bool need_label = false;
bool need_avatar = false;
@@ -259,7 +258,7 @@ void TrayUser::OnUserAddedToSession() {
SessionStateDelegate* session_state_delegate =
Shell::GetInstance()->session_state_delegate();
// Only create views for user items which are logged in.
- if (multiprofile_index_ >= session_state_delegate->NumberOfLoggedInUsers())
+ if (user_index_ >= session_state_delegate->NumberOfLoggedInUsers())
return;
// Enforce a layout change that newly added items become visible.
@@ -274,11 +273,11 @@ void TrayUser::UpdateAvatarImage(user::LoginStatus status) {
SessionStateDelegate* session_state_delegate =
Shell::GetInstance()->session_state_delegate();
if (!avatar_ ||
- multiprofile_index_ >= session_state_delegate->NumberOfLoggedInUsers())
+ user_index_ >= session_state_delegate->NumberOfLoggedInUsers())
return;
const user_manager::UserInfo* user_info =
- session_state_delegate->GetUserInfo(multiprofile_index_);
+ session_state_delegate->GetUserInfo(user_index_);
CHECK(user_info);
avatar_->SetImage(user_info->GetImage(),
gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
diff --git a/ash/system/user/tray_user.h b/ash/system/user/tray_user.h
index f66d672..f13005c 100644
--- a/ash/system/user/tray_user.h
+++ b/ash/system/user/tray_user.h
@@ -31,11 +31,11 @@ class UserView;
class ASH_EXPORT TrayUser : public SystemTrayItem,
public UserObserver {
public:
- // The given |multiprofile_index| is the user number in a multi profile
- // scenario. Index #0 is the running user, the other indices are other logged
- // in users (if there are any). Depending on the multi user mode, there will
- // be either one (index #0) or all users be visible in the system tray.
- TrayUser(SystemTray* system_tray, MultiProfileIndex index);
+ // The given |index| is the user index in a multi profile scenario. Index #0
+ // is the active user, the other indices are other logged in users (if there
+ // are any). Depending on the multi user mode, there will be either one (index
+ // #0) or all users be visible in the system tray.
+ TrayUser(SystemTray* system_tray, UserIndex index);
~TrayUser() override;
// Allows unit tests to see if the item was created.
@@ -82,7 +82,7 @@ class ASH_EXPORT TrayUser : public SystemTrayItem,
void UpdateLayoutOfItem();
// The user index to use.
- MultiProfileIndex multiprofile_index_;
+ UserIndex user_index_;
tray::UserView* user_;
diff --git a/ash/system/user/user_card_view.cc b/ash/system/user/user_card_view.cc
index 5201688..e582c8a 100644
--- a/ash/system/user/user_card_view.cc
+++ b/ash/system/user/user_card_view.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <vector>
+#include "ash/content/shell_content_state.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray_delegate.h"
@@ -60,7 +61,7 @@ const base::char16 kDisplayNameMark[] = {0x2060, 0};
#if defined(OS_CHROMEOS)
class MediaIndicator : public views::View, public MediaCaptureObserver {
public:
- explicit MediaIndicator(MultiProfileIndex index)
+ explicit MediaIndicator(UserIndex index)
: index_(index), label_(new views::Label) {
SetLayoutManager(new views::FillLayout);
views::ImageView* icon = new views::ImageView;
@@ -83,11 +84,8 @@ class MediaIndicator : public views::View, public MediaCaptureObserver {
// MediaCaptureObserver:
void OnMediaCaptureChanged() override {
- Shell* shell = Shell::GetInstance();
- content::BrowserContext* context =
- shell->session_state_delegate()->GetBrowserContextByIndex(index_);
MediaCaptureState state =
- Shell::GetInstance()->media_delegate()->GetMediaCaptureState(context);
+ Shell::GetInstance()->media_delegate()->GetMediaCaptureState(index_);
int res_id = 0;
switch (state) {
case MEDIA_CAPTURE_AUDIO_VIDEO:
@@ -114,7 +112,7 @@ class MediaIndicator : public views::View, public MediaCaptureObserver {
}
private:
- MultiProfileIndex index_;
+ UserIndex index_;
views::Label* label_;
DISALLOW_COPY_AND_ASSIGN(MediaIndicator);
@@ -338,13 +336,13 @@ void PublicAccountUserDetails::CalculatePreferredSize(int max_allowed_width) {
UserCardView::UserCardView(user::LoginStatus login_status,
int max_width,
- int multiprofile_index) {
+ int user_index) {
SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
if (login_status == user::LOGGED_IN_PUBLIC) {
AddPublicModeUserContent(max_width);
} else {
- AddUserContent(login_status, multiprofile_index);
+ AddUserContent(login_status, user_index);
}
}
@@ -367,20 +365,20 @@ void UserCardView::AddPublicModeUserContent(int max_width) {
}
void UserCardView::AddUserContent(user::LoginStatus login_status,
- int multiprofile_index) {
- views::View* icon = CreateIcon(login_status, multiprofile_index);
+ int user_index) {
+ views::View* icon = CreateIcon(login_status, user_index);
AddChildView(icon);
views::Label* user_name = NULL;
SessionStateDelegate* delegate =
Shell::GetInstance()->session_state_delegate();
- if (!multiprofile_index) {
+ if (!user_index) {
base::string16 user_name_string =
login_status == user::LOGGED_IN_GUEST
? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
- : delegate->GetUserInfo(multiprofile_index)->GetDisplayName();
+ : delegate->GetUserInfo(user_index)->GetDisplayName();
if (user_name_string.empty() && IsMultiAccountSupportedAndUserActive())
- user_name_string = base::ASCIIToUTF16(
- delegate->GetUserInfo(multiprofile_index)->GetEmail());
+ user_name_string =
+ base::ASCIIToUTF16(delegate->GetUserInfo(user_index)->GetEmail());
if (!user_name_string.empty()) {
user_name = new views::Label(user_name_string);
user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
@@ -389,14 +387,13 @@ void UserCardView::AddUserContent(user::LoginStatus login_status,
views::Label* user_email = NULL;
if (login_status != user::LOGGED_IN_GUEST &&
- (multiprofile_index || !IsMultiAccountSupportedAndUserActive())) {
+ (user_index || !IsMultiAccountSupportedAndUserActive())) {
SystemTrayDelegate* tray_delegate =
Shell::GetInstance()->system_tray_delegate();
base::string16 user_email_string =
tray_delegate->IsUserSupervised()
? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)
- : base::UTF8ToUTF16(
- delegate->GetUserInfo(multiprofile_index)->GetEmail());
+ : base::UTF8ToUTF16(delegate->GetUserInfo(user_index)->GetEmail());
if (!user_email_string.empty()) {
user_email = new views::Label(user_email_string);
user_email->SetFontList(
@@ -407,7 +404,7 @@ void UserCardView::AddUserContent(user::LoginStatus login_status,
}
// Adjust text properties dependent on if it is an active or inactive user.
- if (multiprofile_index) {
+ if (user_index) {
// Fade the text of non active users to 50%.
SkColor text_color = user_email->enabled_color();
text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2);
@@ -430,7 +427,7 @@ void UserCardView::AddUserContent(user::LoginStatus login_status,
if (user_email) {
#if defined(OS_CHROMEOS)
// Only non active user can have a media indicator.
- MediaIndicator* media_indicator = new MediaIndicator(multiprofile_index);
+ MediaIndicator* media_indicator = new MediaIndicator(user_index);
views::View* email_indicator_view = new views::View;
email_indicator_view->SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
@@ -451,9 +448,9 @@ void UserCardView::AddUserContent(user::LoginStatus login_status,
}
views::View* UserCardView::CreateIcon(user::LoginStatus login_status,
- int multiprofile_index) {
+ int user_index) {
RoundedImageView* icon =
- new RoundedImageView(kTrayAvatarCornerRadius, multiprofile_index == 0);
+ new RoundedImageView(kTrayAvatarCornerRadius, user_index == 0);
if (login_status == user::LOGGED_IN_GUEST) {
icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON)
@@ -462,9 +459,7 @@ views::View* UserCardView::CreateIcon(user::LoginStatus login_status,
} else {
SessionStateDelegate* delegate =
Shell::GetInstance()->session_state_delegate();
- content::BrowserContext* context =
- delegate->GetBrowserContextByIndex(multiprofile_index);
- icon->SetImage(delegate->GetUserInfo(context)->GetImage(),
+ icon->SetImage(delegate->GetUserInfo(user_index)->GetImage(),
gfx::Size(kTrayAvatarSize, kTrayAvatarSize));
}
return icon;
diff --git a/ash/system/user/user_card_view.h b/ash/system/user/user_card_view.h
index 147d3d9..130558d 100644
--- a/ash/system/user/user_card_view.h
+++ b/ash/system/user/user_card_view.h
@@ -17,9 +17,7 @@ namespace tray {
class UserCardView : public views::View {
public:
// |max_width| takes effect only if |login_status| is LOGGED_IN_PUBLIC.
- UserCardView(user::LoginStatus login_status,
- int max_width,
- int multiprofile_index);
+ UserCardView(user::LoginStatus login_status, int max_width, int user_index);
~UserCardView() override;
// views::View overrides.
@@ -29,11 +27,10 @@ class UserCardView : public views::View {
// Creates the content for the public mode.
void AddPublicModeUserContent(int max_width);
- void AddUserContent(user::LoginStatus login_status, int multiprofile_index);
+ void AddUserContent(user::LoginStatus login_status, int user_index);
// Create a user icon representation.
- views::View* CreateIcon(user::LoginStatus login_status,
- int multiprofile_index);
+ views::View* CreateIcon(user::LoginStatus login_status, int user_index);
DISALLOW_COPY_AND_ASSIGN(UserCardView);
};
diff --git a/ash/system/user/user_view.cc b/ash/system/user/user_view.cc
index 3947138..7f7ece5 100644
--- a/ash/system/user/user_view.cc
+++ b/ash/system/user/user_view.cc
@@ -65,7 +65,7 @@ const int kTrayUserTileHoverBorderInset = 10;
const int kPopupMessageOffset = 25;
// Switch to a user with the given |user_index|.
-void SwitchUser(ash::MultiProfileIndex user_index) {
+void SwitchUser(ash::UserIndex user_index) {
// Do not switch users when the log screen is presented.
if (ash::Shell::GetInstance()
->session_state_delegate()
@@ -193,9 +193,9 @@ void AddUserView::AddContent() {
UserView::UserView(SystemTrayItem* owner,
user::LoginStatus login,
- MultiProfileIndex index,
+ UserIndex index,
bool for_detailed_view)
- : multiprofile_index_(index),
+ : user_index_(index),
user_card_view_(NULL),
owner_(owner),
is_user_card_button_(false),
@@ -216,7 +216,7 @@ UserView::UserView(SystemTrayItem* owner,
// The logout button must be added before the user card so that the user card
// can correctly calculate the remaining available width.
// Note that only the current multiprofile user gets a button.
- if (!multiprofile_index_)
+ if (!user_index_)
AddLogoutButton(login);
AddUserCard(login);
}
@@ -250,7 +250,7 @@ gfx::Rect UserView::GetBoundsInScreenOfUserButtonForTest() {
gfx::Size UserView::GetPreferredSize() const {
gfx::Size size = views::View::GetPreferredSize();
// Only the active user panel will be forced to a certain height.
- if (!multiprofile_index_) {
+ if (!user_index_) {
size.set_height(
std::max(size.height(), kTrayPopupItemHeight + GetInsets().height()));
}
@@ -313,16 +313,16 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) {
ash::UMA_STATUS_AREA_SIGN_OUT);
RemoveAddUserMenuOption();
Shell::GetInstance()->system_tray_delegate()->SignOut();
- } else if (sender == user_card_view_ && !multiprofile_index_ &&
+ } else if (sender == user_card_view_ && !user_index_ &&
IsMultiAccountSupportedAndUserActive()) {
owner_->TransitionDetailedView();
} else if (sender == user_card_view_ &&
IsMultiProfileSupportedAndUserActive()) {
- if (!multiprofile_index_) {
+ if (!user_index_) {
ToggleAddUserMenuOption();
} else {
RemoveAddUserMenuOption();
- SwitchUser(multiprofile_index_);
+ SwitchUser(user_index_);
// Since the user list is about to change the system menu should get
// closed.
owner_->system_tray()->CloseSystemBubble();
@@ -390,8 +390,7 @@ void UserView::AddUserCard(user::LoginStatus login) {
(2 * kTrayPopupPaddingHorizontal + kTrayPopupPaddingBetweenItems);
if (logout_button_)
max_card_width -= logout_button_->GetPreferredSize().width();
- user_card_view_ =
- new UserCardView(login, max_card_width, multiprofile_index_);
+ user_card_view_ = new UserCardView(login, max_card_width, user_index_);
// The entry is clickable when no system modal dialog is open and one of the
// multi user options is active.
bool clickable = !Shell::GetInstance()->IsSystemModalWindowOpen() &&
@@ -400,7 +399,7 @@ void UserView::AddUserCard(user::LoginStatus login) {
if (clickable) {
// To allow the border to start before the icon, reduce the size before and
// add an inset to the icon to get the spacing.
- if (!multiprofile_index_) {
+ if (!user_index_) {
SetBorder(views::Border::CreateEmptyBorder(
kTrayPopupUserCardVerticalPadding,
kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset,
@@ -413,7 +412,7 @@ void UserView::AddUserCard(user::LoginStatus login) {
views::View* contents_view = user_card_view_;
ButtonFromView* button = NULL;
if (!for_detailed_view_) {
- if (multiprofile_index_) {
+ if (user_index_) {
// Since the activation border needs to be drawn around the tile, we
// have to put the tile into another view which fills the menu panel,
// but keeping the offsets of the content.
@@ -428,10 +427,7 @@ void UserView::AddUserCard(user::LoginStatus login) {
contents_view->AddChildView(user_card_view_);
insets = gfx::Insets(1, 1, 1, 3);
}
- button = new ButtonFromView(contents_view,
- this,
- !multiprofile_index_,
- insets);
+ button = new ButtonFromView(contents_view, this, !user_index_, insets);
} else {
// We want user card for detailed view to have exactly the same look
// as user card for default view. That's why we wrap it in a button
diff --git a/ash/system/user/user_view.h b/ash/system/user/user_view.h
index 2c42f1d..562ce67 100644
--- a/ash/system/user/user_view.h
+++ b/ash/system/user/user_view.h
@@ -40,7 +40,7 @@ class UserView : public views::View,
public:
UserView(SystemTrayItem* owner,
ash::user::LoginStatus login,
- MultiProfileIndex index,
+ UserIndex index,
bool for_detailed_view);
~UserView() override;
@@ -75,7 +75,7 @@ class UserView : public views::View,
// Removes the add user menu option.
void RemoveAddUserMenuOption();
- MultiProfileIndex multiprofile_index_;
+ UserIndex user_index_;
// The view of the user card.
views::View* user_card_view_;
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index 562759c..336d9c7 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -48,8 +48,9 @@ namespace test {
AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop)
: message_loop_(message_loop),
- test_shell_delegate_(NULL),
- test_screenshot_delegate_(NULL) {
+ test_shell_delegate_(nullptr),
+ test_screenshot_delegate_(nullptr),
+ content_state_(nullptr) {
CHECK(message_loop_);
#if defined(OS_CHROMEOS)
dbus_thread_manager_initialized_ = false;
@@ -99,7 +100,8 @@ void AshTestHelper::SetUp(bool start_session) {
// created in AshTestBase tests.
chromeos::CrasAudioHandler::InitializeForTesting();
#endif
- ShellContentState::SetInstance(new TestShellContentState);
+ ShellContentState::SetInstance(content_state_ ? content_state_
+ : new TestShellContentState);
ShellInitParams init_params;
init_params.delegate = test_shell_delegate_;
diff --git a/ash/test/ash_test_helper.h b/ash/test/ash_test_helper.h
index 36958bd..eb5bf66 100644
--- a/ash/test/ash_test_helper.h
+++ b/ash/test/ash_test_helper.h
@@ -25,6 +25,7 @@ class ViewsDelegate;
}
namespace ash {
+class ShellContentState;
namespace test {
class TestScreenshotDelegate;
@@ -63,6 +64,9 @@ class AshTestHelper {
TestScreenshotDelegate* test_screenshot_delegate() {
return test_screenshot_delegate_;
}
+ void set_content_state(ShellContentState* content_state) {
+ content_state_ = content_state;
+ }
// True if the running environment supports multiple displays,
// or false otherwise (e.g. win8 bot).
@@ -82,6 +86,8 @@ class AshTestHelper {
scoped_ptr<views::ViewsDelegate> views_delegate_;
+ ShellContentState* content_state_;
+
#if defined(OS_CHROMEOS)
// Check if DBus Thread Manager was initialized here.
bool dbus_thread_manager_initialized_;
diff --git a/ash/test/content/test_shell_content_state.cc b/ash/test/content/test_shell_content_state.cc
index a4c2ef0..a46094b 100644
--- a/ash/test/content/test_shell_content_state.cc
+++ b/ash/test/content/test_shell_content_state.cc
@@ -19,4 +19,20 @@ content::BrowserContext* TestShellContentState::GetActiveBrowserContext() {
return active_browser_context_.get();
}
+content::BrowserContext* TestShellContentState::GetBrowserContextByIndex(
+ UserIndex index) {
+ return nullptr;
+}
+
+content::BrowserContext* TestShellContentState::GetBrowserContextForWindow(
+ aura::Window* window) {
+ return nullptr;
+}
+
+content::BrowserContext*
+TestShellContentState::GetUserPresentingBrowserContextForWindow(
+ aura::Window* window) {
+ return nullptr;
+}
+
} // namespace ash
diff --git a/ash/test/content/test_shell_content_state.h b/ash/test/content/test_shell_content_state.h
index b22df2f..1f96795 100644
--- a/ash/test/content/test_shell_content_state.h
+++ b/ash/test/content/test_shell_content_state.h
@@ -23,6 +23,11 @@ class TestShellContentState : public ShellContentState {
// Overridden from ShellContentState:
content::BrowserContext* GetActiveBrowserContext() override;
+ content::BrowserContext* GetBrowserContextByIndex(UserIndex index) override;
+ content::BrowserContext* GetBrowserContextForWindow(
+ aura::Window* window) override;
+ content::BrowserContext* GetUserPresentingBrowserContextForWindow(
+ aura::Window* window) override;
scoped_ptr<content::BrowserContext> active_browser_context_;
diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc
index 426b750..7f2e648 100644
--- a/ash/test/test_session_state_delegate.cc
+++ b/ash/test/test_session_state_delegate.cc
@@ -108,23 +108,6 @@ const user_manager::UserInfo* TestSessionStateDelegate::GetActiveUserInfo()
return user_list_[active_user_index_];
}
-content::BrowserContext*
-TestSessionStateDelegate::GetBrowserContextByIndex(
- MultiProfileIndex index) {
- return NULL;
-}
-
-content::BrowserContext* TestSessionStateDelegate::GetBrowserContextForWindow(
- aura::Window* window) {
- return NULL;
-}
-
-content::BrowserContext*
-TestSessionStateDelegate::GetUserPresentingBrowserContextForWindow(
- aura::Window* window) {
- return NULL;
-}
-
int TestSessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const {
return 3;
}
@@ -217,20 +200,20 @@ void TestSessionStateDelegate::SetUserImage(
}
const user_manager::UserInfo* TestSessionStateDelegate::GetUserInfo(
- MultiProfileIndex index) const {
+ UserIndex index) const {
int max = static_cast<int>(user_list_.size());
return user_list_[index < max ? index : max - 1];
}
-const user_manager::UserInfo* TestSessionStateDelegate::GetUserInfo(
- content::BrowserContext* context) const {
- return user_list_[active_user_index_];
-}
-
bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) const {
return !GetActiveUserInfo()->GetImage().isNull();
}
+gfx::ImageSkia TestSessionStateDelegate::GetAvatarImageForWindow(
+ aura::Window* window) const {
+ return gfx::ImageSkia();
+}
+
void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) {
// Make sure this is a user id and not an email address.
EXPECT_EQ(user_id, GetUserIDFromEmail(user_id));
diff --git a/ash/test/test_session_state_delegate.h b/ash/test/test_session_state_delegate.h
index 64b3c82..10b1429 100644
--- a/ash/test/test_session_state_delegate.h
+++ b/ash/test/test_session_state_delegate.h
@@ -31,12 +31,6 @@ class TestSessionStateDelegate : public SessionStateDelegate {
const user_manager::UserInfo* GetActiveUserInfo() const;
// SessionStateDelegate:
- content::BrowserContext* GetBrowserContextByIndex(
- MultiProfileIndex index) override;
- content::BrowserContext* GetBrowserContextForWindow(
- aura::Window* window) override;
- content::BrowserContext* GetUserPresentingBrowserContextForWindow(
- aura::Window* window) override;
int GetMaximumNumberOfLoggedInUsers() const override;
int NumberOfLoggedInUsers() const override;
bool IsActiveUserSessionStarted() const override;
@@ -48,10 +42,9 @@ class TestSessionStateDelegate : public SessionStateDelegate {
bool IsUserSessionBlocked() const override;
SessionState GetSessionState() const override;
const user_manager::UserInfo* GetUserInfo(
- ash::MultiProfileIndex index) const override;
- const user_manager::UserInfo* GetUserInfo(
- content::BrowserContext* context) const override;
+ ash::UserIndex index) const override;
bool ShouldShowAvatar(aura::Window* window) const override;
+ gfx::ImageSkia GetAvatarImageForWindow(aura::Window* window) const override;
void SwitchActiveUser(const std::string& user_id) override;
void CycleActiveUser(CycleUser cycle_user) override;
bool IsMultiProfileAllowedByPrimaryUserPolicy() const override;
diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc
index 689f272..8eb4c2a 100644
--- a/ash/test/test_shell_delegate.cc
+++ b/ash/test/test_shell_delegate.cc
@@ -71,8 +71,7 @@ class MediaDelegateImpl : public MediaDelegate {
void HandleMediaNextTrack() override {}
void HandleMediaPlayPause() override {}
void HandleMediaPrevTrack() override {}
- MediaCaptureState GetMediaCaptureState(
- content::BrowserContext* context) override {
+ MediaCaptureState GetMediaCaptureState(UserIndex index) override {
return state_;
}