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
3 // found in the LICENSE file.
5 #include "content/renderer/media/render_media_client.h"
7 #include "base/lazy_instance.h"
8 #include "base/logging.h"
9 #include "base/time/default_tick_clock.h"
10 #include "content/public/common/content_client.h"
11 #include "content/public/renderer/content_renderer_client.h"
15 static base::LazyInstance
<RenderMediaClient
> g_render_media_client
=
16 LAZY_INSTANCE_INITIALIZER
;
18 void RenderMediaClient::Initialize() {
19 g_render_media_client
.Get();
22 RenderMediaClient::RenderMediaClient()
23 : has_updated_(false),
24 is_update_needed_(true),
25 tick_clock_(new base::DefaultTickClock()) {
26 media::SetMediaClient(this);
29 RenderMediaClient::~RenderMediaClient() {
32 void RenderMediaClient::AddKeySystemsInfoForUMA(
33 std::vector
<media::KeySystemInfoForUMA
>* key_systems_info_for_uma
) {
34 DVLOG(2) << __FUNCTION__
;
35 #if defined(WIDEVINE_CDM_AVAILABLE)
36 key_systems_info_for_uma
->push_back(media::KeySystemInfoForUMA(
37 kWidevineKeySystem
, kWidevineKeySystemNameForUMA
, true));
38 #endif // WIDEVINE_CDM_AVAILABLE
41 bool RenderMediaClient::IsKeySystemsUpdateNeeded() {
42 DVLOG(2) << __FUNCTION__
;
43 DCHECK(thread_checker_
.CalledOnValidThread());
45 // Always needs update if we have never updated, regardless the
46 // |last_update_time_ticks_|'s initial value.
48 DCHECK(is_update_needed_
);
52 if (!is_update_needed_
)
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
58 static const int kMinUpdateIntervalInMilliseconds
= 1000;
59 if ((tick_clock_
->NowTicks() - last_update_time_ticks_
).InMilliseconds() <
60 kMinUpdateIntervalInMilliseconds
) {
67 void RenderMediaClient::AddSupportedKeySystems(
68 std::vector
<media::KeySystemInfo
>* key_systems_info
) {
69 DVLOG(2) << __FUNCTION__
;
70 DCHECK(thread_checker_
.CalledOnValidThread());
72 GetContentClient()->renderer()->AddKeySystems(key_systems_info
);
75 last_update_time_ticks_
= tick_clock_
->NowTicks();
77 // Check whether all potentially supported key systems are supported. If so,
78 // no need to update again.
79 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
80 for (const media::KeySystemInfo
& key_system_info
: *key_systems_info
) {
81 if (key_system_info
.key_system
== kWidevineKeySystem
)
82 is_update_needed_
= false;
85 is_update_needed_
= false;
89 void RenderMediaClient::SetTickClockForTesting(
90 scoped_ptr
<base::TickClock
> tick_clock
) {
91 tick_clock_
.swap(tick_clock
);
94 // This functions is for testing purpose only. The declaration in the
95 // header file is guarded by "#if defined(UNIT_TEST)" so that it can be used
96 // by tests but not non-test code. However, this .cc file is compiled as part of
97 // "content" where "UNIT_TEST" is not defined. So we need to specify
98 // "CONTENT_EXPORT" here again so that it is visible to tests.
99 CONTENT_EXPORT RenderMediaClient
* GetRenderMediaClientInstanceForTesting() {
100 return g_render_media_client
.Pointer();
103 } // namespace content