diff options
author | zturner@chromium.org <zturner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 19:44:05 +0000 |
---|---|---|
committer | zturner@chromium.org <zturner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 19:44:05 +0000 |
commit | cb1782c27b114d0784be5b9eaa1cca3887edebb4 (patch) | |
tree | 26180ab3fc059cd193a8e662101b8f3fa26f85a5 /ash | |
parent | e39ea7dae0b2b4669b0c25652c2067162ab73973 (diff) | |
download | chromium_src-cb1782c27b114d0784be5b9eaa1cca3887edebb4.zip chromium_src-cb1782c27b114d0784be5b9eaa1cca3887edebb4.tar.gz chromium_src-cb1782c27b114d0784be5b9eaa1cca3887edebb4.tar.bz2 |
Resubmit 'Enable the volume slider in Windows Ash'.
Previous 2 submissions were causing the Vista waterfall builder to fail
with uninitialized COM errors. This change addresses that by
initializing COM on Vista+, not just Win7+.
TBRing all reviewers since this change has already been reviewed.
BUG=227247
TEST=Ran ash_unittests on a Vista VM
* All tests failed without my change.
* All tests passed with my change.
TBR=henrika,sky,jennyz
Review URL: https://codereview.chromium.org/197643003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256608 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 4 | ||||
-rw-r--r-- | ash/system/audio/tray_audio_delegate.h | 2 | ||||
-rw-r--r-- | ash/system/tray/system_tray.cc | 5 | ||||
-rw-r--r-- | ash/system/win/OWNERS | 1 | ||||
-rw-r--r-- | ash/system/win/audio/tray_audio_delegate_win.cc | 117 | ||||
-rw-r--r-- | ash/system/win/audio/tray_audio_delegate_win.h | 40 | ||||
-rw-r--r-- | ash/system/win/audio/tray_audio_win.cc | 25 | ||||
-rw-r--r-- | ash/system/win/audio/tray_audio_win.h | 28 | ||||
-rw-r--r-- | ash/test/ash_test_helper_unittest.cc | 4 | ||||
-rw-r--r-- | ash/test/test_suite.cc | 8 |
10 files changed, 231 insertions, 3 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index f9a221d..d7282b7 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -453,6 +453,10 @@ 'system/user/user_observer.h', 'system/web_notification/web_notification_tray.cc', 'system/web_notification/web_notification_tray.h', + 'system/win/audio/tray_audio_delegate_win.cc', + 'system/win/audio/tray_audio_delegate_win.h', + 'system/win/audio/tray_audio_win.cc', + 'system/win/audio/tray_audio_win.h', 'touch/touch_hud_debug.cc', 'touch/touch_hud_debug.h', 'touch/touch_hud_projection.cc', diff --git a/ash/system/audio/tray_audio_delegate.h b/ash/system/audio/tray_audio_delegate.h index 823bfff..8a6260f 100644 --- a/ash/system/audio/tray_audio_delegate.h +++ b/ash/system/audio/tray_audio_delegate.h @@ -8,7 +8,7 @@ namespace ash { namespace system { -class TrayAudioDelegate { +class ASH_EXPORT TrayAudioDelegate { public: enum { kNoAudioDeviceIcon = -1 }; diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index b73857e..e5d111e 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -61,6 +61,9 @@ #include "ash/system/chromeos/tray_display.h" #include "ash/system/chromeos/tray_tracing.h" #include "ui/message_center/message_center.h" +#elif defined(OS_WIN) +#include "ash/system/win/audio/tray_audio_win.h" +#include "media/audio/win/core_audio_util_win.h" #endif using views::TrayBubbleView; @@ -199,6 +202,8 @@ void SystemTray::CreateItems(SystemTrayDelegate* delegate) { AddTrayItem(tray_date_); #elif defined(OS_WIN) AddTrayItem(tray_accessibility_); + if (media::CoreAudioUtil::IsSupported()) + AddTrayItem(new internal::TrayAudioWin(this)); AddTrayItem(new internal::TrayUpdate(this)); AddTrayItem(tray_date_); #elif defined(OS_LINUX) diff --git a/ash/system/win/OWNERS b/ash/system/win/OWNERS new file mode 100644 index 0000000..45cb82b --- /dev/null +++ b/ash/system/win/OWNERS @@ -0,0 +1 @@ +zturner@chromium.org
\ No newline at end of file diff --git a/ash/system/win/audio/tray_audio_delegate_win.cc b/ash/system/win/audio/tray_audio_delegate_win.cc new file mode 100644 index 0000000..57c7b56 --- /dev/null +++ b/ash/system/win/audio/tray_audio_delegate_win.cc @@ -0,0 +1,117 @@ +// 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. + +#include "ash/system/win/audio/tray_audio_delegate_win.h" + +#include <audiopolicy.h> +#include <cmath> + +#include "grit/ash_resources.h" +#include "grit/ash_strings.h" +#include "media/audio/win/core_audio_util_win.h" + +using base::win::ScopedComPtr; + +namespace { + +// Volume value which should be considered as muted in range [0, 100]. +const int kMuteThresholdPercent = 1; + +// Lowest volume which is considered to be audible in the range [0, 100]. +const int kDefaultUnmuteVolumePercent = 4; + +} // namespace + +namespace ash { +namespace system { + +void TrayAudioDelegateWin::AdjustOutputVolumeToAudibleLevel() { + if (GetOutputVolumeLevel() <= kMuteThresholdPercent) + SetOutputVolumeLevel(kDefaultUnmuteVolumePercent); +} + +int TrayAudioDelegateWin::GetOutputDefaultVolumeMuteLevel() { + return kMuteThresholdPercent; +} + +int TrayAudioDelegateWin::GetOutputVolumeLevel() { + ScopedComPtr<ISimpleAudioVolume> volume_control = + CreateDefaultVolumeControl(); + if (!volume_control) + return 0; + + float level = 0.0f; + if (FAILED(volume_control->GetMasterVolume(&level))) + return 0; + + // MSVC prior to 2013 doesn't have a round function. The below code is not + // conformant to C99 round(), but since we know that 0 <= level <= 100, it + // should be ok. + return static_cast<int>(level + 0.5); +} + +int TrayAudioDelegateWin::GetActiveOutputDeviceIconId() { + return kNoAudioDeviceIcon; +} + +bool TrayAudioDelegateWin::HasAlternativeSources() { + return false; +} + +bool TrayAudioDelegateWin::IsOutputAudioMuted() { + ScopedComPtr<ISimpleAudioVolume> volume_control = + CreateDefaultVolumeControl(); + + if (!volume_control) + return false; + + BOOL mute = FALSE; + if (FAILED(volume_control->GetMute(&mute))) + return false; + + return !!mute; +} + +void TrayAudioDelegateWin::SetOutputAudioIsMuted(bool is_muted) { + ScopedComPtr<ISimpleAudioVolume> volume_control = + CreateDefaultVolumeControl(); + + if (!volume_control) + return; + + volume_control->SetMute(is_muted, NULL); +} + +void TrayAudioDelegateWin::SetOutputVolumeLevel(int level) { + ScopedComPtr<ISimpleAudioVolume> volume_control = + CreateDefaultVolumeControl(); + + if (!volume_control) + return; + + float volume_level = static_cast<float>(level) / 100.0f; + volume_control->SetMasterVolume(volume_level, NULL); +} + +ScopedComPtr<ISimpleAudioVolume> +TrayAudioDelegateWin::CreateDefaultVolumeControl() { + ScopedComPtr<ISimpleAudioVolume> volume_control; + ScopedComPtr<IAudioSessionManager> session_manager; + + ScopedComPtr<IMMDevice> device = + media::CoreAudioUtil::CreateDefaultDevice(eRender, eConsole); + if (!device || + FAILED(device->Activate(__uuidof(IAudioSessionManager), CLSCTX_ALL, NULL, + session_manager.ReceiveVoid()))) { + return volume_control; + } + + session_manager->GetSimpleAudioVolume(NULL, FALSE, + volume_control.Receive()); + + return volume_control; +} + +} // namespace system +} // namespace ash diff --git a/ash/system/win/audio/tray_audio_delegate_win.h b/ash/system/win/audio/tray_audio_delegate_win.h new file mode 100644 index 0000000..4014f95 --- /dev/null +++ b/ash/system/win/audio/tray_audio_delegate_win.h @@ -0,0 +1,40 @@ +// 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_SYSTEM_WIN_AUDIO_TRAY_AUDIO_DELEGATE_WIN_H_ +#define ASH_SYSTEM_WIN_AUDIO_TRAY_AUDIO_DELEGATE_WIN_H_ + +#include <audioclient.h> +#include <mmdeviceapi.h> + +#include "ash/ash_export.h" +#include "ash/system/audio/tray_audio_delegate.h" +#include "base/compiler_specific.h" +#include "base/win/scoped_comptr.h" + +namespace ash { +namespace system { + +class ASH_EXPORT TrayAudioDelegateWin : public TrayAudioDelegate { + public: + virtual ~TrayAudioDelegateWin() {} + + // Overridden from TrayAudioDelegate. + virtual void AdjustOutputVolumeToAudibleLevel() OVERRIDE; + virtual int GetOutputDefaultVolumeMuteLevel() OVERRIDE; + virtual int GetOutputVolumeLevel() OVERRIDE; + virtual int GetActiveOutputDeviceIconId() OVERRIDE; + virtual bool HasAlternativeSources() OVERRIDE; + virtual bool IsOutputAudioMuted() OVERRIDE; + virtual void SetOutputAudioIsMuted(bool is_muted) OVERRIDE; + virtual void SetOutputVolumeLevel(int level) OVERRIDE; + + private: + base::win::ScopedComPtr<ISimpleAudioVolume> CreateDefaultVolumeControl(); +}; + +} // namespace system +} // namespace ash + +#endif // ASH_SYSTEM_WIN_AUDIO_TRAY_AUDIO_DELEGATE_WIN_H_
\ No newline at end of file diff --git a/ash/system/win/audio/tray_audio_win.cc b/ash/system/win/audio/tray_audio_win.cc new file mode 100644 index 0000000..0d2226c --- /dev/null +++ b/ash/system/win/audio/tray_audio_win.cc @@ -0,0 +1,25 @@ +// 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. + +#include "ash/system/win/audio/tray_audio_win.h" + +#include "ash/system/win/audio/tray_audio_delegate_win.h" + +namespace ash { + +using system::TrayAudioDelegate; +using system::TrayAudioDelegateWin; + +namespace internal { + +TrayAudioWin::TrayAudioWin(SystemTray* system_tray) + : TrayAudio(system_tray, + scoped_ptr<TrayAudioDelegate>(new TrayAudioDelegateWin())) { +} + +TrayAudioWin::~TrayAudioWin() { +} + +} // namespace internal +} // namespace ash diff --git a/ash/system/win/audio/tray_audio_win.h b/ash/system/win/audio/tray_audio_win.h new file mode 100644 index 0000000..33ca7cb --- /dev/null +++ b/ash/system/win/audio/tray_audio_win.h @@ -0,0 +1,28 @@ +// 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_SYSTEM_WIN_AUDIO_TRAY_AUDIO_WIN_H_ +#define ASH_SYSTEM_WIN_AUDIO_TRAY_AUDIO_WIN_H_ + +#include "ash/ash_export.h" +#include "ash/system/audio/tray_audio.h" +#include "base/memory/scoped_ptr.h" + +namespace ash { + +namespace internal { + +class TrayAudioWin : public TrayAudio { + public: + explicit TrayAudioWin(SystemTray* system_tray); + virtual ~TrayAudioWin(); + + private: + DISALLOW_COPY_AND_ASSIGN(TrayAudioWin); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SYSTEM_WIN_AUDIO_TRAY_AUDIO_WIN_H_
\ No newline at end of file diff --git a/ash/test/ash_test_helper_unittest.cc b/ash/test/ash_test_helper_unittest.cc index 52e73fb..f5eae60 100644 --- a/ash/test/ash_test_helper_unittest.cc +++ b/ash/test/ash_test_helper_unittest.cc @@ -8,6 +8,10 @@ #include "ui/aura/window_event_dispatcher.h" #include "ui/views/widget/widget.h" +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + // Tests for AshTestHelper. Who will watch the watchers? And who will test // the tests? class AshTestHelperTest : public testing::Test { diff --git a/ash/test/test_suite.cc b/ash/test/test_suite.cc index 2e971eb..7955264 100644 --- a/ash/test/test_suite.cc +++ b/ash/test/test_suite.cc @@ -33,12 +33,16 @@ void AuraShellTestSuite::Initialize() { gfx::GLSurface::InitializeOneOffForTests(); #if defined(OS_WIN) - if (base::win::GetVersion() >= base::win::VERSION_WIN8 && + base::win::Version version = base::win::GetVersion(); + // Although Ash officially is only supported for users on Win7+, we still run + // ash_unittests on Vista builders, so we still need to initialize COM. + if (version >= base::win::VERSION_VISTA && !CommandLine::ForCurrentProcess()->HasSwitch( ash::switches::kForceAshToDesktop)) { com_initializer_.reset(new base::win::ScopedCOMInitializer()); ui::win::CreateATLModuleIfNeeded(); - ASSERT_TRUE(win8::MakeTestDefaultBrowserSynchronously()); + if (version >= base::win::VERSION_WIN8) + ASSERT_TRUE(win8::MakeTestDefaultBrowserSynchronously()); } #endif |