Skip to content

Commit

Permalink
CleanUp: Introduce UserInfo. Move session_state stuff to ash/session.
Browse files Browse the repository at this point in the history
BUG=None
R=nkostylev@chromium.org
TBR=sky@chromium.org

Review URL: https://codereview.chromium.org/253063002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267158 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Apr 30, 2014
1 parent b8e9c84 commit 5a40d60
Show file tree
Hide file tree
Showing 90 changed files with 493 additions and 382 deletions.
4 changes: 2 additions & 2 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "ash/root_window_controller.h"
#include "ash/rotator/screen_rotation.h"
#include "ash/screenshot_delegate.h"
#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_delegate.h"
#include "ash/shelf/shelf_model.h"
Expand Down Expand Up @@ -71,7 +71,7 @@
#include "ui/views/widget/widget.h"

#if defined(OS_CHROMEOS)
#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/system/chromeos/keyboard_brightness_controller.h"
#include "base/sys_info.h"
#include "chromeos/ime/ime_keyboard.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/accelerators/nested_dispatcher_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#include "ash/accelerators/accelerator_controller.h"
#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
Expand Down
15 changes: 8 additions & 7 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@
'screen_util.cc',
'screen_util.h',
'screenshot_delegate.h',
'session_state_delegate.h',
'session_state_observer.cc',
'session_state_observer.h',
'session/session_state_delegate.h',
'session/session_state_observer.cc',
'session/session_state_observer.h',
'session/user_info.h',
'shelf/app_list_button.cc',
'shelf/app_list_button.h',
'shelf/app_list_shelf_item_delegate.cc',
Expand Down Expand Up @@ -940,8 +941,8 @@
'root_window_controller_unittest.cc',
'screen_util_unittest.cc',
'screensaver/screensaver_view_unittest.cc',
'session_state_delegate_stub.cc',
'session_state_delegate_stub.h',
'session/session_state_delegate_stub.cc',
'session/session_state_delegate_stub.h',
'shelf/scoped_observer_with_duplicated_sources_unittest.cc',
'shelf/shelf_layout_manager_unittest.cc',
'shelf/shelf_model_unittest.cc',
Expand Down Expand Up @@ -1136,8 +1137,8 @@
'ash_with_content',
],
'sources': [
'session_state_delegate_stub.cc',
'session_state_delegate_stub.h',
'session/session_state_delegate_stub.cc',
'session/session_state_delegate_stub.h',
'shell/app_list.cc',
'shell/bubble.cc',
'shell/content_client/shell_browser_main_parts.cc',
Expand Down
2 changes: 1 addition & 1 deletion ash/desktop_background/desktop_background_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "ash/desktop_background/user_wallpaper_delegate.h"
#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/window_animations.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/frame/custom_frame_view_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "ash/frame/frame_border_hit_test_controller.h"
#include "ash/frame/frame_util.h"
#include "ash/frame/header_painter.h"
#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_observer.h"
#include "ash/wm/immersive_fullscreen_controller.h"
Expand Down
9 changes: 6 additions & 3 deletions ash/frame/frame_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "ash/frame/frame_util.h"

#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/session/user_info.h"
#include "ash/shell.h"
#include "grit/ash_resources.h"
#include "ui/base/resource/resource_bundle.h"
Expand All @@ -20,8 +21,10 @@ gfx::Image GetAvatarImageForContext(content::BrowserContext* context) {
static const gfx::ImageSkia* holder_mask =
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_AVATAR_HOLDER_MASK);
gfx::ImageSkia user_image =
Shell::GetInstance()->session_state_delegate()->GetUserImage(context);
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 =
Expand Down
2 changes: 1 addition & 1 deletion ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "ash/high_contrast/high_contrast_controller.h"
#include "ash/host/ash_window_tree_host.h"
#include "ash/root_window_settings.h"
#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shelf/shelf_widget.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/root_window_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "ash/root_window_controller.h"

#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SESSION_STATE_DELEGATE_H_
#define ASH_SESSION_STATE_DELEGATE_H_
#ifndef ASH_SESSION_SESSION_STATE_DELEGATE_H_
#define ASH_SESSION_SESSION_STATE_DELEGATE_H_

#include <string>
#include <vector>
Expand All @@ -26,6 +26,7 @@ class ImageSkia;
namespace ash {

class SessionStateObserver;
class UserInfo;

// 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.
Expand Down Expand Up @@ -108,34 +109,18 @@ class ASH_EXPORT SessionStateDelegate {
// Returns current session state.
virtual SessionState GetSessionState() const = 0;

// Gets the displayed name for the user with the given |index|.
// Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|.
virtual const base::string16 GetUserDisplayName(
MultiProfileIndex index) const = 0;

// Gets the given name of the user with |index|. An empty string can be
// returned if the given name of the user is unknown.
// Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|.
virtual const base::string16 GetUserGivenName(
MultiProfileIndex index) const = 0;

// Gets the display email address for the user with the given |index|.
// The display email address might contains some periods in the email name
// as well as capitalized letters. For example: "Foo.Bar@mock.com".
// Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|.
virtual const std::string GetUserEmail(MultiProfileIndex index) const = 0;
// TODO(oshima): consolidate these two GetUserInfo.

// Gets the user id (sanitized email address) for the user with the given
// |index|. The function would return something like "foobar@mock.com".
// Gets the user info for the user with the given |index|.
// Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|.
virtual const std::string GetUserID(MultiProfileIndex index) const = 0;
virtual const UserInfo* GetUserInfo(MultiProfileIndex index) const = 0;

// Gets the avatar image for the user associated with the |context|.
virtual const gfx::ImageSkia& GetUserImage(
virtual const UserInfo* GetUserInfo(
content::BrowserContext* context) const = 0;

// Whether or not the window's title should show the avatar.
virtual bool ShouldShowAvatar(aura::Window* window) = 0;
virtual bool ShouldShowAvatar(aura::Window* window) const = 0;

// Switches to another active user with |user_id|
// (if that user has already signed in).
Expand All @@ -152,4 +137,4 @@ class ASH_EXPORT SessionStateDelegate {

} // namespace ash

#endif // ASH_SESSION_STATE_DELEGATE_H_
#endif // ASH_SESSION_SESSION_STATE_DELEGATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,60 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/session_state_delegate_stub.h"
#include "ash/session/session_state_delegate_stub.h"

#include "ash/session/user_info.h"
#include "ash/shell.h"
#include "ash/shell/example_factory.h"
#include "ash/shell_delegate.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/gfx/image/image_skia.h"

namespace ash {
namespace {

SessionStateDelegateStub::SessionStateDelegateStub() : screen_locked_(false) {
class UserInfoStub : public UserInfo {
public:
UserInfoStub() {}
virtual ~UserInfoStub() {}

// UserInfo:
virtual base::string16 GetDisplayName() const OVERRIDE {
return base::UTF8ToUTF16("stub-user");
}
virtual base::string16 GetGivenName() const OVERRIDE {
return base::UTF8ToUTF16("Stub");
}
virtual std::string GetEmail() const OVERRIDE {
return "stub-user@domain.com";
}
virtual std::string GetUserID() const OVERRIDE { return GetEmail(); }
virtual const gfx::ImageSkia& GetImage() const OVERRIDE {
return user_image_;
}

private:
gfx::ImageSkia user_image_;

DISALLOW_COPY_AND_ASSIGN(UserInfoStub);
};

} // namespace

SessionStateDelegateStub::SessionStateDelegateStub()
: screen_locked_(false), user_info_(new UserInfoStub()) {
}

SessionStateDelegateStub::~SessionStateDelegateStub() {
}

content::BrowserContext*
SessionStateDelegateStub::GetBrowserContextByIndex(
content::BrowserContext* SessionStateDelegateStub::GetBrowserContextByIndex(
MultiProfileIndex index) {
return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
}

content::BrowserContext*
SessionStateDelegateStub::GetBrowserContextForWindow(
content::BrowserContext* SessionStateDelegateStub::GetBrowserContextForWindow(
aura::Window* window) {
return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
}
Expand Down Expand Up @@ -65,44 +95,29 @@ void SessionStateDelegateStub::UnlockScreen() {
Shell::GetInstance()->UpdateShelfVisibility();
}

bool SessionStateDelegateStub::IsUserSessionBlocked() const {
bool SessionStateDelegateStub::IsUserSessionBlocked() const {
return !IsActiveUserSessionStarted() || IsScreenLocked();
}

SessionStateDelegate::SessionState SessionStateDelegateStub::GetSessionState()
const {
// Assume that if session is not active we're at login.
return IsActiveUserSessionStarted() ?
SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY;
}

const base::string16 SessionStateDelegateStub::GetUserDisplayName(
MultiProfileIndex index) const {
return base::UTF8ToUTF16("stub-user");
}

const base::string16 SessionStateDelegateStub::GetUserGivenName(
MultiProfileIndex index) const {
return base::UTF8ToUTF16("Stub");
}

const std::string SessionStateDelegateStub::GetUserEmail(
MultiProfileIndex index) const {
return "stub-user@domain.com";
return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
: SESSION_STATE_LOGIN_PRIMARY;
}

const std::string SessionStateDelegateStub::GetUserID(
const UserInfo* SessionStateDelegateStub::GetUserInfo(
MultiProfileIndex index) const {
return GetUserEmail(index);
return user_info_.get();
}

const gfx::ImageSkia& SessionStateDelegateStub::GetUserImage(
const UserInfo* SessionStateDelegateStub::GetUserInfo(
content::BrowserContext* context) const {
return user_image_;
return user_info_.get();
}

bool SessionStateDelegateStub::ShouldShowAvatar(aura::Window* window) {
return !user_image_.isNull();
bool SessionStateDelegateStub::ShouldShowAvatar(aura::Window* window) const {
return !user_info_->GetImage().isNull();
}

void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SESSION_STATE_DELEGATE_STUB_H_
#define ASH_SESSION_STATE_DELEGATE_STUB_H_
#ifndef ASH_SESSION_SESSION_STATE_DELEGATE_STUB_H_
#define ASH_SESSION_SESSION_STATE_DELEGATE_STUB_H_

#include "ash/session_state_delegate.h"
#include "ash/session/session_state_delegate.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/gfx/image/image_skia.h"
#include "base/memory/scoped_ptr.h"

namespace ash {

Expand All @@ -33,17 +33,10 @@ class SessionStateDelegateStub : public SessionStateDelegate {
virtual void UnlockScreen() OVERRIDE;
virtual bool IsUserSessionBlocked() const OVERRIDE;
virtual SessionState GetSessionState() const OVERRIDE;
virtual const base::string16 GetUserDisplayName(
ash::MultiProfileIndex index) const OVERRIDE;
virtual const base::string16 GetUserGivenName(
ash::MultiProfileIndex index) const OVERRIDE;
virtual const std::string GetUserEmail(
ash::MultiProfileIndex index) const OVERRIDE;
virtual const std::string GetUserID(
ash::MultiProfileIndex index) const OVERRIDE;
virtual const gfx::ImageSkia& GetUserImage(
virtual const UserInfo* GetUserInfo(MultiProfileIndex index) const OVERRIDE;
virtual const UserInfo* GetUserInfo(
content::BrowserContext* context) const OVERRIDE;
virtual bool ShouldShowAvatar(aura::Window* window) OVERRIDE;
virtual bool ShouldShowAvatar(aura::Window* window) const OVERRIDE;
virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE;
virtual void CycleActiveUser(CycleUser cycle_user) OVERRIDE;
virtual void AddSessionStateObserver(
Expand All @@ -54,12 +47,12 @@ class SessionStateDelegateStub : public SessionStateDelegate {
private:
bool screen_locked_;

// A pseudo user image.
gfx::ImageSkia user_image_;
// A pseudo user info.
scoped_ptr<UserInfo> user_info_;

DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateStub);
};

} // namespace ash

#endif // ASH_SESSION_STATE_DELEGATE_STUB_H_
#endif // ASH_SESSION_SESSION_STATE_DELEGATE_STUB_H_
25 changes: 25 additions & 0 deletions ash/session/session_state_observer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2013 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/session/session_state_observer.h"

#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"

namespace ash {

ScopedSessionStateObserver::ScopedSessionStateObserver(
ash::SessionStateObserver* observer)
: observer_(observer) {
ash::Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(
observer_);
}

ScopedSessionStateObserver::~ScopedSessionStateObserver() {
ash::Shell::GetInstance()
->session_state_delegate()
->RemoveSessionStateObserver(observer_);
}

} // namespace ash
Loading

0 comments on commit 5a40d60

Please sign in to comment.