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 GetID() const OVERRIDE { return GetEmail(); } |
| 34 virtual const gfx::ImageSkia& GetImage() const OVERRIDE { |
| 35 return user_image_; |
| 36 } |
| 37 |
| 38 private: |
| 39 // A pseudo user image. |
| 40 gfx::ImageSkia user_image_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(UserInfoStub); |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 SessionStateDelegateStub::SessionStateDelegateStub() |
| 48 : screen_locked_(false), user_info_(new UserInfoStub()) { |
16 } | 49 } |
17 | 50 |
18 SessionStateDelegateStub::~SessionStateDelegateStub() { | 51 SessionStateDelegateStub::~SessionStateDelegateStub() { |
19 } | 52 } |
20 | 53 |
21 content::BrowserContext* | 54 content::BrowserContext* SessionStateDelegateStub::GetBrowserContextByIndex( |
22 SessionStateDelegateStub::GetBrowserContextByIndex( | |
23 MultiProfileIndex index) { | 55 MultiProfileIndex index) { |
24 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); | 56 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); |
25 } | 57 } |
26 | 58 |
27 content::BrowserContext* | 59 content::BrowserContext* SessionStateDelegateStub::GetBrowserContextForWindow( |
28 SessionStateDelegateStub::GetBrowserContextForWindow( | |
29 aura::Window* window) { | 60 aura::Window* window) { |
30 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); | 61 return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); |
31 } | 62 } |
32 | 63 |
33 int SessionStateDelegateStub::GetMaximumNumberOfLoggedInUsers() const { | 64 int SessionStateDelegateStub::GetMaximumNumberOfLoggedInUsers() const { |
34 return 3; | 65 return 3; |
35 } | 66 } |
36 | 67 |
37 int SessionStateDelegateStub::NumberOfLoggedInUsers() const { | 68 int SessionStateDelegateStub::NumberOfLoggedInUsers() const { |
38 return 1; | 69 return 1; |
(...skipping 19 matching lines...) Expand all Loading... |
58 shell::CreateLockScreen(); | 89 shell::CreateLockScreen(); |
59 screen_locked_ = true; | 90 screen_locked_ = true; |
60 Shell::GetInstance()->UpdateShelfVisibility(); | 91 Shell::GetInstance()->UpdateShelfVisibility(); |
61 } | 92 } |
62 | 93 |
63 void SessionStateDelegateStub::UnlockScreen() { | 94 void SessionStateDelegateStub::UnlockScreen() { |
64 screen_locked_ = false; | 95 screen_locked_ = false; |
65 Shell::GetInstance()->UpdateShelfVisibility(); | 96 Shell::GetInstance()->UpdateShelfVisibility(); |
66 } | 97 } |
67 | 98 |
68 bool SessionStateDelegateStub::IsUserSessionBlocked() const { | 99 bool SessionStateDelegateStub::IsUserSessionBlocked() const { |
69 return !IsActiveUserSessionStarted() || IsScreenLocked(); | 100 return !IsActiveUserSessionStarted() || IsScreenLocked(); |
70 } | 101 } |
71 | 102 |
72 SessionStateDelegate::SessionState SessionStateDelegateStub::GetSessionState() | 103 SessionStateDelegate::SessionState SessionStateDelegateStub::GetSessionState() |
73 const { | 104 const { |
74 // Assume that if session is not active we're at login. | 105 // Assume that if session is not active we're at login. |
75 return IsActiveUserSessionStarted() ? | 106 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE |
76 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY; | 107 : SESSION_STATE_LOGIN_PRIMARY; |
77 } | 108 } |
78 | 109 |
79 const base::string16 SessionStateDelegateStub::GetUserDisplayName( | 110 const UserInfo* SessionStateDelegateStub::GetUserInfo( |
80 MultiProfileIndex index) const { | 111 MultiProfileIndex index) const { |
81 return base::UTF8ToUTF16("stub-user"); | 112 return user_info_.get(); |
82 } | 113 } |
83 | 114 |
84 const base::string16 SessionStateDelegateStub::GetUserGivenName( | 115 const UserInfo* SessionStateDelegateStub::GetUserInfo( |
85 MultiProfileIndex index) const { | 116 content::BrowserContext* context) const { |
86 return base::UTF8ToUTF16("Stub"); | 117 return user_info_.get(); |
87 } | 118 } |
88 | 119 |
89 const std::string SessionStateDelegateStub::GetUserEmail( | 120 bool SessionStateDelegateStub::ShouldShowAvatar(aura::Window* window) const { |
90 MultiProfileIndex index) const { | 121 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 } | 122 } |
107 | 123 |
108 void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) { | 124 void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) { |
109 } | 125 } |
110 | 126 |
111 void SessionStateDelegateStub::CycleActiveUser(CycleUser cycle_user) { | 127 void SessionStateDelegateStub::CycleActiveUser(CycleUser cycle_user) { |
112 } | 128 } |
113 | 129 |
114 void SessionStateDelegateStub::AddSessionStateObserver( | 130 void SessionStateDelegateStub::AddSessionStateObserver( |
115 ash::SessionStateObserver* observer) { | 131 ash::SessionStateObserver* observer) { |
116 } | 132 } |
117 | 133 |
118 void SessionStateDelegateStub::RemoveSessionStateObserver( | 134 void SessionStateDelegateStub::RemoveSessionStateObserver( |
119 ash::SessionStateObserver* observer) { | 135 ash::SessionStateObserver* observer) { |
120 } | 136 } |
121 | 137 |
122 } // namespace ash | 138 } // namespace ash |
OLD | NEW |