| 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 "apps/app_lifetime_monitor.h" | 7 #include "apps/app_lifetime_monitor.h" |
| 8 #include "apps/app_lifetime_monitor_factory.h" | 8 #include "apps/app_lifetime_monitor_factory.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 37 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 38 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" | 38 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" |
| 39 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" | 39 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" |
| 40 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 40 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 41 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 41 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 42 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
| 43 #include "chromeos/dbus/power_manager_client.h" | 43 #include "chromeos/dbus/power_manager_client.h" |
| 44 #include "components/user_manager/user_manager.h" | 44 #include "components/user_manager/user_manager.h" |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 #if defined(OS_WIN) |
| 48 #include "base/win/windows_version.h" |
| 49 #endif |
| 50 |
| 47 namespace { | 51 namespace { |
| 48 | 52 |
| 53 enum BluetoothType { |
| 54 BT_NO_ADAPTER, |
| 55 BT_NORMAL, |
| 56 BT_LOW_ENERGY_CAPABLE, |
| 57 BT_MAX_TYPE |
| 58 }; |
| 59 |
| 49 PrefService* GetLocalState() { | 60 PrefService* GetLocalState() { |
| 50 return g_browser_process ? g_browser_process->local_state() : NULL; | 61 return g_browser_process ? g_browser_process->local_state() : NULL; |
| 51 } | 62 } |
| 52 | 63 |
| 53 } // namespace | 64 } // namespace |
| 54 | 65 |
| 55 EasyUnlockService::UserSettings::UserSettings() | 66 EasyUnlockService::UserSettings::UserSettings() |
| 56 : require_close_proximity(false) { | 67 : require_close_proximity(false) { |
| 57 } | 68 } |
| 58 | 69 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 70 #if defined(OS_CHROMEOS) | 81 #if defined(OS_CHROMEOS) |
| 71 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(&user); | 82 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(&user); |
| 72 if (!profile) | 83 if (!profile) |
| 73 return NULL; | 84 return NULL; |
| 74 return EasyUnlockService::Get(profile); | 85 return EasyUnlockService::Get(profile); |
| 75 #else | 86 #else |
| 76 return NULL; | 87 return NULL; |
| 77 #endif | 88 #endif |
| 78 } | 89 } |
| 79 | 90 |
| 91 bool EasyUnlockService::bluetooth_adapter_has_been_reported; |
| 92 |
| 80 // static | 93 // static |
| 81 bool EasyUnlockService::IsSignInEnabled() { | 94 bool EasyUnlockService::IsSignInEnabled() { |
| 82 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 95 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 83 proximity_auth::switches::kDisableEasyUnlock); | 96 proximity_auth::switches::kDisableEasyUnlock); |
| 84 } | 97 } |
| 85 | 98 |
| 86 class EasyUnlockService::BluetoothDetector | 99 class EasyUnlockService::BluetoothDetector |
| 87 : public device::BluetoothAdapter::Observer, | 100 : public device::BluetoothAdapter::Observer, |
| 88 public apps::AppLifetimeMonitor::Observer { | 101 public apps::AppLifetimeMonitor::Observer { |
| 89 public: | 102 public: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 111 } | 124 } |
| 112 | 125 |
| 113 bool IsPresent() const { return adapter_.get() && adapter_->IsPresent(); } | 126 bool IsPresent() const { return adapter_.get() && adapter_->IsPresent(); } |
| 114 | 127 |
| 115 // device::BluetoothAdapter::Observer: | 128 // device::BluetoothAdapter::Observer: |
| 116 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 129 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
| 117 bool present) override { | 130 bool present) override { |
| 118 service_->OnBluetoothAdapterPresentChanged(); | 131 service_->OnBluetoothAdapterPresentChanged(); |
| 119 } | 132 } |
| 120 | 133 |
| 134 device::BluetoothAdapter* getAdapter() { |
| 135 return adapter_.get(); |
| 136 } |
| 137 |
| 121 private: | 138 private: |
| 122 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { | 139 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { |
| 123 adapter_ = adapter; | 140 adapter_ = adapter; |
| 124 adapter_->AddObserver(this); | 141 adapter_->AddObserver(this); |
| 125 service_->OnBluetoothAdapterPresentChanged(); | 142 service_->OnBluetoothAdapterPresentChanged(); |
| 126 | 143 |
| 127 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability | 144 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability |
| 128 // to be turned on except through the Easy Unlock setup. If we step on any | 145 // to be turned on except through the Easy Unlock setup. If we step on any |
| 129 // toes in the future then we need to revisit this guard. | 146 // toes in the future then we need to revisit this guard. |
| 130 if (adapter_->IsDiscoverable()) | 147 if (adapter_->IsDiscoverable()) |
| 131 TurnOffBluetoothDiscoverability(); | 148 TurnOffBluetoothDiscoverability(); |
| 149 |
| 150 #if !defined(OS_CHROMEOS) |
| 151 // Bluetooth detection causes serious performance degradations on Mac |
| 152 // and possibly other platforms as well: http://crbug.com/467316 |
| 153 // Since this feature is currently only offered for ChromeOS we just |
| 154 // turn it off on other platforms once the inforamtion about the |
| 155 // adapter has been gathered and reported. |
| 156 // TODO(bcwhite,xiyuan): Revisit when non-chromeos platforms are supported. |
| 157 adapter_->RemoveObserver(this); |
| 158 adapter_ = NULL; |
| 159 #endif // !defined(OS_CHROMEOS) |
| 132 } | 160 } |
| 133 | 161 |
| 134 // apps::AppLifetimeMonitor::Observer: | 162 // apps::AppLifetimeMonitor::Observer: |
| 135 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { | 163 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { |
| 136 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. | 164 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. |
| 137 if (app_id == extension_misc::kEasyUnlockAppId) | 165 if (app_id == extension_misc::kEasyUnlockAppId) |
| 138 TurnOffBluetoothDiscoverability(); | 166 TurnOffBluetoothDiscoverability(); |
| 139 } | 167 } |
| 140 | 168 |
| 141 void OnAppStop(Profile* profile, const std::string& app_id) override { | 169 void OnAppStop(Profile* profile, const std::string& app_id) override { |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 if (screenlock_state_handler_) | 682 if (screenlock_state_handler_) |
| 655 screenlock_state_handler_->SetHardlockState(state); | 683 screenlock_state_handler_->SetHardlockState(state); |
| 656 if (state != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) | 684 if (state != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) |
| 657 auth_attempt_.reset(); | 685 auth_attempt_.reset(); |
| 658 } | 686 } |
| 659 | 687 |
| 660 void EasyUnlockService::InitializeOnAppManagerReady() { | 688 void EasyUnlockService::InitializeOnAppManagerReady() { |
| 661 CHECK(app_manager_.get()); | 689 CHECK(app_manager_.get()); |
| 662 | 690 |
| 663 InitializeInternal(); | 691 InitializeInternal(); |
| 664 | |
| 665 #if defined(OS_CHROMEOS) | |
| 666 // Only start Bluetooth detection for ChromeOS since the feature is | |
| 667 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms | |
| 668 // previously introduced a performance regression: http://crbug.com/404482 | |
| 669 // Make sure not to reintroduce a performance regression if re-enabling on | |
| 670 // additional platforms. | |
| 671 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | |
| 672 bluetooth_detector_->Initialize(); | 692 bluetooth_detector_->Initialize(); |
| 673 #endif // defined(OS_CHROMEOS) | |
| 674 } | 693 } |
| 675 | 694 |
| 676 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { | 695 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
| 677 UpdateAppState(); | 696 UpdateAppState(); |
| 697 |
| 698 if (!bluetooth_adapter_has_been_reported) { |
| 699 bluetooth_adapter_has_been_reported = true; |
| 700 int bttype = BT_NO_ADAPTER; |
| 701 if (bluetooth_detector_->IsPresent()) { |
| 702 bttype = BT_LOW_ENERGY_CAPABLE; |
| 703 #if defined(OS_WIN) |
| 704 if (base::win::GetVersion() < base::win::VERSION_WIN8) { |
| 705 bttype = BT_NORMAL; |
| 706 } |
| 707 #endif |
| 708 } |
| 709 UMA_HISTOGRAM_ENUMERATION( |
| 710 "EasyUnlock.BluetoothAvailability", bttype, BT_MAX_TYPE); |
| 711 } |
| 678 } | 712 } |
| 679 | 713 |
| 680 void EasyUnlockService::SetHardlockStateForUser( | 714 void EasyUnlockService::SetHardlockStateForUser( |
| 681 const std::string& user_id, | 715 const std::string& user_id, |
| 682 EasyUnlockScreenlockStateHandler::HardlockState state) { | 716 EasyUnlockScreenlockStateHandler::HardlockState state) { |
| 683 DCHECK(!user_id.empty()); | 717 DCHECK(!user_id.empty()); |
| 684 | 718 |
| 685 PrefService* local_state = GetLocalState(); | 719 PrefService* local_state = GetLocalState(); |
| 686 if (!local_state) | 720 if (!local_state) |
| 687 return; | 721 return; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 833 |
| 800 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 834 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
| 801 // failed. | 835 // failed. |
| 802 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 836 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
| 803 ->PrepareTpmKey(true /* check_private_key */, | 837 ->PrepareTpmKey(true /* check_private_key */, |
| 804 base::Closure()); | 838 base::Closure()); |
| 805 #endif // defined(OS_CHROMEOS) | 839 #endif // defined(OS_CHROMEOS) |
| 806 | 840 |
| 807 tpm_key_checked_ = true; | 841 tpm_key_checked_ = true; |
| 808 } | 842 } |
| OLD | NEW |