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

Side by Side Diff: content/browser/media/session/media_session_controllers_manager.cc

Issue 1698933004: Make MediaSession a runtime-enabled feature on Desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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
(Empty)
1 // Copyright 2016 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 "content/browser/media/session/media_session_controllers_manager.h"
6
7 #include "base/command_line.h"
8 #include "content/browser/media/session/media_session.h"
9 #include "content/browser/media/session/media_session_controller.h"
10 #include "content/browser/media/session/media_session_observer.h"
11 #include "media/base/media_switches.h"
12
13 namespace content {
14
15 namespace {
16
17 bool IsDefaultMediaSessionEnabled() {
18 #if defined(OS_ANDROID)
19 return true;
20 #else
21 return base::CommandLine::ForCurrentProcess()->HasSwitch(
22 switches::kEnableDefaultMediaSession);
23 #endif
24 }
25
26 } // anonymous namespace
27
28 MediaSessionControllersManager::MediaSessionControllersManager(
29 MediaWebContentsObserver* media_web_contents_observer)
30 : media_web_contents_observer_(media_web_contents_observer) {
31 }
32
33 MediaSessionControllersManager::~MediaSessionControllersManager() = default;
34
35 void MediaSessionControllersManager::RenderFrameDeleted(
36 RenderFrameHost* render_frame_host) {
37 if (!IsDefaultMediaSessionEnabled())
38 return;
39
40 for (auto it = controllers_map_.begin(); it != controllers_map_.end();) {
41 if (it->first.first == render_frame_host)
42 it = controllers_map_.erase(it);
43 else
44 ++it;
45 }
46 }
47
48 bool MediaSessionControllersManager::RequestPlay(const MediaPlayerId& id,
49 bool has_audio, bool is_remote, base::TimeDelta duration) {
50 if (!IsDefaultMediaSessionEnabled())
51 return true;
52
53 // Since we don't remove session instances on pause, there may be an existing
54 // instance for this playback attempt.
55 //
56 // In this case, try to reinitialize it with the new settings. If they are
57 // the same, this is a no-op. If the reinitialize fails, destroy the
58 // controller. A later playback attempt will create a new controller.
59 auto it = controllers_map_.find(id);
60 if (it != controllers_map_.end()) {
61 if (it->second->Initialize(has_audio, is_remote, duration))
62 return true;
63 controllers_map_.erase(it);
64 return false;
65 }
66
67 scoped_ptr<MediaSessionController> controller(
68 new MediaSessionController(id, media_web_contents_observer_));
69
70 if (!controller->Initialize(has_audio, is_remote, duration))
71 return false;
72
73 controllers_map_[id] = std::move(controller);
74 return true;
75 }
76
77 void MediaSessionControllersManager::OnPause(const MediaPlayerId& id) {
78 if (!IsDefaultMediaSessionEnabled())
79 return;
80
81 auto it = controllers_map_.find(id);
82 if (it == controllers_map_.end())
83 return;
84
85 it->second->OnPlaybackPaused();
86 }
87
88 void MediaSessionControllersManager::OnEnd(const MediaPlayerId& id) {
89 if (!IsDefaultMediaSessionEnabled())
90 return;
91 controllers_map_.erase(id);
92 }
93
94 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698