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

Side by Side Diff: chrome/browser/ui/ash/volume_controller_chromeos.cc

Issue 10911261: chromeos: Stop calling ProfileManager::GetDefaultProfile() from extension event dispatch functions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added function comments Created 8 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" 5 #include "chrome/browser/ui/ash/volume_controller_chromeos.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/audio/audio_handler.h" 8 #include "chrome/browser/chromeos/audio/audio_handler.h"
9 #include "chrome/browser/extensions/system/system_api.h" 9 #include "chrome/browser/extensions/system/system_api.h"
10 #include "chrome/browser/profiles/profile_manager.h"
10 #include "content/public/browser/user_metrics.h" 11 #include "content/public/browser/user_metrics.h"
11 12
12 namespace { 13 namespace {
13 14
14 // Percent by which the volume should be changed when a volume key is pressed. 15 // Percent by which the volume should be changed when a volume key is pressed.
15 const double kStepPercentage = 4.0; 16 const double kStepPercentage = 4.0;
16 17
17 } // namespace 18 } // namespace
18 19
19 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) { 20 bool VolumeController::HandleVolumeMute(const ui::Accelerator& accelerator) {
20 if (accelerator.key_code() == ui::VKEY_F8) 21 if (accelerator.key_code() == ui::VKEY_F8)
21 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8")); 22 content::RecordAction(content::UserMetricsAction("Accel_VolumeMute_F8"));
22 23
23 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); 24 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
24 25
25 // Always muting (and not toggling) as per final decision on 26 // Always muting (and not toggling) as per final decision on
26 // http://crosbug.com/3751 27 // http://crosbug.com/3751
27 audio_handler->SetMuted(true); 28 audio_handler->SetMuted(true);
28 29
29 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), 30 Profile* profile = ProfileManager::GetDefaultProfile();
30 audio_handler->IsMuted()); 31 if (profile) {
32 extensions::DispatchVolumeChangedEvent(profile,
33 audio_handler->GetVolumePercent(),
34 audio_handler->IsMuted());
35 }
31 return true; 36 return true;
32 } 37 }
33 38
34 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) { 39 bool VolumeController::HandleVolumeDown(const ui::Accelerator& accelerator) {
35 if (accelerator.key_code() == ui::VKEY_F9) 40 if (accelerator.key_code() == ui::VKEY_F9)
36 content::RecordAction(content::UserMetricsAction("Accel_VolumeDown_F9")); 41 content::RecordAction(content::UserMetricsAction("Accel_VolumeDown_F9"));
37 42
38 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); 43 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
39 if (audio_handler->IsMuted()) 44 if (audio_handler->IsMuted())
40 audio_handler->SetVolumePercent(0.0); 45 audio_handler->SetVolumePercent(0.0);
41 else 46 else
42 audio_handler->AdjustVolumeByPercent(-kStepPercentage); 47 audio_handler->AdjustVolumeByPercent(-kStepPercentage);
43 48
44 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), 49 Profile* profile = ProfileManager::GetDefaultProfile();
45 audio_handler->IsMuted()); 50 if (profile) {
51 extensions::DispatchVolumeChangedEvent(profile,
52 audio_handler->GetVolumePercent(),
53 audio_handler->IsMuted());
54 }
46 return true; 55 return true;
47 } 56 }
48 57
49 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) { 58 bool VolumeController::HandleVolumeUp(const ui::Accelerator& accelerator) {
50 if (accelerator.key_code() == ui::VKEY_F10) 59 if (accelerator.key_code() == ui::VKEY_F10)
51 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10")); 60 content::RecordAction(content::UserMetricsAction("Accel_VolumeUp_F10"));
52 61
53 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); 62 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
54 if (audio_handler->IsMuted()) { 63 if (audio_handler->IsMuted()) {
55 audio_handler->SetMuted(false); 64 audio_handler->SetMuted(false);
56 // If volume percent is still 0.0 after reset the mute status, it means that 65 // If volume percent is still 0.0 after reset the mute status, it means that
57 // the mute status was done by VolumeDown, so we need to increase 66 // the mute status was done by VolumeDown, so we need to increase
58 // the volume as usual. 67 // the volume as usual.
59 if (audio_handler->GetVolumePercent() == 0.0) 68 if (audio_handler->GetVolumePercent() == 0.0)
60 audio_handler->AdjustVolumeByPercent(kStepPercentage); 69 audio_handler->AdjustVolumeByPercent(kStepPercentage);
61 } else { 70 } else {
62 audio_handler->AdjustVolumeByPercent(kStepPercentage); 71 audio_handler->AdjustVolumeByPercent(kStepPercentage);
63 } 72 }
64 73
65 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), 74 Profile* profile = ProfileManager::GetDefaultProfile();
66 audio_handler->IsMuted()); 75 if (profile) {
76 extensions::DispatchVolumeChangedEvent(profile,
77 audio_handler->GetVolumePercent(),
78 audio_handler->IsMuted());
79 }
67 return true; 80 return true;
68 } 81 }
69 82
70 bool VolumeController::IsAudioMuted() const { 83 bool VolumeController::IsAudioMuted() const {
71 return chromeos::AudioHandler::GetInstance()->IsMuted(); 84 return chromeos::AudioHandler::GetInstance()->IsMuted();
72 } 85 }
73 86
74 void VolumeController::SetAudioMuted(bool muted) { 87 void VolumeController::SetAudioMuted(bool muted) {
75 chromeos::AudioHandler::GetInstance()->SetMuted(muted); 88 chromeos::AudioHandler::GetInstance()->SetMuted(muted);
76 } 89 }
77 90
78 // Gets the volume level. The range is [0, 1.0]. 91 // Gets the volume level. The range is [0, 1.0].
79 float VolumeController::GetVolumeLevel() const { 92 float VolumeController::GetVolumeLevel() const {
80 return chromeos::AudioHandler::GetInstance()->GetVolumePercent() / 100.f; 93 return chromeos::AudioHandler::GetInstance()->GetVolumePercent() / 100.f;
81 } 94 }
82 95
83 // Sets the volume level. The range is [0, 1.0]. 96 // Sets the volume level. The range is [0, 1.0].
84 void VolumeController::SetVolumeLevel(float level) { 97 void VolumeController::SetVolumeLevel(float level) {
85 chromeos::AudioHandler::GetInstance()->SetVolumePercent(level * 100.f); 98 chromeos::AudioHandler::GetInstance()->SetVolumePercent(level * 100.f);
86 } 99 }
87 100
88 void VolumeController::SetVolumePercent(double percent) { 101 void VolumeController::SetVolumePercent(double percent) {
89 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance(); 102 chromeos::AudioHandler* audio_handler = chromeos::AudioHandler::GetInstance();
90 audio_handler->SetVolumePercent(percent); 103 audio_handler->SetVolumePercent(percent);
91 extensions::DispatchVolumeChangedEvent(audio_handler->GetVolumePercent(), 104 Profile* profile = ProfileManager::GetDefaultProfile();
92 audio_handler->IsMuted()); 105 if (profile) {
106 extensions::DispatchVolumeChangedEvent(profile,
107 audio_handler->GetVolumePercent(),
108 audio_handler->IsMuted());
109 }
93 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698