Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/signin/easy_unlock_service.cc

Issue 576343002: [Easy signin] Add method to get user info to easyUnlockPrivate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win fix Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/easy_unlock_service.h" 5 #include "chrome/browser/signin/easy_unlock_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/component_loader.h" 13 #include "chrome/browser/extensions/component_loader.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" 16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h"
17 #include "chrome/browser/signin/easy_unlock_service_factory.h" 17 #include "chrome/browser/signin/easy_unlock_service_factory.h"
18 #include "chrome/browser/signin/easy_unlock_service_observer.h" 18 #include "chrome/browser/signin/easy_unlock_service_observer.h"
19 #include "chrome/browser/signin/screenlock_bridge.h" 19 #include "chrome/browser/signin/screenlock_bridge.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/api/easy_unlock_private.h"
21 #include "chrome/common/extensions/extension_constants.h" 22 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "device/bluetooth/bluetooth_adapter.h" 25 #include "device/bluetooth/bluetooth_adapter.h"
25 #include "device/bluetooth/bluetooth_adapter_factory.h" 26 #include "device/bluetooth/bluetooth_adapter_factory.h"
27 #include "extensions/browser/event_router.h"
26 #include "extensions/browser/extension_registry.h" 28 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_system.h" 29 #include "extensions/browser/extension_system.h"
28 #include "extensions/common/one_shot_event.h" 30 #include "extensions/common/one_shot_event.h"
29 #include "grit/browser_resources.h" 31 #include "grit/browser_resources.h"
30 32
31 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
32 #include "chromeos/dbus/dbus_thread_manager.h" 34 #include "chromeos/dbus/dbus_thread_manager.h"
33 #include "chromeos/dbus/power_manager_client.h" 35 #include "chromeos/dbus/power_manager_client.h"
34 #endif 36 #endif
35 37
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 123
122 EasyUnlockService* service_; 124 EasyUnlockService* service_;
123 125
124 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); 126 DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
125 }; 127 };
126 #endif 128 #endif
127 129
128 EasyUnlockService::EasyUnlockService(Profile* profile) 130 EasyUnlockService::EasyUnlockService(Profile* profile)
129 : profile_(profile), 131 : profile_(profile),
130 bluetooth_detector_(new BluetoothDetector(this)), 132 bluetooth_detector_(new BluetoothDetector(this)),
133 shut_down_(false),
131 weak_ptr_factory_(this) { 134 weak_ptr_factory_(this) {
132 extensions::ExtensionSystem::Get(profile_)->ready().Post( 135 extensions::ExtensionSystem::Get(profile_)->ready().Post(
133 FROM_HERE, 136 FROM_HERE,
134 base::Bind(&EasyUnlockService::Initialize, 137 base::Bind(&EasyUnlockService::Initialize,
135 weak_ptr_factory_.GetWeakPtr())); 138 weak_ptr_factory_.GetWeakPtr()));
136 } 139 }
137 140
138 EasyUnlockService::~EasyUnlockService() { 141 EasyUnlockService::~EasyUnlockService() {
139 } 142 }
140 143
(...skipping 12 matching lines...) Expand all
153 prefs::kEasyUnlockPairing, 156 prefs::kEasyUnlockPairing,
154 new base::DictionaryValue(), 157 new base::DictionaryValue(),
155 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 158 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
156 registry->RegisterBooleanPref( 159 registry->RegisterBooleanPref(
157 prefs::kEasyUnlockAllowed, 160 prefs::kEasyUnlockAllowed,
158 true, 161 true,
159 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 162 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
160 } 163 }
161 164
162 bool EasyUnlockService::IsAllowed() { 165 bool EasyUnlockService::IsAllowed() {
166 if (shut_down_)
167 return false;
168
163 if (!IsAllowedInternal()) 169 if (!IsAllowedInternal())
164 return false; 170 return false;
165 171
166 #if defined(OS_CHROMEOS) 172 #if defined(OS_CHROMEOS)
167 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) 173 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed))
168 return false; 174 return false;
169 175
170 // Respect existing policy and skip finch test. 176 // Respect existing policy and skip finch test.
171 if (!profile_->GetPrefs()->IsManagedPreference(prefs::kEasyUnlockAllowed)) { 177 if (!profile_->GetPrefs()->IsManagedPreference(prefs::kEasyUnlockAllowed)) {
172 // It is disabled when the trial exists and is in "Disable" group. 178 // It is disabled when the trial exists and is in "Disable" group.
(...skipping 25 matching lines...) Expand all
198 } 204 }
199 205
200 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) { 206 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) {
201 observers_.AddObserver(observer); 207 observers_.AddObserver(observer);
202 } 208 }
203 209
204 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) { 210 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) {
205 observers_.RemoveObserver(observer); 211 observers_.RemoveObserver(observer);
206 } 212 }
207 213
214 void EasyUnlockService::Shutdown() {
215 if (shut_down_)
216 return;
217 shut_down_ = true;
218
219 ShutdownInternal();
220
221 weak_ptr_factory_.InvalidateWeakPtrs();
222
223 ResetScreenlockStateHandler();
224 bluetooth_detector_.reset();
225 #if defined(OS_CHROMEOS)
226 power_monitor_.reset();
227 #endif
228 }
229
208 void EasyUnlockService::LoadApp() { 230 void EasyUnlockService::LoadApp() {
209 DCHECK(IsAllowed()); 231 DCHECK(IsAllowed());
210 232
211 #if defined(GOOGLE_CHROME_BUILD) 233 #if defined(GOOGLE_CHROME_BUILD)
212 base::FilePath easy_unlock_path; 234 base::FilePath easy_unlock_path;
213 #if defined(OS_CHROMEOS) 235 #if defined(OS_CHROMEOS)
214 easy_unlock_path = base::FilePath("/usr/share/chromeos-assets/easy_unlock"); 236 easy_unlock_path = base::FilePath("/usr/share/chromeos-assets/easy_unlock");
215 #endif // defined(OS_CHROMEOS) 237 #endif // defined(OS_CHROMEOS)
216 238
217 #ifndef NDEBUG 239 #ifndef NDEBUG
218 // Only allow app path override switch for debug build. 240 // Only allow app path override switch for debug build.
219 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 241 const CommandLine* command_line = CommandLine::ForCurrentProcess();
220 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { 242 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) {
221 easy_unlock_path = 243 easy_unlock_path =
222 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); 244 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath);
223 } 245 }
224 #endif // !defined(NDEBUG) 246 #endif // !defined(NDEBUG)
225 247
226 if (!easy_unlock_path.empty()) { 248 if (!easy_unlock_path.empty()) {
227 extensions::ComponentLoader* loader = GetComponentLoader(profile_); 249 extensions::ComponentLoader* loader = GetComponentLoader(profile_);
228 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) 250 if (!loader->Exists(extension_misc::kEasyUnlockAppId))
229 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); 251 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path);
230 252
231 ExtensionService* extension_service = 253 ExtensionService* extension_service =
232 extensions::ExtensionSystem::Get(profile_)->extension_service(); 254 extensions::ExtensionSystem::Get(profile_)->extension_service();
233 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); 255 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId);
256
257 NotifyUserUpdated();
234 } 258 }
235 #endif // defined(GOOGLE_CHROME_BUILD) 259 #endif // defined(GOOGLE_CHROME_BUILD)
236 } 260 }
237 261
238 void EasyUnlockService::DisableAppIfLoaded() { 262 void EasyUnlockService::DisableAppIfLoaded() {
239 // Make sure lock screen state set by the extension gets reset. 263 // Make sure lock screen state set by the extension gets reset.
240 screenlock_state_handler_.reset(); 264 ResetScreenlockStateHandler();
241 265
242 extensions::ComponentLoader* loader = GetComponentLoader(profile_); 266 extensions::ComponentLoader* loader = GetComponentLoader(profile_);
243 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) 267 if (!loader->Exists(extension_misc::kEasyUnlockAppId))
244 return; 268 return;
245 269
246 ExtensionService* extension_service = 270 ExtensionService* extension_service =
247 extensions::ExtensionSystem::Get(profile_)->extension_service(); 271 extensions::ExtensionSystem::Get(profile_)->extension_service();
248 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, 272 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId,
249 extensions::Extension::DISABLE_RELOAD); 273 extensions::Extension::DISABLE_RELOAD);
250 } 274 }
251 275
276 void EasyUnlockService::UnloadApp() {
277 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId);
278 }
279
252 void EasyUnlockService::ReloadApp() { 280 void EasyUnlockService::ReloadApp() {
253 // Make sure lock screen state set by the extension gets reset. 281 // Make sure lock screen state set by the extension gets reset.
254 screenlock_state_handler_.reset(); 282 ResetScreenlockStateHandler();
255 283
256 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { 284 if (!GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId))
257 extensions::ExtensionSystem* extension_system = 285 return;
258 extensions::ExtensionSystem::Get(profile_); 286 extensions::ExtensionSystem* extension_system =
259 extension_system->extension_service()->ReloadExtension( 287 extensions::ExtensionSystem::Get(profile_);
260 extension_misc::kEasyUnlockAppId); 288 extension_system->extension_service()->ReloadExtension(
261 } 289 extension_misc::kEasyUnlockAppId);
290 NotifyUserUpdated();
262 } 291 }
263 292
264 void EasyUnlockService::UpdateAppState() { 293 void EasyUnlockService::UpdateAppState() {
265 if (IsAllowed()) { 294 if (IsAllowed()) {
266 LoadApp(); 295 LoadApp();
267 296
268 #if defined(OS_CHROMEOS) 297 #if defined(OS_CHROMEOS)
269 if (!power_monitor_) 298 if (!power_monitor_)
270 power_monitor_.reset(new PowerMonitor(this)); 299 power_monitor_.reset(new PowerMonitor(this));
271 #endif 300 #endif
272 } else { 301 } else {
273 DisableAppIfLoaded(); 302 DisableAppIfLoaded();
274 #if defined(OS_CHROMEOS) 303 #if defined(OS_CHROMEOS)
275 power_monitor_.reset(); 304 power_monitor_.reset();
276 #endif 305 #endif
277 } 306 }
278 } 307 }
279 308
309 void EasyUnlockService::NotifyUserUpdated() {
310 std::string user_id = GetUserEmail();
311 if (user_id.empty())
312 return;
313
314 // Notify the easy unlock app that the user info changed.
315 extensions::api::easy_unlock_private::UserInfo info;
316 info.user_id = user_id;
317 info.logged_in = GetType() == TYPE_REGULAR;
318 info.data_ready = GetRemoteDevices() != NULL;
319
320 scoped_ptr<base::ListValue> args(new base::ListValue());
321 args->Append(info.ToValue().release());
322
323 scoped_ptr<extensions::Event> event(new extensions::Event(
324 extensions::api::easy_unlock_private::OnUserInfoUpdated::kEventName,
325 args.Pass()));
326
327 extensions::EventRouter::Get(profile_)->DispatchEventToExtension(
328 extension_misc::kEasyUnlockAppId, event.Pass());
329 }
330
280 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { 331 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() {
281 FOR_EACH_OBSERVER( 332 FOR_EACH_OBSERVER(
282 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); 333 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged());
283 } 334 }
284 335
336 void EasyUnlockService::ResetScreenlockStateHandler() {
337 screenlock_state_handler_.reset();
338 }
339
285 void EasyUnlockService::Initialize() { 340 void EasyUnlockService::Initialize() {
286 InitializeInternal(); 341 InitializeInternal();
287 342
288 #if defined(OS_CHROMEOS) 343 #if defined(OS_CHROMEOS)
289 // Only start Bluetooth detection for ChromeOS since the feature is 344 // Only start Bluetooth detection for ChromeOS since the feature is
290 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms 345 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms
291 // previously introduced a performance regression: http://crbug.com/404482 346 // previously introduced a performance regression: http://crbug.com/404482
292 // Make sure not to reintroduce a performance regression if re-enabling on 347 // Make sure not to reintroduce a performance regression if re-enabling on
293 // additional platforms. 348 // additional platforms.
294 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. 349 // TODO(xiyuan): Revisit when non-chromeos platforms are supported.
295 bluetooth_detector_->Initialize(); 350 bluetooth_detector_->Initialize();
296 #endif // defined(OS_CHROMEOS) 351 #endif // defined(OS_CHROMEOS)
297 } 352 }
298 353
299 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { 354 void EasyUnlockService::OnBluetoothAdapterPresentChanged() {
300 UpdateAppState(); 355 UpdateAppState();
301 } 356 }
302 357
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service.h ('k') | chrome/browser/signin/easy_unlock_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698