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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/media_delegate_chromeos.cc
diff --git a/chrome/browser/ui/ash/media_delegate_chromeos.cc b/chrome/browser/ui/ash/media_delegate_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..847820055099a3bbc816167dc64d267e1d9af961
--- /dev/null
+++ b/chrome/browser/ui/ash/media_delegate_chromeos.cc
@@ -0,0 +1,129 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/ash/media_delegate_chromeos.h"
+
+#include "ash/session/session_state_delegate.h"
+#include "ash/session/user_info.h"
+#include "ash/shell.h"
+#include "ash/system/tray/system_tray_notifier.h"
+#include "chrome/browser/chromeos/extensions/media_player_api.h"
+#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
+#include "chrome/browser/media/media_stream_capture_indicator.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "content/public/browser/web_contents.h"
+
+namespace {
+
+int GetMediaCaptureState(Browser* browser, content::BrowserContext* context) {
+ scoped_refptr<MediaStreamCaptureIndicator> indicator =
+ MediaCaptureDevicesDispatcher::GetInstance()
+ ->GetMediaStreamCaptureIndicator();
+
+ TabStripModel* tab_strip_model = browser->tab_strip_model();
+ int state = 0;
+ for (int i = 0; i < tab_strip_model->count(); ++i) {
+ content::WebContents* web_contents = tab_strip_model->GetWebContentsAt(i);
+ if (web_contents->GetBrowserContext() != context)
+ continue;
+ if (indicator->IsCapturingVideo(web_contents))
+ state |= ash::MEDIA_CAPTURE_VIDEO;
+ if (indicator->IsCapturingAudio(web_contents))
+ state |= ash::MEDIA_CAPTURE_AUDIO;
+ if (state == ash::MEDIA_CAPTURE_AUDIO_VIDEO)
+ break;
+ }
+ return state;
+}
+
+ash::MediaCaptureState GetBackgroundMediaCaptureStateInternal(
+ content::BrowserContext* context) {
+ if (!context)
+ return ash::MEDIA_CAPTURE_NONE;
+
+ const ash::SessionStateDelegate* session_state_delegate =
+ ash::Shell::GetInstance()->session_state_delegate();
+
+ chrome::MultiUserWindowManager* multi_user_window_manager =
+ chrome::MultiUserWindowManager::GetInstance();
+
+ const BrowserList* desktop_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+
+ const ash::UserInfo* desktop_user_info =
+ session_state_delegate->GetUserInfo(0);
+
+ int foreground_state = 0;
+ int background_state = 0;
+
+ // TODO(oshima): Check extensions/apps.
+ for (BrowserList::BrowserVector::const_iterator iter = desktop_list->begin();
+ iter != desktop_list->end();
+ ++iter) {
+ aura::Window* window = (*iter)->window()->GetNativeWindow();
+
+ if (multi_user_window_manager->IsWindowOnDesktopOfUser(
+ window, desktop_user_info->GetUserID())) {
+ if (foreground_state != ash::MEDIA_CAPTURE_AUDIO_VIDEO)
+ foreground_state |= GetMediaCaptureState(*iter, context);
+ } else if (background_state != ash::MEDIA_CAPTURE_AUDIO_VIDEO) {
+ background_state |= GetMediaCaptureState(*iter, context);
+ }
+ // If there are foreground tasks that record both, then
+ // no need to show indicator.
+ 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
+ return ash::MEDIA_CAPTURE_NONE;
+ }
+
+ return static_cast<ash::MediaCaptureState>(background_state &
+ ~foreground_state);
+}
+
+} // namespace
+
+MediaDelegateChromeOS::MediaDelegateChromeOS() {
+ MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
+}
+
+MediaDelegateChromeOS::~MediaDelegateChromeOS() {
+ MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
+}
+
+void MediaDelegateChromeOS::HandleMediaNextTrack() {
+ extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
+ ->media_player_event_router()
+ ->NotifyNextTrack();
+}
+
+void MediaDelegateChromeOS::HandleMediaPlayPause() {
+ extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
+ ->media_player_event_router()
+ ->NotifyTogglePlayState();
+}
+
+void MediaDelegateChromeOS::HandleMediaPrevTrack() {
+ extensions::MediaPlayerAPI::Get(ProfileManager::GetActiveUserProfile())
+ ->media_player_event_router()
+ ->NotifyPrevTrack();
+}
+
+ash::MediaCaptureState MediaDelegateChromeOS::GetBackgroundMediaCaptureState(
+ content::BrowserContext* context) {
+ return GetBackgroundMediaCaptureStateInternal(context);
+}
+
+void MediaDelegateChromeOS::OnRequestUpdate(
+ int render_process_id,
+ int render_view_id,
+ const content::MediaStreamDevice& device,
+ const content::MediaRequestState state) {
+ ash::Shell::GetInstance()
+ ->system_tray_notifier()
+ ->NotifyMediaCaptureChanged();
+}

Powered by Google App Engine
This is Rietveld 408576698