summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 21:05:20 +0000
committerygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 21:05:20 +0000
commitce89d9393565d4757d9ba436a7bef9262671f3b2 (patch)
tree3f60b1ae1e26d929cf27644e9e1977f34d283e5f
parent86f438f8e442c5709e95a80bd6c1942e07b7f448 (diff)
downloadchromium_src-ce89d9393565d4757d9ba436a7bef9262671f3b2.zip
chromium_src-ce89d9393565d4757d9ba436a7bef9262671f3b2.tar.gz
chromium_src-ce89d9393565d4757d9ba436a7bef9262671f3b2.tar.bz2
Fixed sounds registration in SoundsManager.
BUG=321335 TEST=manual tests on Lumpy, media_unittests:SoundsManager* Review URL: https://codereview.chromium.org/108403003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240176 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/accessibility_delegate.h4
-rw-r--r--ash/default_accessibility_delegate.cc4
-rw-r--r--ash/default_accessibility_delegate.h1
-rw-r--r--ash/wm/lock_state_controller.cc20
-rw-r--r--chrome/browser/chromeos/accessibility/accessibility_manager.cc52
-rw-r--r--chrome/browser/chromeos/accessibility/accessibility_manager.h15
-rw-r--r--chrome/browser/chromeos/login/login_display_host_impl.cc59
-rw-r--r--chrome/browser/chromeos/login/screen_locker.cc21
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc4
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate_views.cc4
-rw-r--r--chromeos/audio/chromeos_sounds.h23
-rw-r--r--chromeos/chromeos.gyp1
-rw-r--r--media/audio/sounds/sounds_manager.cc88
-rw-r--r--media/audio/sounds/sounds_manager.h30
-rw-r--r--media/audio/sounds/sounds_manager_unittest.cc17
-rw-r--r--media/audio/sounds/test_data.h2
16 files changed, 206 insertions, 139 deletions
diff --git a/ash/accessibility_delegate.h b/ash/accessibility_delegate.h
index 7bfd5b4..0d47c38 100644
--- a/ash/accessibility_delegate.h
+++ b/ash/accessibility_delegate.h
@@ -7,6 +7,7 @@
#include "ash/ash_export.h"
#include "ash/magnifier/magnifier_constants.h"
+#include "base/time/time.h"
namespace ash {
@@ -81,6 +82,9 @@ class ASH_EXPORT AccessibilityDelegate {
// Gets the last accessibility alert that was triggered.
virtual AccessibilityAlert GetLastAccessibilityAlert() = 0;
+
+ // Initiates play of shutdown sound and returns it's duration.
+ virtual base::TimeDelta PlayShutdownSound() const = 0;
};
} // namespace ash
diff --git a/ash/default_accessibility_delegate.cc b/ash/default_accessibility_delegate.cc
index 5bce4a5..1976a89 100644
--- a/ash/default_accessibility_delegate.cc
+++ b/ash/default_accessibility_delegate.cc
@@ -93,5 +93,9 @@ AccessibilityAlert DefaultAccessibilityDelegate::GetLastAccessibilityAlert() {
return accessibility_alert_;
}
+base::TimeDelta DefaultAccessibilityDelegate::PlayShutdownSound() const {
+ return base::TimeDelta();
+}
+
} // namespace internal
} // namespace ash
diff --git a/ash/default_accessibility_delegate.h b/ash/default_accessibility_delegate.h
index 11e3c6a..3e66944 100644
--- a/ash/default_accessibility_delegate.h
+++ b/ash/default_accessibility_delegate.h
@@ -37,6 +37,7 @@ class ASH_EXPORT DefaultAccessibilityDelegate : public AccessibilityDelegate {
virtual double GetSavedScreenMagnifierScale() OVERRIDE;
virtual void TriggerAccessibilityAlert(AccessibilityAlert alert) OVERRIDE;
virtual AccessibilityAlert GetLastAccessibilityAlert() OVERRIDE;
+ virtual base::TimeDelta PlayShutdownSound() const OVERRIDE;
private:
bool spoken_feedback_enabled_;
diff --git a/ash/wm/lock_state_controller.cc b/ash/wm/lock_state_controller.cc
index d6c83f7..6c720ce 100644
--- a/ash/wm/lock_state_controller.cc
+++ b/ash/wm/lock_state_controller.cc
@@ -369,8 +369,7 @@ void LockStateController::OnPreShutdownAnimationTimeout() {
StartRealShutdownTimer(false);
}
-void LockStateController::StartRealShutdownTimer(
- bool with_animation_time) {
+void LockStateController::StartRealShutdownTimer(bool with_animation_time) {
base::TimeDelta duration =
base::TimeDelta::FromMilliseconds(kShutdownRequestDelayMs);
if (with_animation_time) {
@@ -381,20 +380,15 @@ void LockStateController::StartRealShutdownTimer(
#if defined(OS_CHROMEOS)
const AccessibilityDelegate* const delegate =
Shell::GetInstance()->accessibility_delegate();
- if (delegate->IsSpokenFeedbackEnabled()) {
- const base::TimeDelta shutdown_sound_duration = std::min(
- SoundsManager::Get()->GetDuration(SoundsManager::SOUND_SHUTDOWN),
- base::TimeDelta::FromMilliseconds(kMaxShutdownSoundDurationMs));
- duration = std::max(duration, shutdown_sound_duration);
- SoundsManager::Get()->Play(SoundsManager::SOUND_SHUTDOWN);
- }
+ base::TimeDelta sound_duration = delegate->PlayShutdownSound();
+ sound_duration =
+ std::min(sound_duration,
+ base::TimeDelta::FromMilliseconds(kMaxShutdownSoundDurationMs));
+ duration = std::max(duration, sound_duration);
#endif
real_shutdown_timer_.Start(
- FROM_HERE,
- duration,
- this,
- &LockStateController::OnRealShutdownTimeout);
+ FROM_HERE, duration, this, &LockStateController::OnRealShutdownTimeout);
}
void LockStateController::OnRealShutdownTimeout() {
diff --git a/chrome/browser/chromeos/accessibility/accessibility_manager.cc b/chrome/browser/chromeos/accessibility/accessibility_manager.cc
index 74b4eff..b981919 100644
--- a/chrome/browser/chromeos/accessibility/accessibility_manager.cc
+++ b/chrome/browser/chromeos/accessibility/accessibility_manager.cc
@@ -37,6 +37,7 @@
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
#include "chrome/common/pref_names.h"
+#include "chromeos/audio/chromeos_sounds.h"
#include "chromeos/login/login_state.h"
#include "content/public/browser/browser_accessibility_state.h"
#include "content/public/browser/browser_thread.h"
@@ -290,7 +291,8 @@ AccessibilityManager::AccessibilityManager()
autoclick_delay_ms_(ash::AutoclickController::kDefaultAutoclickDelayMs),
spoken_feedback_notification_(ash::A11Y_NOTIFICATION_NONE),
weak_ptr_factory_(this),
- should_speak_chrome_vox_announcements_on_user_screen_(true) {
+ should_speak_chrome_vox_announcements_on_user_screen_(true),
+ system_sounds_enabled_(false) {
notification_registrar_.Add(this,
chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources());
@@ -312,21 +314,15 @@ AccessibilityManager::AccessibilityManager()
GetBrailleController()->AddObserver(this);
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
- std::vector<base::StringPiece> sound_resources(
- media::SoundsManager::SOUND_COUNT);
- sound_resources[media::SoundsManager::SOUND_STARTUP] =
- bundle.GetRawDataResource(IDR_SOUND_STARTUP_WAV);
- sound_resources[media::SoundsManager::SOUND_LOCK] =
- bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV);
- sound_resources[media::SoundsManager::SOUND_UNLOCK] =
- bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV);
- sound_resources[media::SoundsManager::SOUND_SHUTDOWN] =
- bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV);
- sound_resources[media::SoundsManager::SOUND_SPOKEN_FEEDBACK_ENABLED] =
- bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV);
- sound_resources[media::SoundsManager::SOUND_SPOKEN_FEEDBACK_DISABLED] =
- bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV);
- media::SoundsManager::Get()->Initialize(sound_resources);
+ media::SoundsManager* manager = media::SoundsManager::Get();
+ manager->Initialize(SOUND_SHUTDOWN,
+ bundle.GetRawDataResource(IDR_SOUND_SHUTDOWN_WAV));
+ manager->Initialize(
+ SOUND_SPOKEN_FEEDBACK_ENABLED,
+ bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_ENABLED_WAV));
+ manager->Initialize(
+ SOUND_SPOKEN_FEEDBACK_DISABLED,
+ bundle.GetRawDataResource(IDR_SOUND_SPOKEN_FEEDBACK_DISABLED_WAV));
}
AccessibilityManager::~AccessibilityManager() {
@@ -512,8 +508,7 @@ void AccessibilityManager::LoadChromeVoxToLockScreen() {
}
void AccessibilityManager::UnloadChromeVox() {
- media::SoundsManager::Get()->Play(
- media::SoundsManager::SOUND_SPOKEN_FEEDBACK_DISABLED);
+ PlaySound(SOUND_SPOKEN_FEEDBACK_DISABLED);
if (chrome_vox_loaded_on_lock_screen_)
UnloadChromeVoxFromLockScreen();
@@ -738,6 +733,19 @@ void AccessibilityManager::SetBrailleControllerForTest(
g_braille_controller_for_test = controller;
}
+void AccessibilityManager::EnableSystemSounds(bool system_sounds_enabled) {
+ system_sounds_enabled_ = system_sounds_enabled;
+}
+
+base::TimeDelta AccessibilityManager::PlayShutdownSound() {
+ if (!IsSpokenFeedbackEnabled() || !system_sounds_enabled_)
+ return base::TimeDelta();
+ system_sounds_enabled_ = false;
+ media::SoundsManager* manager = media::SoundsManager::Get();
+ manager->Play(SOUND_SHUTDOWN);
+ return manager->GetDuration(SOUND_SHUTDOWN);
+}
+
void AccessibilityManager::UpdateChromeOSAccessibilityHistograms() {
UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSpokenFeedback",
IsSpokenFeedbackEnabled());
@@ -882,8 +890,7 @@ void AccessibilityManager::OnListenerRemoved(
void AccessibilityManager::SetUpPreLoadChromeVox(Profile* profile) {
// Do any setup work needed immediately before ChromeVox actually loads.
- media::SoundsManager::Get()->Play(
- media::SoundsManager::SOUND_SPOKEN_FEEDBACK_ENABLED);
+ PlaySound(SOUND_SPOKEN_FEEDBACK_ENABLED);
if (profile) {
extensions::ExtensionSystem::Get(profile)->
@@ -901,4 +908,9 @@ void AccessibilityManager::TearDownPostUnloadChromeVox(Profile* profile) {
}
}
+void AccessibilityManager::PlaySound(int sound_key) const {
+ if (system_sounds_enabled_)
+ media::SoundsManager::Get()->Play(sound_key);
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/accessibility/accessibility_manager.h b/chrome/browser/chromeos/accessibility/accessibility_manager.h
index d7d4f6d..e6dadbe 100644
--- a/chrome/browser/chromeos/accessibility/accessibility_manager.h
+++ b/chrome/browser/chromeos/accessibility/accessibility_manager.h
@@ -8,6 +8,7 @@
#include "ash/accessibility_delegate.h"
#include "base/memory/weak_ptr.h"
#include "base/prefs/pref_change_registrar.h"
+#include "base/time/time.h"
#include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/extensions/api/braille_display_private/braille_controller.h"
#include "chrome/browser/extensions/extension_system.h"
@@ -114,6 +115,12 @@ class AccessibilityManager : public content::NotificationObserver,
static void SetBrailleControllerForTest(
extensions::api::braille_display_private::BrailleController* controller);
+ // Enables/disables system sounds.
+ void EnableSystemSounds(bool system_sounds_enabled);
+
+ // Initiates play of shutdown sound and returns it's duration.
+ base::TimeDelta PlayShutdownSound();
+
protected:
AccessibilityManager();
virtual ~AccessibilityManager();
@@ -161,6 +168,12 @@ class AccessibilityManager : public content::NotificationObserver,
virtual void OnListenerRemoved(
const extensions::EventListenerInfo& details) OVERRIDE;
+ // Plays sound identified by |sound_key| if |system_sounds_enabled_|.
+ // |sound_key| must be an ID for sound registered by
+ // AccessibilityManager. If there is no such sound or
+ // !|system_sounds_enabled_|, sound isn't played.
+ void PlaySound(int sound_key) const;
+
// Profile which has the current a11y context.
Profile* profile_;
@@ -192,6 +205,8 @@ class AccessibilityManager : public content::NotificationObserver,
bool should_speak_chrome_vox_announcements_on_user_screen_;
+ bool system_sounds_enabled_;
+
DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
};
diff --git a/chrome/browser/chromeos/login/login_display_host_impl.cc b/chrome/browser/chromeos/login/login_display_host_impl.cc
index 648bb67..3b4148d 100644
--- a/chrome/browser/chromeos/login/login_display_host_impl.cc
+++ b/chrome/browser/chromeos/login/login_display_host_impl.cc
@@ -55,6 +55,7 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "chromeos/audio/chromeos_sounds.h"
#include "chromeos/chromeos_constants.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -228,6 +229,10 @@ void OnLanguageSwitchedCallback(
self->first_screen_name, self->startup_manifest, self->display_host);
}
+void EnableSystemSoundsForAccessibility() {
+ chromeos::AccessibilityManager::Get()->EnableSystemSounds(true);
+}
+
} // namespace
namespace chromeos {
@@ -291,15 +296,14 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& background_bounds)
bool is_registered = StartupUtils::IsDeviceRegistered();
bool zero_delay_enabled = WizardController::IsZeroDelayEnabled();
- bool disable_boot_animation = CommandLine::ForCurrentProcess()->
- HasSwitch(switches::kDisableBootAnimation);
- bool disable_oobe_animation = CommandLine::ForCurrentProcess()->
- HasSwitch(switches::kDisableOobeAnimation);
+ bool disable_boot_animation = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableBootAnimation);
+ bool disable_oobe_animation = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableOobeAnimation);
- waiting_for_wallpaper_load_ =
- !zero_delay_enabled &&
- (is_registered || !disable_oobe_animation) &&
- (!is_registered || !disable_boot_animation);
+ waiting_for_wallpaper_load_ = !zero_delay_enabled &&
+ (is_registered || !disable_oobe_animation) &&
+ (!is_registered || !disable_boot_animation);
// For slower hardware we have boot animation disabled so
// we'll be initializing WebUI hidden, waiting for user pods to load and then
@@ -311,8 +315,9 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& background_bounds)
// Check if WebUI init type is overriden.
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshWebUIInit)) {
- const std::string override_type = CommandLine::ForCurrentProcess()->
- GetSwitchValueASCII(switches::kAshWebUIInit);
+ const std::string override_type =
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kAshWebUIInit);
if (override_type == kWebUIInitParallel)
initialize_webui_hidden_ = true;
else if (override_type == kWebUIInitPostpone)
@@ -329,17 +334,20 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& background_bounds)
initialize_webui_hidden_ = false;
if (waiting_for_wallpaper_load_) {
- registrar_.Add(this, chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
+ registrar_.Add(this,
+ chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
content::NotificationService::AllSources());
}
// When we wait for WebUI to be initialized we wait for one of
// these notifications.
- if ((waiting_for_user_pods_ || waiting_for_wallpaper_load_)
- && initialize_webui_hidden_) {
- registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
+ if ((waiting_for_user_pods_ || waiting_for_wallpaper_load_) &&
+ initialize_webui_hidden_) {
+ registrar_.Add(this,
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
content::NotificationService::AllSources());
- registrar_.Add(this, chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN,
+ registrar_.Add(this,
+ chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN,
content::NotificationService::AllSources());
}
LOG(WARNING) << "Login WebUI >> "
@@ -347,6 +355,11 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& background_bounds)
<< " wait_for_wp_load_: " << waiting_for_wallpaper_load_
<< " wait_for_pods_: " << waiting_for_user_pods_
<< " init_webui_hidden_: " << initialize_webui_hidden_;
+
+ media::SoundsManager* manager = media::SoundsManager::Get();
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ manager->Initialize(chromeos::SOUND_STARTUP,
+ bundle.GetRawDataResource(IDR_SOUND_STARTUP_WAV));
}
LoginDisplayHostImpl::~LoginDisplayHostImpl() {
@@ -373,7 +386,7 @@ LoginDisplayHostImpl::~LoginDisplayHostImpl() {
// TODO(tengs): This should be refactored together with the first run UI.
// See crbug.com/314934.
if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableDriveOfflineFirstRun)) {
+ switches::kEnableDriveOfflineFirstRun)) {
if (UserManager::Get()->IsCurrentUserNew()) {
// DriveOptInController will delete itself when finished.
(new DriveFirstRunController())->EnableOfflineMode();
@@ -1024,10 +1037,18 @@ void LoginDisplayHostImpl::TryToPlayStartupSound() {
return;
}
+ AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
+ media::SoundsManager* sounds_manager = media::SoundsManager::Get();
+ startup_sound_played_ = true;
if (!startup_sound_honors_spoken_feedback_ ||
- chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) {
- startup_sound_played_ = true;
- media::SoundsManager::Get()->Play(media::SoundsManager::SOUND_STARTUP);
+ accessibility_manager->IsSpokenFeedbackEnabled()) {
+ sounds_manager->Play(SOUND_STARTUP);
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&EnableSystemSoundsForAccessibility),
+ sounds_manager->GetDuration(SOUND_STARTUP));
+ } else {
+ accessibility_manager->EnableSystemSounds(true);
}
}
diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc
index 77eee09..6397050 100644
--- a/chrome/browser/chromeos/login/screen_locker.cc
+++ b/chrome/browser/chromeos/login/screen_locker.cc
@@ -37,14 +37,17 @@
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/common/chrome_switches.h"
+#include "chromeos/audio/chromeos_sounds.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h"
+#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
#include "media/audio/sounds/sounds_manager.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
#include "url/gurl.h"
using content::BrowserThread;
@@ -133,9 +136,9 @@ class ScreenLockObserver : public chromeos::SessionManagerClient::Observer,
DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver);
};
-void PlaySound(media::SoundsManager::Sound sound) {
+void PlaySound(int sound_key) {
if (chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled())
- media::SoundsManager::Get()->Play(sound);
+ media::SoundsManager::Get()->Play(sound_key);
}
static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer =
@@ -161,9 +164,17 @@ ScreenLocker::ScreenLocker(const UserList& users)
DCHECK(!screen_locker_);
screen_locker_ = this;
- ash::Shell::GetInstance()->lock_state_controller()->
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ media::SoundsManager* manager = media::SoundsManager::Get();
+ manager->Initialize(SOUND_LOCK,
+ bundle.GetRawDataResource(IDR_SOUND_LOCK_WAV));
+ manager->Initialize(SOUND_UNLOCK,
+ bundle.GetRawDataResource(IDR_SOUND_UNLOCK_WAV));
+
+ ash::Shell::GetInstance()->
+ lock_state_controller()->
SetLockScreenDisplayedCallback(
- base::Bind(&PlaySound, media::SoundsManager::SOUND_LOCK));
+ base::Bind(&PlaySound, static_cast<int>(chromeos::SOUND_LOCK)));
}
void ScreenLocker::Init() {
@@ -383,7 +394,7 @@ void ScreenLocker::ScheduleDeletion() {
return;
VLOG(1) << "Deleting ScreenLocker " << screen_locker_;
- PlaySound(media::SoundsManager::SOUND_UNLOCK);
+ PlaySound(SOUND_UNLOCK);
delete screen_locker_;
screen_locker_ = NULL;
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc
index f83e204..d2a0317 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc
@@ -167,6 +167,10 @@ class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
return ash::A11Y_ALERT_NONE;
}
+ virtual base::TimeDelta PlayShutdownSound() const OVERRIDE {
+ return chromeos::AccessibilityManager::Get()->PlayShutdownSound();
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(AccessibilityDelegateImpl);
};
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc
index 3e12d75..b415956 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc
+++ b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc
@@ -131,6 +131,10 @@ class EmptyAccessibilityDelegate : public ash::AccessibilityDelegate {
return ash::A11Y_ALERT_NONE;
}
+ base::TimeDelta PlayShutdownSound() const OVERRIDE {
+ return base::TimeDelta();
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate);
};
diff --git a/chromeos/audio/chromeos_sounds.h b/chromeos/audio/chromeos_sounds.h
new file mode 100644
index 0000000..f9b19bd
--- /dev/null
+++ b/chromeos/audio/chromeos_sounds.h
@@ -0,0 +1,23 @@
+// 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 CHROMEOS_AUDIO_CHROMEOS_SOUNDS_H_
+#define CHROMEOS_AUDIO_CHROMEOS_SOUNDS_H_
+
+// This file declares sound resources keys for ChromeOS.
+namespace chromeos {
+
+enum {
+ SOUND_START = 0,
+ SOUND_STARTUP = SOUND_START,
+ SOUND_LOCK,
+ SOUND_UNLOCK,
+ SOUND_SHUTDOWN,
+ SOUND_SPOKEN_FEEDBACK_ENABLED,
+ SOUND_SPOKEN_FEEDBACK_DISABLED
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_AUDIO_CHROMEOS_SOUNDS_H_
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index be08509..635c705 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -43,6 +43,7 @@
'audio/cras_audio_handler.h',
'audio/audio_devices_pref_handler_stub.cc',
'audio/audio_devices_pref_handler_stub.h',
+ 'audio/chromeos_sounds.h',
'attestation/attestation_constants.cc',
'attestation/attestation_constants.h',
'attestation/attestation_flow.cc',
diff --git a/media/audio/sounds/sounds_manager.cc b/media/audio/sounds/sounds_manager.cc
index 6564f9f..e93dc65 100644
--- a/media/audio/sounds/sounds_manager.cc
+++ b/media/audio/sounds/sounds_manager.cc
@@ -28,60 +28,52 @@ class SoundsManagerImpl : public SoundsManager {
virtual ~SoundsManagerImpl();
// SoundsManager implementation:
- virtual bool Initialize(
- const std::vector<base::StringPiece>& resources) OVERRIDE;
- virtual bool Play(Sound sound) OVERRIDE;
- virtual base::TimeDelta GetDuration(Sound sound) OVERRIDE;
+ virtual bool Initialize(SoundKey key,
+ const base::StringPiece& data) OVERRIDE;
+ virtual bool Play(SoundKey key) OVERRIDE;
+ virtual base::TimeDelta GetDuration(SoundKey key) OVERRIDE;
private:
- std::vector<linked_ptr<AudioStreamHandler> > handlers_;
+ base::hash_map<SoundKey, linked_ptr<AudioStreamHandler> > handlers_;
scoped_refptr<base::MessageLoopProxy> message_loop_;
DISALLOW_COPY_AND_ASSIGN(SoundsManagerImpl);
};
SoundsManagerImpl::SoundsManagerImpl()
- : handlers_(SOUND_COUNT),
- message_loop_(AudioManager::Get()->GetMessageLoop()) {
-}
+ : message_loop_(AudioManager::Get()->GetMessageLoop()) {}
-SoundsManagerImpl::~SoundsManagerImpl() {
- DCHECK(CalledOnValidThread());
-}
+SoundsManagerImpl::~SoundsManagerImpl() { DCHECK(CalledOnValidThread()); }
-bool SoundsManagerImpl::Initialize(
- const std::vector<base::StringPiece>& resources) {
- if (resources.size() != static_cast<size_t>(SOUND_COUNT)) {
- LOG(ERROR) << "Incorrect num of sounds.";
+bool SoundsManagerImpl::Initialize(SoundKey key,
+ const base::StringPiece& data) {
+ if (handlers_.find(key) != handlers_.end() && handlers_[key]->IsInitialized())
+ return true;
+ linked_ptr<AudioStreamHandler> handler(new AudioStreamHandler(data));
+ if (!handler->IsInitialized()) {
+ LOG(WARNING) << "Can't initialize AudioStreamHandler for key=" << key;
return false;
}
- for (size_t i = 0; i < resources.size(); ++i) {
- handlers_[i].reset(new AudioStreamHandler(resources[i]));
- if (!handlers_[i]->IsInitialized()) {
- LOG(WARNING) << "Can't initialize AudioStreamHandler for sound "
- << i << ".";
- return false;
- }
- }
+ handlers_[key] = handler;
return true;
}
-bool SoundsManagerImpl::Play(Sound sound) {
+bool SoundsManagerImpl::Play(SoundKey key) {
DCHECK(CalledOnValidThread());
- DCHECK(sound < SOUND_COUNT);
- if (!handlers_[sound].get() || !handlers_[sound]->IsInitialized())
+ if (handlers_.find(key) == handlers_.end() ||
+ !handlers_[key]->IsInitialized()) {
return false;
- return handlers_[sound]->Play();
+ }
+ return handlers_[key]->Play();
}
-base::TimeDelta SoundsManagerImpl::GetDuration(Sound sound) {
+base::TimeDelta SoundsManagerImpl::GetDuration(SoundKey key) {
DCHECK(CalledOnValidThread());
- if (sound >= SOUND_COUNT ||
- !handlers_[sound].get() ||
- !handlers_[sound]->IsInitialized()) {
+ if (handlers_.find(key) == handlers_.end() ||
+ !handlers_[key]->IsInitialized()) {
return base::TimeDelta();
}
- const WavAudioHandler& wav_audio = handlers_[sound]->wav_audio_handler();
+ const WavAudioHandler& wav_audio = handlers_[key]->wav_audio_handler();
const int64 size = wav_audio.size();
const int64 rate = wav_audio.byte_rate();
return base::TimeDelta::FromMicroseconds(size * 1000000 / rate);
@@ -95,52 +87,46 @@ class SoundsManagerStub : public SoundsManager {
virtual ~SoundsManagerStub();
// SoundsManager implementation:
- virtual bool Initialize(
- const std::vector<base::StringPiece>& resources) OVERRIDE;
- virtual bool Play(Sound sound) OVERRIDE;
- virtual base::TimeDelta GetDuration(Sound sound) OVERRIDE;
+ virtual bool Initialize(SoundKey key,
+ const base::StringPiece& data) OVERRIDE;
+ virtual bool Play(SoundKey key) OVERRIDE;
+ virtual base::TimeDelta GetDuration(SoundKey key) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(SoundsManagerStub);
};
-SoundsManagerStub::SoundsManagerStub() {
-}
+SoundsManagerStub::SoundsManagerStub() {}
-SoundsManagerStub::~SoundsManagerStub() {
- DCHECK(CalledOnValidThread());
-}
+SoundsManagerStub::~SoundsManagerStub() { DCHECK(CalledOnValidThread()); }
-bool SoundsManagerStub::Initialize(
- const std::vector<base::StringPiece>& /* resources */) {
+bool SoundsManagerStub::Initialize(SoundKey /* key */,
+ const base::StringPiece& /* data */) {
DCHECK(CalledOnValidThread());
return false;
}
-bool SoundsManagerStub::Play(Sound /* sound */) {
+bool SoundsManagerStub::Play(SoundKey /* key */) {
DCHECK(CalledOnValidThread());
return false;
}
-base::TimeDelta SoundsManagerStub::GetDuration(Sound /* sound */) {
+base::TimeDelta SoundsManagerStub::GetDuration(SoundKey /* key */) {
DCHECK(CalledOnValidThread());
return base::TimeDelta();
}
} // namespace
-SoundsManager::SoundsManager() {
-}
+SoundsManager::SoundsManager() {}
-SoundsManager::~SoundsManager() {
- DCHECK(CalledOnValidThread());
-}
+SoundsManager::~SoundsManager() { DCHECK(CalledOnValidThread()); }
// static
void SoundsManager::Create() {
CHECK(!g_instance) << "SoundsManager::Create() is called twice";
const bool enabled = !CommandLine::ForCurrentProcess()->HasSwitch(
- ::switches::kDisableSystemSoundsManager);
+ ::switches::kDisableSystemSoundsManager);
if (enabled)
g_instance = new SoundsManagerImpl();
else
diff --git a/media/audio/sounds/sounds_manager.h b/media/audio/sounds/sounds_manager.h
index 16fbd1b..7ff6aaf 100644
--- a/media/audio/sounds/sounds_manager.h
+++ b/media/audio/sounds/sounds_manager.h
@@ -5,9 +5,8 @@
#ifndef MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
#define MEDIA_AUDIO_SOUNDS_SOUNDS_MANAGER_H_
-#include <vector>
-
#include "base/basictypes.h"
+#include "base/containers/hash_tables.h"
#include "base/strings/string_piece.h"
#include "base/threading/non_thread_safe.h"
#include "base/time/time.h"
@@ -19,17 +18,7 @@ namespace media {
// should be accessed from the Audio thread.
class MEDIA_EXPORT SoundsManager : public base::NonThreadSafe {
public:
- // TODO(dalecurtis): Define elsewhere (belongs under chromeos). See
- // crbug.com/321335.
- enum Sound {
- SOUND_STARTUP = 0,
- SOUND_LOCK,
- SOUND_UNLOCK,
- SOUND_SHUTDOWN,
- SOUND_SPOKEN_FEEDBACK_ENABLED,
- SOUND_SPOKEN_FEEDBACK_DISABLED,
- SOUND_COUNT
- };
+ typedef int SoundKey;
// Creates a singleton instance of the SoundsManager.
static void Create();
@@ -43,15 +32,16 @@ class MEDIA_EXPORT SoundsManager : public base::NonThreadSafe {
// Initializes SoundsManager with the wav data for the system
// sounds. Returns true if SoundsManager was successfully
// initialized.
- virtual bool Initialize(const std::vector<base::StringPiece>& resources) = 0;
+ virtual bool Initialize(SoundKey key, const base::StringPiece& data) = 0;
- // Plays |sound|, returns false if SoundsManager was not properly
- // initialized.
- virtual bool Play(Sound sound) = 0;
+ // Plays sound identified by |key|, returns false if SoundsManager
+ // was not properly initialized.
+ virtual bool Play(SoundKey key) = 0;
- // Returns duration of the |sound|. If SoundsManager was not
- // properly initialized returns an empty value.
- virtual base::TimeDelta GetDuration(Sound sound) = 0;
+ // Returns duration of the sound identified by |key|. If SoundsManager
+ // was not properly initialized or |key| was not registered, this
+ // method returns an empty value.
+ virtual base::TimeDelta GetDuration(SoundKey key) = 0;
protected:
SoundsManager();
diff --git a/media/audio/sounds/sounds_manager_unittest.cc b/media/audio/sounds/sounds_manager_unittest.cc
index 05f26b2..5aa3694 100644
--- a/media/audio/sounds/sounds_manager_unittest.cc
+++ b/media/audio/sounds/sounds_manager_unittest.cc
@@ -26,14 +26,6 @@ class SoundsManagerTest : public testing::Test {
virtual void SetUp() OVERRIDE {
audio_manager_.reset(AudioManager::CreateForTesting());
SoundsManager::Create();
-
- std::vector<base::StringPiece> resources;
- for (size_t i = 0;
- i < static_cast<size_t>(SoundsManager::SOUND_COUNT); ++i) {
- resources.push_back(base::StringPiece(kTestAudioData,
- arraysize(kTestAudioData)));
- }
- CHECK(SoundsManager::Get()->Initialize(resources));
}
virtual void TearDown() OVERRIDE {
@@ -59,9 +51,12 @@ TEST_F(SoundsManagerTest, Play) {
SetObserverForTesting(&observer);
- ASSERT_EQ(41, SoundsManager::Get()->GetDuration(
- SoundsManager::SOUND_STARTUP).InMicroseconds());
- ASSERT_TRUE(SoundsManager::Get()->Play(SoundsManager::SOUND_STARTUP));
+ ASSERT_TRUE(SoundsManager::Get()->Initialize(
+ kTestAudioKey,
+ base::StringPiece(kTestAudioData, arraysize(kTestAudioData))));
+ ASSERT_EQ(41,
+ SoundsManager::Get()->GetDuration(kTestAudioKey).InMicroseconds());
+ ASSERT_TRUE(SoundsManager::Get()->Play(kTestAudioKey));
run_loop.Run();
ASSERT_EQ(1, observer.num_play_requests());
diff --git a/media/audio/sounds/test_data.h b/media/audio/sounds/test_data.h
index 71822b3..d7fb11d 100644
--- a/media/audio/sounds/test_data.h
+++ b/media/audio/sounds/test_data.h
@@ -16,6 +16,8 @@ class MessageLoop;
namespace media {
+const int kTestAudioKey = 1000;
+
const char kTestAudioData[] = "RIFF\x26\x00\x00\x00WAVEfmt \x10\x00\x00\x00"
"\x01\x00\x02\x00\x80\xbb\x00\x00\x00\x77\x01\x00\x02\x00\x10\x00"
"data\x04\x00\x00\x00\x01\x00\x01\x00";