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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 122 } |
112 | 123 |
113 bool IsPresent() const { return adapter_.get() && adapter_->IsPresent(); } | 124 bool IsPresent() const { return adapter_.get() && adapter_->IsPresent(); } |
114 | 125 |
115 // device::BluetoothAdapter::Observer: | 126 // device::BluetoothAdapter::Observer: |
116 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 127 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
117 bool present) override { | 128 bool present) override { |
118 service_->OnBluetoothAdapterPresentChanged(); | 129 service_->OnBluetoothAdapterPresentChanged(); |
119 } | 130 } |
120 | 131 |
| 132 device::BluetoothAdapter* getAdapter() { |
| 133 return adapter_.get(); |
| 134 } |
| 135 |
121 private: | 136 private: |
122 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { | 137 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { |
123 adapter_ = adapter; | 138 adapter_ = adapter; |
124 adapter_->AddObserver(this); | 139 adapter_->AddObserver(this); |
125 service_->OnBluetoothAdapterPresentChanged(); | 140 service_->OnBluetoothAdapterPresentChanged(); |
126 | 141 |
127 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability | 142 // 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 | 143 // 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. | 144 // toes in the future then we need to revisit this guard. |
130 if (adapter_->IsDiscoverable()) | 145 if (adapter_->IsDiscoverable()) |
131 TurnOffBluetoothDiscoverability(); | 146 TurnOffBluetoothDiscoverability(); |
| 147 |
| 148 #if !defined(OS_CHROMEOS) |
| 149 // Bluetooth detection causes serious performance degradations on Mac |
| 150 // and possibly other platforms as well: http://crbug.com/467316 |
| 151 // Since this feature is currently only offered for ChromeOS we just |
| 152 // turn it off on other platforms once the inforamtion about the |
| 153 // adapter has been gathered and reported. |
| 154 // TODO(bcwhite,xiyuan): Revisit when non-chromeos platforms are supported. |
| 155 adapter_->RemoveObserver(this); |
| 156 adapter_ = NULL; |
| 157 #endif // !defined(OS_CHROMEOS) |
132 } | 158 } |
133 | 159 |
134 // apps::AppLifetimeMonitor::Observer: | 160 // apps::AppLifetimeMonitor::Observer: |
135 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { | 161 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { |
136 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. | 162 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. |
137 if (app_id == extension_misc::kEasyUnlockAppId) | 163 if (app_id == extension_misc::kEasyUnlockAppId) |
138 TurnOffBluetoothDiscoverability(); | 164 TurnOffBluetoothDiscoverability(); |
139 } | 165 } |
140 | 166 |
141 void OnAppStop(Profile* profile, const std::string& app_id) override { | 167 void OnAppStop(Profile* profile, const std::string& app_id) override { |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 if (screenlock_state_handler_) | 683 if (screenlock_state_handler_) |
658 screenlock_state_handler_->SetHardlockState(state); | 684 screenlock_state_handler_->SetHardlockState(state); |
659 if (state != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) | 685 if (state != EasyUnlockScreenlockStateHandler::NO_HARDLOCK) |
660 auth_attempt_.reset(); | 686 auth_attempt_.reset(); |
661 } | 687 } |
662 | 688 |
663 void EasyUnlockService::InitializeOnAppManagerReady() { | 689 void EasyUnlockService::InitializeOnAppManagerReady() { |
664 CHECK(app_manager_.get()); | 690 CHECK(app_manager_.get()); |
665 | 691 |
666 InitializeInternal(); | 692 InitializeInternal(); |
667 | |
668 #if defined(OS_CHROMEOS) | |
669 // Only start Bluetooth detection for ChromeOS since the feature is | |
670 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms | |
671 // previously introduced a performance regression: http://crbug.com/404482 | |
672 // Make sure not to reintroduce a performance regression if re-enabling on | |
673 // additional platforms. | |
674 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | |
675 bluetooth_detector_->Initialize(); | 693 bluetooth_detector_->Initialize(); |
676 #endif // defined(OS_CHROMEOS) | |
677 } | 694 } |
678 | 695 |
679 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { | 696 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
680 UpdateAppState(); | 697 UpdateAppState(); |
| 698 |
| 699 // Whether we've already passed Bluetooth availability information to UMA. |
| 700 // This is static because there may be multiple instances and we want to |
| 701 // report this system-level stat only once per run of Chrome. |
| 702 static bool bluetooth_adapter_has_been_reported = false; |
| 703 |
| 704 if (!bluetooth_adapter_has_been_reported) { |
| 705 bluetooth_adapter_has_been_reported = true; |
| 706 int bttype = BT_NO_ADAPTER; |
| 707 if (bluetooth_detector_->IsPresent()) { |
| 708 bttype = BT_LOW_ENERGY_CAPABLE; |
| 709 #if defined(OS_WIN) |
| 710 if (base::win::GetVersion() < base::win::VERSION_WIN8) { |
| 711 bttype = BT_NORMAL; |
| 712 } |
| 713 #endif |
| 714 } |
| 715 UMA_HISTOGRAM_ENUMERATION( |
| 716 "EasyUnlock.BluetoothAvailability", bttype, BT_MAX_TYPE); |
| 717 } |
681 } | 718 } |
682 | 719 |
683 void EasyUnlockService::SetHardlockStateForUser( | 720 void EasyUnlockService::SetHardlockStateForUser( |
684 const std::string& user_id, | 721 const std::string& user_id, |
685 EasyUnlockScreenlockStateHandler::HardlockState state) { | 722 EasyUnlockScreenlockStateHandler::HardlockState state) { |
686 DCHECK(!user_id.empty()); | 723 DCHECK(!user_id.empty()); |
687 | 724 |
688 PrefService* local_state = GetLocalState(); | 725 PrefService* local_state = GetLocalState(); |
689 if (!local_state) | 726 if (!local_state) |
690 return; | 727 return; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 839 |
803 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 840 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
804 // failed. | 841 // failed. |
805 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 842 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
806 ->PrepareTpmKey(true /* check_private_key */, | 843 ->PrepareTpmKey(true /* check_private_key */, |
807 base::Closure()); | 844 base::Closure()); |
808 #endif // defined(OS_CHROMEOS) | 845 #endif // defined(OS_CHROMEOS) |
809 | 846 |
810 tpm_key_checked_ = true; | 847 tpm_key_checked_ = true; |
811 } | 848 } |
OLD | NEW |