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/proximity_auth/screenlock_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 "components/proximity_auth/proximity_auth_client.h" |
10 #include "chrome/browser/signin/signin_manager_factory.h" | |
11 #include "components/signin/core/browser/signin_manager.h" | |
12 | 10 |
13 #if defined(OS_CHROMEOS) | 11 #if defined(OS_CHROMEOS) |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/session_manager_client.h" | 13 #include "chromeos/dbus/session_manager_client.h" |
16 #endif | 14 #endif |
17 | 15 |
16 namespace proximity_auth { | |
17 | |
Ilya Sherman
2015/04/24 21:22:02
Optional nit: I'd omit this newline.
msarda
2015/04/27 11:29:25
Done.
| |
18 namespace { | 18 namespace { |
19 | 19 |
20 base::LazyInstance<ScreenlockBridge> g_screenlock_bridge_bridge_instance = | |
21 LAZY_INSTANCE_INITIALIZER; | |
22 | |
23 // Ids for the icons that are supported by lock screen and signin screen | 20 // Ids for the icons that are supported by lock screen and signin screen |
24 // account picker as user pod custom icons. | 21 // account picker as user pod custom icons. |
25 // The id's should be kept in sync with values used by user_pod_row.js. | 22 // The id's should be kept in sync with values used by user_pod_row.js. |
26 const char kLockedUserPodCustomIconId[] = "locked"; | 23 const char kLockedUserPodCustomIconId[] = "locked"; |
27 const char kLockedToBeActivatedUserPodCustomIconId[] = "locked-to-be-activated"; | 24 const char kLockedToBeActivatedUserPodCustomIconId[] = "locked-to-be-activated"; |
28 const char kLockedWithProximityHintUserPodCustomIconId[] = | 25 const char kLockedWithProximityHintUserPodCustomIconId[] = |
29 "locked-with-proximity-hint"; | 26 "locked-with-proximity-hint"; |
30 const char kUnlockedUserPodCustomIconId[] = "unlocked"; | 27 const char kUnlockedUserPodCustomIconId[] = "unlocked"; |
31 const char kHardlockedUserPodCustomIconId[] = "hardlocked"; | 28 const char kHardlockedUserPodCustomIconId[] = "hardlocked"; |
32 const char kSpinnerUserPodCustomIconId[] = "spinner"; | 29 const char kSpinnerUserPodCustomIconId[] = "spinner"; |
(...skipping 13 matching lines...) Expand all Loading... | |
46 return kHardlockedUserPodCustomIconId; | 43 return kHardlockedUserPodCustomIconId; |
47 case ScreenlockBridge::USER_POD_CUSTOM_ICON_SPINNER: | 44 case ScreenlockBridge::USER_POD_CUSTOM_ICON_SPINNER: |
48 return kSpinnerUserPodCustomIconId; | 45 return kSpinnerUserPodCustomIconId; |
49 default: | 46 default: |
50 return ""; | 47 return ""; |
51 } | 48 } |
52 } | 49 } |
53 | 50 |
54 } // namespace | 51 } // namespace |
55 | 52 |
56 // static | 53 ScreenlockBridge::ScreenlockBridge(ProximityAuthClient* client) |
57 ScreenlockBridge* ScreenlockBridge::Get() { | 54 : client_(client), lock_handler_(nullptr) { |
58 return g_screenlock_bridge_bridge_instance.Pointer(); | 55 DCHECK(client_); |
56 } | |
57 | |
58 ScreenlockBridge::~ScreenlockBridge() { | |
59 } | 59 } |
60 | 60 |
61 ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions() | 61 ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions() |
62 : autoshow_tooltip_(false), | 62 : autoshow_tooltip_(false), |
63 hardlock_on_click_(false), | 63 hardlock_on_click_(false), |
64 is_trial_run_(false) { | 64 is_trial_run_(false) { |
65 } | 65 } |
66 | 66 |
67 ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {} | 67 ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() { |
68 } | |
68 | 69 |
69 scoped_ptr<base::DictionaryValue> | 70 scoped_ptr<base::DictionaryValue> |
70 ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const { | 71 ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const { |
71 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 72 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
72 std::string icon_id = GetIdForIcon(icon_); | 73 std::string icon_id = GetIdForIcon(icon_); |
73 result->SetString("id", icon_id); | 74 result->SetString("id", icon_id); |
74 | 75 |
75 if (!tooltip_.empty()) { | 76 if (!tooltip_.empty()) { |
76 base::DictionaryValue* tooltip_options = new base::DictionaryValue(); | 77 base::DictionaryValue* tooltip_options = new base::DictionaryValue(); |
77 tooltip_options->SetString("text", tooltip_); | 78 tooltip_options->SetString("text", tooltip_); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 110 } |
110 | 111 |
111 void ScreenlockBridge::UserPodCustomIconOptions::SetHardlockOnClick() { | 112 void ScreenlockBridge::UserPodCustomIconOptions::SetHardlockOnClick() { |
112 hardlock_on_click_ = true; | 113 hardlock_on_click_ = true; |
113 } | 114 } |
114 | 115 |
115 void ScreenlockBridge::UserPodCustomIconOptions::SetTrialRun() { | 116 void ScreenlockBridge::UserPodCustomIconOptions::SetTrialRun() { |
116 is_trial_run_ = true; | 117 is_trial_run_ = true; |
117 } | 118 } |
118 | 119 |
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) { | |
130 } | |
131 | |
132 ScreenlockBridge::~ScreenlockBridge() { | |
133 } | |
134 | |
135 void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) { | 120 void ScreenlockBridge::SetLockHandler(LockHandler* lock_handler) { |
136 DCHECK(lock_handler_ == NULL || lock_handler == NULL); | 121 DCHECK(lock_handler_ == nullptr || lock_handler == nullptr); |
137 | 122 |
138 // Don't notify observers if there is no change -- i.e. if the screen was | 123 // Don't notify observers if there is no change -- i.e. if the screen was |
139 // already unlocked, and is remaining unlocked. | 124 // already unlocked, and is remaining unlocked. |
140 if (lock_handler == lock_handler_) | 125 if (lock_handler == lock_handler_) |
141 return; | 126 return; |
142 | 127 |
143 // TODO(isherman): If |lock_handler| is null, then |lock_handler_| might have | 128 // TODO(isherman): If |lock_handler| is null, then |lock_handler_| might have |
144 // been freed. Cache the screen type rather than querying it below. | 129 // been freed. Cache the screen type rather than querying it below. |
145 LockHandler::ScreenType screen_type; | 130 LockHandler::ScreenType screen_type; |
146 if (lock_handler_) | 131 if (lock_handler_) |
147 screen_type = lock_handler_->GetScreenType(); | 132 screen_type = lock_handler_->GetScreenType(); |
148 else | 133 else |
149 screen_type = lock_handler->GetScreenType(); | 134 screen_type = lock_handler->GetScreenType(); |
150 | 135 |
151 lock_handler_ = lock_handler; | 136 lock_handler_ = lock_handler; |
152 if (lock_handler_) | 137 if (lock_handler_) |
153 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidLock(screen_type)); | 138 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidLock(screen_type)); |
154 else | 139 else |
155 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidUnlock(screen_type)); | 140 FOR_EACH_OBSERVER(Observer, observers_, OnScreenDidUnlock(screen_type)); |
156 } | 141 } |
157 | 142 |
158 void ScreenlockBridge::SetFocusedUser(const std::string& user_id) { | 143 void ScreenlockBridge::SetFocusedUser(const std::string& user_id) { |
159 if (user_id == focused_user_id_) | 144 if (user_id == focused_user_id_) |
160 return; | 145 return; |
161 focused_user_id_ = user_id; | 146 focused_user_id_ = user_id; |
162 FOR_EACH_OBSERVER(Observer, observers_, OnFocusedUserChanged(user_id)); | 147 FOR_EACH_OBSERVER(Observer, observers_, OnFocusedUserChanged(user_id)); |
163 } | 148 } |
164 | 149 |
165 bool ScreenlockBridge::IsLocked() const { | 150 bool ScreenlockBridge::IsLocked() const { |
166 return lock_handler_ != NULL; | 151 return lock_handler_ != nullptr; |
167 } | 152 } |
168 | 153 |
169 void ScreenlockBridge::Lock(Profile* profile) { | 154 void ScreenlockBridge::Lock(content::BrowserContext* browser_context) { |
170 #if defined(OS_CHROMEOS) | 155 #if defined(OS_CHROMEOS) |
171 chromeos::SessionManagerClient* session_manager = | 156 chromeos::SessionManagerClient* session_manager = |
172 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 157 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
173 session_manager->RequestLockScreen(); | 158 session_manager->RequestLockScreen(); |
174 #else | 159 #else |
175 profiles::LockProfile(profile); | 160 client_->Lock(browser_context); |
176 #endif | 161 #endif |
177 } | 162 } |
178 | 163 |
179 void ScreenlockBridge::Unlock(Profile* profile) { | 164 void ScreenlockBridge::Unlock(content::BrowserContext* browser_context) { |
180 if (lock_handler_) | 165 if (lock_handler_) { |
181 lock_handler_->Unlock(GetAuthenticatedUserEmail(profile)); | 166 lock_handler_->Unlock(client_->GetAuthenticatedUsername(browser_context)); |
167 } | |
Ilya Sherman
2015/04/24 21:22:02
nit: No need for curlies.
msarda
2015/04/27 11:29:25
Done.
| |
182 } | 168 } |
183 | 169 |
184 void ScreenlockBridge::AddObserver(Observer* observer) { | 170 void ScreenlockBridge::AddObserver(Observer* observer) { |
185 observers_.AddObserver(observer); | 171 observers_.AddObserver(observer); |
186 } | 172 } |
187 | 173 |
188 void ScreenlockBridge::RemoveObserver(Observer* observer) { | 174 void ScreenlockBridge::RemoveObserver(Observer* observer) { |
189 observers_.RemoveObserver(observer); | 175 observers_.RemoveObserver(observer); |
190 } | 176 } |
177 | |
178 } // namespace proximity_auth | |
OLD | NEW |