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

Unified Diff: chrome/renderer/media/chrome_key_systems_provider.cc

Issue 2712983004: Simplify/Cleanup MediaClient (Closed)
Patch Set: Fix test leak 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/media/chrome_key_systems_provider.cc
diff --git a/chrome/renderer/media/chrome_key_systems_provider.cc b/chrome/renderer/media/chrome_key_systems_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d53bd9dbe9a4f5ea122fef1251b10957719af85b
--- /dev/null
+++ b/chrome/renderer/media/chrome_key_systems_provider.cc
@@ -0,0 +1,83 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/media/chrome_key_systems_provider.h"
+
+#include "base/time/default_tick_clock.h"
+#include "chrome/renderer/media/chrome_key_systems.h"
+
+#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
+
+namespace chrome {
+
+ChromeKeySystemsProvider::ChromeKeySystemsProvider()
+ : has_updated_(false),
+ is_update_needed_(true),
+ tick_clock_(new base::DefaultTickClock()) {}
+
+ChromeKeySystemsProvider::~ChromeKeySystemsProvider() {}
+
+void ChromeKeySystemsProvider::AddSupportedKeySystems(
+ std::vector<std::unique_ptr<media::KeySystemProperties>>* key_systems) {
+ DCHECK(key_systems);
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ if (!test_provider_.is_null()) {
+ test_provider_.Run(key_systems);
+ } else {
+ AddChromeKeySystems(key_systems);
+ }
+
+ has_updated_ = true;
+ last_update_time_ticks_ = tick_clock_->NowTicks();
+
+// Check whether all potentially supported key systems are supported. If so,
+// no need to update again.
+#if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
+ for (const auto& properties : *key_systems) {
+ if (properties->GetKeySystemName() == kWidevineKeySystem) {
+ is_update_needed_ = false;
+ }
+ }
+#else
+ is_update_needed_ = false;
+#endif
+}
+
+bool ChromeKeySystemsProvider::IsKeySystemsUpdateNeeded() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // Always needs update if we have never updated, regardless the
+ // |last_update_time_ticks_|'s initial value.
+ if (!has_updated_) {
+ DCHECK(is_update_needed_);
+ return true;
+ }
+
+ if (!is_update_needed_)
+ return false;
+
+ // The update could be expensive. For example, it could involve a sync IPC to
+ // the browser process. Use a minimum update interval to avoid unnecessarily
+ // frequent update.
+ static const int kMinUpdateIntervalInMilliseconds = 1000;
+ if ((tick_clock_->NowTicks() - last_update_time_ticks_).InMilliseconds() <
+ kMinUpdateIntervalInMilliseconds) {
+ return false;
+ }
+
+ return true;
+}
+
+void ChromeKeySystemsProvider::SetTickClockForTesting(
+ std::unique_ptr<base::TickClock> tick_clock) {
+ tick_clock_.swap(tick_clock);
+}
+
+void ChromeKeySystemsProvider::SetProviderDelegateForTesting(
+ const KeySystemsProviderDelegate& test_provider) {
+ test_provider_ = test_provider;
+}
+
+} // namespace chrome
« no previous file with comments | « chrome/renderer/media/chrome_key_systems_provider.h ('k') | chrome/renderer/media/chrome_key_systems_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698