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 "components/signin/content/screenlock_bridge.h" |
Ilya Sherman
2015/04/21 23:02:39
I think the proximity_auth component is more appro
| |
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" | |
10 #include "chrome/browser/signin/signin_manager_factory.h" | |
11 #include "components/signin/core/browser/signin_manager.h" | |
12 | 9 |
13 #if defined(OS_CHROMEOS) | 10 #if defined(OS_CHROMEOS) |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/session_manager_client.h" | 12 #include "chromeos/dbus/session_manager_client.h" |
16 #endif | 13 #endif |
17 | 14 |
18 namespace { | 15 namespace { |
19 | 16 |
20 base::LazyInstance<ScreenlockBridge> g_screenlock_bridge_bridge_instance = | 17 base::LazyInstance<ScreenlockBridge> g_screenlock_bridge_bridge_instance = |
21 LAZY_INSTANCE_INITIALIZER; | 18 LAZY_INSTANCE_INITIALIZER; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 ScreenlockBridge* ScreenlockBridge::Get() { | 54 ScreenlockBridge* ScreenlockBridge::Get() { |
58 return g_screenlock_bridge_bridge_instance.Pointer(); | 55 return g_screenlock_bridge_bridge_instance.Pointer(); |
59 } | 56 } |
60 | 57 |
61 ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions() | 58 ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions() |
62 : autoshow_tooltip_(false), | 59 : autoshow_tooltip_(false), |
63 hardlock_on_click_(false), | 60 hardlock_on_click_(false), |
64 is_trial_run_(false) { | 61 is_trial_run_(false) { |
65 } | 62 } |
66 | 63 |
67 ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {} | 64 ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() { |
65 } | |
68 | 66 |
69 scoped_ptr<base::DictionaryValue> | 67 scoped_ptr<base::DictionaryValue> |
70 ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const { | 68 ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const { |
71 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 69 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
72 std::string icon_id = GetIdForIcon(icon_); | 70 std::string icon_id = GetIdForIcon(icon_); |
73 result->SetString("id", icon_id); | 71 result->SetString("id", icon_id); |
74 | 72 |
75 if (!tooltip_.empty()) { | 73 if (!tooltip_.empty()) { |
76 base::DictionaryValue* tooltip_options = new base::DictionaryValue(); | 74 base::DictionaryValue* tooltip_options = new base::DictionaryValue(); |
77 tooltip_options->SetString("text", tooltip_); | 75 tooltip_options->SetString("text", tooltip_); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 107 } |
110 | 108 |
111 void ScreenlockBridge::UserPodCustomIconOptions::SetHardlockOnClick() { | 109 void ScreenlockBridge::UserPodCustomIconOptions::SetHardlockOnClick() { |
112 hardlock_on_click_ = true; | 110 hardlock_on_click_ = true; |
113 } | 111 } |
114 | 112 |
115 void ScreenlockBridge::UserPodCustomIconOptions::SetTrialRun() { | 113 void ScreenlockBridge::UserPodCustomIconOptions::SetTrialRun() { |
116 is_trial_run_ = true; | 114 is_trial_run_ = true; |
117 } | 115 } |
118 | 116 |
119 // static | |
120 std::string ScreenlockBridge::GetAuthenticatedUserEmail( | |
121 const Profile* profile) { | |
122 // |profile| has to be a signed-in profile with SigninManager already | |
123 // created. Otherwise, just crash to collect stack. | |
124 const SigninManagerBase* signin_manager = | |
125 SigninManagerFactory::GetForProfileIfExists(profile); | |
126 return signin_manager->GetAuthenticatedUsername(); | |
127 } | |
128 | |
129 ScreenlockBridge::ScreenlockBridge() : lock_handler_(NULL) { | 117 ScreenlockBridge::ScreenlockBridge() : lock_handler_(NULL) { |
130 } | 118 } |
131 | 119 |
132 ScreenlockBridge::~ScreenlockBridge() { | 120 ScreenlockBridge::~ScreenlockBridge() { |
133 } | 121 } |
134 | 122 |
135 void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) { | 123 void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) { |
136 DCHECK(lock_handler_ == NULL || lock_handler == NULL); | 124 DCHECK(lock_handler_ == NULL || lock_handler == NULL); |
137 | 125 |
138 // Don't notify observers if there is no change -- i.e. if the screen was | 126 // Don't notify observers if there is no change -- i.e. if the screen was |
(...skipping 20 matching lines...) Expand all Loading... | |
159 if (user_id == focused_user_id_) | 147 if (user_id == focused_user_id_) |
160 return; | 148 return; |
161 focused_user_id_ = user_id; | 149 focused_user_id_ = user_id; |
162 FOR_EACH_OBSERVER(Observer, observers_, OnFocusedUserChanged(user_id)); | 150 FOR_EACH_OBSERVER(Observer, observers_, OnFocusedUserChanged(user_id)); |
163 } | 151 } |
164 | 152 |
165 bool ScreenlockBridge::IsLocked() const { | 153 bool ScreenlockBridge::IsLocked() const { |
166 return lock_handler_ != NULL; | 154 return lock_handler_ != NULL; |
167 } | 155 } |
168 | 156 |
169 void ScreenlockBridge::Lock(Profile* profile) { | 157 void ScreenlockBridge::Lock(content::BrowserContext* browser_context) { |
170 #if defined(OS_CHROMEOS) | 158 #if defined(OS_CHROMEOS) |
171 chromeos::SessionManagerClient* session_manager = | 159 chromeos::SessionManagerClient* session_manager = |
172 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 160 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
173 session_manager->RequestLockScreen(); | 161 session_manager->RequestLockScreen(); |
174 #else | 162 #else |
175 profiles::LockProfile(profile); | 163 if (lock_handler_) |
164 lock_handler_->Lock(browser_context); | |
176 #endif | 165 #endif |
177 } | 166 } |
178 | 167 |
179 void ScreenlockBridge::Unlock(Profile* profile) { | 168 void ScreenlockBridge::Unlock(content::BrowserContext* browser_context) { |
180 if (lock_handler_) | 169 if (lock_handler_) |
181 lock_handler_->Unlock(GetAuthenticatedUserEmail(profile)); | 170 lock_handler_->Unlock(browser_context); |
182 } | 171 } |
183 | 172 |
184 void ScreenlockBridge::AddObserver(Observer* observer) { | 173 void ScreenlockBridge::AddObserver(Observer* observer) { |
185 observers_.AddObserver(observer); | 174 observers_.AddObserver(observer); |
186 } | 175 } |
187 | 176 |
188 void ScreenlockBridge::RemoveObserver(Observer* observer) { | 177 void ScreenlockBridge::RemoveObserver(Observer* observer) { |
189 observers_.RemoveObserver(observer); | 178 observers_.RemoveObserver(observer); |
190 } | 179 } |
OLD | NEW |