OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/signin/screenlock_bridge.h" | 5 #include "chrome/browser/signin/signin_screen_bridge.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "chrome/browser/profiles/profile_window.h" | 9 #include "chrome/browser/profiles/profile_window.h" |
10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
11 #include "components/signin/core/browser/signin_manager.h" | 11 #include "components/signin/core/browser/signin_manager.h" |
12 | 12 |
13 #if defined(OS_CHROMEOS) | 13 #if defined(OS_CHROMEOS) |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/session_manager_client.h" | 15 #include "chromeos/dbus/session_manager_client.h" |
16 #endif | 16 #endif |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 base::LazyInstance<ScreenlockBridge> g_screenlock_bridge_bridge_instance = | 20 base::LazyInstance<SigninScreenBridge> g_signin_screen_bridge_bridge_instance = |
21 LAZY_INSTANCE_INITIALIZER; | 21 LAZY_INSTANCE_INITIALIZER; |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 // static | 25 // static |
26 ScreenlockBridge* ScreenlockBridge::Get() { | 26 SigninScreenBridge* SigninScreenBridge::Get() { |
27 return g_screenlock_bridge_bridge_instance.Pointer(); | 27 return g_signin_screen_bridge_bridge_instance.Pointer(); |
28 } | 28 } |
29 | 29 |
30 ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions() | 30 SigninScreenBridge::UserPodCustomIconOptions::UserPodCustomIconOptions() |
31 : width_(0u), | 31 : width_(0u), |
32 height_(0u), | 32 height_(0u), |
33 animation_set_(false), | 33 animation_set_(false), |
34 animation_resource_width_(0u), | 34 animation_resource_width_(0u), |
35 animation_frame_length_ms_(0u), | 35 animation_frame_length_ms_(0u), |
36 opacity_(100u), | 36 opacity_(100u), |
37 autoshow_tooltip_(false), | 37 autoshow_tooltip_(false), |
38 hardlock_on_click_(false) { | 38 hardlock_on_click_(false) { |
39 } | 39 } |
40 | 40 |
41 ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {} | 41 SigninScreenBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {} |
42 | 42 |
43 scoped_ptr<base::DictionaryValue> | 43 scoped_ptr<base::DictionaryValue> |
44 ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const { | 44 SigninScreenBridge::UserPodCustomIconOptions::ToDictionaryValue() const { |
45 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 45 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
46 if (icon_resource_url_.empty()) | 46 if (icon_resource_url_.empty()) |
47 return result.Pass(); | 47 return result.Pass(); |
48 | 48 |
49 result->SetString("resourceUrl", icon_resource_url_); | 49 result->SetString("resourceUrl", icon_resource_url_); |
50 | 50 |
51 if (!tooltip_.empty()) { | 51 if (!tooltip_.empty()) { |
52 base::DictionaryValue* tooltip_options = new base::DictionaryValue(); | 52 base::DictionaryValue* tooltip_options = new base::DictionaryValue(); |
53 tooltip_options->SetString("text", tooltip_); | 53 tooltip_options->SetString("text", tooltip_); |
54 tooltip_options->SetBoolean("autoshow", autoshow_tooltip_); | 54 tooltip_options->SetBoolean("autoshow", autoshow_tooltip_); |
(...skipping 15 matching lines...) Expand all Loading... |
70 animation_frame_length_ms_); | 70 animation_frame_length_ms_); |
71 result->Set("animation", animation); | 71 result->Set("animation", animation); |
72 } | 72 } |
73 | 73 |
74 if (hardlock_on_click_) | 74 if (hardlock_on_click_) |
75 result->SetBoolean("hardlockOnClick", true); | 75 result->SetBoolean("hardlockOnClick", true); |
76 | 76 |
77 return result.Pass(); | 77 return result.Pass(); |
78 } | 78 } |
79 | 79 |
80 void ScreenlockBridge::UserPodCustomIconOptions::SetIconAsResourceURL( | 80 void SigninScreenBridge::UserPodCustomIconOptions::SetIconAsResourceURL( |
81 const std::string& url) { | 81 const std::string& url) { |
82 icon_resource_url_ = url; | 82 icon_resource_url_ = url; |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 void ScreenlockBridge::UserPodCustomIconOptions::SetSize(size_t icon_width, | 86 void SigninScreenBridge::UserPodCustomIconOptions::SetSize(size_t icon_width, |
87 size_t icon_height) { | 87 size_t icon_height) { |
88 width_ = icon_width; | 88 width_ = icon_width; |
89 height_ = icon_height; | 89 height_ = icon_height; |
90 } | 90 } |
91 | 91 |
92 void ScreenlockBridge::UserPodCustomIconOptions::SetAnimation( | 92 void SigninScreenBridge::UserPodCustomIconOptions::SetAnimation( |
93 size_t resource_width, | 93 size_t resource_width, |
94 size_t frame_length_ms) { | 94 size_t frame_length_ms) { |
95 animation_set_ = true; | 95 animation_set_ = true; |
96 animation_resource_width_ = resource_width; | 96 animation_resource_width_ = resource_width; |
97 animation_frame_length_ms_ = frame_length_ms; | 97 animation_frame_length_ms_ = frame_length_ms; |
98 } | 98 } |
99 | 99 |
100 void ScreenlockBridge::UserPodCustomIconOptions::SetOpacity(size_t opacity) { | 100 void SigninScreenBridge::UserPodCustomIconOptions::SetOpacity(size_t opacity) { |
101 DCHECK_LE(opacity, 100u); | 101 DCHECK_LE(opacity, 100u); |
102 opacity_ = opacity; | 102 opacity_ = opacity; |
103 } | 103 } |
104 | 104 |
105 void ScreenlockBridge::UserPodCustomIconOptions::SetTooltip( | 105 void SigninScreenBridge::UserPodCustomIconOptions::SetTooltip( |
106 const base::string16& tooltip, | 106 const base::string16& tooltip, |
107 bool autoshow) { | 107 bool autoshow) { |
108 tooltip_ = tooltip; | 108 tooltip_ = tooltip; |
109 autoshow_tooltip_ = autoshow; | 109 autoshow_tooltip_ = autoshow; |
110 } | 110 } |
111 | 111 |
112 void ScreenlockBridge::UserPodCustomIconOptions::SetHardlockOnClick() { | 112 void SigninScreenBridge::UserPodCustomIconOptions::SetHardlockOnClick() { |
113 hardlock_on_click_ = true; | 113 hardlock_on_click_ = true; |
114 } | 114 } |
115 | 115 |
116 // static | 116 // static |
117 std::string ScreenlockBridge::GetAuthenticatedUserEmail(Profile* profile) { | 117 std::string SigninScreenBridge::GetAuthenticatedUserEmail(Profile* profile) { |
118 // |profile| has to be a signed-in profile with SigninManager already | 118 // |profile| has to be a signed-in profile with SigninManager already |
119 // created. Otherwise, just crash to collect stack. | 119 // created. Otherwise, just crash to collect stack. |
120 SigninManagerBase* signin_manager = | 120 SigninManagerBase* signin_manager = |
121 SigninManagerFactory::GetForProfileIfExists(profile); | 121 SigninManagerFactory::GetForProfileIfExists(profile); |
122 return signin_manager->GetAuthenticatedUsername(); | 122 return signin_manager->GetAuthenticatedUsername(); |
123 } | 123 } |
124 | 124 |
125 ScreenlockBridge::ScreenlockBridge() : lock_handler_(NULL) { | 125 SigninScreenBridge::SigninScreenBridge() : lock_handler_(NULL) { |
126 } | 126 } |
127 | 127 |
128 ScreenlockBridge::~ScreenlockBridge() { | 128 SigninScreenBridge::~SigninScreenBridge() { |
129 } | 129 } |
130 | 130 |
131 void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) { | 131 void SigninScreenBridge::SetLockHandler(LockHandler* lock_handler) { |
132 DCHECK(lock_handler_ == NULL || lock_handler == NULL); | 132 DCHECK(lock_handler_ == NULL || lock_handler == NULL); |
133 lock_handler_ = lock_handler; | 133 lock_handler_ = lock_handler; |
134 if (lock_handler_) | 134 if (lock_handler_) |
135 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidLock()); | 135 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidLock()); |
136 else | 136 else |
137 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidUnlock()); | 137 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidUnlock()); |
138 } | 138 } |
139 | 139 |
140 void ScreenlockBridge::SetFocusedUser(const std::string& user_id) { | 140 void SigninScreenBridge::SetFocusedUser(const std::string& user_id) { |
141 if (user_id == focused_user_id_) | 141 if (user_id == focused_user_id_) |
142 return; | 142 return; |
143 focused_user_id_ = user_id; | 143 focused_user_id_ = user_id; |
144 FOR_EACH_OBSERVER(Observer, observers_, OnFocusedUserChanged(user_id)); | 144 FOR_EACH_OBSERVER(Observer, observers_, OnFocusedUserChanged(user_id)); |
145 } | 145 } |
146 | 146 |
147 bool ScreenlockBridge::IsLocked() const { | 147 bool SigninScreenBridge::IsLocked() const { |
148 return lock_handler_ != NULL; | 148 return lock_handler_ != NULL; |
149 } | 149 } |
150 | 150 |
151 void ScreenlockBridge::Lock(Profile* profile) { | 151 void SigninScreenBridge::Lock(Profile* profile) { |
152 #if defined(OS_CHROMEOS) | 152 #if defined(OS_CHROMEOS) |
153 chromeos::SessionManagerClient* session_manager = | 153 chromeos::SessionManagerClient* session_manager = |
154 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 154 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
155 session_manager->RequestLockScreen(); | 155 session_manager->RequestLockScreen(); |
156 #else | 156 #else |
157 profiles::LockProfile(profile); | 157 profiles::LockProfile(profile); |
158 #endif | 158 #endif |
159 } | 159 } |
160 | 160 |
161 void ScreenlockBridge::Unlock(Profile* profile) { | 161 void SigninScreenBridge::Unlock(Profile* profile) { |
162 if (lock_handler_) | 162 if (lock_handler_) |
163 lock_handler_->Unlock(GetAuthenticatedUserEmail(profile)); | 163 lock_handler_->Unlock(GetAuthenticatedUserEmail(profile)); |
164 } | 164 } |
165 | 165 |
166 void ScreenlockBridge::AddObserver(Observer* observer) { | 166 void SigninScreenBridge::AddObserver(Observer* observer) { |
167 observers_.AddObserver(observer); | 167 observers_.AddObserver(observer); |
168 } | 168 } |
169 | 169 |
170 void ScreenlockBridge::RemoveObserver(Observer* observer) { | 170 void SigninScreenBridge::RemoveObserver(Observer* observer) { |
171 observers_.RemoveObserver(observer); | 171 observers_.RemoveObserver(observer); |
172 } | 172 } |
OLD | NEW |