OLD | NEW |
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/chromeos/extensions/media_player_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "chrome/browser/extensions/event_router.h" | 8 #include "chrome/browser/extensions/event_router.h" |
9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 | 11 |
| 12 static void BroadcastEvent(Profile* profile, const std::string& event_name) { |
| 13 if (profile && extensions::ExtensionSystem::Get(profile)->event_router()) { |
| 14 scoped_ptr<ListValue> args(new ListValue()); |
| 15 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 16 event_name, args.Pass())); |
| 17 extensions::ExtensionSystem::Get(profile)->event_router()-> |
| 18 BroadcastEvent(event.Pass()); |
| 19 } |
| 20 } |
| 21 |
12 ExtensionMediaPlayerEventRouter::ExtensionMediaPlayerEventRouter() | 22 ExtensionMediaPlayerEventRouter::ExtensionMediaPlayerEventRouter() |
13 : profile_(NULL) { | 23 : profile_(NULL) { |
14 } | 24 } |
15 | 25 |
16 ExtensionMediaPlayerEventRouter* | 26 ExtensionMediaPlayerEventRouter* |
17 ExtensionMediaPlayerEventRouter::GetInstance() { | 27 ExtensionMediaPlayerEventRouter::GetInstance() { |
18 return Singleton<ExtensionMediaPlayerEventRouter>::get(); | 28 return Singleton<ExtensionMediaPlayerEventRouter>::get(); |
19 } | 29 } |
20 | 30 |
21 void ExtensionMediaPlayerEventRouter::Init(Profile* profile) { | 31 void ExtensionMediaPlayerEventRouter::Init(Profile* profile) { |
22 profile_ = profile; | 32 profile_ = profile; |
23 } | 33 } |
24 | 34 |
25 void ExtensionMediaPlayerEventRouter::NotifyNextTrack() { | 35 void ExtensionMediaPlayerEventRouter::NotifyNextTrack() { |
26 if (profile_ && extensions::ExtensionSystem::Get(profile_)->event_router()) { | 36 BroadcastEvent(profile_, "mediaPlayerPrivate.onNextTrack"); |
27 scoped_ptr<ListValue> args(new ListValue()); | |
28 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
29 DispatchEventToRenderers("mediaPlayerPrivate.onNextTrack", args.Pass(), | |
30 NULL, GURL()); | |
31 } | |
32 } | 37 } |
33 | 38 |
34 void ExtensionMediaPlayerEventRouter::NotifyPlaylistChanged() { | 39 void ExtensionMediaPlayerEventRouter::NotifyPlaylistChanged() { |
35 if (profile_ && extensions::ExtensionSystem::Get(profile_)->event_router()) { | 40 BroadcastEvent(profile_, "mediaPlayerPrivate.onPlaylistChanged"); |
36 scoped_ptr<ListValue> args(new ListValue()); | |
37 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
38 DispatchEventToRenderers("mediaPlayerPrivate.onPlaylistChanged", | |
39 args.Pass(), NULL, GURL()); | |
40 } | |
41 } | 41 } |
42 | 42 |
43 void ExtensionMediaPlayerEventRouter::NotifyPrevTrack() { | 43 void ExtensionMediaPlayerEventRouter::NotifyPrevTrack() { |
44 if (profile_ && extensions::ExtensionSystem::Get(profile_)->event_router()) { | 44 BroadcastEvent(profile_, "mediaPlayerPrivate.onPrevTrack"); |
45 scoped_ptr<ListValue> args(new ListValue()); | |
46 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
47 DispatchEventToRenderers("mediaPlayerPrivate.onPrevTrack", args.Pass(), | |
48 NULL, GURL()); | |
49 } | |
50 } | 45 } |
51 | 46 |
52 void ExtensionMediaPlayerEventRouter::NotifyTogglePlayState() { | 47 void ExtensionMediaPlayerEventRouter::NotifyTogglePlayState() { |
53 if (profile_ && extensions::ExtensionSystem::Get(profile_)->event_router()) { | 48 BroadcastEvent(profile_, "mediaPlayerPrivate.onTogglePlayState"); |
54 scoped_ptr<ListValue> args(new ListValue()); | |
55 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
56 DispatchEventToRenderers("mediaPlayerPrivate.onTogglePlayState", | |
57 args.Pass(), NULL, GURL()); | |
58 } | |
59 } | 49 } |
OLD | NEW |