| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "extensions/browser/api/audio/audio_api.h" | 5 #include "extensions/browser/api/audio/audio_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 delete service_; | 33 delete service_; |
| 34 service_ = NULL; | 34 service_ = NULL; |
| 35 } | 35 } |
| 36 | 36 |
| 37 AudioService* AudioAPI::GetService() const { | 37 AudioService* AudioAPI::GetService() const { |
| 38 return service_; | 38 return service_; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void AudioAPI::OnDeviceChanged() { | 41 void AudioAPI::OnDeviceChanged() { |
| 42 if (EventRouter::Get(browser_context_)) { | 42 if (EventRouter::Get(browser_context_)) { |
| 43 scoped_ptr<Event> event(new Event( | 43 std::unique_ptr<Event> event(new Event( |
| 44 events::AUDIO_ON_DEVICE_CHANGED, audio::OnDeviceChanged::kEventName, | 44 events::AUDIO_ON_DEVICE_CHANGED, audio::OnDeviceChanged::kEventName, |
| 45 scoped_ptr<base::ListValue>(new base::ListValue()))); | 45 std::unique_ptr<base::ListValue>(new base::ListValue()))); |
| 46 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 46 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 void AudioAPI::OnLevelChanged(const std::string& id, int level) { | 50 void AudioAPI::OnLevelChanged(const std::string& id, int level) { |
| 51 if (EventRouter::Get(browser_context_)) { | 51 if (EventRouter::Get(browser_context_)) { |
| 52 scoped_ptr<base::ListValue> args = audio::OnLevelChanged::Create(id, level); | 52 std::unique_ptr<base::ListValue> args = |
| 53 scoped_ptr<Event> event(new Event(events::AUDIO_ON_LEVEL_CHANGED, | 53 audio::OnLevelChanged::Create(id, level); |
| 54 audio::OnLevelChanged::kEventName, | 54 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_LEVEL_CHANGED, |
| 55 std::move(args))); | 55 audio::OnLevelChanged::kEventName, |
| 56 std::move(args))); |
| 56 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 57 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 void AudioAPI::OnMuteChanged(bool is_input, bool is_muted) { | 61 void AudioAPI::OnMuteChanged(bool is_input, bool is_muted) { |
| 61 if (EventRouter::Get(browser_context_)) { | 62 if (EventRouter::Get(browser_context_)) { |
| 62 scoped_ptr<base::ListValue> args = | 63 std::unique_ptr<base::ListValue> args = |
| 63 audio::OnMuteChanged::Create(is_input, is_muted); | 64 audio::OnMuteChanged::Create(is_input, is_muted); |
| 64 scoped_ptr<Event> event(new Event(events::AUDIO_ON_MUTE_CHANGED, | 65 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_MUTE_CHANGED, |
| 65 audio::OnMuteChanged::kEventName, | 66 audio::OnMuteChanged::kEventName, |
| 66 std::move(args))); | 67 std::move(args))); |
| 67 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 68 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 | 71 |
| 71 void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) { | 72 void AudioAPI::OnDevicesChanged(const DeviceInfoList& devices) { |
| 72 if (EventRouter::Get(browser_context_)) { | 73 if (EventRouter::Get(browser_context_)) { |
| 73 scoped_ptr<base::ListValue> args = audio::OnDevicesChanged::Create(devices); | 74 std::unique_ptr<base::ListValue> args = |
| 74 scoped_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, | 75 audio::OnDevicesChanged::Create(devices); |
| 75 audio::OnDevicesChanged::kEventName, | 76 std::unique_ptr<Event> event(new Event(events::AUDIO_ON_DEVICES_CHANGED, |
| 76 std::move(args))); | 77 audio::OnDevicesChanged::kEventName, |
| 78 std::move(args))); |
| 77 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); | 79 EventRouter::Get(browser_context_)->BroadcastEvent(std::move(event)); |
| 78 } | 80 } |
| 79 } | 81 } |
| 80 | 82 |
| 81 /////////////////////////////////////////////////////////////////////////////// | 83 /////////////////////////////////////////////////////////////////////////////// |
| 82 | 84 |
| 83 bool AudioGetInfoFunction::RunSync() { | 85 bool AudioGetInfoFunction::RunSync() { |
| 84 AudioService* service = | 86 AudioService* service = |
| 85 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); | 87 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| 86 DCHECK(service); | 88 DCHECK(service); |
| 87 OutputInfo output_info; | 89 OutputInfo output_info; |
| 88 InputInfo input_info; | 90 InputInfo input_info; |
| 89 if (!service->GetInfo(&output_info, &input_info)) { | 91 if (!service->GetInfo(&output_info, &input_info)) { |
| 90 SetError("Error occurred when querying audio device information."); | 92 SetError("Error occurred when querying audio device information."); |
| 91 return false; | 93 return false; |
| 92 } | 94 } |
| 93 | 95 |
| 94 results_ = audio::GetInfo::Results::Create(output_info, input_info); | 96 results_ = audio::GetInfo::Results::Create(output_info, input_info); |
| 95 return true; | 97 return true; |
| 96 } | 98 } |
| 97 | 99 |
| 98 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
| 99 | 101 |
| 100 bool AudioSetActiveDevicesFunction::RunSync() { | 102 bool AudioSetActiveDevicesFunction::RunSync() { |
| 101 scoped_ptr<audio::SetActiveDevices::Params> params( | 103 std::unique_ptr<audio::SetActiveDevices::Params> params( |
| 102 audio::SetActiveDevices::Params::Create(*args_)); | 104 audio::SetActiveDevices::Params::Create(*args_)); |
| 103 EXTENSION_FUNCTION_VALIDATE(params.get()); | 105 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 104 | 106 |
| 105 AudioService* service = | 107 AudioService* service = |
| 106 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); | 108 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| 107 DCHECK(service); | 109 DCHECK(service); |
| 108 | 110 |
| 109 service->SetActiveDevices(params->ids); | 111 service->SetActiveDevices(params->ids); |
| 110 return true; | 112 return true; |
| 111 } | 113 } |
| 112 | 114 |
| 113 /////////////////////////////////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////////////////////////////////// |
| 114 | 116 |
| 115 bool AudioSetPropertiesFunction::RunSync() { | 117 bool AudioSetPropertiesFunction::RunSync() { |
| 116 scoped_ptr<audio::SetProperties::Params> params( | 118 std::unique_ptr<audio::SetProperties::Params> params( |
| 117 audio::SetProperties::Params::Create(*args_)); | 119 audio::SetProperties::Params::Create(*args_)); |
| 118 EXTENSION_FUNCTION_VALIDATE(params.get()); | 120 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 119 | 121 |
| 120 AudioService* service = | 122 AudioService* service = |
| 121 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); | 123 AudioAPI::GetFactoryInstance()->Get(browser_context())->GetService(); |
| 122 DCHECK(service); | 124 DCHECK(service); |
| 123 | 125 |
| 124 int volume_value = params->properties.volume.get() ? | 126 int volume_value = params->properties.volume.get() ? |
| 125 *params->properties.volume : -1; | 127 *params->properties.volume : -1; |
| 126 | 128 |
| 127 int gain_value = params->properties.gain.get() ? | 129 int gain_value = params->properties.gain.get() ? |
| 128 *params->properties.gain : -1; | 130 *params->properties.gain : -1; |
| 129 | 131 |
| 130 if (!service->SetDeviceProperties(params->id, | 132 if (!service->SetDeviceProperties(params->id, |
| 131 params->properties.is_muted, | 133 params->properties.is_muted, |
| 132 volume_value, | 134 volume_value, |
| 133 gain_value)) | 135 gain_value)) |
| 134 return false; | 136 return false; |
| 135 else | 137 else |
| 136 return true; | 138 return true; |
| 137 } | 139 } |
| 138 | 140 |
| 139 /////////////////////////////////////////////////////////////////////////////// | 141 /////////////////////////////////////////////////////////////////////////////// |
| 140 | 142 |
| 141 } // namespace extensions | 143 } // namespace extensions |
| OLD | NEW |