| 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/common/extensions/api/audio.h" | 9 #include "chrome/common/extensions/api/audio.h" |
| 10 #include "extensions/browser/event_router.h" | 10 #include "extensions/browser/event_router.h" |
| 11 #include "extensions/browser/extension_system.h" | 11 #include "extensions/browser/extension_system.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 namespace audio = api::audio; | 15 namespace audio = api::audio; |
| 16 | 16 |
| 17 static base::LazyInstance<ProfileKeyedAPIFactory<AudioAPI> > | 17 static base::LazyInstance<ProfileKeyedAPIFactory<AudioAPI> > |
| 18 g_factory = LAZY_INSTANCE_INITIALIZER; | 18 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 ProfileKeyedAPIFactory<AudioAPI>* AudioAPI::GetFactoryInstance() { | 21 ProfileKeyedAPIFactory<AudioAPI>* AudioAPI::GetFactoryInstance() { |
| 22 return g_factory.Pointer(); | 22 return g_factory.Pointer(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 AudioAPI::AudioAPI(Profile* profile) | 25 AudioAPI::AudioAPI(content::BrowserContext* context) |
| 26 : profile_(profile), | 26 : context_(context), service_(AudioService::CreateInstance()) { |
| 27 service_(AudioService::CreateInstance()) { | |
| 28 service_->AddObserver(this); | 27 service_->AddObserver(this); |
| 29 } | 28 } |
| 30 | 29 |
| 31 AudioAPI::~AudioAPI() { | 30 AudioAPI::~AudioAPI() { |
| 32 service_->RemoveObserver(this); | 31 service_->RemoveObserver(this); |
| 33 delete service_; | 32 delete service_; |
| 34 service_ = NULL; | 33 service_ = NULL; |
| 35 } | 34 } |
| 36 | 35 |
| 37 AudioService* AudioAPI::GetService() const { | 36 AudioService* AudioAPI::GetService() const { |
| 38 return service_; | 37 return service_; |
| 39 } | 38 } |
| 40 | 39 |
| 41 void AudioAPI::OnDeviceChanged() { | 40 void AudioAPI::OnDeviceChanged() { |
| 42 if (profile_ && ExtensionSystem::Get(profile_)->event_router()) { | 41 if (context_ && ExtensionSystem::Get(context_)->event_router()) { |
| 43 scoped_ptr<Event> event(new Event( | 42 scoped_ptr<Event> event(new Event( |
| 44 audio::OnDeviceChanged::kEventName, | 43 audio::OnDeviceChanged::kEventName, |
| 45 scoped_ptr<base::ListValue>(new base::ListValue()))); | 44 scoped_ptr<base::ListValue>(new base::ListValue()))); |
| 46 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent( | 45 ExtensionSystem::Get(context_)->event_router()->BroadcastEvent( |
| 47 event.Pass()); | 46 event.Pass()); |
| 48 } | 47 } |
| 49 } | 48 } |
| 50 | 49 |
| 51 bool AudioGetInfoFunction::RunImpl() { | 50 bool AudioGetInfoFunction::RunImpl() { |
| 52 AudioService* service = | 51 AudioService* service = |
| 53 AudioAPI::GetFactoryInstance()->GetForProfile(GetProfile())->GetService(); | 52 AudioAPI::GetFactoryInstance()->GetForProfile(GetProfile())->GetService(); |
| 54 DCHECK(service); | 53 DCHECK(service); |
| 55 service->StartGetInfo(base::Bind(&AudioGetInfoFunction::OnGetInfoCompleted, | 54 service->StartGetInfo(base::Bind(&AudioGetInfoFunction::OnGetInfoCompleted, |
| 56 this)); | 55 this)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (!service->SetDeviceProperties(params->id, | 97 if (!service->SetDeviceProperties(params->id, |
| 99 params->properties.is_muted, | 98 params->properties.is_muted, |
| 100 volume_value, | 99 volume_value, |
| 101 gain_value)) | 100 gain_value)) |
| 102 return false; | 101 return false; |
| 103 else | 102 else |
| 104 return true; | 103 return true; |
| 105 } | 104 } |
| 106 | 105 |
| 107 } // namespace extensions | 106 } // namespace extensions |
| OLD | NEW |