Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3754)

Unified Diff: chrome/browser/signin/easy_unlock_service.cc

Issue 472733002: No Easy unlock if bluetooth is not available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix uninit var Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/signin/easy_unlock_service.cc
diff --git a/chrome/browser/signin/easy_unlock_service.cc b/chrome/browser/signin/easy_unlock_service.cc
index 1afcbc9e128e45c78b357f083d75025b091eac08..a6a77c0b9dfdaaf5efa6c18dc4c6e0c05121c85d 100644
--- a/chrome/browser/signin/easy_unlock_service.cc
+++ b/chrome/browser/signin/easy_unlock_service.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "base/values.h"
@@ -18,6 +19,8 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
+#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/one_shot_event.h"
#include "grit/browser_resources.h"
@@ -44,8 +47,57 @@ EasyUnlockService* EasyUnlockService::Get(Profile* profile) {
return EasyUnlockServiceFactory::GetForProfile(profile);
}
+class EasyUnlockService::BluetoothDetector
+ : public device::BluetoothAdapter::Observer {
+ public:
+ explicit BluetoothDetector(EasyUnlockService* service)
+ : service_(service), weak_ptr_factory_(this) {}
Ilya Sherman 2014/08/14 07:29:41 nit: One per line, please.
xiyuan 2014/08/14 20:27:43 Done. I personally like one-per-line style but "gi
+
+ virtual ~BluetoothDetector() {
+ if (adapter_)
+ adapter_->RemoveObserver(this);
+ }
+
+ void Initialize() {
+ if (!device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable())
+ return;
+
+ device::BluetoothAdapterFactory::GetAdapter(
+ base::Bind(&BluetoothDetector::OnAdapterInitialized,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+
+ bool IsPresent() const {
+ return adapter_ && adapter_->IsPresent();
+ }
+
+ // device::BluetoothAdapter::Observer
+ virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter,
+ bool present) OVERRIDE {
+ ReportAdapterPresent();
Ilya Sherman 2014/08/14 07:29:41 If the adapter was removed from the system, should
xiyuan 2014/08/14 20:27:43 Nope. The BluetoothAdapter instance never changes
armansito 2014/08/14 20:55:05 Yep, exactly. We have a singleton BluetoothAdapter
+ }
+
+ private:
+ void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) {
+ adapter_ = adapter;
+ adapter_->AddObserver(this);
+ ReportAdapterPresent();
+ }
+
+ void ReportAdapterPresent() {
+ service_->OnBluetoothAdapterPresentChanged();
+ }
+
+ EasyUnlockService* service_;
Ilya Sherman 2014/08/14 07:29:41 nit: Please document lifetime expectations.
xiyuan 2014/08/14 20:27:43 Done.
+ scoped_refptr<device::BluetoothAdapter> adapter_;
+ base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_;
+ DISALLOW_COPY_AND_ASSIGN(BluetoothDetector);
+};
+
EasyUnlockService::EasyUnlockService(Profile* profile)
- : profile_(profile), weak_ptr_factory_(this) {
+ : profile_(profile),
+ bluetooth_detector_(new BluetoothDetector(this)),
+ weak_ptr_factory_(this) {
extensions::ExtensionSystem::Get(profile_)->ready().Post(
FROM_HERE,
base::Bind(&EasyUnlockService::Initialize,
@@ -98,7 +150,13 @@ bool EasyUnlockService::IsAllowed() {
return false;
// It is only disabled when the trial exists and is in "Disable" group.
Ilya Sherman 2014/08/14 07:29:41 nit: Please update this comment.
xiyuan 2014/08/14 20:27:43 Removed "only".
- return base::FieldTrialList::FindFullName("EasyUnlock") != "Disable";
+ if (base::FieldTrialList::FindFullName("EasyUnlock") == "Disable")
+ return false;
+
+ if (!bluetooth_detector_->IsPresent())
+ return false;
+
+ return true;
Ilya Sherman 2014/08/14 07:29:41 Hmm, do we not have any command-line switches asso
xiyuan 2014/08/14 20:27:43 We used to have one but it is removed now when tur
#else
// TODO(xiyuan): Revisit when non-chromeos platforms are supported.
return false;
@@ -111,6 +169,8 @@ void EasyUnlockService::Initialize() {
prefs::kEasyUnlockAllowed,
base::Bind(&EasyUnlockService::OnPrefsChanged, base::Unretained(this)));
OnPrefsChanged();
+
+ bluetooth_detector_->Initialize();
}
void EasyUnlockService::LoadApp() {
@@ -142,9 +202,18 @@ void EasyUnlockService::UnloadApp() {
GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId);
}
-void EasyUnlockService::OnPrefsChanged() {
+void EasyUnlockService::CheckIsAllowed() {
Ilya Sherman 2014/08/14 07:29:41 nit: Perhaps name this something more like "Update
xiyuan 2014/08/14 20:27:43 Done.
if (IsAllowed())
LoadApp();
else
UnloadApp();
}
+
+void EasyUnlockService::OnPrefsChanged() {
+ CheckIsAllowed();
+}
+
+void EasyUnlockService::OnBluetoothAdapterPresentChanged() {
+ CheckIsAllowed();
+}
+

Powered by Google App Engine
This is Rietveld 408576698