Commit a052727f authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Make Bluetooth feature pod button togglable

According to UX spec, if a feature pod button is togglable and has a
detailed view, the icon click should toggle the feature and the label
click should show the detailed view.

This CL changes the behavior of Bluetooth feature pod button to follow
this rule.

UX spec: http://shortn/_U7QSE9nhSk

TEST=manual
BUG=821671

Change-Id: Ia4158975c6a0d7c409c1bacd58786223eea4567e
Reviewed-on: https://chromium-review.googlesource.com/1013130Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551380}
parent 5593f24a
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/bluetooth/bluetooth_power_controller.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h" #include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/unified/feature_pod_button.h" #include "ash/system/unified/feature_pod_button.h"
...@@ -35,6 +34,12 @@ FeaturePodButton* BluetoothFeaturePodController::CreateButton() { ...@@ -35,6 +34,12 @@ FeaturePodButton* BluetoothFeaturePodController::CreateButton() {
} }
void BluetoothFeaturePodController::OnIconPressed() { void BluetoothFeaturePodController::OnIconPressed() {
Shell::Get()->tray_bluetooth_helper()->SetBluetoothEnabled(
!button_->IsToggled());
}
void BluetoothFeaturePodController::OnLabelPressed() {
Shell::Get()->tray_bluetooth_helper()->SetBluetoothEnabled(true);
tray_controller_->ShowBluetoothDetailedView(); tray_controller_->ShowBluetoothDetailedView();
} }
......
...@@ -24,6 +24,7 @@ class BluetoothFeaturePodController : public FeaturePodControllerBase, ...@@ -24,6 +24,7 @@ class BluetoothFeaturePodController : public FeaturePodControllerBase,
// FeaturePodControllerBase: // FeaturePodControllerBase:
FeaturePodButton* CreateButton() override; FeaturePodButton* CreateButton() override;
void OnIconPressed() override; void OnIconPressed() override;
void OnLabelPressed() override;
private: private:
void UpdateButton(); void UpdateButton();
......
...@@ -37,17 +37,13 @@ BluetoothPowerController::~BluetoothPowerController() { ...@@ -37,17 +37,13 @@ BluetoothPowerController::~BluetoothPowerController() {
Shell::Get()->session_controller()->RemoveObserver(this); Shell::Get()->session_controller()->RemoveObserver(this);
} }
void BluetoothPowerController::ToggleBluetoothEnabled() { void BluetoothPowerController::SetBluetoothEnabled(bool enabled) {
if (active_user_pref_service_) { if (active_user_pref_service_) {
active_user_pref_service_->SetBoolean( active_user_pref_service_->SetBoolean(prefs::kUserBluetoothAdapterEnabled,
prefs::kUserBluetoothAdapterEnabled, enabled);
!active_user_pref_service_->GetBoolean(
prefs::kUserBluetoothAdapterEnabled));
} else if (local_state_pref_service_) { } else if (local_state_pref_service_) {
local_state_pref_service_->SetBoolean( local_state_pref_service_->SetBoolean(prefs::kSystemBluetoothAdapterEnabled,
prefs::kSystemBluetoothAdapterEnabled, enabled);
!local_state_pref_service_->GetBoolean(
prefs::kSystemBluetoothAdapterEnabled));
} else { } else {
DLOG(ERROR) DLOG(ERROR)
<< "active user and local state pref service cannot both be null"; << "active user and local state pref service cannot both be null";
......
...@@ -35,8 +35,8 @@ class ASH_EXPORT BluetoothPowerController ...@@ -35,8 +35,8 @@ class ASH_EXPORT BluetoothPowerController
BluetoothPowerController(); BluetoothPowerController();
~BluetoothPowerController() override; ~BluetoothPowerController() override;
// Toggles the bluetooth power setting on or off. // Changes the bluetooth power setting to |enabled|.
void ToggleBluetoothEnabled(); void SetBluetoothEnabled(bool enabled);
static void RegisterLocalStatePrefs(PrefRegistrySimple* registry); static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
static void RegisterProfilePrefs(PrefRegistrySimple* registry); static void RegisterProfilePrefs(PrefRegistrySimple* registry);
......
...@@ -116,10 +116,10 @@ TEST_F(BluetoothPowerControllerTest, ToggleBluetoothEnabled) { ...@@ -116,10 +116,10 @@ TEST_F(BluetoothPowerControllerTest, ToggleBluetoothEnabled) {
// local state prefs. // local state prefs.
EXPECT_FALSE( EXPECT_FALSE(
local_state_prefs_.GetBoolean(prefs::kSystemBluetoothAdapterEnabled)); local_state_prefs_.GetBoolean(prefs::kSystemBluetoothAdapterEnabled));
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(true);
EXPECT_TRUE( EXPECT_TRUE(
local_state_prefs_.GetBoolean(prefs::kSystemBluetoothAdapterEnabled)); local_state_prefs_.GetBoolean(prefs::kSystemBluetoothAdapterEnabled));
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(false);
EXPECT_FALSE( EXPECT_FALSE(
local_state_prefs_.GetBoolean(prefs::kSystemBluetoothAdapterEnabled)); local_state_prefs_.GetBoolean(prefs::kSystemBluetoothAdapterEnabled));
...@@ -128,10 +128,10 @@ TEST_F(BluetoothPowerControllerTest, ToggleBluetoothEnabled) { ...@@ -128,10 +128,10 @@ TEST_F(BluetoothPowerControllerTest, ToggleBluetoothEnabled) {
AddUserSessionAndStartWatchingPrefsChanges(kUser1Email); AddUserSessionAndStartWatchingPrefsChanges(kUser1Email);
EXPECT_FALSE( EXPECT_FALSE(
active_user_prefs_.GetBoolean(prefs::kUserBluetoothAdapterEnabled)); active_user_prefs_.GetBoolean(prefs::kUserBluetoothAdapterEnabled));
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(true);
EXPECT_TRUE( EXPECT_TRUE(
active_user_prefs_.GetBoolean(prefs::kUserBluetoothAdapterEnabled)); active_user_prefs_.GetBoolean(prefs::kUserBluetoothAdapterEnabled));
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(false);
EXPECT_FALSE( EXPECT_FALSE(
active_user_prefs_.GetBoolean(prefs::kUserBluetoothAdapterEnabled)); active_user_prefs_.GetBoolean(prefs::kUserBluetoothAdapterEnabled));
} }
...@@ -357,10 +357,10 @@ TEST_F(BluetoothPowerControllerIntegrationTest, Basics) { ...@@ -357,10 +357,10 @@ TEST_F(BluetoothPowerControllerIntegrationTest, Basics) {
// Verify toggling bluetooth before login. // Verify toggling bluetooth before login.
PrefService* local_state = ash_test_helper()->GetLocalStatePrefService(); PrefService* local_state = ash_test_helper()->GetLocalStatePrefService();
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(true);
EXPECT_TRUE(local_state->GetBoolean(prefs::kSystemBluetoothAdapterEnabled)); EXPECT_TRUE(local_state->GetBoolean(prefs::kSystemBluetoothAdapterEnabled));
EXPECT_TRUE(adapter->IsPowered()); EXPECT_TRUE(adapter->IsPowered());
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(false);
EXPECT_FALSE(local_state->GetBoolean(prefs::kSystemBluetoothAdapterEnabled)); EXPECT_FALSE(local_state->GetBoolean(prefs::kSystemBluetoothAdapterEnabled));
EXPECT_FALSE(adapter->IsPowered()); EXPECT_FALSE(adapter->IsPowered());
...@@ -368,10 +368,10 @@ TEST_F(BluetoothPowerControllerIntegrationTest, Basics) { ...@@ -368,10 +368,10 @@ TEST_F(BluetoothPowerControllerIntegrationTest, Basics) {
SimulateUserLogin(kUser1Email); SimulateUserLogin(kUser1Email);
PrefService* user_prefs = PrefService* user_prefs =
Shell::Get()->session_controller()->GetLastActiveUserPrefService(); Shell::Get()->session_controller()->GetLastActiveUserPrefService();
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(true);
EXPECT_TRUE(user_prefs->GetBoolean(prefs::kUserBluetoothAdapterEnabled)); EXPECT_TRUE(user_prefs->GetBoolean(prefs::kUserBluetoothAdapterEnabled));
EXPECT_TRUE(adapter->IsPowered()); EXPECT_TRUE(adapter->IsPowered());
GetController()->ToggleBluetoothEnabled(); GetController()->SetBluetoothEnabled(false);
EXPECT_FALSE(user_prefs->GetBoolean(prefs::kUserBluetoothAdapterEnabled)); EXPECT_FALSE(user_prefs->GetBoolean(prefs::kUserBluetoothAdapterEnabled));
EXPECT_FALSE(adapter->IsPowered()); EXPECT_FALSE(adapter->IsPowered());
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/bluetooth/bluetooth_power_controller.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h" #include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/tray/hover_highlight_view.h" #include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
...@@ -402,13 +401,8 @@ class BluetoothDetailedView : public TrayDetailsView { ...@@ -402,13 +401,8 @@ class BluetoothDetailedView : public TrayDetailsView {
void HandleButtonPressed(views::Button* sender, void HandleButtonPressed(views::Button* sender,
const ui::Event& event) override { const ui::Event& event) override {
if (sender == toggle_) { if (sender == toggle_) {
TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper(); Shell::Get()->tray_bluetooth_helper()->SetBluetoothEnabled(
BluetoothPowerController* power_controller = toggle_->is_on());
Shell::Get()->bluetooth_power_controller();
Shell::Get()->metrics()->RecordUserMetricsAction(
helper->GetBluetoothEnabled() ? UMA_STATUS_AREA_BLUETOOTH_DISABLED
: UMA_STATUS_AREA_BLUETOOTH_ENABLED);
power_controller->ToggleBluetoothEnabled();
} else if (sender == settings_) { } else if (sender == settings_) {
ShowSettings(); ShowSettings();
} else { } else {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/system/bluetooth/tray_bluetooth_helper.h" #include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/bluetooth/bluetooth_power_controller.h"
#include "ash/system/tray/system_tray_controller.h" #include "ash/system/tray/system_tray_controller.h"
#include "ash/system/tray/system_tray_notifier.h" #include "ash/system/tray/system_tray_notifier.h"
#include "base/bind.h" #include "base/bind.h"
...@@ -139,6 +140,15 @@ bool TrayBluetoothHelper::GetBluetoothEnabled() { ...@@ -139,6 +140,15 @@ bool TrayBluetoothHelper::GetBluetoothEnabled() {
return adapter_ && adapter_->IsPowered(); return adapter_ && adapter_->IsPowered();
} }
void TrayBluetoothHelper::SetBluetoothEnabled(bool enabled) {
if (GetBluetoothEnabled() != enabled) {
Shell::Get()->metrics()->RecordUserMetricsAction(
enabled ? UMA_STATUS_AREA_BLUETOOTH_ENABLED
: UMA_STATUS_AREA_BLUETOOTH_DISABLED);
}
Shell::Get()->bluetooth_power_controller()->SetBluetoothEnabled(enabled);
}
bool TrayBluetoothHelper::HasBluetoothDiscoverySession() { bool TrayBluetoothHelper::HasBluetoothDiscoverySession() {
return discovery_session_ && discovery_session_->IsActive(); return discovery_session_ && discovery_session_->IsActive();
} }
......
...@@ -74,6 +74,11 @@ class ASH_EXPORT TrayBluetoothHelper ...@@ -74,6 +74,11 @@ class ASH_EXPORT TrayBluetoothHelper
// Returns whether bluetooth is enabled. // Returns whether bluetooth is enabled.
bool GetBluetoothEnabled(); bool GetBluetoothEnabled();
// Changes bluetooth state to |enabled|. If the current state and |enabled|
// are same, it does nothing. If they're different, it toggles the state and
// records UMA.
void SetBluetoothEnabled(bool enabled);
// Returns whether the delegate has initiated a bluetooth discovery session. // Returns whether the delegate has initiated a bluetooth discovery session.
bool HasBluetoothDiscoverySession(); bool HasBluetoothDiscoverySession();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment