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

Side by Side Diff: chrome/browser/ui/ash/media_delegate_chromeos.cc

Issue 253183003: Media indicator for background recording task (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: support apps/exetnsions Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/media_delegate_chromeos.h"
6
7 #include "apps/app_window.h"
8 #include "apps/app_window_registry.h"
9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_notifier.h"
11 #include "base/message_loop/message_loop.h"
12 #include "chrome/browser/chromeos/extensions/media_player_api.h"
13 #include "chrome/browser/chromeos/extensions/media_player_event_router.h"
14 #include "chrome/browser/media/media_stream_capture_indicator.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/web_contents.h"
22 #include "extensions/browser/extension_system.h"
23 #include "extensions/browser/process_manager.h"
24
25 namespace {
26
27 void GetMediaCaptureState(
28 const MediaStreamCaptureIndicator* indicator,
29 content::WebContents* web_contents,
30 int* media_state_out) {
31 if (indicator->IsCapturingVideo(web_contents))
32 *media_state_out |= ash::MEDIA_CAPTURE_VIDEO;
33 if (indicator->IsCapturingAudio(web_contents))
34 *media_state_out |= ash::MEDIA_CAPTURE_AUDIO;
35 }
36
37 void GetBrowserMediaCaptureState(
38 const MediaStreamCaptureIndicator* indicator,
39 const content::BrowserContext* context,
40 int* media_state_out) {
41
42 const BrowserList* desktop_list =
43 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
44
45 for (BrowserList::BrowserVector::const_iterator iter = desktop_list->begin();
46 iter != desktop_list->end();
47 ++iter) {
48 TabStripModel* tab_strip_model = (*iter)->tab_strip_model();
49 for (int i = 0; i < tab_strip_model->count(); ++i) {
50 content::WebContents* web_contents = tab_strip_model->GetWebContentsAt(i);
51 if (web_contents->GetBrowserContext() != context)
Mr4D (OOO till 08-26) 2014/05/02 18:07:29 Moment - didn't we want to find the state for the
oshima 2014/05/02 18:59:05 The context passed by caller is other user's conte
Mr4D (OOO till 08-26) 2014/05/02 19:27:27 Right. But I was looking at the code for performan
52 continue;
53 GetMediaCaptureState(indicator, web_contents, media_state_out);
54 if (*media_state_out == ash::MEDIA_CAPTURE_AUDIO_VIDEO)
55 return;
56 }
57 }
58 }
59
60 void GetAppMediaCaptureState(
61 const MediaStreamCaptureIndicator* indicator,
62 content::BrowserContext* context,
63 int* media_state_out) {
64 const apps::AppWindowRegistry::AppWindowList& apps =
65 apps::AppWindowRegistry::Get(context)->app_windows();
66 for (apps::AppWindowRegistry::AppWindowList::const_iterator iter =
67 apps.begin();
68 iter != apps.end();
69 ++iter) {
70 GetMediaCaptureState(indicator, (*iter)->web_contents(), media_state_out);
71 if (*media_state_out == ash::MEDIA_CAPTURE_AUDIO_VIDEO)
72 return;
73 }
74 }
75
76 void GetExtensionMediaCaptureState(
77 const MediaStreamCaptureIndicator* indicator,
78 content::BrowserContext* context,
79 int* media_state_out) {
80 extensions::ProcessManager* process_manager =
81 extensions::ExtensionSystem::Get(context)->process_manager();
82 const extensions::ProcessManager::ViewSet view_set =
83 process_manager->GetAllViews();
84 for (extensions::ProcessManager::ViewSet::const_iterator iter =
85 view_set.begin();
86 iter != view_set.end();
87 ++iter) {
88 content::WebContents* web_contents =
89 content::WebContents::FromRenderViewHost(*iter);
90 // RVH may not have web contents.
91 if (!web_contents)
92 continue;
93 GetMediaCaptureState(indicator, web_contents, media_state_out);
94 if (*media_state_out == ash::MEDIA_CAPTURE_AUDIO_VIDEO)
95 return;
96 }
97 }
98
99 ash::MediaCaptureState GetMediaCaptureStateOfAllWebContents(
100 content::BrowserContext* context) {
101 if (!context)
102 return ash::MEDIA_CAPTURE_NONE;
103
104 scoped_refptr<MediaStreamCaptureIndicator> indicator =
105 MediaCaptureDevicesDispatcher::GetInstance()
106 ->GetMediaStreamCaptureIndicator();
107
108 int media_state = ash::MEDIA_CAPTURE_NONE;
109 // Browser windows
110 GetBrowserMediaCaptureState(indicator.get(), context, &media_state);
111
112 // App windows
113 if (media_state != ash::MEDIA_CAPTURE_AUDIO_VIDEO)
Mr4D (OOO till 08-26) 2014/05/02 18:07:29 You might want to use brackets here to cover this
oshima 2014/05/02 18:59:05 I changed to early exit instead. I think it's easi
114 GetAppMediaCaptureState(indicator.get(), context, &media_state);
115
116 // Extensions
117 if (media_state != ash::MEDIA_CAPTURE_AUDIO_VIDEO)
118 GetExtensionMediaCaptureState(indicator.get(), context, &media_state);
119
120 return static_cast<ash::MediaCaptureState>(media_state);
121 }
122
123 } // namespace
124
125 MediaDelegateChromeOS::MediaDelegateChromeOS() : weak_ptr_factory_(this) {
126 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
127 }
128
129 MediaDelegateChromeOS::~MediaDelegateChromeOS() {
130 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
131 }
132
133 void MediaDelegateChromeOS::HandleMediaNextTrack() {
134 extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
135 ->media_player_event_router()
136 ->NotifyNextTrack();
137 }
138
139 void MediaDelegateChromeOS::HandleMediaPlayPause() {
140 extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
141 ->media_player_event_router()
142 ->NotifyTogglePlayState();
143 }
144
145 void MediaDelegateChromeOS::HandleMediaPrevTrack() {
146 extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
147 ->media_player_event_router()
148 ->NotifyPrevTrack();
149 }
150
151 ash::MediaCaptureState MediaDelegateChromeOS::GetMediaCaptureState(
152 content::BrowserContext* context) {
153 return GetMediaCaptureStateOfAllWebContents(context);
154 }
155
156 void MediaDelegateChromeOS::OnRequestUpdate(
157 int render_process_id,
158 int render_view_id,
159 const content::MediaStreamDevice& device,
160 const content::MediaRequestState state) {
161 base::MessageLoopForUI::current()->PostTask(
162 FROM_HERE,
163 base::Bind(&MediaDelegateChromeOS::NotifyMediaCaptureChange,
164 weak_ptr_factory_.GetWeakPtr()));
165 }
166
167 void MediaDelegateChromeOS::NotifyMediaCaptureChange() {
168 ash::Shell::GetInstance()
169 ->system_tray_notifier()
170 ->NotifyMediaCaptureChanged();
171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698