Skip to content

Commit

Permalink
Implement skeleton MediaRouterDebugger class.
Browse files Browse the repository at this point in the history
Implements a skeleton MediaRouterDebugger interface. Eventually additional API's will be implemented for fetching debugging stats.

Additionally a simple impl has been created that enables and disables Rtcp reporting.

Bug: b/265820417
Change-Id: I4fb3e9e6008feb8feebd2575c9bb50a4c820e43b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4196076
Commit-Queue: george benz <gbj@google.com>
Reviewed-by: Mark Foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1099004}
  • Loading branch information
George Benz authored and Chromium LUCI CQ committed Jan 31, 2023
1 parent 9e3d792 commit 8635d52
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chrome/browser/media/router/mojo/media_router_mojo_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,10 @@ LoggerImpl* MediaRouterMojoImpl::GetLogger() {
return &logger_;
}

MediaRouterDebugger& MediaRouterMojoImpl::GetDebugger() {
return media_router_debugger_;
}

void MediaRouterMojoImpl::GetLogsAsString(GetLogsAsStringCallback callback) {
std::move(callback).Run(logger_.GetLogsAsJson());
}
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/media/router/mojo/media_router_mojo_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "components/media_router/browser/issue_manager.h"
#include "components/media_router/browser/logger_impl.h"
#include "components/media_router/browser/media_router_base.h"
#include "components/media_router/browser/media_router_debugger.h"
#include "components/media_router/browser/media_routes_observer.h"
#include "components/media_router/common/issue.h"
#include "components/media_router/common/mojom/logger.mojom.h"
Expand Down Expand Up @@ -143,6 +144,8 @@ class MediaRouterMojoImpl : public MediaRouterBase,

LoggerImpl* GetLogger() override;

MediaRouterDebugger& GetDebugger() override;

// Mojo remotes to media route providers. Providers are added via
// RegisterMediaRouteProvider().
base::flat_map<mojom::MediaRouteProviderId,
Expand Down Expand Up @@ -447,6 +450,8 @@ class MediaRouterMojoImpl : public MediaRouterBase,
// Collects logs from the Media Router and the native Media Route Providers.
// TODO(crbug.com/1077138): Limit logging before Media Router usage.
LoggerImpl logger_;

MediaRouterDebugger media_router_debugger_;
};

} // namespace media_router
Expand Down
3 changes: 3 additions & 0 deletions components/media_router/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source_set("browser") {
"media_router.h",
"media_router_base.cc",
"media_router_base.h",
"media_router_debugger.cc",
"media_router_debugger.h",
"media_router_dialog_controller.cc",
"media_router_dialog_controller.h",
"media_router_factory.cc",
Expand Down Expand Up @@ -115,6 +117,7 @@ source_set("unit_tests") {

sources = [
"media_router_base_unittest.cc",
"media_router_debugger_unittest.cc",
"media_router_dialog_controller_unittest.cc",
"media_router_factory_unittest.cc",
"media_router_metrics_unittest.cc",
Expand Down
5 changes: 5 additions & 0 deletions components/media_router/browser/media_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#if !BUILDFLAG(IS_ANDROID)
#include "components/media_router/browser/logger_impl.h"
#include "components/media_router/browser/media_router_debugger.h"
#include "components/media_router/common/mojom/media_controller.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
Expand Down Expand Up @@ -187,6 +188,10 @@ class MediaRouter : public KeyedService {

// Returns a pointer to LoggerImpl that can be used to add logging messages.
virtual LoggerImpl* GetLogger() = 0;

// Returns the instance of the debugger for this MediaRouter instance.
virtual MediaRouterDebugger& GetDebugger() = 0;

#endif // !BUILDFLAG(IS_ANDROID)

private:
Expand Down
27 changes: 27 additions & 0 deletions components/media_router/browser/media_router_debugger.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/media_router/browser/media_router_debugger.h"

#include "media/base/media_switches.h"

namespace media_router {

MediaRouterDebugger::MediaRouterDebugger() = default;
MediaRouterDebugger::~MediaRouterDebugger() = default;

void MediaRouterDebugger::EnableRtcpReports() {
is_rtcp_reports_enabled_ = true;
}

void MediaRouterDebugger::DisableRtcpReports() {
is_rtcp_reports_enabled_ = false;
}

bool MediaRouterDebugger::IsRtcpReportsEnabled() const {
return is_rtcp_reports_enabled_ &&
base::FeatureList::IsEnabled(media::kEnableRtcpReporting);
}

} // namespace media_router
31 changes: 31 additions & 0 deletions components/media_router/browser/media_router_debugger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_MEDIA_ROUTER_BROWSER_MEDIA_ROUTER_DEBUGGER_H_
#define COMPONENTS_MEDIA_ROUTER_BROWSER_MEDIA_ROUTER_DEBUGGER_H_

namespace media_router {

// An interface for media router debugging and feedback.
class MediaRouterDebugger {
public:
MediaRouterDebugger();

MediaRouterDebugger(const MediaRouterDebugger&) = delete;
MediaRouterDebugger& operator=(const MediaRouterDebugger&) = delete;

virtual ~MediaRouterDebugger();

void EnableRtcpReports();
void DisableRtcpReports();

bool IsRtcpReportsEnabled() const;

protected:
bool is_rtcp_reports_enabled_ = false;
};

} // namespace media_router

#endif // COMPONENTS_MEDIA_ROUTER_BROWSER_MEDIA_ROUTER_DEBUGGER_H_
43 changes: 43 additions & 0 deletions components/media_router/browser/media_router_debugger_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/media_router/browser/media_router_debugger.h"

#include "base/test/scoped_feature_list.h"
#include "content/public/test/browser_task_environment.h"
#include "media/base/media_switches.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media_router {

class MediaRouterDebuggerTest : public ::testing::Test {
public:
MediaRouterDebuggerTest()
: debugger_(std::make_unique<MediaRouterDebugger>()) {}
MediaRouterDebuggerTest(const MediaRouterDebuggerTest&) = delete;
~MediaRouterDebuggerTest() override = default;
MediaRouterDebuggerTest& operator=(const MediaRouterDebuggerTest&) = delete;

protected:
std::unique_ptr<MediaRouterDebugger> debugger_;
content::BrowserTaskEnvironment test_environment_;
};

TEST_F(MediaRouterDebuggerTest, TestIsRtcpReportsEnabled) {
// Tests default condition.
EXPECT_FALSE(debugger_->IsRtcpReportsEnabled());

// Reports should still be disabled since we the feature flag has not been
// set.
debugger_->EnableRtcpReports();
EXPECT_FALSE(debugger_->IsRtcpReportsEnabled());

// All conditions should be met and the function should return true now.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({media::kEnableRtcpReporting}, {});

EXPECT_TRUE(debugger_->IsRtcpReportsEnabled());
}

} // namespace media_router
2 changes: 2 additions & 0 deletions components/media_router/browser/test/mock_media_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "build/build_config.h"
#include "components/media_router/browser/logger_impl.h"
#include "components/media_router/browser/media_router_base.h"
#include "components/media_router/browser/media_router_debugger.h"
#include "components/media_router/browser/media_routes_observer.h"
#include "components/media_router/common/media_route.h"
#include "components/media_router/common/media_sink.h"
Expand Down Expand Up @@ -122,6 +123,7 @@ class MockMediaRouter : public MediaRouterBase {
MOCK_CONST_METHOD0(GetLogs, base::Value());
MOCK_CONST_METHOD0(GetState, base::Value::Dict());
MOCK_METHOD0(GetLogger, LoggerImpl*());
MOCK_METHOD0(GetDebugger, MediaRouterDebugger&());
#endif // !BUILDFLAG(IS_ANDROID)
MOCK_METHOD1(OnAddPresentationConnectionStateChangedCallbackInvoked,
void(const content::PresentationConnectionStateChangedCallback&
Expand Down

0 comments on commit 8635d52

Please sign in to comment.