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

Side by Side Diff: chrome/renderer/media/chrome_key_systems_provider.cc

Issue 2712983004: Simplify/Cleanup MediaClient (Closed)
Patch Set: Test fix. 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
(Empty)
1 // Copyright 2017 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 "chrome/renderer/media/chrome_key_systems_provider.h"
6
7 #include "base/time/default_tick_clock.h"
8 #include "chrome/renderer/media/chrome_key_systems.h"
9
10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
11
12 namespace chrome {
13
14 ChromeKeySystemsProvider::ChromeKeySystemsProvider()
15 : has_updated_(false),
16 is_update_needed_(true),
17 tick_clock_(new base::DefaultTickClock()) {}
18
19 ChromeKeySystemsProvider::~ChromeKeySystemsProvider() {}
20
21 void ChromeKeySystemsProvider::AddSupportedKeySystems(
22 std::vector<std::unique_ptr<media::KeySystemProperties>>* key_systems) {
23 DCHECK(key_systems);
24 DCHECK(thread_checker_.CalledOnValidThread());
25
26 if (test_provider_.get()) {
27 test_provider_->AddTestKeySystems(key_systems);
28 } else {
29 AddChromeKeySystems(key_systems);
30 }
31
32 has_updated_ = true;
33 last_update_time_ticks_ = tick_clock_->NowTicks();
34
35 // Check whether all potentially supported key systems are supported. If so,
36 // no need to update again.
37 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
38 for (const auto& properties : *key_systems) {
39 if (properties->GetKeySystemName() == kWidevineKeySystem) {
40 is_update_needed_ = false;
41 }
42 }
43 #else
44 is_update_needed_ = false;
45 #endif
46 }
47
48 bool ChromeKeySystemsProvider::IsKeySystemsUpdateNeeded() {
49 DCHECK(thread_checker_.CalledOnValidThread());
50
51 // Always needs update if we have never updated, regardless the
52 // |last_update_time_ticks_|'s initial value.
53 if (!has_updated_) {
54 DCHECK(is_update_needed_);
55 return true;
56 }
57
58 if (!is_update_needed_)
59 return false;
60
61 // The update could be expensive. For example, it could involve a sync IPC to
62 // the browser process. Use a minimum update interval to avoid unnecessarily
63 // frequent update.
64 static const int kMinUpdateIntervalInMilliseconds = 1000;
65 if ((tick_clock_->NowTicks() - last_update_time_ticks_).InMilliseconds() <
66 kMinUpdateIntervalInMilliseconds) {
67 return false;
68 }
69
70 return true;
71 }
72
73 void ChromeKeySystemsProvider::SetTickClockForTesting(
74 std::unique_ptr<base::TickClock> tick_clock) {
75 tick_clock_.swap(tick_clock);
76 }
77
78 void ChromeKeySystemsProvider::SetProviderDelegateForTesting(
79 std::unique_ptr<TestKeySystemsProviderDelegate> test_provider) {
80 test_provider_.swap(test_provider);
81 }
82
83 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698