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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "apps/app_lifetime_monitor.h" | 9 #include "apps/app_lifetime_monitor.h" |
10 #include "apps/app_lifetime_monitor_factory.h" | 10 #include "apps/app_lifetime_monitor_factory.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" | 57 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_
factory.h" |
58 #include "chrome/browser/chromeos/login/easy_unlock/secure_message_delegate_chro
meos.h" | 58 #include "chrome/browser/chromeos/login/easy_unlock/secure_message_delegate_chro
meos.h" |
59 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 59 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
60 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 60 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
61 #include "chromeos/dbus/dbus_thread_manager.h" | 61 #include "chromeos/dbus/dbus_thread_manager.h" |
62 #include "chromeos/dbus/power_manager_client.h" | 62 #include "chromeos/dbus/power_manager_client.h" |
63 #include "components/session_manager/core/session_manager.h" | 63 #include "components/session_manager/core/session_manager.h" |
64 #include "components/signin/core/account_id/account_id.h" | 64 #include "components/signin/core/account_id/account_id.h" |
65 #endif | 65 #endif |
66 | 66 |
67 #if defined(OS_WIN) | |
68 #include "base/win/windows_version.h" | |
69 #endif | |
70 | |
71 using proximity_auth::ScreenlockState; | 67 using proximity_auth::ScreenlockState; |
72 | 68 |
73 namespace { | 69 namespace { |
74 | 70 |
75 enum BluetoothType { | |
76 BT_NO_ADAPTER, | |
77 BT_NORMAL, | |
78 BT_LOW_ENERGY_CAPABLE, | |
79 BT_MAX_TYPE | |
80 }; | |
81 | |
82 PrefService* GetLocalState() { | 71 PrefService* GetLocalState() { |
83 return g_browser_process ? g_browser_process->local_state() : NULL; | 72 return g_browser_process ? g_browser_process->local_state() : NULL; |
84 } | 73 } |
85 | 74 |
86 } // namespace | 75 } // namespace |
87 | 76 |
88 EasyUnlockService::UserSettings::UserSettings() | 77 EasyUnlockService::UserSettings::UserSettings() |
89 : require_close_proximity(false) { | 78 : require_close_proximity(false) { |
90 } | 79 } |
91 | 80 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 127 } |
139 | 128 |
140 bool IsPresent() const { return adapter_.get() && adapter_->IsPresent(); } | 129 bool IsPresent() const { return adapter_.get() && adapter_->IsPresent(); } |
141 | 130 |
142 // device::BluetoothAdapter::Observer: | 131 // device::BluetoothAdapter::Observer: |
143 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 132 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
144 bool present) override { | 133 bool present) override { |
145 service_->OnBluetoothAdapterPresentChanged(); | 134 service_->OnBluetoothAdapterPresentChanged(); |
146 } | 135 } |
147 | 136 |
148 device::BluetoothAdapter* getAdapter() { | |
149 return adapter_.get(); | |
150 } | |
151 | |
152 private: | 137 private: |
153 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { | 138 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { |
154 adapter_ = adapter; | 139 adapter_ = adapter; |
155 adapter_->AddObserver(this); | 140 adapter_->AddObserver(this); |
156 service_->OnBluetoothAdapterPresentChanged(); | 141 service_->OnBluetoothAdapterPresentChanged(); |
157 | 142 |
158 #if !defined(OS_CHROMEOS) | |
159 // Bluetooth detection causes serious performance degradations on Mac | |
160 // and possibly other platforms as well: http://crbug.com/467316 | |
161 // Since this feature is currently only offered for ChromeOS we just | |
162 // turn it off on other platforms once the inforamtion about the | |
163 // adapter has been gathered and reported. | |
164 // TODO(bcwhite,xiyuan): Revisit when non-chromeos platforms are supported. | |
165 adapter_->RemoveObserver(this); | |
166 adapter_ = NULL; | |
167 #else | |
168 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability | 143 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability |
169 // to be turned on except through the Easy Unlock setup. If we step on any | 144 // to be turned on except through the Easy Unlock setup. If we step on any |
170 // toes in the future then we need to revisit this guard. | 145 // toes in the future then we need to revisit this guard. |
171 if (adapter_->IsDiscoverable()) | 146 if (adapter_->IsDiscoverable()) |
172 TurnOffBluetoothDiscoverability(); | 147 TurnOffBluetoothDiscoverability(); |
173 #endif // !defined(OS_CHROMEOS) | |
174 } | 148 } |
175 | 149 |
176 // apps::AppLifetimeMonitor::Observer: | 150 // apps::AppLifetimeMonitor::Observer: |
177 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { | 151 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { |
178 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. | 152 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. |
179 if (app_id == extension_misc::kEasyUnlockAppId) | 153 if (app_id == extension_misc::kEasyUnlockAppId) |
180 TurnOffBluetoothDiscoverability(); | 154 TurnOffBluetoothDiscoverability(); |
181 } | 155 } |
182 | 156 |
183 void OnAppStop(Profile* profile, const std::string& app_id) override { | 157 void OnAppStop(Profile* profile, const std::string& app_id) override { |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 if (screenlock_state_handler_) | 711 if (screenlock_state_handler_) |
738 screenlock_state_handler_->SetHardlockState(state); | 712 screenlock_state_handler_->SetHardlockState(state); |
739 if (state != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) | 713 if (state != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) |
740 auth_attempt_.reset(); | 714 auth_attempt_.reset(); |
741 } | 715 } |
742 | 716 |
743 void EasyUnlockService::InitializeOnAppManagerReady() { | 717 void EasyUnlockService::InitializeOnAppManagerReady() { |
744 CHECK(app_manager_.get()); | 718 CHECK(app_manager_.get()); |
745 | 719 |
746 InitializeInternal(); | 720 InitializeInternal(); |
| 721 |
| 722 #if defined(OS_CHROMEOS) |
| 723 // Only start Bluetooth detection for ChromeOS since the feature is |
| 724 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms |
| 725 // previously introduced a performance regression: http://crbug.com/404482 |
| 726 // Make sure not to reintroduce a performance regression if re-enabling on |
| 727 // additional platforms. |
| 728 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
747 bluetooth_detector_->Initialize(); | 729 bluetooth_detector_->Initialize(); |
| 730 #endif // defined(OS_CHROMEOS) |
748 } | 731 } |
749 | 732 |
750 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { | 733 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
751 UpdateAppState(); | 734 UpdateAppState(); |
752 | |
753 // Whether we've already passed Bluetooth availability information to UMA. | |
754 // This is static because there may be multiple instances and we want to | |
755 // report this system-level stat only once per run of Chrome. | |
756 static bool bluetooth_adapter_has_been_reported = false; | |
757 | |
758 if (!bluetooth_adapter_has_been_reported) { | |
759 bluetooth_adapter_has_been_reported = true; | |
760 int bttype = BT_NO_ADAPTER; | |
761 if (bluetooth_detector_->IsPresent()) { | |
762 bttype = BT_LOW_ENERGY_CAPABLE; | |
763 #if defined(OS_WIN) | |
764 if (base::win::GetVersion() < base::win::VERSION_WIN8) { | |
765 bttype = BT_NORMAL; | |
766 } | |
767 #endif | |
768 } | |
769 UMA_HISTOGRAM_ENUMERATION( | |
770 "EasyUnlock.BluetoothAvailability", bttype, BT_MAX_TYPE); | |
771 } | |
772 } | 735 } |
773 | 736 |
774 void EasyUnlockService::SetHardlockStateForUser( | 737 void EasyUnlockService::SetHardlockStateForUser( |
775 const AccountId& account_id, | 738 const AccountId& account_id, |
776 EasyUnlockScreenlockStateHandler::HardlockState state) { | 739 EasyUnlockScreenlockStateHandler::HardlockState state) { |
777 DCHECK(account_id.is_valid()); | 740 DCHECK(account_id.is_valid()); |
778 | 741 |
779 PrefService* local_state = GetLocalState(); | 742 PrefService* local_state = GetLocalState(); |
780 if (!local_state) | 743 if (!local_state) |
781 return; | 744 return; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 | 882 |
920 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 883 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
921 // failed. | 884 // failed. |
922 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 885 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
923 ->PrepareTpmKey(true /* check_private_key */, | 886 ->PrepareTpmKey(true /* check_private_key */, |
924 base::Closure()); | 887 base::Closure()); |
925 #endif // defined(OS_CHROMEOS) | 888 #endif // defined(OS_CHROMEOS) |
926 | 889 |
927 tpm_key_checked_ = true; | 890 tpm_key_checked_ = true; |
928 } | 891 } |
OLD | NEW |