Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: chrome/browser/chromeos/login/login_display_host_impl.cc

Issue 98583004: Added CrOS startup sound. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/login/login_display_host_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/login_display_host_impl.cc
diff --git a/chrome/browser/chromeos/login/login_display_host_impl.cc b/chrome/browser/chromeos/login/login_display_host_impl.cc
index 8b24997b548401f5c47ad5a67340a1d567297cb4..cd2ece829b9a891155c9d9f5b4ff712027b98a2a 100644
--- a/chrome/browser/chromeos/login/login_display_host_impl.cc
+++ b/chrome/browser/chromeos/login/login_display_host_impl.cc
@@ -83,7 +83,8 @@
namespace {
-const int kStartupSoundInitialDelayMs = 500;
+// Maximum delay for startup sound after 'loginPromptVisible' signal.
+const int kStartupSoundMaxDelayMs = 2000;
// URL which corresponds to the login WebUI.
const char kLoginURL[] = "chrome://oobe/login";
@@ -172,13 +173,6 @@ class AnimationObserver : public ui::ImplicitAnimationObserver {
DISALLOW_COPY_AND_ASSIGN(AnimationObserver);
};
-void PlayStartupSoundHelper(bool startup_sound_honors_spoken_feedback) {
- if (!startup_sound_honors_spoken_feedback ||
- chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) {
- media::SoundsManager::Get()->Play(media::SoundsManager::SOUND_STARTUP);
- }
-}
-
// ShowLoginWizard is split into two parts. This function is sometimes called
// from ShowLoginWizard(), and sometimes from OnLanguageSwitchedCallback()
// (if locale was updated).
@@ -264,10 +258,10 @@ LoginDisplayHostImpl::LoginDisplayHostImpl(const gfx::Rect& background_bounds)
auto_enrollment_check_done_(false),
finalize_animation_type_(ANIMATION_WORKSPACE),
animation_weak_ptr_factory_(this),
- startup_sound_requested_(false),
startup_sound_played_(false),
startup_sound_honors_spoken_feedback_(false) {
DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
+ CrasAudioHandler::Get()->AddAudioObserver(this);
// We need to listen to CLOSE_ALL_BROWSERS_REQUEST but not APP_TERMINATING
// because/ APP_TERMINATING will never be fired as long as this keeps
@@ -353,10 +347,29 @@ 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_;
+
+ 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);
+ for (size_t i = 0; i < sound_resources.size(); ++i) {
+ DCHECK(!sound_resources[i].empty()) << "System sound " << i << " "
+ << "missing.";
+ }
+ if (!media::SoundsManager::Get()->Initialize(sound_resources))
+ LOG(ERROR) << "Failed to initialize SoundsManager.";
}
LoginDisplayHostImpl::~LoginDisplayHostImpl() {
DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
+ CrasAudioHandler::Get()->RemoveAudioObserver(this);
views::FocusManager::set_arrow_key_traversal_enabled(false);
ResetLoginWindowAndView();
@@ -488,7 +501,8 @@ void LoginDisplayHostImpl::GetAutoEnrollmentCheckResult(
void LoginDisplayHostImpl::StartWizard(
const std::string& first_screen_name,
scoped_ptr<DictionaryValue> screen_parameters) {
- TryToPlayStartupSound(false);
+ startup_sound_honors_spoken_feedback_ = false;
+ TryToPlayStartupSound();
// Keep parameters to restore if renderer crashes.
restore_path_ = RESTORE_WIZARD;
@@ -563,7 +577,8 @@ void LoginDisplayHostImpl::StartUserAdding(
void LoginDisplayHostImpl::StartSignInScreen(
const LoginScreenContext& context) {
- TryToPlayStartupSound(true);
+ startup_sound_honors_spoken_feedback_ = true;
+ TryToPlayStartupSound();
restore_path_ = RESTORE_SIGN_IN;
is_showing_login_ = true;
@@ -787,6 +802,10 @@ void LoginDisplayHostImpl::EmitLoginPromptVisibleCalled() {
OnLoginPromptVisible();
}
+void LoginDisplayHostImpl::OnActiveOutputNodeChanged() {
+ TryToPlayStartupSound();
+}
+
////////////////////////////////////////////////////////////////////////////////
// LoginDisplayHostImpl, private
@@ -1010,69 +1029,31 @@ void LoginDisplayHostImpl::NotifyAutoEnrollmentCheckResult(
callbacks[i].Run(should_auto_enroll);
}
-void LoginDisplayHostImpl::TryToPlayStartupSound(bool honor_spoken_feedback) {
- if (startup_sound_requested_)
+void LoginDisplayHostImpl::TryToPlayStartupSound() {
+ if (startup_sound_played_ || login_prompt_visible_time_.is_null() ||
+ !CrasAudioHandler::Get()->GetActiveOutputNode()) {
return;
- startup_sound_requested_ = true;
- startup_sound_honors_spoken_feedback_ = honor_spoken_feedback;
- if (!login_prompt_visible_time_.is_null())
- PlayStartupSound();
-}
+ }
-void LoginDisplayHostImpl::OnLoginPromptVisible() {
- if (!login_prompt_visible_time_.is_null())
+ // Don't play startup sound if login prompt is already visible for a
+ // long time.
+ if (base::TimeTicks::Now() - login_prompt_visible_time_ >
+ base::TimeDelta::FromMilliseconds(kStartupSoundMaxDelayMs)) {
return;
-
- 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);
- for (size_t i = 0; i < sound_resources.size(); ++i) {
- DCHECK(!sound_resources[i].empty()) << "System sound " << i << " "
- << "missing.";
}
- if (!media::SoundsManager::Get()->Initialize(sound_resources))
- LOG(ERROR) << "Failed to initialize SoundsManager.";
- login_prompt_visible_time_ = base::TimeTicks::Now();
- if (startup_sound_requested_ && !startup_sound_played_)
- PlayStartupSound();
+ if (!startup_sound_honors_spoken_feedback_ ||
+ chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) {
+ startup_sound_played_ = true;
+ media::SoundsManager::Get()->Play(media::SoundsManager::SOUND_STARTUP);
+ }
}
-void LoginDisplayHostImpl::PlayStartupSound() {
- if (startup_sound_played_)
+void LoginDisplayHostImpl::OnLoginPromptVisible() {
+ if (!login_prompt_visible_time_.is_null())
return;
- startup_sound_played_ = true;
-
- // TODO (ygorshenin@): remove this as soon as crbug.com/315108 will
- // be fixed.
- return;
-
- const base::TimeDelta delay =
- base::TimeDelta::FromMilliseconds(kStartupSoundInitialDelayMs);
- const base::TimeDelta delta =
- base::TimeTicks::Now() - login_prompt_visible_time_;
-
- // Cras audio server starts initialization after
- // login-prompt-visible signal from session manager. Alas, but it
- // doesn't send notifications after initialization. Thus, we're
- // trying to play startup sound after some delay.
- if (delta > delay) {
- PlayStartupSoundHelper(startup_sound_honors_spoken_feedback_);
- } else {
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&PlayStartupSoundHelper,
- startup_sound_honors_spoken_feedback_),
- delay - delta);
- }
+ login_prompt_visible_time_ = base::TimeTicks::Now();
+ TryToPlayStartupSound();
}
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « chrome/browser/chromeos/login/login_display_host_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698