| 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 "chrome/browser/extensions/api/audio/audio_api.h" | 5 #include "chrome/browser/extensions/api/audio/audio_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/extensions/api/audio.h" | 10 #include "chrome/common/extensions/api/audio.h" |
| 11 #include "extensions/browser/event_router.h" | 11 #include "extensions/browser/event_router.h" |
| 12 #include "extensions/browser/extension_system.h" | 12 #include "extensions/browser/extension_system.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 namespace audio = api::audio; | 16 namespace audio = api::audio; |
| 17 | 17 |
| 18 static base::LazyInstance<ProfileKeyedAPIFactory<AudioAPI> > | 18 static base::LazyInstance<BrowserContextKeyedAPIFactory<AudioAPI> > g_factory = |
| 19 g_factory = LAZY_INSTANCE_INITIALIZER; | 19 LAZY_INSTANCE_INITIALIZER; |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 ProfileKeyedAPIFactory<AudioAPI>* AudioAPI::GetFactoryInstance() { | 22 BrowserContextKeyedAPIFactory<AudioAPI>* AudioAPI::GetFactoryInstance() { |
| 23 return g_factory.Pointer(); | 23 return g_factory.Pointer(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 AudioAPI::AudioAPI(content::BrowserContext* context) | 26 AudioAPI::AudioAPI(content::BrowserContext* context) |
| 27 : browser_context_(context), service_(AudioService::CreateInstance()) { | 27 : browser_context_(context), service_(AudioService::CreateInstance()) { |
| 28 service_->AddObserver(this); | 28 service_->AddObserver(this); |
| 29 } | 29 } |
| 30 | 30 |
| 31 AudioAPI::~AudioAPI() { | 31 AudioAPI::~AudioAPI() { |
| 32 service_->RemoveObserver(this); | 32 service_->RemoveObserver(this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 scoped_ptr<Event> event(new Event( | 44 scoped_ptr<Event> event(new Event( |
| 45 audio::OnDeviceChanged::kEventName, | 45 audio::OnDeviceChanged::kEventName, |
| 46 scoped_ptr<base::ListValue>(new base::ListValue()))); | 46 scoped_ptr<base::ListValue>(new base::ListValue()))); |
| 47 ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent( | 47 ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent( |
| 48 event.Pass()); | 48 event.Pass()); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool AudioGetInfoFunction::RunImpl() { | 52 bool AudioGetInfoFunction::RunImpl() { |
| 53 AudioService* service = | 53 AudioService* service = |
| 54 AudioAPI::GetFactoryInstance()->GetForProfile(GetProfile())->GetService(); | 54 AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); |
| 55 DCHECK(service); | 55 DCHECK(service); |
| 56 service->StartGetInfo(base::Bind(&AudioGetInfoFunction::OnGetInfoCompleted, | 56 service->StartGetInfo(base::Bind(&AudioGetInfoFunction::OnGetInfoCompleted, |
| 57 this)); | 57 this)); |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void AudioGetInfoFunction::OnGetInfoCompleted(const OutputInfo& output_info, | 61 void AudioGetInfoFunction::OnGetInfoCompleted(const OutputInfo& output_info, |
| 62 const InputInfo& input_info, | 62 const InputInfo& input_info, |
| 63 bool success) { | 63 bool success) { |
| 64 if (success) | 64 if (success) |
| 65 results_ = api::audio::GetInfo::Results::Create(output_info, input_info); | 65 results_ = api::audio::GetInfo::Results::Create(output_info, input_info); |
| 66 else | 66 else |
| 67 SetError("Error occurred when querying audio device information."); | 67 SetError("Error occurred when querying audio device information."); |
| 68 SendResponse(success); | 68 SendResponse(success); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool AudioSetActiveDevicesFunction::RunImpl() { | 71 bool AudioSetActiveDevicesFunction::RunImpl() { |
| 72 scoped_ptr<api::audio::SetActiveDevices::Params> params( | 72 scoped_ptr<api::audio::SetActiveDevices::Params> params( |
| 73 api::audio::SetActiveDevices::Params::Create(*args_)); | 73 api::audio::SetActiveDevices::Params::Create(*args_)); |
| 74 EXTENSION_FUNCTION_VALIDATE(params.get()); | 74 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 75 | 75 |
| 76 AudioService* service = | 76 AudioService* service = |
| 77 AudioAPI::GetFactoryInstance()->GetForProfile(GetProfile())->GetService(); | 77 AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); |
| 78 DCHECK(service); | 78 DCHECK(service); |
| 79 | 79 |
| 80 service->SetActiveDevices(params->ids); | 80 service->SetActiveDevices(params->ids); |
| 81 return true; | 81 return true; |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool AudioSetPropertiesFunction::RunImpl() { | 84 bool AudioSetPropertiesFunction::RunImpl() { |
| 85 scoped_ptr<api::audio::SetProperties::Params> params( | 85 scoped_ptr<api::audio::SetProperties::Params> params( |
| 86 api::audio::SetProperties::Params::Create(*args_)); | 86 api::audio::SetProperties::Params::Create(*args_)); |
| 87 EXTENSION_FUNCTION_VALIDATE(params.get()); | 87 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 88 | 88 |
| 89 AudioService* service = | 89 AudioService* service = |
| 90 AudioAPI::GetFactoryInstance()->GetForProfile(GetProfile())->GetService(); | 90 AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); |
| 91 DCHECK(service); | 91 DCHECK(service); |
| 92 | 92 |
| 93 int volume_value = params->properties.volume.get() ? | 93 int volume_value = params->properties.volume.get() ? |
| 94 *params->properties.volume : -1; | 94 *params->properties.volume : -1; |
| 95 | 95 |
| 96 int gain_value = params->properties.gain.get() ? | 96 int gain_value = params->properties.gain.get() ? |
| 97 *params->properties.gain : -1; | 97 *params->properties.gain : -1; |
| 98 | 98 |
| 99 if (!service->SetDeviceProperties(params->id, | 99 if (!service->SetDeviceProperties(params->id, |
| 100 params->properties.is_muted, | 100 params->properties.is_muted, |
| 101 volume_value, | 101 volume_value, |
| 102 gain_value)) | 102 gain_value)) |
| 103 return false; | 103 return false; |
| 104 else | 104 else |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace extensions | 108 } // namespace extensions |
| OLD | NEW |