Skip to content

Commit

Permalink
Fixed sounds registration in SoundsManager.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ygorshenin@chromium.org committed Dec 11, 2013
1 parent 86f438f commit ce89d93
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 139 deletions.
4 changes: 4 additions & 0 deletions ash/accessibility_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ash/ash_export.h"
#include "ash/magnifier/magnifier_constants.h"
#include "base/time/time.h"

namespace ash {

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ash/default_accessibility_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ AccessibilityAlert DefaultAccessibilityDelegate::GetLastAccessibilityAlert() {
return accessibility_alert_;
}

base::TimeDelta DefaultAccessibilityDelegate::PlayShutdownSound() const {
return base::TimeDelta();
}

} // namespace internal
} // namespace ash
1 change: 1 addition & 0 deletions ash/default_accessibility_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
20 changes: 7 additions & 13 deletions ash/wm/lock_state_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
52 changes: 32 additions & 20 deletions chrome/browser/chromeos/accessibility/accessibility_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand All @@ -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() {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)->
Expand All @@ -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
15 changes: 15 additions & 0 deletions chrome/browser/chromeos/accessibility/accessibility_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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_;

Expand Down Expand Up @@ -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);
};

Expand Down
59 changes: 40 additions & 19 deletions chrome/browser/chromeos/login/login_display_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -329,24 +334,32 @@ 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 >> "
<< "zero_delay: " << zero_delay_enabled
<< " 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() {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down
21 changes: 16 additions & 5 deletions chrome/browser/chromeos/login/screen_locker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit ce89d93

Please sign in to comment.