Chromium Code Reviews| 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.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" | |
| 11 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| 12 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 13 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
| 14 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/extensions/component_loader.h" | 17 #include "chrome/browser/extensions/component_loader.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 if (!profile) | 73 if (!profile) |
| 75 return NULL; | 74 return NULL; |
| 76 return EasyUnlockService::Get(profile); | 75 return EasyUnlockService::Get(profile); |
| 77 #else | 76 #else |
| 78 return NULL; | 77 return NULL; |
| 79 #endif | 78 #endif |
| 80 } | 79 } |
| 81 | 80 |
| 82 // static | 81 // static |
| 83 bool EasyUnlockService::IsSignInEnabled() { | 82 bool EasyUnlockService::IsSignInEnabled() { |
| 84 // Note: It's important to query the field trial state first, to ensure that | 83 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 85 // UMA reports the correct group. | 84 proximity_auth::switches::kDisableEasySignin); |
|
Ilya Sherman
2014/12/05 23:22:07
I wonder whether it's still worth having separate
xiyuan
2014/12/06 00:36:23
Makes sense.
But found that we had a bug (http://
| |
| 86 const std::string group = base::FieldTrialList::FindFullName("EasySignIn"); | |
| 87 | |
| 88 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 89 proximity_auth::switches::kDisableEasySignin)) { | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 94 proximity_auth::switches::kEnableEasySignin)) { | |
| 95 return true; | |
| 96 } | |
| 97 | |
| 98 return group == "Enable"; | |
| 99 } | 85 } |
| 100 | 86 |
| 101 class EasyUnlockService::BluetoothDetector | 87 class EasyUnlockService::BluetoothDetector |
| 102 : public device::BluetoothAdapter::Observer { | 88 : public device::BluetoothAdapter::Observer { |
| 103 public: | 89 public: |
| 104 explicit BluetoothDetector(EasyUnlockService* service) | 90 explicit BluetoothDetector(EasyUnlockService* service) |
| 105 : service_(service), | 91 : service_(service), |
| 106 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
| 107 } | 93 } |
| 108 | 94 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 return; | 227 return; |
| 242 | 228 |
| 243 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); | 229 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); |
| 244 update->RemoveWithoutPathExpansion(user_id, NULL); | 230 update->RemoveWithoutPathExpansion(user_id, NULL); |
| 245 } | 231 } |
| 246 | 232 |
| 247 bool EasyUnlockService::IsAllowed() { | 233 bool EasyUnlockService::IsAllowed() { |
| 248 if (shut_down_) | 234 if (shut_down_) |
| 249 return false; | 235 return false; |
| 250 | 236 |
| 237 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 238 proximity_auth::switches::kDisableEasyUnlock)) { | |
| 239 return false; | |
| 240 } | |
| 241 | |
| 251 if (!IsAllowedInternal()) | 242 if (!IsAllowedInternal()) |
| 252 return false; | 243 return false; |
| 253 | 244 |
| 254 #if defined(OS_CHROMEOS) | 245 #if defined(OS_CHROMEOS) |
| 255 if (!bluetooth_detector_->IsPresent()) | 246 if (!bluetooth_detector_->IsPresent()) |
| 256 return false; | 247 return false; |
| 257 | 248 |
| 258 return true; | 249 return true; |
| 259 #else | 250 #else |
| 260 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 251 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 } | 653 } |
| 663 #endif | 654 #endif |
| 664 | 655 |
| 665 void EasyUnlockService::PrepareForSuspend() { | 656 void EasyUnlockService::PrepareForSuspend() { |
| 666 DisableAppIfLoaded(); | 657 DisableAppIfLoaded(); |
| 667 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { | 658 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { |
| 668 UpdateScreenlockState( | 659 UpdateScreenlockState( |
| 669 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 660 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 670 } | 661 } |
| 671 } | 662 } |
| OLD | NEW |