OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/session_state_delegate_stub.h" | 5 #include "ash/session/session_state_delegate_stub.h" |
6 | 6 |
| 7 #include "ash/session/user_info.h" |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/shell/example_factory.h" | 9 #include "ash/shell/example_factory.h" |
9 #include "ash/shell_delegate.h" | 10 #include "ash/shell_delegate.h" |
10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "ui/gfx/image/image_skia.h" |
12 | 14 |
13 namespace ash { | 15 namespace ash { |
| 16 namespace { |
14 | 17 |
15 SessionStateDelegateStub::SessionStateDelegateStub() : screen_locked_(false) { | 18 class UserInfoStub : public UserInfo { |
| 19 public: |
| 20 UserInfoStub() {} |
| 21 virtual ~UserInfoStub() {} |
| 22 |
| 23 // UserInfo: |
| 24 virtual base::string16 GetDisplayName() const OVERRIDE { |
| 25 return base::UTF8ToUTF16("stub-user"); |
| 26 } |
| 27 virtual base::string16 GetGivenName() const OVERRIDE { |
| 28 return base::UTF8ToUTF16("Stub"); |
| 29 } |
| 30 virtual std::string GetEmail() const OVERRIDE { |
| 31 return "stub-user@domain.com"; |
| 32 } |
| 33 virtual std::string GetUserID() const OVERRIDE { return GetEmail(); } |
| 34 virtual const gfx::ImageSkia& GetImage() const OVERRIDE { |
| 35 return user_image_; |
| 36 } |
| 37 |
| 38 private: |
| 39 gfx::ImageSkia user_image_; |
| 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(UserInfoStub); |
| 42 }; |
| 43 |
| 44 } // namespace |
| 45 |
| 46 SessionStateDelegateStub::SessionStateDelegateStub() |
| 47 : screen_locked_(false), user_info_(new UserInfoStub()) { |
16 } | 48 } |
17 | 49 |
18 SessionStateDelegateStub::~SessionStateDelegateStub() { | 50 SessionStateDelegateStub::~SessionStateDelegateStub() { |
19 } | 51 } |
20 | 52 |
21 content::BrowserContext* | 53 content::BrowserContext* SessionStateDelegateStub::GetBrowserContextByIndex( |
22 SessionStateDelegateStub::GetBrowserContextByIndex( | |
23 MultiProfileIndex index) { | 54 MultiProfileIndex index) { |
24 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); | 55 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); |
25 } | 56 } |
26 | 57 |
27 content::BrowserContext* | 58 content::BrowserContext* SessionStateDelegateStub::GetBrowserContextForWindow( |
28 SessionStateDelegateStub::GetBrowserContextForWindow( | |
29 aura::Window* window) { | 59 aura::Window* window) { |
30 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); | 60 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); |
31 } | 61 } |
32 | 62 |
33 int SessionStateDelegateStub::GetMaximumNumberOfLoggedInUsers() const { | 63 int SessionStateDelegateStub::GetMaximumNumberOfLoggedInUsers() const { |
34 return 3; | 64 return 3; |
35 } | 65 } |
36 | 66 |
37 int SessionStateDelegateStub::NumberOfLoggedInUsers() const { | 67 int SessionStateDelegateStub::NumberOfLoggedInUsers() const { |
38 return 1; | 68 return 1; |
(...skipping 19 matching lines...) Expand all Loading... |
58 shell::CreateLockScreen(); | 88 shell::CreateLockScreen(); |
59 screen_locked_ = true; | 89 screen_locked_ = true; |
60 Shell::GetInstance()->UpdateShelfVisibility(); | 90 Shell::GetInstance()->UpdateShelfVisibility(); |
61 } | 91 } |
62 | 92 |
63 void SessionStateDelegateStub::UnlockScreen() { | 93 void SessionStateDelegateStub::UnlockScreen() { |
64 screen_locked_ = false; | 94 screen_locked_ = false; |
65 Shell::GetInstance()->UpdateShelfVisibility(); | 95 Shell::GetInstance()->UpdateShelfVisibility(); |
66 } | 96 } |
67 | 97 |
68 bool SessionStateDelegateStub::IsUserSessionBlocked() const { | 98 bool SessionStateDelegateStub::IsUserSessionBlocked() const { |
69 return !IsActiveUserSessionStarted() || IsScreenLocked(); | 99 return !IsActiveUserSessionStarted() || IsScreenLocked(); |
70 } | 100 } |
71 | 101 |
72 SessionStateDelegate::SessionState SessionStateDelegateStub::GetSessionState() | 102 SessionStateDelegate::SessionState SessionStateDelegateStub::GetSessionState() |
73 const { | 103 const { |
74 // Assume that if session is not active we're at login. | 104 // Assume that if session is not active we're at login. |
75 return IsActiveUserSessionStarted() ? | 105 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE |
76 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY; | 106 : SESSION_STATE_LOGIN_PRIMARY; |
77 } | 107 } |
78 | 108 |
79 const base::string16 SessionStateDelegateStub::GetUserDisplayName( | 109 const UserInfo* SessionStateDelegateStub::GetUserInfo( |
80 MultiProfileIndex index) const { | 110 MultiProfileIndex index) const { |
81 return base::UTF8ToUTF16("stub-user"); | 111 return user_info_.get(); |
82 } | 112 } |
83 | 113 |
84 const base::string16 SessionStateDelegateStub::GetUserGivenName( | 114 const UserInfo* SessionStateDelegateStub::GetUserInfo( |
85 MultiProfileIndex index) const { | 115 content::BrowserContext* context) const { |
86 return base::UTF8ToUTF16("Stub"); | 116 return user_info_.get(); |
87 } | 117 } |
88 | 118 |
89 const std::string SessionStateDelegateStub::GetUserEmail( | 119 bool SessionStateDelegateStub::ShouldShowAvatar(aura::Window* window) const { |
90 MultiProfileIndex index) const { | 120 return !user_info_->GetImage().isNull(); |
91 return "stub-user@domain.com"; | |
92 } | |
93 | |
94 const std::string SessionStateDelegateStub::GetUserID( | |
95 MultiProfileIndex index) const { | |
96 return GetUserEmail(index); | |
97 } | |
98 | |
99 const gfx::ImageSkia& SessionStateDelegateStub::GetUserImage( | |
100 content::BrowserContext* context) const { | |
101 return user_image_; | |
102 } | |
103 | |
104 bool SessionStateDelegateStub::ShouldShowAvatar(aura::Window* window) { | |
105 return !user_image_.isNull(); | |
106 } | 121 } |
107 | 122 |
108 void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) { | 123 void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) { |
109 } | 124 } |
110 | 125 |
111 void SessionStateDelegateStub::CycleActiveUser(CycleUser cycle_user) { | 126 void SessionStateDelegateStub::CycleActiveUser(CycleUser cycle_user) { |
112 } | 127 } |
113 | 128 |
114 void SessionStateDelegateStub::AddSessionStateObserver( | 129 void SessionStateDelegateStub::AddSessionStateObserver( |
115 ash::SessionStateObserver* observer) { | 130 ash::SessionStateObserver* observer) { |
116 } | 131 } |
117 | 132 |
118 void SessionStateDelegateStub::RemoveSessionStateObserver( | 133 void SessionStateDelegateStub::RemoveSessionStateObserver( |
119 ash::SessionStateObserver* observer) { | 134 ash::SessionStateObserver* observer) { |
120 } | 135 } |
121 | 136 |
122 } // namespace ash | 137 } // namespace ash |
OLD | NEW |