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

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: remove windows specific stuff 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 MediaSessionControllersManager::MediaSessionControllersManager(
16 MediaWebContentsObserver* media_web_contents_observer)
17 : media_web_contents_observer_(media_web_contents_observer) {
18 }
19
20 MediaSessionControllersManager::~MediaSessionControllersManager() = default;
21
22 void MediaSessionControllersManager::Clear(RenderFrameHost* render_frame_host) {
23 if (!IsDefaultMediaSessionEnabled())
24 return;
25
26 for (auto it = controllers_map_.begin(); it != controllers_map_.end();) {
27 if (it->first.first == render_frame_host)
28 it = controllers_map_.erase(it);
29 else
30 ++it;
31 }
32 }
33
34 bool MediaSessionControllersManager::RequestPlay(const MediaPlayerId& id,
35 bool has_audio, bool is_remote, base::TimeDelta duration) {
36 if (!IsDefaultMediaSessionEnabled())
37 return true;
38
39 // Since we don't remove session instances on pause, there may be an existing
40 // instance for this playback attempt.
41 //
42 // In this case, try to reinitialize it with the new settings. If they are
43 // the same, this is a no-op. If the reinitialize fails, destroy the
44 // controller. A later playback attempt will create a new controller.
45 auto it = controllers_map_.find(id);
46 if (it != controllers_map_.end()) {
47 if (!it->second->Initialize(has_audio, is_remote, duration))
48 controllers_map_.erase(it);
49 return false;
50 }
51
52 scoped_ptr<MediaSessionController> controller(
53 new MediaSessionController(id, media_web_contents_observer_));
54
55 if (!controller->Initialize(has_audio, is_remote, duration))
56 return false;
57
58 controllers_map_[id] = std::move(controller);
59 return true;
60 }
61
62 void MediaSessionControllersManager::OnPause(const MediaPlayerId& id) {
63 if (!IsDefaultMediaSessionEnabled())
64 return;
65
66 auto it = controllers_map_.find(id);
67 if (it == controllers_map_.end())
68 return;
69
70 it->second->OnPlaybackPaused();
71 }
72
73 void MediaSessionControllersManager::OnEnd(const MediaPlayerId& id) {
74 if (!IsDefaultMediaSessionEnabled())
75 return;
76 controllers_map_.erase(id);
77 }
78
79 // static
80 bool MediaSessionControllersManager::IsDefaultMediaSessionEnabled() {
81 #if defined(OS_ANDROID)
82 return true;
83 #else
84 return base::CommandLine::ForCurrentProcess()->HasSwitch(
85 switches::kEnableDefaultMediaSession);
86 #endif
87 }
88
89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698