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/easy_unlock_service_regular.h" | 5 #include "chrome/browser/signin/easy_unlock_service_regular.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/field_trial.h" | |
10 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "base/values.h" | 11 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" | 14 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" |
16 #include "chrome/browser/signin/screenlock_bridge.h" | 15 #include "chrome/browser/signin/screenlock_bridge.h" |
17 #include "chrome/browser/ui/extensions/app_launch_params.h" | 16 #include "chrome/browser/ui/extensions/app_launch_params.h" |
18 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
21 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
22 #include "components/proximity_auth/switches.h" | |
23 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
24 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
25 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
26 | 24 |
27 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
28 #include "apps/app_lifetime_monitor_factory.h" | 26 #include "apps/app_lifetime_monitor_factory.h" |
29 #include "base/thread_task_runner_handle.h" | 27 #include "base/thread_task_runner_handle.h" |
30 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 28 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
31 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.h" | 29 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.h" |
32 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 30 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
33 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
34 #include "components/user_manager/user_manager.h" | 32 #include "components/user_manager/user_manager.h" |
35 #endif | 33 #endif |
36 | 34 |
37 namespace { | 35 namespace { |
38 | 36 |
39 // Key name of the local device permit record dictonary in kEasyUnlockPairing. | 37 // Key name of the local device permit record dictonary in kEasyUnlockPairing. |
40 const char kKeyPermitAccess[] = "permitAccess"; | 38 const char kKeyPermitAccess[] = "permitAccess"; |
41 | 39 |
42 // Key name of the remote device list in kEasyUnlockPairing. | 40 // Key name of the remote device list in kEasyUnlockPairing. |
43 const char kKeyDevices[] = "devices"; | 41 const char kKeyDevices[] = "devices"; |
44 | 42 |
45 // Key name of the phone public key in a device dictionary. | 43 // Key name of the phone public key in a device dictionary. |
46 const char kKeyPhoneId[] = "permitRecord.id"; | 44 const char kKeyPhoneId[] = "permitRecord.id"; |
47 | 45 |
48 #if defined(OS_CHROMEOS) | |
49 // Returns true iff the proximity authentication feature is enabled. | |
50 bool IsEnabled() { | |
51 // Note: It's important to query the field trial state first, to ensure that | |
52 // UMA reports the correct group. | |
53 const std::string group = base::FieldTrialList::FindFullName("EasyUnlock"); | |
54 | |
55 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
56 proximity_auth::switches::kDisableEasyUnlock)) { | |
57 return false; | |
58 } | |
59 | |
60 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
61 proximity_auth::switches::kEnableEasyUnlock)) { | |
62 return true; | |
63 } | |
64 | |
65 return group == "Enable"; | |
66 } | |
67 #endif // defined(OS_CHROMEOS) | |
68 | |
69 } // namespace | 46 } // namespace |
70 | 47 |
71 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) | 48 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) |
72 : EasyUnlockService(profile), | 49 : EasyUnlockService(profile), |
73 turn_off_flow_status_(EasyUnlockService::IDLE), | 50 turn_off_flow_status_(EasyUnlockService::IDLE), |
74 weak_ptr_factory_(this) { | 51 weak_ptr_factory_(this) { |
75 } | 52 } |
76 | 53 |
77 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { | 54 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { |
78 } | 55 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 #if defined(OS_CHROMEOS) | 274 #if defined(OS_CHROMEOS) |
298 if (!user_manager::UserManager::Get()->IsLoggedInAsUserWithGaiaAccount()) | 275 if (!user_manager::UserManager::Get()->IsLoggedInAsUserWithGaiaAccount()) |
299 return false; | 276 return false; |
300 | 277 |
301 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile())) | 278 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile())) |
302 return false; | 279 return false; |
303 | 280 |
304 if (!profile()->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) | 281 if (!profile()->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) |
305 return false; | 282 return false; |
306 | 283 |
307 // If the preference is managed, respect the existing policy. | |
308 if (!profile()->GetPrefs()->IsManagedPreference(prefs::kEasyUnlockAllowed)) | |
309 return IsEnabled(); | |
310 | |
311 return true; | 284 return true; |
312 #else | 285 #else |
313 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 286 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
314 return false; | 287 return false; |
315 #endif | 288 #endif |
316 } | 289 } |
317 | 290 |
318 void EasyUnlockServiceRegular::OnPrefsChanged() { | 291 void EasyUnlockServiceRegular::OnPrefsChanged() { |
319 UpdateAppState(); | 292 UpdateAppState(); |
320 } | 293 } |
321 | 294 |
322 void EasyUnlockServiceRegular::SetTurnOffFlowStatus(TurnOffFlowStatus status) { | 295 void EasyUnlockServiceRegular::SetTurnOffFlowStatus(TurnOffFlowStatus status) { |
323 turn_off_flow_status_ = status; | 296 turn_off_flow_status_ = status; |
324 NotifyTurnOffOperationStatusChanged(); | 297 NotifyTurnOffOperationStatusChanged(); |
325 } | 298 } |
326 | 299 |
327 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) { | 300 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) { |
328 turn_off_flow_.reset(); | 301 turn_off_flow_.reset(); |
329 | 302 |
330 if (!success) { | 303 if (!success) { |
331 SetTurnOffFlowStatus(FAIL); | 304 SetTurnOffFlowStatus(FAIL); |
332 return; | 305 return; |
333 } | 306 } |
334 | 307 |
335 ClearRemoteDevices(); | 308 ClearRemoteDevices(); |
336 SetTurnOffFlowStatus(IDLE); | 309 SetTurnOffFlowStatus(IDLE); |
337 ReloadApp(); | 310 ReloadApp(); |
338 } | 311 } |
OLD | NEW |