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

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: test 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 "ash/session/session_state_delegate.h"
8 #include "ash/session/user_info.h"
9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_notifier.h"
11 #include "chrome/browser/chromeos/extensions/media_player_api.h"
12 #include "chrome/browser/chromeos/extensions/media_player_event_router.h"
13 #include "chrome/browser/media/media_stream_capture_indicator.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/ash/multi_user/multi_user_window_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/web_contents.h"
21
22 namespace {
23
24 int GetMediaCaptureState(Browser* browser, content::BrowserContext* context) {
25 scoped_refptr<MediaStreamCaptureIndicator> indicator =
26 MediaCaptureDevicesDispatcher::GetInstance()
27 ->GetMediaStreamCaptureIndicator();
28
29 TabStripModel* tab_strip_model = browser->tab_strip_model();
30 int state = 0;
31 for (int i = 0; i < tab_strip_model->count(); ++i) {
32 content::WebContents* web_contents = tab_strip_model->GetWebContentsAt(i);
33 if (web_contents->GetBrowserContext() != context)
34 continue;
35 if (indicator->IsCapturingVideo(web_contents))
36 state |= ash::MEDIA_CAPTURE_VIDEO;
37 if (indicator->IsCapturingAudio(web_contents))
38 state |= ash::MEDIA_CAPTURE_AUDIO;
39 if (state == ash::MEDIA_CAPTURE_AUDIO_VIDEO)
40 break;
41 }
42 return state;
43 }
44
45 ash::MediaCaptureState GetBackgroundMediaCaptureStateInternal(
46 content::BrowserContext* context) {
47 if (!context)
48 return ash::MEDIA_CAPTURE_NONE;
49
50 const ash::SessionStateDelegate* session_state_delegate =
51 ash::Shell::GetInstance()->session_state_delegate();
52
53 chrome::MultiUserWindowManager* multi_user_window_manager =
54 chrome::MultiUserWindowManager::GetInstance();
55
56 const BrowserList* desktop_list =
57 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
58
59 const ash::UserInfo* desktop_user_info =
60 session_state_delegate->GetUserInfo(0);
61
62 int foreground_state = 0;
63 int background_state = 0;
64
65 // TODO(oshima): Check extensions/apps.
66 for (BrowserList::BrowserVector::const_iterator iter = desktop_list->begin();
67 iter != desktop_list->end();
68 ++iter) {
69 aura::Window* window = (*iter)->window()->GetNativeWindow();
70
71 if (multi_user_window_manager->IsWindowOnDesktopOfUser(
72 window, desktop_user_info->GetUserID())) {
73 if (foreground_state != ash::MEDIA_CAPTURE_AUDIO_VIDEO)
74 foreground_state |= GetMediaCaptureState(*iter, context);
75 } else if (background_state != ash::MEDIA_CAPTURE_AUDIO_VIDEO) {
76 background_state |= GetMediaCaptureState(*iter, context);
77 }
78 // If there are foreground tasks that record both, then
79 // no need to show indicator.
80 if (foreground_state == ash::MEDIA_CAPTURE_AUDIO_VIDEO)
Mr4D (OOO till 08-26) 2014/04/30 18:24:36 Why is that? If both are capturing - which is poss
oshima 2014/04/30 20:40:31 I confirmed this behavior with kuscher. I'm happy
Mr4D (OOO till 08-26) 2014/05/01 14:36:57 Yes, please let's discuss with kuscher since this
81 return ash::MEDIA_CAPTURE_NONE;
82 }
83
84 return static_cast<ash::MediaCaptureState>(background_state &
85 ~foreground_state);
86 }
87
88 } // namespace
89
90 MediaDelegateChromeOS::MediaDelegateChromeOS() {
91 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
92 }
93
94 MediaDelegateChromeOS::~MediaDelegateChromeOS() {
95 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
96 }
97
98 void MediaDelegateChromeOS::HandleMediaNextTrack() {
99 extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
100 ->media_player_event_router()
101 ->NotifyNextTrack();
102 }
103
104 void MediaDelegateChromeOS::HandleMediaPlayPause() {
105 extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
106 ->media_player_event_router()
107 ->NotifyTogglePlayState();
108 }
109
110 void MediaDelegateChromeOS::HandleMediaPrevTrack() {
111 extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
112 ->media_player_event_router()
113 ->NotifyPrevTrack();
114 }
115
116 ash::MediaCaptureState MediaDelegateChromeOS::GetBackgroundMediaCaptureState(
117 content::BrowserContext* context) {
118 return GetBackgroundMediaCaptureStateInternal(context);
119 }
120
121 void MediaDelegateChromeOS::OnRequestUpdate(
122 int render_process_id,
123 int render_view_id,
124 const content::MediaStreamDevice& device,
125 const content::MediaRequestState state) {
126 ash::Shell::GetInstance()
127 ->system_tray_notifier()
128 ->NotifyMediaCaptureChanged();
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698