Skip to content

Commit

Permalink
Introduce MediaDelegate
Browse files Browse the repository at this point in the history
BUG=none

Review URL: https://codereview.chromium.org/48523010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232330 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Nov 1, 2013
1 parent b6bd591 commit efc897f
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 68 deletions.
7 changes: 4 additions & 3 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ash/launcher/launcher_model.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/magnifier/partial_magnification_controller.h"
#include "ash/media_delegate.h"
#include "ash/multi_profile_uma.h"
#include "ash/new_window_delegate.h"
#include "ash/root_window_controller.h"
Expand Down Expand Up @@ -313,17 +314,17 @@ bool HandleMagnifyScreen(int delta_index) {
}

bool HandleMediaNextTrack() {
Shell::GetInstance()->delegate()->HandleMediaNextTrack();
Shell::GetInstance()->media_delegate()->HandleMediaNextTrack();
return true;
}

bool HandleMediaPlayPause() {
Shell::GetInstance()->delegate()->HandleMediaPlayPause();
Shell::GetInstance()->media_delegate()->HandleMediaPlayPause();
return true;
}

bool HandleMediaPrevTrack() {
Shell::GetInstance()->delegate()->HandleMediaPrevTrack();
Shell::GetInstance()->media_delegate()->HandleMediaPrevTrack();
return true;
}

Expand Down
1 change: 0 additions & 1 deletion ash/accessibility_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum AccessibilityNotificationVisibility {
// A deletate class to control accessibility features.
class ASH_EXPORT AccessibilityDelegate {
public:
AccessibilityDelegate() {}
virtual ~AccessibilityDelegate() {}

// Invoked to toggle spoken feedback for accessibility
Expand Down
27 changes: 27 additions & 0 deletions ash/media_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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_MEDIA_DELEGATE_H_
#define ASH_MEDIA_DELEGATE_H_

namespace ash {

// 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;
};

} // namespace ash

#endif // ASH_MEDIA_DELEGATE_H_
1 change: 0 additions & 1 deletion ash/new_window_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace ash {
// ash.
class NewWindowDelegate {
public:
NewWindowDelegate() {}
virtual ~NewWindowDelegate() {}

// Invoked when the user uses Ctrl+T to open a new tab.
Expand Down
4 changes: 4 additions & 0 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ash/launcher/launcher_model_util.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/magnifier/partial_magnification_controller.h"
#include "ash/media_delegate.h"
#include "ash/new_window_delegate.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
Expand Down Expand Up @@ -665,6 +666,8 @@ Shell::~Shell() {

keyboard_controller_.reset();
accessibility_delegate_.reset();
new_window_delegate_.reset();
media_delegate_.reset();

#if defined(OS_CHROMEOS) && defined(USE_X11)
if (display_change_observer_)
Expand Down Expand Up @@ -842,6 +845,7 @@ void Shell::Init() {
session_state_delegate_.reset(delegate_->CreateSessionStateDelegate());
accessibility_delegate_.reset(delegate_->CreateAccessibilityDelegate());
new_window_delegate_.reset(delegate_->CreateNewWindowDelegate());
media_delegate_.reset(delegate_->CreateMediaDelegate());

if (!command_line->HasSwitch(views::corewm::switches::kNoDropShadows)) {
resize_shadow_controller_.reset(new internal::ResizeShadowController());
Expand Down
6 changes: 6 additions & 0 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class LauncherItemDelegateManager;
class LauncherModel;
class LockStateController;
class MagnificationController;
class MediaDelegate;
class MruWindowTracker;
class NestedDispatcherController;
class NewWindowDelegate;
Expand Down Expand Up @@ -377,6 +378,10 @@ class ASH_EXPORT Shell
return new_window_delegate_.get();
}

MediaDelegate* media_delegate() {
return media_delegate_.get();
}

HighContrastController* high_contrast_controller() {
return high_contrast_controller_.get();
}
Expand Down Expand Up @@ -586,6 +591,7 @@ class ASH_EXPORT Shell
scoped_ptr<SessionStateDelegate> session_state_delegate_;
scoped_ptr<AccessibilityDelegate> accessibility_delegate_;
scoped_ptr<NewWindowDelegate> new_window_delegate_;
scoped_ptr<MediaDelegate> media_delegate_;
scoped_ptr<LauncherDelegate> launcher_delegate_;
scoped_ptr<LauncherItemDelegateManager> launcher_item_delegate_manager_;

Expand Down
27 changes: 18 additions & 9 deletions ash/shell/shell_delegate_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ash/default_user_wallpaper_delegate.h"
#include "ash/host/root_window_host_factory.h"
#include "ash/keyboard_controller_proxy_stub.h"
#include "ash/media_delegate.h"
#include "ash/new_window_delegate.h"
#include "ash/session_state_delegate.h"
#include "ash/session_state_delegate_stub.h"
Expand Down Expand Up @@ -51,6 +52,19 @@ class NewWindowDelegateImpl : public NewWindowDelegate {
DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
};

class MediaDelegateImpl : public MediaDelegate {
public:
MediaDelegateImpl() {}
virtual ~MediaDelegateImpl() {}

virtual void HandleMediaNextTrack() OVERRIDE {}
virtual void HandleMediaPlayPause() OVERRIDE {}
virtual void HandleMediaPrevTrack() OVERRIDE {}

private:
DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
};

} // namespace

ShellDelegateImpl::ShellDelegateImpl()
Expand Down Expand Up @@ -136,22 +150,17 @@ ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
return new NewWindowDelegateImpl;
}

ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
return new MediaDelegateImpl;
}

aura::client::UserActionClient* ShellDelegateImpl::CreateUserActionClient() {
return NULL;
}

void ShellDelegateImpl::RecordUserMetricsAction(UserMetricsAction action) {
}

void ShellDelegateImpl::HandleMediaNextTrack() {
}

void ShellDelegateImpl::HandleMediaPlayPause() {
}

void ShellDelegateImpl::HandleMediaPrevTrack() {
}

ui::MenuModel* ShellDelegateImpl::CreateContextMenu(aura::Window* root) {
return new ContextMenu(root);
}
Expand Down
4 changes: 1 addition & 3 deletions ash/shell/shell_delegate_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual ash::SessionStateDelegate* CreateSessionStateDelegate() OVERRIDE;
virtual ash::AccessibilityDelegate* CreateAccessibilityDelegate() OVERRIDE;
virtual ash::NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE;
virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;
virtual void HandleMediaNextTrack() OVERRIDE;
virtual void HandleMediaPlayPause() OVERRIDE;
virtual void HandleMediaPrevTrack() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(
aura::Window* root_window) OVERRIDE;
virtual RootWindowHostFactory* CreateRootWindowHostFactory() OVERRIDE;
Expand Down
13 changes: 4 additions & 9 deletions ash/shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CapsLockDelegate;
class LauncherDelegate;
class LauncherModel;
struct LauncherItem;
class MediaDelegate;
class NewWindowDelegate;
class RootWindowHostFactory;
class AccessibilityDelegate;
Expand Down Expand Up @@ -168,21 +169,15 @@ class ASH_EXPORT ShellDelegate {
// Creates an application delegate. Shell takes ownership of the delegate.
virtual NewWindowDelegate* CreateNewWindowDelegate() = 0;

// Creates a media delegate. Shell takes ownership of the delegate.
virtual MediaDelegate* CreateMediaDelegate() = 0;

// Creates a user action client. Shell takes ownership of the object.
virtual aura::client::UserActionClient* CreateUserActionClient() = 0;

// Records that the user performed an action.
virtual void RecordUserMetricsAction(UserMetricsAction action) = 0;

// 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;

// Creates a menu model of the context for the |root_window|.
virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window) = 0;

Expand Down
21 changes: 12 additions & 9 deletions ash/test/test_shell_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ash/default_accessibility_delegate.h"
#include "ash/host/root_window_host_factory.h"
#include "ash/keyboard_controller_proxy_stub.h"
#include "ash/media_delegate.h"
#include "ash/new_window_delegate.h"
#include "ash/session_state_delegate.h"
#include "ash/shell.h"
Expand Down Expand Up @@ -39,6 +40,13 @@ class NewWindowDelegateImpl : public NewWindowDelegate {
virtual void OpenFeedbackPage() OVERRIDE {}
};

class MediaDelegateImpl : public MediaDelegate {
public:
virtual void HandleMediaNextTrack() OVERRIDE {}
virtual void HandleMediaPlayPause() OVERRIDE {}
virtual void HandleMediaPrevTrack() OVERRIDE {}
};

} // namespace

TestShellDelegate::TestShellDelegate()
Expand Down Expand Up @@ -121,22 +129,17 @@ NewWindowDelegate* TestShellDelegate::CreateNewWindowDelegate() {
return new NewWindowDelegateImpl;
}

MediaDelegate* TestShellDelegate::CreateMediaDelegate() {
return new MediaDelegateImpl;
}

aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() {
return NULL;
}

void TestShellDelegate::RecordUserMetricsAction(UserMetricsAction action) {
}

void TestShellDelegate::HandleMediaNextTrack() {
}

void TestShellDelegate::HandleMediaPlayPause() {
}

void TestShellDelegate::HandleMediaPrevTrack() {
}

ui::MenuModel* TestShellDelegate::CreateContextMenu(aura::Window* root) {
return NULL;
}
Expand Down
4 changes: 1 addition & 3 deletions ash/test/test_shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ class TestShellDelegate : public ShellDelegate {
virtual SessionStateDelegate* CreateSessionStateDelegate() OVERRIDE;
virtual AccessibilityDelegate* CreateAccessibilityDelegate() OVERRIDE;
virtual NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE;
virtual MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;
virtual void HandleMediaNextTrack() OVERRIDE;
virtual void HandleMediaPlayPause() OVERRIDE;
virtual void HandleMediaPrevTrack() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(aura::Window* root) OVERRIDE;
virtual RootWindowHostFactory* CreateRootWindowHostFactory() OVERRIDE;
virtual base::string16 GetProductName() const OVERRIDE;
Expand Down
4 changes: 1 addition & 3 deletions chrome/browser/ui/ash/chrome_shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual ash::SessionStateDelegate* CreateSessionStateDelegate() OVERRIDE;
virtual ash::AccessibilityDelegate* CreateAccessibilityDelegate() OVERRIDE;
virtual ash::NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE;
virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void RecordUserMetricsAction(ash::UserMetricsAction action) OVERRIDE;
virtual void HandleMediaNextTrack() OVERRIDE;
virtual void HandleMediaPlayPause() OVERRIDE;
virtual void HandleMediaPrevTrack() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(aura::Window* root) OVERRIDE;
virtual ash::RootWindowHostFactory* CreateRootWindowHostFactory() OVERRIDE;
virtual string16 GetProductName() const OVERRIDE;
Expand Down
50 changes: 32 additions & 18 deletions chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/ui/ash/chrome_shell_delegate.h"

#include "ash/accessibility_delegate.h"
#include "ash/media_delegate.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
Expand Down Expand Up @@ -145,6 +146,33 @@ class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
DISALLOW_COPY_AND_ASSIGN(AccessibilityDelegateImpl);
};

class MediaDelegateImpl : public ash::MediaDelegate {
public:
MediaDelegateImpl() {}
virtual ~MediaDelegateImpl() {}

virtual void HandleMediaNextTrack() OVERRIDE {
extensions::MediaPlayerAPI::Get(
ProfileManager::GetDefaultProfileOrOffTheRecord())->
media_player_event_router()->NotifyNextTrack();
}

virtual void HandleMediaPlayPause() OVERRIDE {
extensions::MediaPlayerAPI::Get(
ProfileManager::GetDefaultProfileOrOffTheRecord())->
media_player_event_router()->NotifyTogglePlayState();
}

virtual void HandleMediaPrevTrack() OVERRIDE {
extensions::MediaPlayerAPI::Get(
ProfileManager::GetDefaultProfileOrOffTheRecord())->
media_player_event_router()->NotifyPrevTrack();
}

private:
DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
};

} // anonymous namespace

bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
Expand Down Expand Up @@ -180,6 +208,10 @@ ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
return new ChromeNewWindowDelegateChromeos;
}

ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
return new MediaDelegateImpl;
}

ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
return chromeos::CreateSystemTrayDelegate();
}
Expand All @@ -188,24 +220,6 @@ ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
return chromeos::CreateUserWallpaperDelegate();
}

void ChromeShellDelegate::HandleMediaNextTrack() {
extensions::MediaPlayerAPI::Get(
ProfileManager::GetDefaultProfileOrOffTheRecord())->
media_player_event_router()->NotifyNextTrack();
}

void ChromeShellDelegate::HandleMediaPlayPause() {
extensions::MediaPlayerAPI::Get(
ProfileManager::GetDefaultProfileOrOffTheRecord())->
media_player_event_router()->NotifyTogglePlayState();
}

void ChromeShellDelegate::HandleMediaPrevTrack() {
extensions::MediaPlayerAPI::Get(
ProfileManager::GetDefaultProfileOrOffTheRecord())->
media_player_event_router()->NotifyPrevTrack();
}

void ChromeShellDelegate::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
Expand Down
Loading

0 comments on commit efc897f

Please sign in to comment.