Commit 5d277693 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

bluetooth: Stop using SystemTrayNotifier

SystemTrayNotifier will be removed, so move the observer list direclty
into TrayBluetoothHelper.

Bug: 882346
Change-Id: I316a43cc98d879003e378e01994e40038e557f93
Reviewed-on: https://chromium-review.googlesource.com/c/1343588Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609811}
parent 85cd2a96
......@@ -663,7 +663,6 @@ component("ash") {
"system/bluetooth/bluetooth_feature_pod_controller.h",
"system/bluetooth/bluetooth_notification_controller.cc",
"system/bluetooth/bluetooth_notification_controller.h",
"system/bluetooth/bluetooth_observer.h",
"system/bluetooth/bluetooth_power_controller.cc",
"system/bluetooth/bluetooth_power_controller.h",
"system/bluetooth/tray_bluetooth_helper.cc",
......
......@@ -9,7 +9,6 @@
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "base/i18n/number_formatting.h"
......@@ -22,11 +21,13 @@ namespace ash {
BluetoothFeaturePodController::BluetoothFeaturePodController(
UnifiedSystemTrayController* tray_controller)
: tray_controller_(tray_controller) {
Shell::Get()->system_tray_notifier()->AddBluetoothObserver(this);
Shell::Get()->tray_bluetooth_helper()->AddObserver(this);
}
BluetoothFeaturePodController::~BluetoothFeaturePodController() {
Shell::Get()->system_tray_notifier()->RemoveBluetoothObserver(this);
auto* helper = Shell::Get()->tray_bluetooth_helper();
if (helper)
helper->RemoveObserver(this);
}
FeaturePodButton* BluetoothFeaturePodController::CreateButton() {
......
......@@ -5,7 +5,7 @@
#ifndef ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_
#define ASH_SYSTEM_BLUETOOTH_BLUETOOTH_FEATURE_POD_CONTROLLER_H_
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "base/macros.h"
#include "base/strings/string16.h"
......@@ -16,7 +16,7 @@ class UnifiedSystemTrayController;
// Controller of a feature pod button of bluetooth.
class BluetoothFeaturePodController : public FeaturePodControllerBase,
public BluetoothObserver {
public TrayBluetoothHelper::Observer {
public:
BluetoothFeaturePodController(UnifiedSystemTrayController* tray_controller);
~BluetoothFeaturePodController() override;
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_BLUETOOTH_BLUETOOTH_OBSERVER_H_
#define ASH_SYSTEM_BLUETOOTH_BLUETOOTH_OBSERVER_H_
namespace ash {
class BluetoothObserver {
public:
virtual ~BluetoothObserver() {}
// Called when the state of Bluetooth in the system changes.
virtual void OnBluetoothSystemStateChanged() {}
// Called when a Bluetooth scan has started or stopped.
virtual void OnBluetoothScanStateChanged() {}
// Called when a device was added, removed, or changed.
virtual void OnBluetoothDeviceListChanged() {}
};
} // namespace ash
#endif // ASH_SYSTEM_BLUETOOTH_BLUETOOTH_OBSERVER_H_
......@@ -19,6 +19,14 @@ TrayBluetoothHelper::TrayBluetoothHelper() = default;
TrayBluetoothHelper::~TrayBluetoothHelper() = default;
void TrayBluetoothHelper::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void TrayBluetoothHelper::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
bool TrayBluetoothHelper::IsBluetoothStateAvailable() {
switch (GetBluetoothState()) {
case BluetoothSystem::State::kUnsupported:
......@@ -31,4 +39,19 @@ bool TrayBluetoothHelper::IsBluetoothStateAvailable() {
}
}
void TrayBluetoothHelper::NotifyBluetoothSystemStateChanged() {
for (auto& observer : observers_)
observer.OnBluetoothSystemStateChanged();
}
void TrayBluetoothHelper::NotifyBluetoothScanStateChanged() {
for (auto& observer : observers_)
observer.OnBluetoothScanStateChanged();
}
void TrayBluetoothHelper::NotifyBluetoothDeviceListChanged() {
for (auto& observer : observers_)
observer.OnBluetoothDeviceListChanged();
}
} // namespace ash
......@@ -42,9 +42,24 @@ using BluetoothDeviceList = std::vector<BluetoothDeviceInfo>;
// de-virtualize this class and remove its legacy implementation.
class TrayBluetoothHelper {
public:
class Observer : public base::CheckedObserver {
public:
// Called when the state of Bluetooth in the system changes.
virtual void OnBluetoothSystemStateChanged() {}
// Called when a Bluetooth scan has started or stopped.
virtual void OnBluetoothScanStateChanged() {}
// Called when a device was added, removed, or changed.
virtual void OnBluetoothDeviceListChanged() {}
};
TrayBluetoothHelper();
virtual ~TrayBluetoothHelper();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// Initializes and gets the adapter asynchronously.
virtual void Initialize() = 0;
......@@ -75,6 +90,13 @@ class TrayBluetoothHelper {
// Returns whether the delegate has initiated a bluetooth discovery session.
virtual bool HasBluetoothDiscoverySession() = 0;
protected:
void NotifyBluetoothSystemStateChanged();
void NotifyBluetoothScanStateChanged();
void NotifyBluetoothDeviceListChanged();
base::ObserverList<Observer> observers_;
private:
DISALLOW_COPY_AND_ASSIGN(TrayBluetoothHelper);
};
......
......@@ -84,13 +84,13 @@ bool TrayBluetoothHelperExperimental::HasBluetoothDiscoverySession() {
void TrayBluetoothHelperExperimental::OnStateChanged(
device::mojom::BluetoothSystem::State state) {
cached_state_ = state;
Shell::Get()->system_tray_notifier()->NotifyBluetoothSystemStateChanged();
NotifyBluetoothSystemStateChanged();
}
void TrayBluetoothHelperExperimental::OnScanStateChanged(
device::mojom::BluetoothSystem::ScanState state) {
cached_scan_state_ = state;
Shell::Get()->system_tray_notifier()->NotifyBluetoothScanStateChanged();
NotifyBluetoothScanStateChanged();
}
} // namespace ash
......@@ -10,7 +10,6 @@
#include "ash/shell.h"
#include "ash/system/bluetooth/bluetooth_power_controller.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/metrics/user_metrics.h"
......@@ -35,10 +34,6 @@ void BluetoothSetDiscoveringError() {
void BluetoothDeviceConnectError(
device::BluetoothDevice::ConnectErrorCode error_code) {}
ash::SystemTrayNotifier* GetSystemTrayNotifier() {
return Shell::Get()->system_tray_notifier();
}
BluetoothDeviceInfo GetBluetoothDeviceInfo(device::BluetoothDevice* device) {
BluetoothDeviceInfo info;
info.address = device->GetAddress();
......@@ -165,34 +160,34 @@ bool TrayBluetoothHelperLegacy::HasBluetoothDiscoverySession() {
void TrayBluetoothHelperLegacy::AdapterPresentChanged(
device::BluetoothAdapter* adapter,
bool present) {
GetSystemTrayNotifier()->NotifyBluetoothSystemStateChanged();
NotifyBluetoothSystemStateChanged();
}
void TrayBluetoothHelperLegacy::AdapterPoweredChanged(
device::BluetoothAdapter* adapter,
bool powered) {
GetSystemTrayNotifier()->NotifyBluetoothSystemStateChanged();
NotifyBluetoothSystemStateChanged();
}
void TrayBluetoothHelperLegacy::AdapterDiscoveringChanged(
device::BluetoothAdapter* adapter,
bool discovering) {
GetSystemTrayNotifier()->NotifyBluetoothScanStateChanged();
NotifyBluetoothScanStateChanged();
}
void TrayBluetoothHelperLegacy::DeviceAdded(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
GetSystemTrayNotifier()->NotifyBluetoothDeviceListChanged();
NotifyBluetoothDeviceListChanged();
}
void TrayBluetoothHelperLegacy::DeviceChanged(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
GetSystemTrayNotifier()->NotifyBluetoothDeviceListChanged();
NotifyBluetoothDeviceListChanged();
}
void TrayBluetoothHelperLegacy::DeviceRemoved(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
GetSystemTrayNotifier()->NotifyBluetoothDeviceListChanged();
NotifyBluetoothDeviceListChanged();
}
void TrayBluetoothHelperLegacy::OnStartDiscoverySession(
......@@ -204,7 +199,7 @@ void TrayBluetoothHelperLegacy::OnStartDiscoverySession(
return;
VLOG(1) << "Claiming new Bluetooth device discovery session.";
discovery_session_ = std::move(discovery_session);
GetSystemTrayNotifier()->NotifyBluetoothScanStateChanged();
NotifyBluetoothScanStateChanged();
}
} // namespace ash
......@@ -56,15 +56,19 @@ UnifiedBluetoothDetailedViewController::UnifiedBluetoothDetailedViewController(
UnifiedSystemTrayController* tray_controller)
: detailed_view_delegate_(
std::make_unique<UnifiedDetailedViewDelegate>(tray_controller)) {
Shell::Get()->system_tray_notifier()->AddBluetoothObserver(this);
Shell::Get()->tray_bluetooth_helper()->AddObserver(this);
}
UnifiedBluetoothDetailedViewController::
~UnifiedBluetoothDetailedViewController() {
Shell::Get()->system_tray_notifier()->RemoveBluetoothObserver(this);
// Stop discovering bluetooth devices when exiting BT detailed view.
TrayBluetoothHelper* helper = Shell::Get()->tray_bluetooth_helper();
if (helper && helper->HasBluetoothDiscoverySession()) {
if (!helper)
return;
helper->RemoveObserver(this);
if (helper->HasBluetoothDiscoverySession()) {
helper->StopBluetoothDiscovering();
}
}
......
......@@ -7,7 +7,6 @@
#include <memory>
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/bluetooth/tray_bluetooth_helper.h"
#include "ash/system/unified/detailed_view_controller.h"
#include "base/macros.h"
......@@ -23,8 +22,9 @@ class DetailedViewDelegate;
class UnifiedSystemTrayController;
// Controller of Bluetooth detailed view in UnifiedSystemTray.
class UnifiedBluetoothDetailedViewController : public DetailedViewController,
public BluetoothObserver {
class UnifiedBluetoothDetailedViewController
: public DetailedViewController,
public TrayBluetoothHelper::Observer {
public:
explicit UnifiedBluetoothDetailedViewController(
UnifiedSystemTrayController* tray_controller);
......
......@@ -4,7 +4,6 @@
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/ime/ime_observer.h"
#include "ash/system/network/network_observer.h"
#include "ash/system/screen_security/screen_capture_observer.h"
......@@ -18,29 +17,6 @@ SystemTrayNotifier::SystemTrayNotifier() = default;
SystemTrayNotifier::~SystemTrayNotifier() = default;
void SystemTrayNotifier::AddBluetoothObserver(BluetoothObserver* observer) {
bluetooth_observers_.AddObserver(observer);
}
void SystemTrayNotifier::RemoveBluetoothObserver(BluetoothObserver* observer) {
bluetooth_observers_.RemoveObserver(observer);
}
void SystemTrayNotifier::NotifyBluetoothSystemStateChanged() {
for (auto& observer : bluetooth_observers_)
observer.OnBluetoothSystemStateChanged();
}
void SystemTrayNotifier::NotifyBluetoothScanStateChanged() {
for (auto& observer : bluetooth_observers_)
observer.OnBluetoothScanStateChanged();
}
void SystemTrayNotifier::NotifyBluetoothDeviceListChanged() {
for (auto& observer : bluetooth_observers_)
observer.OnBluetoothDeviceListChanged();
}
void SystemTrayNotifier::AddIMEObserver(IMEObserver* observer) {
ime_observers_.AddObserver(observer);
}
......
......@@ -16,7 +16,6 @@
namespace ash {
class BluetoothObserver;
class IMEObserver;
class NetworkObserver;
class ScreenCaptureObserver;
......@@ -34,13 +33,6 @@ class ASH_EXPORT SystemTrayNotifier {
SystemTrayNotifier();
~SystemTrayNotifier();
// Bluetooth.
void AddBluetoothObserver(BluetoothObserver* observer);
void RemoveBluetoothObserver(BluetoothObserver* observer);
void NotifyBluetoothSystemStateChanged();
void NotifyBluetoothScanStateChanged();
void NotifyBluetoothDeviceListChanged();
// Input methods.
void AddIMEObserver(IMEObserver* observer);
void RemoveIMEObserver(IMEObserver* observer);
......@@ -77,7 +69,6 @@ class ASH_EXPORT SystemTrayNotifier {
void NotifyVirtualKeyboardSuppressionChanged(bool suppressed);
private:
base::ObserverList<BluetoothObserver>::Unchecked bluetooth_observers_;
base::ObserverList<IMEObserver>::Unchecked ime_observers_;
base::ObserverList<NetworkObserver>::Unchecked network_observers_;
base::ObserverList<ScreenCaptureObserver>::Unchecked
......
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