Commit 6a2d7f26 authored by erg's avatar erg Committed by Commit bot

mash: Mojoify the MediaDelegate interface.

Instead of a MediaDelegate returned by the ShellDelegate, we now have a
MediaController on the ash side, which receives a MediaClient from the
chrome side at startup.

This also makes minor changes to the interface to send information with
a notification instead of having ash try to read the information back
after notification.

BUG=647409

Review-Url: https://codereview.chromium.org/2563643003
Cr-Commit-Position: refs/heads/master@{#438046}
parent 6ea15211
......@@ -119,6 +119,8 @@ component("ash") {
"common/login_status.h",
"common/material_design/material_design_controller.cc",
"common/material_design/material_design_controller.h",
"common/media_controller.cc",
"common/media_controller.h",
"common/metrics/gesture_action_type.h",
"common/metrics/pointer_metrics_recorder.cc",
"common/metrics/pointer_metrics_recorder.h",
......@@ -228,7 +230,6 @@ component("ash") {
"common/system/chromeos/ime_menu/ime_menu_tray.h",
"common/system/chromeos/keyboard_brightness_controller.cc",
"common/system/chromeos/keyboard_brightness_controller.h",
"common/system/chromeos/media_security/media_capture_observer.h",
"common/system/chromeos/media_security/multi_profile_media_tray_item.cc",
"common/system/chromeos/media_security/multi_profile_media_tray_item.h",
"common/system/chromeos/network/network_detailed_view.h",
......
......@@ -13,7 +13,7 @@
#include "ash/common/accessibility_types.h"
#include "ash/common/focus_cycler.h"
#include "ash/common/ime_control_delegate.h"
#include "ash/common/media_delegate.h"
#include "ash/common/media_controller.h"
#include "ash/common/multi_profile_uma.h"
#include "ash/common/new_window_controller.h"
#include "ash/common/session/session_state_delegate.h"
......@@ -133,15 +133,15 @@ void HandleLaunchLastApp() {
}
void HandleMediaNextTrack() {
WmShell::Get()->media_delegate()->HandleMediaNextTrack();
WmShell::Get()->media_controller()->HandleMediaNextTrack();
}
void HandleMediaPlayPause() {
WmShell::Get()->media_delegate()->HandleMediaPlayPause();
WmShell::Get()->media_controller()->HandleMediaPlayPause();
}
void HandleMediaPrevTrack() {
WmShell::Get()->media_delegate()->HandleMediaPrevTrack();
WmShell::Get()->media_controller()->HandleMediaPrevTrack();
}
bool CanHandleNewIncognitoWindow() {
......
// 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 "ash/common/media_controller.h"
namespace ash {
MediaController::MediaController() {}
MediaController::~MediaController() {}
void MediaController::BindRequest(mojom::MediaControllerRequest request) {
bindings_.AddBinding(this, std::move(request));
}
void MediaController::AddObserver(MediaCaptureObserver* observer) {
observers_.AddObserver(observer);
}
void MediaController::RemoveObserver(MediaCaptureObserver* observer) {
observers_.RemoveObserver(observer);
}
void MediaController::HandleMediaNextTrack() {
if (client_)
client_->HandleMediaNextTrack();
}
void MediaController::HandleMediaPlayPause() {
if (client_)
client_->HandleMediaPlayPause();
}
void MediaController::HandleMediaPrevTrack() {
if (client_)
client_->HandleMediaPrevTrack();
}
void MediaController::RequestCaptureState() {
if (client_)
client_->RequestCaptureState();
}
void MediaController::SetClient(mojom::MediaClientAssociatedPtrInfo client) {
client_.Bind(std::move(client));
}
void MediaController::NotifyCaptureState(
const std::vector<mojom::MediaCaptureState>& capture_states) {
for (auto& observer : observers_)
observer.OnMediaCaptureChanged(capture_states);
}
} // namespace ash
// 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.
#ifndef ASH_COMMON_MEDIA_CONTROLLER_H_
#define ASH_COMMON_MEDIA_CONTROLLER_H_
#include "ash/public/interfaces/media.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding_set.h"
namespace ash {
// Forwards notifications from the MediaController to observers.
class MediaCaptureObserver {
public:
// Called when media capture state has changed.
virtual void OnMediaCaptureChanged(
const std::vector<mojom::MediaCaptureState>& capture_states) = 0;
protected:
virtual ~MediaCaptureObserver() {}
};
// Provides the MediaController interface to the outside world. This lets a
// consumer of ash provide a MediaClient, which we will dispatch to if one has
// been provided to us.
class MediaController : public mojom::MediaController,
public mojom::MediaClient {
public:
MediaController();
~MediaController() override;
void BindRequest(mojom::MediaControllerRequest request);
void AddObserver(MediaCaptureObserver* observer);
void RemoveObserver(MediaCaptureObserver* observer);
// mojom::MediaClient:
void HandleMediaNextTrack() override;
void HandleMediaPlayPause() override;
void HandleMediaPrevTrack() override;
void RequestCaptureState() override;
private:
friend class MultiProfileMediaTrayItemTest;
// mojom::MediaController:
void SetClient(mojom::MediaClientAssociatedPtrInfo client) override;
void NotifyCaptureState(
const std::vector<mojom::MediaCaptureState>& capture_states) override;
mojo::BindingSet<mojom::MediaController> bindings_;
mojom::MediaClientAssociatedPtr client_;
base::ObserverList<MediaCaptureObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(MediaController);
};
} // namespace ash
#endif // ASH_COMMON_MEDIA_CONTROLLER_H_
// Copyright 2013 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_COMMON_MEDIA_DELEGATE_H_
#define ASH_COMMON_MEDIA_DELEGATE_H_
#include "ash/public/cpp/session_types.h"
namespace ash {
enum MediaCaptureState {
MEDIA_CAPTURE_NONE = 0,
MEDIA_CAPTURE_AUDIO = 1 << 0,
MEDIA_CAPTURE_VIDEO = 1 << 1,
MEDIA_CAPTURE_AUDIO_VIDEO = MEDIA_CAPTURE_AUDIO | MEDIA_CAPTURE_VIDEO,
};
// A delegate class to control media playback.
class MediaDelegate {
public:
virtual ~MediaDelegate() {}
// Handles the Next Track Media shortcut key.
virtual void HandleMediaNextTrack() = 0;
// Handles the Play/Pause Toggle Media shortcut key.
virtual void HandleMediaPlayPause() = 0;
// Handles the Previous Track Media shortcut key.
virtual void HandleMediaPrevTrack() = 0;
// Returns the current media recording state of web contents that belongs to
// the the user @ |index|. See session_types.h for a description of UserIndex.
virtual MediaCaptureState GetMediaCaptureState(UserIndex index) = 0;
};
} // namespace ash
#endif // ASH_COMMON_MEDIA_DELEGATE_H_
......@@ -8,6 +8,7 @@
#include "ash/common/accelerators/accelerator_controller.h"
#include "ash/common/cast_config_controller.h"
#include "ash/common/media_controller.h"
#include "ash/common/new_window_controller.h"
#include "ash/common/session/session_controller.h"
#include "ash/common/shelf/shelf_controller.h"
......@@ -49,6 +50,11 @@ void BindLocaleNotificationControllerOnMainThread(
std::move(request));
}
void BindMediaControllerRequestOnMainThread(
mojom::MediaControllerRequest request) {
WmShell::Get()->media_controller()->BindRequest(std::move(request));
}
void BindNewWindowControllerRequestOnMainThread(
mojom::NewWindowControllerRequest request) {
WmShell::Get()->new_window_controller()->BindRequest(std::move(request));
......@@ -104,6 +110,8 @@ void RegisterInterfaces(
registry->AddInterface(
base::Bind(&BindLocaleNotificationControllerOnMainThread),
main_thread_task_runner);
registry->AddInterface(base::Bind(&BindMediaControllerRequestOnMainThread),
main_thread_task_runner);
registry->AddInterface(
base::Bind(&BindNewWindowControllerRequestOnMainThread),
main_thread_task_runner);
......
......@@ -38,7 +38,6 @@ namespace ash {
class AccessibilityDelegate;
class GPUSupport;
class MediaDelegate;
class PaletteDelegate;
class SessionStateDelegate;
class ShelfDelegate;
......@@ -113,9 +112,6 @@ class ASH_EXPORT ShellDelegate {
// Creates a accessibility delegate. Shell takes ownership of the delegate.
virtual AccessibilityDelegate* CreateAccessibilityDelegate() = 0;
// Creates a media delegate. Shell takes ownership of the delegate.
virtual MediaDelegate* CreateMediaDelegate() = 0;
virtual std::unique_ptr<PaletteDelegate> CreatePaletteDelegate() = 0;
// Creates a menu model for the |wm_shelf| and optional shelf |item|.
......
// Copyright 2014 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_COMMON_SYSTEM_CHROMEOS_MEDIA_SECURITY_MEDIA_CAPTURE_OBSERVER_H_
#define ASH_COMMON_SYSTEM_CHROMEOS_MEDIA_SECURITY_MEDIA_CAPTURE_OBSERVER_H_
namespace ash {
class MediaCaptureObserver {
public:
// Called when media capture state has changed.
virtual void OnMediaCaptureChanged() = 0;
protected:
virtual ~MediaCaptureObserver() {}
};
} // namespace ash
#endif // ASH_COMMON_SYSTEM_CHROMEOS_MEDIA_SECURITY_MEDIA_CAPTURE_OBSERVER_H_
......@@ -5,9 +5,8 @@
#include "ash/common/system/chromeos/media_security/multi_profile_media_tray_item.h"
#include "ash/common/ash_view_ids.h"
#include "ash/common/media_delegate.h"
#include "ash/common/media_controller.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/system/chromeos/media_security/media_capture_observer.h"
#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_item_view.h"
......@@ -32,24 +31,25 @@ class MultiProfileMediaTrayView : public TrayItemView,
UseMd()
? gfx::CreateVectorIcon(kSystemTrayRecordingIcon, kTrayIconColor)
: *bundle.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_RECORDING));
OnMediaCaptureChanged();
WmShell::Get()->system_tray_notifier()->AddMediaCaptureObserver(this);
WmShell::Get()->media_controller()->AddObserver(this);
SetVisible(false);
WmShell::Get()->media_controller()->RequestCaptureState();
set_id(VIEW_ID_MEDIA_TRAY_VIEW);
}
~MultiProfileMediaTrayView() override {
WmShell::Get()->system_tray_notifier()->RemoveMediaCaptureObserver(this);
WmShell::Get()->media_controller()->RemoveObserver(this);
}
// MediaCaptureObserver:
void OnMediaCaptureChanged() override {
MediaDelegate* media_delegate = WmShell::Get()->media_delegate();
void OnMediaCaptureChanged(
const std::vector<mojom::MediaCaptureState>& capture_states) override {
SessionStateDelegate* session_state_delegate =
WmShell::Get()->GetSessionStateDelegate();
// The user at 0 is the current desktop user.
for (UserIndex index = 1;
index < session_state_delegate->NumberOfLoggedInUsers(); ++index) {
if (media_delegate->GetMediaCaptureState(index) != MEDIA_CAPTURE_NONE) {
if (capture_states[index] != mojom::MediaCaptureState::NONE) {
SetVisible(true);
return;
}
......
......@@ -5,11 +5,14 @@
#include "ash/common/system/chromeos/media_security/multi_profile_media_tray_item.h"
#include "ash/common/ash_view_ids.h"
#include "ash/common/media_controller.h"
#include "ash/common/system/status_area_widget.h"
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/system_tray_bubble.h"
#include "ash/common/system/tray/tray_item_view.h"
#include "ash/common/test/test_session_state_delegate.h"
#include "ash/common/wm_shell.h"
#include "ash/public/interfaces/media.mojom.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "ash/test/status_area_widget_test_helper.h"
......@@ -18,12 +21,28 @@
namespace ash {
using MultiProfileMediaTrayItemTest = test::AshTestBase;
class MultiProfileMediaTrayItemTest : public test::AshTestBase {
public:
MultiProfileMediaTrayItemTest() {}
~MultiProfileMediaTrayItemTest() override {}
void SetMediaCaptureState(mojom::MediaCaptureState state) {
// Create the fake update.
test::TestSessionStateDelegate* session_state_delegate =
test::AshTestHelper::GetTestSessionStateDelegate();
std::vector<mojom::MediaCaptureState> v;
for (int i = 0; i < session_state_delegate->NumberOfLoggedInUsers(); ++i)
v.push_back(state);
WmShell::Get()->media_controller()->NotifyCaptureState(v);
}
private:
DISALLOW_COPY_AND_ASSIGN(MultiProfileMediaTrayItemTest);
};
// ash_unittests. still failing.
TEST_F(MultiProfileMediaTrayItemTest, NotifyMediaCaptureChange) {
TrayItemView::DisableAnimationsForTest();
test::TestShellDelegate* shell_delegate =
ash_test_helper()->test_shell_delegate();
test::TestSessionStateDelegate* session_state_delegate =
test::AshTestHelper::GetTestSessionStateDelegate();
session_state_delegate->set_logged_in_users(2);
......@@ -39,18 +58,19 @@ TEST_F(MultiProfileMediaTrayItemTest, NotifyMediaCaptureChange) {
views::View* tray_view =
widget->GetRootView()->GetViewByID(VIEW_ID_MEDIA_TRAY_VIEW);
SetMediaCaptureState(mojom::MediaCaptureState::NONE);
EXPECT_FALSE(tray_view->visible());
EXPECT_FALSE(in_user_view->visible());
shell_delegate->SetMediaCaptureState(MEDIA_CAPTURE_AUDIO);
SetMediaCaptureState(mojom::MediaCaptureState::AUDIO);
EXPECT_TRUE(tray_view->visible());
EXPECT_TRUE(in_user_view->visible());
shell_delegate->SetMediaCaptureState(MEDIA_CAPTURE_AUDIO_VIDEO);
SetMediaCaptureState(mojom::MediaCaptureState::AUDIO_VIDEO);
EXPECT_TRUE(tray_view->visible());
EXPECT_TRUE(in_user_view->visible());
shell_delegate->SetMediaCaptureState(MEDIA_CAPTURE_NONE);
SetMediaCaptureState(mojom::MediaCaptureState::NONE);
EXPECT_FALSE(tray_view->visible());
EXPECT_FALSE(in_user_view->visible());
}
......
......@@ -13,7 +13,6 @@
#if defined(OS_CHROMEOS)
#include "ash/common/system/chromeos/bluetooth/bluetooth_observer.h"
#include "ash/common/system/chromeos/enterprise/enterprise_domain_observer.h"
#include "ash/common/system/chromeos/media_security/media_capture_observer.h"
#include "ash/common/system/chromeos/network/network_observer.h"
#include "ash/common/system/chromeos/network/network_portal_detector_observer.h"
#include "ash/common/system/chromeos/screen_security/screen_capture_observer.h"
......@@ -197,21 +196,6 @@ void SystemTrayNotifier::NotifyLogoutDialogDurationChanged(
observer.OnLogoutDialogDurationChanged(duration);
}
void SystemTrayNotifier::AddMediaCaptureObserver(
MediaCaptureObserver* observer) {
media_capture_observers_.AddObserver(observer);
}
void SystemTrayNotifier::RemoveMediaCaptureObserver(
MediaCaptureObserver* observer) {
media_capture_observers_.RemoveObserver(observer);
}
void SystemTrayNotifier::NotifyMediaCaptureChanged() {
for (auto& observer : media_capture_observers_)
observer.OnMediaCaptureChanged();
}
void SystemTrayNotifier::AddNetworkObserver(NetworkObserver* observer) {
network_observers_.AddObserver(observer);
}
......
......@@ -31,7 +31,6 @@ class BluetoothObserver;
class EnterpriseDomainObserver;
class LastWindowClosedObserver;
class LogoutButtonObserver;
class MediaCaptureObserver;
class NetworkObserver;
class NetworkPortalDetectorObserver;
class ScreenCaptureObserver;
......@@ -101,11 +100,6 @@ class ASH_EXPORT SystemTrayNotifier {
void NotifyShowLoginButtonChanged(bool show_login_button);
void NotifyLogoutDialogDurationChanged(base::TimeDelta duration);
// Media capture.
void AddMediaCaptureObserver(MediaCaptureObserver* observer);
void RemoveMediaCaptureObserver(MediaCaptureObserver* observer);
void NotifyMediaCaptureChanged();
// Network.
void AddNetworkObserver(NetworkObserver* observer);
void RemoveNetworkObserver(NetworkObserver* observer);
......@@ -161,7 +155,6 @@ class ASH_EXPORT SystemTrayNotifier {
base::ObserverList<EnterpriseDomainObserver> enterprise_domain_observers_;
base::ObserverList<LastWindowClosedObserver> last_window_closed_observers_;
base::ObserverList<LogoutButtonObserver> logout_button_observers_;
base::ObserverList<MediaCaptureObserver> media_capture_observers_;
base::ObserverList<NetworkObserver> network_observers_;
base::ObserverList<NetworkPortalDetectorObserver>
network_portal_detector_observers_;
......
......@@ -7,12 +7,13 @@
#include <algorithm>
#include <vector>
#include "ash/common/ash_view_ids.h"
#include "ash/common/login_status.h"
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/media_controller.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/system/tray/system_tray_controller.h"
#include "ash/common/system/tray/system_tray_delegate.h"
#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_popup_item_style.h"
#include "ash/common/system/tray/tray_utils.h"
......@@ -48,11 +49,6 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#if defined(OS_CHROMEOS)
#include "ash/common/ash_view_ids.h"
#include "ash/common/media_delegate.h"
#endif
namespace ash {
namespace tray {
......@@ -93,7 +89,6 @@ views::View* CreateUserAvatarView(LoginStatus login_status, int user_index) {
return image_view;
}
#if defined(OS_CHROMEOS)
class MediaIndicator : public views::View, public MediaCaptureObserver {
public:
explicit MediaIndicator(UserIndex index)
......@@ -108,31 +103,37 @@ class MediaIndicator : public views::View, public MediaCaptureObserver {
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
ui::ResourceBundle::SmallFont));
OnMediaCaptureChanged();
WmShell::Get()->system_tray_notifier()->AddMediaCaptureObserver(this);
WmShell::Get()->media_controller()->AddObserver(this);
SetVisible(false);
WmShell::Get()->media_controller()->RequestCaptureState();
set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR);
}
~MediaIndicator() override {
WmShell::Get()->system_tray_notifier()->RemoveMediaCaptureObserver(this);
WmShell::Get()->media_controller()->RemoveObserver(this);
}
// MediaCaptureObserver:
void OnMediaCaptureChanged() override {
MediaCaptureState state =
WmShell::Get()->media_delegate()->GetMediaCaptureState(index_);
void OnMediaCaptureChanged(
const std::vector<mojom::MediaCaptureState>& capture_states) override {
if (static_cast<size_t>(index_) >= capture_states.size()) {
NOTREACHED();
return;
}
mojom::MediaCaptureState state = capture_states[index_];
int res_id = 0;
switch (state) {
case MEDIA_CAPTURE_AUDIO_VIDEO:
case mojom::MediaCaptureState::AUDIO_VIDEO:
res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO_VIDEO;
break;
case MEDIA_CAPTURE_AUDIO:
case mojom::MediaCaptureState::AUDIO:
res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO;
break;
case MEDIA_CAPTURE_VIDEO:
case mojom::MediaCaptureState::VIDEO:
res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_VIDEO;
break;
case MEDIA_CAPTURE_NONE:
case mojom::MediaCaptureState::NONE:
break;
}
SetMessage(res_id ? l10n_util::GetStringUTF16(res_id) : base::string16());
......@@ -152,7 +153,6 @@ class MediaIndicator : public views::View, public MediaCaptureObserver {
DISALLOW_COPY_AND_ASSIGN(MediaIndicator);
};
#endif
// The user details shown in public account mode. This is essentially a label
// but with custom painting code as the text is styled with multiple colors and
......@@ -389,9 +389,7 @@ UserCardView::UserCardView(LoginStatus login_status,
views::CreateEmptyBorder(0, kMenuExtraMarginFromLeftEdge, 0, 0));
}
#if defined(OS_CHROMEOS)
WmShell::Get()->system_tray_notifier()->AddMediaCaptureObserver(this);
#endif
WmShell::Get()->media_controller()->AddObserver(this);
}
if (login_status == LoginStatus::PUBLIC)
......@@ -403,10 +401,8 @@ UserCardView::UserCardView(LoginStatus login_status,
}
UserCardView::~UserCardView() {
#if defined(OS_CHROMEOS)
if (UseMd())
WmShell::Get()->system_tray_notifier()->RemoveMediaCaptureObserver(this);
#endif
WmShell::Get()->media_controller()->RemoveObserver(this);
}
void UserCardView::PaintChildren(const ui::PaintContext& context) {
......@@ -426,25 +422,24 @@ void UserCardView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetName(base::JoinString(labels, base::ASCIIToUTF16(" ")));
}
void UserCardView::OnMediaCaptureChanged() {
#if defined(OS_CHROMEOS)
void UserCardView::OnMediaCaptureChanged(
const std::vector<mojom::MediaCaptureState>& capture_states) {
if (is_active_user())
return;
MediaCaptureState state =
WmShell::Get()->media_delegate()->GetMediaCaptureState(user_index_);
mojom::MediaCaptureState state = capture_states[user_index_];
int res_id = 0;
switch (state) {
case MEDIA_CAPTURE_AUDIO_VIDEO:
case mojom::MediaCaptureState::AUDIO_VIDEO:
res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO_VIDEO;
break;
case MEDIA_CAPTURE_AUDIO:
case mojom::MediaCaptureState::AUDIO:
res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_AUDIO;
break;
case MEDIA_CAPTURE_VIDEO:
case mojom::MediaCaptureState::VIDEO:
res_id = IDS_ASH_STATUS_TRAY_MEDIA_RECORDING_VIDEO;
break;
case MEDIA_CAPTURE_NONE:
case mojom::MediaCaptureState::NONE:
break;
}
if (res_id)
......@@ -453,7 +448,6 @@ void UserCardView::OnMediaCaptureChanged() {
media_capture_icon_->SetVisible(!!res_id);
user_name_->SetVisible(!res_id);
Layout();
#endif
}
void UserCardView::AddPublicModeUserContent(int max_width) {
......@@ -520,7 +514,6 @@ void UserCardView::AddUserContent(LoginStatus login_status) {
if (user_name)
AddChildView(user_name);
if (user_email) {
#if defined(OS_CHROMEOS)
// Only non active user can have a media indicator.
MediaIndicator* media_indicator = new MediaIndicator(user_index_);
views::View* email_indicator_view = new views::View;
......@@ -535,9 +528,6 @@ void UserCardView::AddUserContent(LoginStatus login_status) {
details->AddChildView(email_indicator_view);
details->AddChildView(media_indicator->GetMessageView());
AddChildView(details);
#else
AddChildView(user_email);
#endif
}
}
}
......@@ -609,12 +599,11 @@ void UserCardView::AddUserContentMd(views::BoxLayout* layout,
gfx::Insets(0, (media_capture_width -
media_capture_icon_->GetPreferredSize().width()) /
2)));
#if defined(OS_CHROMEOS)
media_capture_icon_->set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR);
#endif
AddChildView(media_capture_icon_);
OnMediaCaptureChanged();
WmShell::Get()->media_controller()->RequestCaptureState();
}
}
......
......@@ -5,7 +5,7 @@
#ifndef ASH_COMMON_SYSTEM_USER_USER_CARD_VIEW_H_
#define ASH_COMMON_SYSTEM_USER_USER_CARD_VIEW_H_
#include "ash/common/system/chromeos/media_security/media_capture_observer.h"
#include "ash/common/media_controller.h"
#include "base/macros.h"
#include "ui/views/view.h"
......@@ -34,7 +34,8 @@ class UserCardView : public views::View, public MediaCaptureObserver {
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// MediaCaptureObserver:
void OnMediaCaptureChanged() override;
void OnMediaCaptureChanged(
const std::vector<mojom::MediaCaptureState>& capture_states) override;
private:
// Creates the content for the public mode.
......
......@@ -14,6 +14,7 @@
#include "ash/common/devtools/ash_devtools_dom_agent.h"
#include "ash/common/focus_cycler.h"
#include "ash/common/keyboard/keyboard_ui.h"
#include "ash/common/media_controller.h"
#include "ash/common/new_window_controller.h"
#include "ash/common/palette_delegate.h"
#include "ash/common/session/session_controller.h"
......@@ -80,7 +81,6 @@ void WmShell::Initialize(const scoped_refptr<base::SequencedWorkerPool>& pool) {
// Some delegates access WmShell during their construction. Create them here
// instead of the WmShell constructor.
accessibility_delegate_.reset(delegate_->CreateAccessibilityDelegate());
media_delegate_.reset(delegate_->CreateMediaDelegate());
palette_delegate_ = delegate_->CreatePaletteDelegate();
toast_manager_.reset(new ToastManager);
......@@ -256,6 +256,7 @@ WmShell::WmShell(std::unique_ptr<ShellDelegate> shell_delegate)
immersive_context_(base::MakeUnique<ImmersiveContextAsh>()),
locale_notification_controller_(
base::MakeUnique<LocaleNotificationController>()),
media_controller_(base::MakeUnique<MediaController>()),
new_window_controller_(base::MakeUnique<NewWindowController>()),
session_controller_(base::MakeUnique<SessionController>()),
shelf_controller_(base::MakeUnique<ShelfController>()),
......
......@@ -11,7 +11,6 @@
#include <vector>
#include "ash/ash_export.h"
#include "ash/common/media_delegate.h"
#include "ash/common/metrics/gesture_action_type.h"
#include "ash/common/metrics/user_metrics_action.h"
#include "ash/common/wm/lock_state_observer.h"
......@@ -57,6 +56,7 @@ class KeyboardBrightnessControlDelegate;
class KeyboardUI;
class LocaleNotificationController;
class MaximizeModeController;
class MediaController;
class MruWindowTracker;
class NewWindowController;
class PaletteDelegate;
......@@ -147,7 +147,7 @@ class ASH_EXPORT WmShell {
MruWindowTracker* mru_window_tracker() { return mru_window_tracker_.get(); }
MediaDelegate* media_delegate() { return media_delegate_.get(); }
MediaController* media_controller() { return media_controller_.get(); }
NewWindowController* new_window_controller() {
return new_window_controller_.get();
......@@ -497,7 +497,7 @@ class ASH_EXPORT WmShell {
std::unique_ptr<KeyboardUI> keyboard_ui_;
std::unique_ptr<LocaleNotificationController> locale_notification_controller_;
std::unique_ptr<MaximizeModeController> maximize_mode_controller_;
std::unique_ptr<MediaDelegate> media_delegate_;
std::unique_ptr<MediaController> media_controller_;
std::unique_ptr<MruWindowTracker> mru_window_tracker_;
std::unique_ptr<NewWindowController> new_window_controller_;
std::unique_ptr<PaletteDelegate> palette_delegate_;
......
......@@ -11,6 +11,7 @@
"ash::mojom::AcceleratorController",
"ash::mojom::CastConfig",
"ash::mojom::LocaleNotificationController",
"ash::mojom::MediaController",
"ash::mojom::NewWindowController",
"ash::mojom::SessionController",
"ash::mojom::ShelfController",
......
......@@ -7,7 +7,6 @@
#include <utility>
#include "ash/common/gpu_support_stub.h"
#include "ash/common/media_delegate.h"
#include "ash/common/palette_delegate.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/wm_shell.h"
......@@ -88,24 +87,6 @@ class SessionStateDelegateStub : public SessionStateDelegate {
DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateStub);
};
class MediaDelegateStub : public MediaDelegate {
public:
MediaDelegateStub() {}
~MediaDelegateStub() override {}
// MediaDelegate:
void HandleMediaNextTrack() override { NOTIMPLEMENTED(); }
void HandleMediaPlayPause() override { NOTIMPLEMENTED(); }
void HandleMediaPrevTrack() override { NOTIMPLEMENTED(); }
MediaCaptureState GetMediaCaptureState(UserIndex index) override {
NOTIMPLEMENTED();
return MEDIA_CAPTURE_NONE;
}
private:
DISALLOW_COPY_AND_ASSIGN(MediaDelegateStub);
};
} // namespace
ShellDelegateMus::ShellDelegateMus(service_manager::Connector* connector)
......@@ -197,12 +178,6 @@ AccessibilityDelegate* ShellDelegateMus::CreateAccessibilityDelegate() {
return new AccessibilityDelegateMus(connector_);
}
MediaDelegate* ShellDelegateMus::CreateMediaDelegate() {
// TODO: http://crbug.com/647409.
NOTIMPLEMENTED() << " Using a stub MediaDelegate implementation";
return new MediaDelegateStub;
}
std::unique_ptr<PaletteDelegate> ShellDelegateMus::CreatePaletteDelegate() {
// TODO: http://crbug.com/647417.
NOTIMPLEMENTED();
......
......@@ -40,7 +40,6 @@ class ShellDelegateMus : public ShellDelegate {
std::unique_ptr<WallpaperDelegate> CreateWallpaperDelegate() override;
SessionStateDelegate* CreateSessionStateDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
MediaDelegate* CreateMediaDelegate() override;
std::unique_ptr<PaletteDelegate> CreatePaletteDelegate() override;
ui::MenuModel* CreateContextMenu(WmShelf* wm_shelf,
const ShelfItem* item) override;
......
......@@ -10,6 +10,7 @@ mojom("interfaces") {
"ash_window_type.mojom",
"cast_config.mojom",
"locale.mojom",
"media.mojom",
"new_window.mojom",
"session_controller.mojom",
"shelf.mojom",
......
// 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.
module ash.mojom;
// Describes whether media is currently being captured.
enum MediaCaptureState {
NONE = 0,
AUDIO = 1,
VIDEO = 2,
AUDIO_VIDEO = 3
};
// Allows clients (e.g. Chrome browser) to interface with the ash media
// indicators.
interface MediaController {
// Sets the client interface.
SetClient(associated MediaClient client);
// Called when the media capture state changes on the client, or in response
// to a RequestCaptureState() request. Returns an array of MediaCaptureState
// by index of the shell content. (These indexes are unstable, but are
// unlikely to change in practice, see comments in chrome's MediaClient::
// RequestCaptureState()).
NotifyCaptureState(array<MediaCaptureState> state);
};
// This delegate allows the UI code in ash to forward UI commands.
interface MediaClient {
// Handles the Next Track Media shortcut key.
HandleMediaNextTrack();
// Handles the Play/Pause Toggle Media shortcut key.
HandleMediaPlayPause();
// Handles the Previous Track Media shortcut key.
HandleMediaPrevTrack();
// Requests that the client resends the NotifyMediaCaptureChanged() message.
RequestCaptureState();
};
......@@ -8,7 +8,6 @@
#include "ash/common/accessibility_delegate.h"
#include "ash/common/default_accessibility_delegate.h"
#include "ash/common/gpu_support_stub.h"
#include "ash/common/media_delegate.h"
#include "ash/common/palette_delegate.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/system/tray/default_system_tray_delegate.h"
......@@ -36,23 +35,6 @@ namespace ash {
namespace shell {
namespace {
class MediaDelegateImpl : public MediaDelegate {
public:
MediaDelegateImpl() {}
~MediaDelegateImpl() override {}
// MediaDelegate:
void HandleMediaNextTrack() override {}
void HandleMediaPlayPause() override {}
void HandleMediaPrevTrack() override {}
MediaCaptureState GetMediaCaptureState(UserIndex index) override {
return MEDIA_CAPTURE_VIDEO;
}
private:
DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
};
class PaletteDelegateImpl : public PaletteDelegate {
public:
PaletteDelegateImpl() {}
......@@ -239,10 +221,6 @@ AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
return new DefaultAccessibilityDelegate;
}
MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
return new MediaDelegateImpl;
}
std::unique_ptr<PaletteDelegate> ShellDelegateImpl::CreatePaletteDelegate() {
return base::MakeUnique<PaletteDelegateImpl>();
}
......
......@@ -46,7 +46,6 @@ class ShellDelegateImpl : public ShellDelegate {
std::unique_ptr<WallpaperDelegate> CreateWallpaperDelegate() override;
SessionStateDelegate* CreateSessionStateDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
MediaDelegate* CreateMediaDelegate() override;
std::unique_ptr<PaletteDelegate> CreatePaletteDelegate() override;
ui::MenuModel* CreateContextMenu(WmShelf* wm_shelf,
const ShelfItem* item) override;
......
......@@ -10,7 +10,6 @@
#include "ash/app_list/app_list_presenter_delegate_factory.h"
#include "ash/common/default_accessibility_delegate.h"
#include "ash/common/gpu_support_stub.h"
#include "ash/common/media_delegate.h"
#include "ash/common/palette_delegate.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/test/test_session_state_delegate.h"
......@@ -38,27 +37,6 @@ namespace ash {
namespace test {
namespace {
class MediaDelegateImpl : public MediaDelegate {
public:
MediaDelegateImpl() : state_(MEDIA_CAPTURE_NONE) {}
~MediaDelegateImpl() override {}
void set_media_capture_state(MediaCaptureState state) { state_ = state; }
private:
// MediaDelegate:
void HandleMediaNextTrack() override {}
void HandleMediaPlayPause() override {}
void HandleMediaPrevTrack() override {}
MediaCaptureState GetMediaCaptureState(UserIndex index) override {
return state_;
}
MediaCaptureState state_;
DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
};
class AppListViewDelegateFactoryImpl
: public app_list::AppListViewDelegateFactory {
public:
......@@ -159,10 +137,6 @@ AccessibilityDelegate* TestShellDelegate::CreateAccessibilityDelegate() {
return new DefaultAccessibilityDelegate();
}
MediaDelegate* TestShellDelegate::CreateMediaDelegate() {
return new MediaDelegateImpl;
}
std::unique_ptr<PaletteDelegate> TestShellDelegate::CreatePaletteDelegate() {
return nullptr;
}
......@@ -198,13 +172,5 @@ void TestShellDelegate::SetTouchscreenEnabledInPrefs(bool enabled,
void TestShellDelegate::UpdateTouchscreenStatusFromPrefs() {}
void TestShellDelegate::SetMediaCaptureState(MediaCaptureState state) {
#if defined(OS_CHROMEOS)
static_cast<MediaDelegateImpl*>(WmShell::Get()->media_delegate())
->set_media_capture_state(state);
WmShell::Get()->system_tray_notifier()->NotifyMediaCaptureChanged();
#endif
}
} // namespace test
} // namespace ash
......@@ -8,7 +8,6 @@
#include <memory>
#include <string>
#include "ash/common/media_delegate.h"
#include "ash/common/shell_delegate.h"
#include "ash/common/test/test_session_state_delegate.h"
#include "base/macros.h"
......@@ -52,7 +51,6 @@ class TestShellDelegate : public ShellDelegate {
std::unique_ptr<WallpaperDelegate> CreateWallpaperDelegate() override;
TestSessionStateDelegate* CreateSessionStateDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
MediaDelegate* CreateMediaDelegate() override;
std::unique_ptr<PaletteDelegate> CreatePaletteDelegate() override;
ui::MenuModel* CreateContextMenu(WmShelf* wm_shelf,
const ShelfItem* item) override;
......@@ -71,7 +69,6 @@ class TestShellDelegate : public ShellDelegate {
return app_list_presenter_.get();
}
void SetMediaCaptureState(MediaCaptureState state);
void SetForceMaximizeOnFirstRun(bool maximize) {
force_maximize_on_first_run_ = maximize;
}
......
......@@ -24,6 +24,7 @@
"ash::mojom::AcceleratorController",
"ash::mojom::CastConfig",
"ash::mojom::LocaleNotificationController",
"ash::mojom::MediaController",
"ash::mojom::NewWindowController",
"ash::mojom::SessionController",
"ash::mojom::ShelfController",
......
......@@ -1364,8 +1364,8 @@ split_static_library("ui") {
"ash/launcher/multi_profile_browser_status_monitor.h",
"ash/launcher/settings_window_observer.cc",
"ash/launcher/settings_window_observer.h",
"ash/media_delegate_chromeos.cc",
"ash/media_delegate_chromeos.h",
"ash/media_client.cc",
"ash/media_client.h",
"ash/multi_user/multi_user_context_menu.h",
"ash/multi_user/multi_user_context_menu_chromeos.cc",
"ash/multi_user/multi_user_notification_blocker_chromeos.cc",
......
......@@ -29,7 +29,6 @@
#include "components/sessions/core/tab_restore_service_observer.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "services/service_manager/public/cpp/connector.h"
......
......@@ -49,7 +49,6 @@
#include "chrome/browser/ui/ash/chrome_keyboard_ui.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
#include "chrome/browser/ui/ash/media_delegate_chromeos.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/palette_delegate_chromeos.h"
#include "chrome/browser/ui/ash/session_state_delegate_chromeos.h"
......@@ -533,10 +532,6 @@ ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
return new AccessibilityDelegateImpl;
}
ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
return new MediaDelegateChromeOS;
}
std::unique_ptr<ash::PaletteDelegate>
ChromeShellDelegate::CreatePaletteDelegate() {
return chromeos::PaletteDelegateChromeOS::Create();
......
......@@ -48,7 +48,6 @@ class ChromeShellDelegate : public ash::ShellDelegate,
std::unique_ptr<ash::WallpaperDelegate> CreateWallpaperDelegate() override;
ash::SessionStateDelegate* CreateSessionStateDelegate() override;
ash::AccessibilityDelegate* CreateAccessibilityDelegate() override;
ash::MediaDelegate* CreateMediaDelegate() override;
std::unique_ptr<ash::PaletteDelegate> CreatePaletteDelegate() override;
ui::MenuModel* CreateContextMenu(ash::WmShelf* wm_shelf,
const ash::ShelfItem* item) override;
......
......@@ -2,25 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_MEDIA_DELEGATE_CHROMEOS_H_
#define CHROME_BROWSER_UI_ASH_MEDIA_DELEGATE_CHROMEOS_H_
#ifndef CHROME_BROWSER_UI_ASH_MEDIA_CLIENT_H_
#define CHROME_BROWSER_UI_ASH_MEDIA_CLIENT_H_
#include "ash/common/media_delegate.h"
#include "ash/public/interfaces/media.mojom.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
class MediaDelegateChromeOS : public ash::MediaDelegate,
MediaCaptureDevicesDispatcher::Observer {
class MediaClient : public ash::mojom::MediaClient,
MediaCaptureDevicesDispatcher::Observer {
public:
MediaDelegateChromeOS();
~MediaDelegateChromeOS() override;
MediaClient();
~MediaClient() override;
// ash::MediaDelegate:
// ash::MediaClient:
void HandleMediaNextTrack() override;
void HandleMediaPlayPause() override;
void HandleMediaPrevTrack() override;
ash::MediaCaptureState GetMediaCaptureState(ash::UserIndex index) override;
void RequestCaptureState() override;
// MediaCaptureDevicesDispatcher::Observer:
void OnRequestUpdate(int render_process_id,
......@@ -29,11 +30,18 @@ class MediaDelegateChromeOS : public ash::MediaDelegate,
const content::MediaRequestState state) override;
private:
void NotifyMediaCaptureChange();
// Returns the media capture state for the current user at
// |user_index|. (Note that this isn't stable, see implementation comment on
// RequestCaptureState()).
ash::mojom::MediaCaptureState GetMediaCaptureStateByIndex(int user_index);
base::WeakPtrFactory<MediaDelegateChromeOS> weak_ptr_factory_;
ash::mojom::MediaControllerPtr media_controller_;
DISALLOW_COPY_AND_ASSIGN(MediaDelegateChromeOS);
mojo::AssociatedBinding<ash::mojom::MediaClient> binding_;
base::WeakPtrFactory<MediaClient> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(MediaClient);
};
#endif // CHROME_BROWSER_UI_ASH_MEDIA_DELEGATE_CHROMEOS_H_
#endif // CHROME_BROWSER_UI_ASH_MEDIA_CLIENT_H_
......@@ -5,9 +5,9 @@
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
#include "ash/aura/wm_window_aura.h"
#include "ash/common/media_controller.h"
#include "ash/common/multi_profile_uma.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/common/wm/window_state.h"
#include "ash/common/wm_shell.h"
......@@ -445,7 +445,7 @@ void MultiUserWindowManagerChromeOS::ActiveUserChanged(
this, account_id, GetAdjustedAnimationTimeInMS(kUserFadeTimeMS)));
// Call notifier here instead of observing ActiveUserChanged because
// this must happen after MultiUserWindowManagerChromeOS is notified.
ash::WmShell::Get()->system_tray_notifier()->NotifyMediaCaptureChanged();
ash::WmShell::Get()->media_controller()->RequestCaptureState();
}
void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) {
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/ui/ash/cast_config_client_media_router.h"
#include "chrome/browser/ui/ash/chrome_new_window_client.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_mus.h"
#include "chrome/browser/ui/ash/media_client.h"
#include "chrome/browser/ui/views/ash/tab_scrubber.h"
#include "chrome/browser/ui/views/frame/immersive_context_mus.h"
#include "chrome/browser/ui/views/frame/immersive_handler_factory_mus.h"
......@@ -78,6 +79,7 @@ void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
cast_config_client_media_router_ =
base::MakeUnique<CastConfigClientMediaRouter>();
media_client_ = base::MakeUnique<MediaClient>();
if (!ash::Shell::HasInstance())
return;
......@@ -96,6 +98,7 @@ void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {
volume_controller_.reset();
new_window_client_.reset();
system_tray_client_.reset();
media_client_.reset();
cast_config_client_media_router_.reset();
session_controller_client_.reset();
#endif
......
......@@ -15,6 +15,7 @@ class ChromeLauncherControllerMus;
class ChromeNewWindowClient;
class ImmersiveContextMus;
class ImmersiveHandlerFactoryMus;
class MediaClient;
class SessionControllerClient;
class SystemTrayClient;
class VolumeController;
......@@ -33,6 +34,7 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts {
private:
std::unique_ptr<ChromeLauncherControllerMus> chrome_launcher_controller_mus_;
std::unique_ptr<CastConfigClientMediaRouter> cast_config_client_media_router_;
std::unique_ptr<MediaClient> media_client_;
std::unique_ptr<ImmersiveHandlerFactoryMus> immersive_handler_factory_;
std::unique_ptr<ImmersiveContextMus> immersive_context_;
std::unique_ptr<SessionControllerClient> session_controller_client_;
......
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