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

Side by Side Diff: chrome/browser/extensions/api/audio/audio_api.cc

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 6 years, 8 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
OLDNEW
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"
13 12
14 namespace extensions { 13 namespace extensions {
15 14
16 namespace audio = api::audio; 15 namespace audio = api::audio;
17 16
18 static base::LazyInstance<BrowserContextKeyedAPIFactory<AudioAPI> > g_factory = 17 static base::LazyInstance<BrowserContextKeyedAPIFactory<AudioAPI> > g_factory =
19 LAZY_INSTANCE_INITIALIZER; 18 LAZY_INSTANCE_INITIALIZER;
20 19
21 // static 20 // static
22 BrowserContextKeyedAPIFactory<AudioAPI>* AudioAPI::GetFactoryInstance() { 21 BrowserContextKeyedAPIFactory<AudioAPI>* AudioAPI::GetFactoryInstance() {
23 return g_factory.Pointer(); 22 return g_factory.Pointer();
24 } 23 }
25 24
26 AudioAPI::AudioAPI(content::BrowserContext* context) 25 AudioAPI::AudioAPI(content::BrowserContext* context)
27 : browser_context_(context), service_(AudioService::CreateInstance()) { 26 : browser_context_(context), 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 (browser_context_ && 41 if (browser_context_ && EventRouter::Get(browser_context_)) {
43 ExtensionSystem::Get(browser_context_)->event_router()) {
44 scoped_ptr<Event> event(new Event( 42 scoped_ptr<Event> event(new Event(
45 audio::OnDeviceChanged::kEventName, 43 audio::OnDeviceChanged::kEventName,
46 scoped_ptr<base::ListValue>(new base::ListValue()))); 44 scoped_ptr<base::ListValue>(new base::ListValue())));
47 ExtensionSystem::Get(browser_context_)->event_router()->BroadcastEvent( 45 EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
48 event.Pass());
49 } 46 }
50 } 47 }
51 48
52 bool AudioGetInfoFunction::RunImpl() { 49 bool AudioGetInfoFunction::RunImpl() {
53 AudioService* service = 50 AudioService* service =
54 AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService(); 51 AudioAPI::GetFactoryInstance()->Get(GetProfile())->GetService();
55 DCHECK(service); 52 DCHECK(service);
56 service->StartGetInfo(base::Bind(&AudioGetInfoFunction::OnGetInfoCompleted, 53 service->StartGetInfo(base::Bind(&AudioGetInfoFunction::OnGetInfoCompleted,
57 this)); 54 this));
58 return true; 55 return true;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (!service->SetDeviceProperties(params->id, 96 if (!service->SetDeviceProperties(params->id,
100 params->properties.is_muted, 97 params->properties.is_muted,
101 volume_value, 98 volume_value,
102 gain_value)) 99 gain_value))
103 return false; 100 return false;
104 else 101 else
105 return true; 102 return true;
106 } 103 }
107 104
108 } // namespace extensions 105 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698