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

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

Issue 2798083002: Record user interactions with MediaSession by action type (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/media/session/media_session_impl.h" 5 #include "content/browser/media/session/media_session_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include "content/browser/media/session/audio_focus_delegate.h" 8 #include "content/browser/media/session/audio_focus_delegate.h"
9 #include "content/browser/media/session/media_session_controller.h" 9 #include "content/browser/media/session/media_session_controller.h"
10 #include "content/browser/media/session/media_session_player_observer.h" 10 #include "content/browser/media/session/media_session_player_observer.h"
11 #include "content/browser/media/session/media_session_service_impl.h" 11 #include "content/browser/media/session/media_session_service_impl.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 12 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/public/browser/media_session.h" 13 #include "content/public/browser/media_session.h"
14 #include "content/public/browser/media_session_observer.h" 14 #include "content/public/browser/media_session_observer.h"
15 #include "content/public/browser/navigation_handle.h" 15 #include "content/public/browser/navigation_handle.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "media/base/media_content_type.h" 17 #include "media/base/media_content_type.h"
18 #include "third_party/WebKit/public/platform/modules/mediasession/media_session. mojom.h"
18 19
19 #if defined(OS_ANDROID) 20 #if defined(OS_ANDROID)
20 #include "content/browser/media/session/media_session_android.h" 21 #include "content/browser/media/session/media_session_android.h"
21 #endif // defined(OS_ANDROID) 22 #endif // defined(OS_ANDROID)
22 23
23 namespace content { 24 namespace content {
24 25
26 using MediaSessionUserAction = MediaSessionUmaHelper::MediaSessionUserAction;
27
25 namespace { 28 namespace {
26 29
27 const double kDefaultVolumeMultiplier = 1.0; 30 const double kDefaultVolumeMultiplier = 1.0;
28 const double kDuckingVolumeMultiplier = 0.2; 31 const double kDuckingVolumeMultiplier = 0.2;
29 32
30 using MapRenderFrameHostToDepth = std::map<RenderFrameHost*, size_t>; 33 using MapRenderFrameHostToDepth = std::map<RenderFrameHost*, size_t>;
31 34
32 size_t ComputeFrameDepth(RenderFrameHost* rfh, 35 size_t ComputeFrameDepth(RenderFrameHost* rfh,
33 MapRenderFrameHostToDepth* map_rfh_to_depth) { 36 MapRenderFrameHostToDepth* map_rfh_to_depth) {
34 DCHECK(rfh); 37 DCHECK(rfh);
35 size_t depth = 0; 38 size_t depth = 0;
36 RenderFrameHost* current_frame = rfh; 39 RenderFrameHost* current_frame = rfh;
37 while (current_frame) { 40 while (current_frame) {
38 auto it = map_rfh_to_depth->find(current_frame); 41 auto it = map_rfh_to_depth->find(current_frame);
39 if (it != map_rfh_to_depth->end()) { 42 if (it != map_rfh_to_depth->end()) {
40 depth += it->second; 43 depth += it->second;
41 break; 44 break;
42 } 45 }
43 ++depth; 46 ++depth;
44 current_frame = current_frame->GetParent(); 47 current_frame = current_frame->GetParent();
45 } 48 }
46 (*map_rfh_to_depth)[rfh] = depth; 49 (*map_rfh_to_depth)[rfh] = depth;
47 return depth; 50 return depth;
48 } 51 }
49 52
53 MediaSessionUserAction MediaSessionActionToUserAction(
54 blink::mojom::MediaSessionAction action) {
55 switch (action) {
56 case blink::mojom::MediaSessionAction::PLAY:
57 return MediaSessionUserAction::Play;
58 case blink::mojom::MediaSessionAction::PAUSE:
59 return MediaSessionUserAction::Pause;
60 case blink::mojom::MediaSessionAction::PREVIOUS_TRACK:
61 return MediaSessionUserAction::PreviousTrack;
62 case blink::mojom::MediaSessionAction::NEXT_TRACK:
63 return MediaSessionUserAction::NextTrack;
64 case blink::mojom::MediaSessionAction::SEEK_BACKWARD:
65 return MediaSessionUserAction::SeekBackward;
66 case blink::mojom::MediaSessionAction::SEEK_FORWARD:
67 return MediaSessionUserAction::SeekForward;
68 default:
mlamouri (slow - plz ping) 2017/04/07 11:15:55 Add the case for COUNT here so all cases are taken
Zhiqiang Zhang (Slow) 2017/04/07 15:12:43 Actually, the mojo enum only have LAST (= SEEK_FOR
69 NOTREACHED();
70 }
71 return MediaSessionUserAction::Count;
72 }
73
50 } // anonymous namespace 74 } // anonymous namespace
51 75
52 using MediaSessionSuspendedSource = 76 using MediaSessionSuspendedSource =
53 MediaSessionUmaHelper::MediaSessionSuspendedSource; 77 MediaSessionUmaHelper::MediaSessionSuspendedSource;
54 78
55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MediaSessionImpl); 79 DEFINE_WEB_CONTENTS_USER_DATA_KEY(MediaSessionImpl);
56 80
57 MediaSessionImpl::PlayerIdentifier::PlayerIdentifier( 81 MediaSessionImpl::PlayerIdentifier::PlayerIdentifier(
58 MediaSessionPlayerObserver* observer, 82 MediaSessionPlayerObserver* observer,
59 int player_id) 83 int player_id)
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 327 }
304 328
305 // Otherwise, suspend the session. 329 // Otherwise, suspend the session.
306 DCHECK(IsActive()); 330 DCHECK(IsActive());
307 OnSuspendInternal(SuspendType::CONTENT, State::SUSPENDED); 331 OnSuspendInternal(SuspendType::CONTENT, State::SUSPENDED);
308 } 332 }
309 333
310 void MediaSessionImpl::Resume(SuspendType suspend_type) { 334 void MediaSessionImpl::Resume(SuspendType suspend_type) {
311 DCHECK(IsSuspended()); 335 DCHECK(IsSuspended());
312 336
337 if (suspend_type == SuspendType::UI) {
338 uma_helper_.RecordMediaSessionUserAction(
339 MediaSessionUmaHelper::MediaSessionUserAction::PlayDefault);
340 }
341
313 // When the resume requests comes from another source than system, audio focus 342 // When the resume requests comes from another source than system, audio focus
314 // must be requested. 343 // must be requested.
315 if (suspend_type != SuspendType::SYSTEM) { 344 if (suspend_type != SuspendType::SYSTEM) {
316 // Request audio focus again in case we lost it because another app started 345 // Request audio focus again in case we lost it because another app started
317 // playing while the playback was paused. 346 // playing while the playback was paused.
318 State audio_focus_state = RequestSystemAudioFocus(audio_focus_type_) 347 State audio_focus_state = RequestSystemAudioFocus(audio_focus_type_)
319 ? State::ACTIVE 348 ? State::ACTIVE
320 : State::INACTIVE; 349 : State::INACTIVE;
321 SetAudioFocusState(audio_focus_state); 350 SetAudioFocusState(audio_focus_state);
322 351
323 if (audio_focus_state_ != State::ACTIVE) 352 if (audio_focus_state_ != State::ACTIVE)
324 return; 353 return;
325 } 354 }
326 355
327 OnResumeInternal(suspend_type); 356 OnResumeInternal(suspend_type);
328 } 357 }
329 358
330 void MediaSessionImpl::Suspend(SuspendType suspend_type) { 359 void MediaSessionImpl::Suspend(SuspendType suspend_type) {
331 if (!IsActive()) 360 if (!IsActive())
332 return; 361 return;
333 362
363 if (suspend_type == SuspendType::UI) {
364 uma_helper_.RecordMediaSessionUserAction(
365 MediaSessionUmaHelper::MediaSessionUserAction::PlayDefault);
mlamouri (slow - plz ping) 2017/04/07 11:15:55 ::PauseDefault?
Zhiqiang Zhang (Slow) 2017/04/07 15:12:43 Done.
366 }
367
334 OnSuspendInternal(suspend_type, State::SUSPENDED); 368 OnSuspendInternal(suspend_type, State::SUSPENDED);
335 } 369 }
336 370
337 void MediaSessionImpl::Stop(SuspendType suspend_type) { 371 void MediaSessionImpl::Stop(SuspendType suspend_type) {
338 DCHECK(audio_focus_state_ != State::INACTIVE); 372 DCHECK(audio_focus_state_ != State::INACTIVE);
339 DCHECK(suspend_type != SuspendType::CONTENT); 373 DCHECK(suspend_type != SuspendType::CONTENT);
340 DCHECK(!HasPepper()); 374 DCHECK(!HasPepper());
341 375
376 if (suspend_type == SuspendType::UI) {
377 uma_helper_.RecordMediaSessionUserAction(
378 MediaSessionUmaHelper::MediaSessionUserAction::StopDefault);
379 }
380
342 // TODO(mlamouri): merge the logic between UI and SYSTEM. 381 // TODO(mlamouri): merge the logic between UI and SYSTEM.
343 if (suspend_type == SuspendType::SYSTEM) { 382 if (suspend_type == SuspendType::SYSTEM) {
344 OnSuspendInternal(suspend_type, State::INACTIVE); 383 OnSuspendInternal(suspend_type, State::INACTIVE);
345 return; 384 return;
346 } 385 }
347 386
348 if (audio_focus_state_ != State::SUSPENDED) 387 if (audio_focus_state_ != State::SUSPENDED)
349 OnSuspendInternal(suspend_type, State::SUSPENDED); 388 OnSuspendInternal(suspend_type, State::SUSPENDED);
350 389
351 DCHECK(audio_focus_state_ == State::SUSPENDED); 390 DCHECK(audio_focus_state_ == State::SUSPENDED);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 void MediaSessionImpl::OnMediaSessionActionsChanged( 667 void MediaSessionImpl::OnMediaSessionActionsChanged(
629 MediaSessionServiceImpl* service) { 668 MediaSessionServiceImpl* service) {
630 if (service != routed_service_) 669 if (service != routed_service_)
631 return; 670 return;
632 671
633 NotifyMediaSessionActionsChange(routed_service_->actions()); 672 NotifyMediaSessionActionsChange(routed_service_->actions());
634 } 673 }
635 674
636 void MediaSessionImpl::DidReceiveAction( 675 void MediaSessionImpl::DidReceiveAction(
637 blink::mojom::MediaSessionAction action) { 676 blink::mojom::MediaSessionAction action) {
677 uma_helper_.RecordMediaSessionUserAction(
678 MediaSessionActionToUserAction(action));
679
638 // Pause all players in non-routed frames if the action is PAUSE. 680 // Pause all players in non-routed frames if the action is PAUSE.
639 // 681 //
640 // This is the default PAUSE action handler per Media Session API spec. The 682 // This is the default PAUSE action handler per Media Session API spec. The
641 // reason for pausing all players in all other sessions is to avoid the 683 // reason for pausing all players in all other sessions is to avoid the
642 // players in other frames keep the session active so that the UI will always 684 // players in other frames keep the session active so that the UI will always
643 // show the pause button but it does not pause anything (as the routed frame 685 // show the pause button but it does not pause anything (as the routed frame
644 // already pauses when responding to the PAUSE action while other frames does 686 // already pauses when responding to the PAUSE action while other frames does
645 // not). 687 // not).
646 // 688 //
647 // TODO(zqzhang): Currently, this might not work well on desktop as Pepper and 689 // TODO(zqzhang): Currently, this might not work well on desktop as Pepper and
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 if (!IsServiceActiveForRenderFrameHost(frame)) 766 if (!IsServiceActiveForRenderFrameHost(frame))
725 continue; 767 continue;
726 best_frame = frame; 768 best_frame = frame;
727 min_depth = depth; 769 min_depth = depth;
728 } 770 }
729 771
730 return best_frame ? services_[best_frame] : nullptr; 772 return best_frame ? services_[best_frame] : nullptr;
731 } 773 }
732 774
733 } // namespace content 775 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698