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

Side by Side Diff: content/renderer/media/render_media_client.cc

Issue 2712983004: Simplify/Cleanup MediaClient (Closed)
Patch Set: Little fixes 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 2014 The Chromium Authors. All rights reserved. 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 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/renderer/media/render_media_client.h" 5 #include "content/renderer/media/render_media_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/time/default_tick_clock.h" 9 #include "base/time/default_tick_clock.h"
10 #include "content/public/common/content_client.h" 10 #include "content/public/common/content_client.h"
11 #include "content/public/renderer/content_renderer_client.h" 11 #include "content/public/renderer/content_renderer_client.h"
12 #include "media/base/media_switches.h" 12 #include "media/base/media_switches.h"
13 #include "media/base/video_color_space.h" 13 #include "media/base/video_color_space.h"
14 #include "ui/display/display_switches.h" 14 #include "ui/display/display_switches.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 void RenderMediaClient::Initialize() { 18 void RenderMediaClient::Initialize() {
19 GetInstance(); 19 static RenderMediaClient* client = new RenderMediaClient();
20 media::SetMediaClient(client);
20 } 21 }
21 22
22 RenderMediaClient::RenderMediaClient() 23 RenderMediaClient::RenderMediaClient() {}
23 : has_updated_(false),
24 is_update_needed_(true),
25 tick_clock_(new base::DefaultTickClock()) {
26 media::SetMediaClient(this);
27 }
28 24
29 RenderMediaClient::~RenderMediaClient() { 25 RenderMediaClient::~RenderMediaClient() {
30 } 26 }
31 27
32 void RenderMediaClient::AddKeySystemsInfoForUMA( 28 void RenderMediaClient::AddSupportedKeySystems(
33 std::vector<media::KeySystemInfoForUMA>* key_systems_info_for_uma) { 29 std::vector<std::unique_ptr<media::KeySystemProperties>>* key_systems) {
34 DVLOG(2) << __func__; 30 GetContentClient()->renderer()->AddSupportedKeySystems(key_systems);
35 #if defined(WIDEVINE_CDM_AVAILABLE)
36 key_systems_info_for_uma->push_back(media::KeySystemInfoForUMA(
37 kWidevineKeySystem, kWidevineKeySystemNameForUMA));
38 #endif // WIDEVINE_CDM_AVAILABLE
39 } 31 }
40 32
41 bool RenderMediaClient::IsKeySystemsUpdateNeeded() { 33 bool RenderMediaClient::IsKeySystemsUpdateNeeded() {
42 DVLOG(2) << __func__; 34 return GetContentClient()->renderer()->IsKeySystemsUpdateNeeded();
xhwang 2017/04/03 17:47:13 I am not seeing ChromeContentRendererClient implem
chcunningham 2017/04/03 18:47:38 Chrome inherits the behavior from public/renderer/
xhwang 2017/04/03 18:55:18 Sorry I wasn't super clear on this. chrome/ is ac
chcunningham 2017/04/04 23:44:30 Fixed!
43 DCHECK(thread_checker_.CalledOnValidThread());
44
45 // Always needs update if we have never updated, regardless the
46 // |last_update_time_ticks_|'s initial value.
47 if (!has_updated_) {
48 DCHECK(is_update_needed_);
49 return true;
50 }
51
52 if (!is_update_needed_)
53 return false;
54
55 // The update could be expensive. For example, it could involve a sync IPC to
56 // the browser process. Use a minimum update interval to avoid unnecessarily
57 // frequent update.
58 static const int kMinUpdateIntervalInMilliseconds = 1000;
59 if ((tick_clock_->NowTicks() - last_update_time_ticks_).InMilliseconds() <
60 kMinUpdateIntervalInMilliseconds) {
61 return false;
62 }
63
64 return true;
65 }
66
67 void RenderMediaClient::AddSupportedKeySystems(
68 std::vector<std::unique_ptr<media::KeySystemProperties>>*
69 key_systems_properties) {
70 DVLOG(2) << __func__;
71 DCHECK(thread_checker_.CalledOnValidThread());
72
73 GetContentClient()->renderer()->AddSupportedKeySystems(
74 key_systems_properties);
75
76 has_updated_ = true;
77 last_update_time_ticks_ = tick_clock_->NowTicks();
78
79 // Check whether all potentially supported key systems are supported. If so,
80 // no need to update again.
81 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
82 for (const auto& properties : *key_systems_properties) {
83 if (properties->GetKeySystemName() == kWidevineKeySystem)
84 is_update_needed_ = false;
85 }
86 #else
87 is_update_needed_ = false;
88 #endif
89 }
90
91 void RenderMediaClient::RecordRapporURL(const std::string& metric,
92 const GURL& url) {
93 GetContentClient()->renderer()->RecordRapporURL(metric, url);
94 } 35 }
95 36
96 bool RenderMediaClient::IsSupportedAudioConfig( 37 bool RenderMediaClient::IsSupportedAudioConfig(
97 const media::AudioConfig& config) { 38 const media::AudioConfig& config) {
98 // Render media client does not customize decoder support. Defer to media/. 39 return GetContentClient()->renderer()->IsSupportedAudioConfig(config);
99 return ::media::IsSupportedAudioConfig(config);
100 } 40 }
101 41
102 bool RenderMediaClient::IsSupportedVideoConfig( 42 bool RenderMediaClient::IsSupportedVideoConfig(
103 const media::VideoConfig& config) { 43 const media::VideoConfig& config) {
104 // Render media client does not customize decoder support. Defer to media/. 44 return GetContentClient()->renderer()->IsSupportedVideoConfig(config);
105 return ::media::IsSupportedVideoConfig(config);
106 }
107
108 void RenderMediaClient::SetTickClockForTesting(
109 std::unique_ptr<base::TickClock> tick_clock) {
110 tick_clock_.swap(tick_clock);
111 }
112
113 // static
114 RenderMediaClient* RenderMediaClient::GetInstance() {
115 static RenderMediaClient* client = new RenderMediaClient();
116 return client;
117 } 45 }
118 46
119 } // namespace content 47 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698