Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1606782 - part1 : rename controller related functions and member …
Browse files Browse the repository at this point in the history
…to emphasize that only active controller would be added into the controller list in the service. r=chunmin,bryce

To modify variable and function names to emphasize all media controllers added in the service are active controllers. If the controller doesn't have any controlled media, they won't be added into the service.

Differential Revision: https://phabricator.services.mozilla.com/D58589
  • Loading branch information
alastor0325 committed Jan 15, 2020
1 parent ede1493 commit 1331147
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6053,7 +6053,7 @@ mozilla::ipc::IPCResult ContentParent::RecvNotifyMediaAudibleChanged(
RefPtr<MediaControlService> service = MediaControlService::GetService();
MOZ_ASSERT(!aContext->GetParent(), "Should be top level browsing context!");
RefPtr<MediaController> controller =
service->GetControllerById(aContext->Id());
service->GetActiveControllerById(aContext->Id());
if (controller) {
controller->NotifyMediaAudibleChanged(aAudible);
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/mediacontrol/AudioFocusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void AudioFocusManager::HandleAudioCompetition(uint64_t aId) {
LOG("Controller %" PRId64 " loses audio focus in audio competitition",
controllerId);
RefPtr<MediaController> controller =
mService->GetControllerById(controllerId);
mService->GetActiveControllerById(controllerId);
MOZ_ASSERT(controller);
controller->Stop();
}
Expand Down
2 changes: 1 addition & 1 deletion dom/media/mediacontrol/ContentMediaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void ContentMediaController::NotifyAudibleStateChanged(
// Currently this only happen when we disable e10s, otherwise all controlled
// media would be run in the content process.
RefPtr<MediaController> controller =
MediaControlService::GetService()->GetControllerById(bc->Id());
MediaControlService::GetService()->GetActiveControllerById(bc->Id());
if (controller) {
controller->NotifyMediaAudibleChanged(aAudible);
}
Expand Down
29 changes: 16 additions & 13 deletions dom/media/mediacontrol/MediaControlService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,40 @@ void MediaControlService::Shutdown() {

MediaController* MediaControlService::GetOrCreateControllerById(
uint64_t aId) const {
MediaController* controller = GetControllerById(aId);
MediaController* controller = GetActiveControllerById(aId);
if (!controller) {
controller = new MediaController(aId);
}
return controller;
}

MediaController* MediaControlService::GetControllerById(uint64_t aId) const {
MediaController* MediaControlService::GetActiveControllerById(
uint64_t aId) const {
MOZ_DIAGNOSTIC_ASSERT(mControllerManager);
return mControllerManager->GetControllerById(aId);
}

void MediaControlService::AddMediaController(MediaController* aController) {
void MediaControlService::RegisterActiveMediaController(
MediaController* aController) {
MOZ_DIAGNOSTIC_ASSERT(mControllerManager,
"Add controller before initializing service");
"Register controller before initializing service");
mControllerManager->AddController(aController);
LOG("Add media controller %" PRId64 ", currentNum=%" PRId64,
aController->Id(), GetControllersNum());
mMediaControllerAmountChangedEvent.Notify(GetControllersNum());
LOG("Register media controller %" PRId64 ", currentNum=%" PRId64,
aController->Id(), GetActiveControllersNum());
mMediaControllerAmountChangedEvent.Notify(GetActiveControllersNum());
}

void MediaControlService::RemoveMediaController(MediaController* aController) {
void MediaControlService::UnregisterActiveMediaController(
MediaController* aController) {
MOZ_DIAGNOSTIC_ASSERT(mControllerManager,
"Remove controller before initializing service");
"Unregister controller before initializing service");
mControllerManager->RemoveController(aController);
LOG("Remove media controller %" PRId64 ", currentNum=%" PRId64,
aController->Id(), GetControllersNum());
mMediaControllerAmountChangedEvent.Notify(GetControllersNum());
LOG("Unregister media controller %" PRId64 ", currentNum=%" PRId64,
aController->Id(), GetActiveControllersNum());
mMediaControllerAmountChangedEvent.Notify(GetActiveControllersNum());
}

uint64_t MediaControlService::GetControllersNum() const {
uint64_t MediaControlService::GetActiveControllersNum() const {
MOZ_DIAGNOSTIC_ASSERT(mControllerManager);
return mControllerManager->GetControllersNum();
}
Expand Down
8 changes: 4 additions & 4 deletions dom/media/mediacontrol/MediaControlService.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class MediaControlService final : public nsIObserver {
static RefPtr<MediaControlService> GetService();

MediaController* GetOrCreateControllerById(uint64_t aId) const;
MediaController* GetControllerById(uint64_t aId) const;
MediaController* GetActiveControllerById(uint64_t aId) const;

AudioFocusManager& GetAudioFocusManager() { return mAudioFocusManager; }
MediaControlKeysEventSource* GetMediaControlKeysEventSource() {
return mMediaControlKeysManager;
}

void AddMediaController(MediaController* aController);
void RemoveMediaController(MediaController* aController);
uint64_t GetControllersNum() const;
void RegisterActiveMediaController(MediaController* aController);
void UnregisterActiveMediaController(MediaController* aController);
uint64_t GetActiveControllersNum() const;

// The main controller is the controller which can receive the media control
// key events and would show its metadata to virtual controller interface.
Expand Down
4 changes: 2 additions & 2 deletions dom/media/mediacontrol/MediaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ void MediaController::DecreasePlayingControlledMediaNum() {
void MediaController::Activate() {
RefPtr<MediaControlService> service = MediaControlService::GetService();
MOZ_ASSERT(service);
service->AddMediaController(this);
service->RegisterActiveMediaController(this);
}

void MediaController::Deactivate() {
RefPtr<MediaControlService> service = MediaControlService::GetService();
MOZ_ASSERT(service);
service->RemoveMediaController(this);
service->UnregisterActiveMediaController(this);
service->GetAudioFocusManager().RevokeAudioFocus(Id());
}

Expand Down
8 changes: 4 additions & 4 deletions dom/media/mediacontrol/tests/gtest/TestAudioFocusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ TEST(AudioFocusManager, TestAudioFocusNumsWhenEnableAudioFocusManagement)

RefPtr<MediaController> controller1 =
new MediaController(FIRST_CONTROLLER_ID);
service->AddMediaController(controller1);
service->RegisterActiveMediaController(controller1);
manager.RequestAudioFocus(FIRST_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);

// When controller2 starts, it would win the audio focus from controller1. So
// there would only one audio focus existing.
RefPtr<MediaController> controller2 =
new MediaController(SECOND_CONTROLLER_ID);
service->AddMediaController(controller2);
service->RegisterActiveMediaController(controller2);
manager.RequestAudioFocus(SECOND_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 1);

manager.RevokeAudioFocus(SECOND_CONTROLLER_ID);
ASSERT_TRUE(manager.GetAudioFocusNums() == 0);

service->RemoveMediaController(controller1);
service->RemoveMediaController(controller2);
service->UnregisterActiveMediaController(controller1);
service->UnregisterActiveMediaController(controller2);
}

TEST(AudioFocusManager, TestAudioFocusNumsWhenDisableAudioFocusManagement)
Expand Down
30 changes: 15 additions & 15 deletions dom/media/mediacontrol/tests/gtest/TestMediaControlService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,51 @@ using namespace mozilla::dom;
TEST(MediaControlService, TestAddOrRemoveControllers)
{
RefPtr<MediaControlService> service = MediaControlService::GetService();
ASSERT_TRUE(service->GetControllersNum() == 0);
ASSERT_TRUE(service->GetActiveControllersNum() == 0);

RefPtr<MediaController> controller1 =
new MediaController(FIRST_CONTROLLER_ID);
RefPtr<MediaController> controller2 =
new MediaController(SECOND_CONTROLLER_ID);

service->AddMediaController(controller1);
ASSERT_TRUE(service->GetControllersNum() == 1);
service->RegisterActiveMediaController(controller1);
ASSERT_TRUE(service->GetActiveControllersNum() == 1);

service->AddMediaController(controller2);
ASSERT_TRUE(service->GetControllersNum() == 2);
service->RegisterActiveMediaController(controller2);
ASSERT_TRUE(service->GetActiveControllersNum() == 2);

service->RemoveMediaController(controller1);
ASSERT_TRUE(service->GetControllersNum() == 1);
service->UnregisterActiveMediaController(controller1);
ASSERT_TRUE(service->GetActiveControllersNum() == 1);

service->RemoveMediaController(controller2);
ASSERT_TRUE(service->GetControllersNum() == 0);
service->UnregisterActiveMediaController(controller2);
ASSERT_TRUE(service->GetActiveControllersNum() == 0);
}

TEST(MediaControlService, TestMainController)
{
RefPtr<MediaControlService> service = MediaControlService::GetService();
ASSERT_TRUE(service->GetControllersNum() == 0);
ASSERT_TRUE(service->GetActiveControllersNum() == 0);

RefPtr<MediaController> controller1 =
new MediaController(FIRST_CONTROLLER_ID);
service->AddMediaController(controller1);
service->RegisterActiveMediaController(controller1);

RefPtr<MediaController> mainController = service->GetMainController();
ASSERT_TRUE(mainController->Id() == FIRST_CONTROLLER_ID);

RefPtr<MediaController> controller2 =
new MediaController(SECOND_CONTROLLER_ID);
service->AddMediaController(controller2);
service->RegisterActiveMediaController(controller2);

mainController = service->GetMainController();
ASSERT_TRUE(mainController->Id() == SECOND_CONTROLLER_ID);

service->RemoveMediaController(controller2);
service->UnregisterActiveMediaController(controller2);
mainController = service->GetMainController();
ASSERT_TRUE(mainController->Id() == FIRST_CONTROLLER_ID);

service->RemoveMediaController(controller1);
service->UnregisterActiveMediaController(controller1);
mainController = service->GetMainController();
ASSERT_TRUE(service->GetControllersNum() == 0);
ASSERT_TRUE(service->GetActiveControllersNum() == 0);
ASSERT_TRUE(!mainController);
}
6 changes: 3 additions & 3 deletions dom/media/mediacontrol/tests/gtest/TestMediaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ TEST(MediaController, NotifyMediaStateChanged)
TEST(MediaController, ActiveAndDeactiveController)
{
RefPtr<MediaControlService> service = MediaControlService::GetService();
ASSERT_TRUE(service->GetControllersNum() == 0);
ASSERT_TRUE(service->GetActiveControllersNum() == 0);

RefPtr<MediaController> controller1 =
new MediaController(FIRST_CONTROLLER_ID);

controller1->NotifyMediaStateChanged(ControlledMediaState::eStarted);
ASSERT_TRUE(service->GetControllersNum() == 1);
ASSERT_TRUE(service->GetActiveControllersNum() == 1);

controller1->NotifyMediaStateChanged(ControlledMediaState::eStopped);
ASSERT_TRUE(service->GetControllersNum() == 0);
ASSERT_TRUE(service->GetActiveControllersNum() == 0);
}

TEST(MediaController, AudibleChanged)
Expand Down

0 comments on commit 1331147

Please sign in to comment.