blob: 33c91212daa3da1493fd4e8eff5eae5fc2a82be4 [file] [log] [blame]
// Copyright 2016 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.
#include <string>
#include "base/macros.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "components/arc/common/audio.mojom.h"
#include "components/arc/connection_observer.h"
#include "components/keyed_service/core/keyed_service.h"
namespace content {
class BrowserContext;
} // namespace content
namespace arc {
class ArcBridgeService;
class ArcAudioBridge : public KeyedService,
public ConnectionObserver<mojom::AudioInstance>,
public mojom::AudioHost,
public chromeos::CrasAudioHandler::AudioObserver {
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcAudioBridge* GetForBrowserContext(content::BrowserContext* context);
ArcAudioBridge(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcAudioBridge() override;
// ConnectionObserver<mojom::AudioInstance> overrides.
void OnConnectionReady() override;
void OnConnectionClosed() override;
// mojom::AudioHost overrides.
void ShowVolumeControls() override;
void OnSystemVolumeUpdateRequest(int32_t percent) override;
// chromeos::CrasAudioHandler::AudioObserver overrides.
void OnAudioNodesChanged() override;
void OnOutputNodeVolumeChanged(uint64_t node_id, int volume) override;
void OnOutputMuteChanged(bool mute_on) override;
void SendSwitchState(bool headphone_inserted, bool microphone_inserted);
void SendVolumeState();
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
chromeos::CrasAudioHandler* cras_audio_handler_ = nullptr;
int volume_ = 0; // Volume range: 0-100.
bool muted_ = false;
// Avoids sending requests when the instance is unavailable.
// TODO( Remove once the root cause is fixed.
bool available_ = false;
} // namespace arc