summaryrefslogtreecommitdiffstats
path: root/media/blink
diff options
context:
space:
mode:
authorxhwang <xhwang@chromium.org>2014-10-16 10:29:49 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-16 17:30:04 +0000
commitf440ca2e146138fd2ecdf71f37b4432cf61ce09e (patch)
tree43336a8d284e310790183e72ad2f5852b520ff52 /media/blink
parentcf850d3670ddbe7eb25684f33bb6aeb9a9a53b71 (diff)
downloadchromium_src-f440ca2e146138fd2ecdf71f37b4432cf61ce09e.zip
chromium_src-f440ca2e146138fd2ecdf71f37b4432cf61ce09e.tar.gz
chromium_src-f440ca2e146138fd2ecdf71f37b4432cf61ce09e.tar.bz2
Move CdmResultPromise to media/blink.
BUG=422730 Review URL: https://codereview.chromium.org/651113002 Cr-Commit-Position: refs/heads/master@{#299912}
Diffstat (limited to 'media/blink')
-rw-r--r--media/blink/BUILD.gn9
-rw-r--r--media/blink/cdm_result_promise.h89
-rw-r--r--media/blink/cdm_result_promise_helper.cc68
-rw-r--r--media/blink/cdm_result_promise_helper.h42
-rw-r--r--media/blink/media_blink.gyp9
-rw-r--r--media/blink/new_session_cdm_result_promise.cc44
-rw-r--r--media/blink/new_session_cdm_result_promise.h55
7 files changed, 312 insertions, 4 deletions
diff --git a/media/blink/BUILD.gn b/media/blink/BUILD.gn
index 17cf57e..67682d6 100644
--- a/media/blink/BUILD.gn
+++ b/media/blink/BUILD.gn
@@ -27,10 +27,15 @@ component("blink") {
"buffered_data_source_host_impl.h",
"buffered_resource_loader.cc",
"buffered_resource_loader.h",
- "encrypted_media_player_support.cc",
- "encrypted_media_player_support.h",
"cache_util.cc",
"cache_util.h",
+ "cdm_result_promise.h",
+ "cdm_result_promise_helper.cc",
+ "cdm_result_promise_helper.h",
+ "encrypted_media_player_support.cc",
+ "encrypted_media_player_support.h",
+ "new_session_cdm_result_promise.cc",
+ "new_session_cdm_result_promise.h",
"null_encrypted_media_player_support.cc",
"null_encrypted_media_player_support.h",
"texttrack_impl.cc",
diff --git a/media/blink/cdm_result_promise.h b/media/blink/cdm_result_promise.h
new file mode 100644
index 0000000..6ae5778
--- /dev/null
+++ b/media/blink/cdm_result_promise.h
@@ -0,0 +1,89 @@
+// Copyright 2014 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.
+
+#ifndef MEDIA_BLINK_CDM_RESULT_PROMISE_H_
+#define MEDIA_BLINK_CDM_RESULT_PROMISE_H_
+
+#include "base/basictypes.h"
+#include "media/base/cdm_promise.h"
+#include "media/base/media_keys.h"
+#include "media/blink/cdm_result_promise_helper.h"
+#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
+
+namespace media {
+
+// Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate
+// so that it can be passed through Chromium. When resolve(T) is called, the
+// appropriate complete...() method on WebContentDecryptionModuleResult will be
+// invoked. If reject() is called instead,
+// WebContentDecryptionModuleResult::completeWithError() is called.
+// If constructed with a |uma_name|, CdmResultPromise will report the promise
+// result (success or rejection code) to UMA.
+template <typename... T>
+class CdmResultPromise : public media::CdmPromiseTemplate<T...> {
+ public:
+ CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
+ const std::string& uma_name);
+ virtual ~CdmResultPromise();
+
+ // CdmPromiseTemplate<T> implementation.
+ virtual void resolve(const T&... result) override;
+ virtual void reject(media::MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) override;
+
+ private:
+ using media::CdmPromiseTemplate<T...>::MarkPromiseSettled;
+
+ blink::WebContentDecryptionModuleResult web_cdm_result_;
+
+ // UMA name to report result to.
+ std::string uma_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
+};
+
+template <typename... T>
+CdmResultPromise<T...>::CdmResultPromise(
+ const blink::WebContentDecryptionModuleResult& result,
+ const std::string& uma_name)
+ : web_cdm_result_(result), uma_name_(uma_name) {
+}
+
+template <typename... T>
+CdmResultPromise<T...>::~CdmResultPromise() {
+}
+
+// "inline" is needed to prevent multiple definition error.
+
+template <>
+inline void CdmResultPromise<>::resolve() {
+ MarkPromiseSettled();
+ ReportCdmResultUMA(uma_name_, SUCCESS);
+ web_cdm_result_.complete();
+}
+
+template <>
+inline void CdmResultPromise<media::KeyIdsVector>::resolve(
+ const media::KeyIdsVector& result) {
+ // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
+ // handle the set of keys.
+ reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
+}
+
+template <typename... T>
+void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ MarkPromiseSettled();
+ ReportCdmResultUMA(uma_name_,
+ ConvertCdmExceptionToResultForUMA(exception_code));
+ web_cdm_result_.completeWithError(ConvertCdmException(exception_code),
+ system_code,
+ blink::WebString::fromUTF8(error_message));
+}
+
+} // namespace media
+
+#endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_
diff --git a/media/blink/cdm_result_promise_helper.cc b/media/blink/cdm_result_promise_helper.cc
new file mode 100644
index 0000000..c96121a
--- /dev/null
+++ b/media/blink/cdm_result_promise_helper.cc
@@ -0,0 +1,68 @@
+// Copyright 2014 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 "media/blink/cdm_result_promise_helper.h"
+
+#include "base/logging.h"
+#include "base/metrics/histogram.h"
+
+namespace media {
+
+CdmResultForUMA ConvertCdmExceptionToResultForUMA(
+ MediaKeys::Exception exception_code) {
+ switch (exception_code) {
+ case MediaKeys::NOT_SUPPORTED_ERROR:
+ return NOT_SUPPORTED_ERROR;
+ case MediaKeys::INVALID_STATE_ERROR:
+ return INVALID_STATE_ERROR;
+ case MediaKeys::INVALID_ACCESS_ERROR:
+ return INVALID_ACCESS_ERROR;
+ case MediaKeys::QUOTA_EXCEEDED_ERROR:
+ return QUOTA_EXCEEDED_ERROR;
+ case MediaKeys::UNKNOWN_ERROR:
+ return UNKNOWN_ERROR;
+ case MediaKeys::CLIENT_ERROR:
+ return CLIENT_ERROR;
+ case MediaKeys::OUTPUT_ERROR:
+ return OUTPUT_ERROR;
+ }
+ NOTREACHED();
+ return UNKNOWN_ERROR;
+}
+
+blink::WebContentDecryptionModuleException ConvertCdmException(
+ MediaKeys::Exception exception_code) {
+ switch (exception_code) {
+ case MediaKeys::NOT_SUPPORTED_ERROR:
+ return blink::WebContentDecryptionModuleExceptionNotSupportedError;
+ case MediaKeys::INVALID_STATE_ERROR:
+ return blink::WebContentDecryptionModuleExceptionInvalidStateError;
+ case MediaKeys::INVALID_ACCESS_ERROR:
+ return blink::WebContentDecryptionModuleExceptionInvalidAccessError;
+ case MediaKeys::QUOTA_EXCEEDED_ERROR:
+ return blink::WebContentDecryptionModuleExceptionQuotaExceededError;
+ case MediaKeys::UNKNOWN_ERROR:
+ return blink::WebContentDecryptionModuleExceptionUnknownError;
+ case MediaKeys::CLIENT_ERROR:
+ return blink::WebContentDecryptionModuleExceptionClientError;
+ case MediaKeys::OUTPUT_ERROR:
+ return blink::WebContentDecryptionModuleExceptionOutputError;
+ }
+ NOTREACHED();
+ return blink::WebContentDecryptionModuleExceptionUnknownError;
+}
+
+void ReportCdmResultUMA(const std::string& uma_name, CdmResultForUMA result) {
+ if (uma_name.empty())
+ return;
+
+ base::LinearHistogram::FactoryGet(
+ uma_name,
+ 1,
+ NUM_RESULT_CODES,
+ NUM_RESULT_CODES + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result);
+}
+
+} // namespace media
diff --git a/media/blink/cdm_result_promise_helper.h b/media/blink/cdm_result_promise_helper.h
new file mode 100644
index 0000000..2fe385d
--- /dev/null
+++ b/media/blink/cdm_result_promise_helper.h
@@ -0,0 +1,42 @@
+// Copyright 2014 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.
+
+#ifndef MEDIA_BLINK_CDM_RESULT_PROMISE_HELPER_H_
+#define MEDIA_BLINK_CDM_RESULT_PROMISE_HELPER_H_
+
+#include <string>
+
+#include "media/base/media_export.h"
+#include "media/base/media_keys.h"
+#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
+
+namespace media {
+
+// A superset of media::MediaKeys::Exception for UMA reporting. These values
+// should never be changed as it will affect existing reporting, and must match
+// the values for CdmPromiseResult in tools/metrics/histograms/histograms.xml.
+enum CdmResultForUMA {
+ SUCCESS = 0,
+ NOT_SUPPORTED_ERROR = 1,
+ INVALID_STATE_ERROR = 2,
+ INVALID_ACCESS_ERROR = 3,
+ QUOTA_EXCEEDED_ERROR = 4,
+ UNKNOWN_ERROR = 5,
+ CLIENT_ERROR = 6,
+ OUTPUT_ERROR = 7,
+ NUM_RESULT_CODES
+};
+
+MEDIA_EXPORT CdmResultForUMA
+ ConvertCdmExceptionToResultForUMA(MediaKeys::Exception exception_code);
+
+MEDIA_EXPORT blink::WebContentDecryptionModuleException ConvertCdmException(
+ MediaKeys::Exception exception_code);
+
+MEDIA_EXPORT void ReportCdmResultUMA(const std::string& uma_name,
+ CdmResultForUMA result);
+
+} // namespace media
+
+#endif // MEDIA_BLINK_CDM_RESULT_PROMISE_HELPER_H_
diff --git a/media/blink/media_blink.gyp b/media/blink/media_blink.gyp
index 72751c7..ca92dce 100644
--- a/media/blink/media_blink.gyp
+++ b/media/blink/media_blink.gyp
@@ -32,10 +32,15 @@
'buffered_data_source_host_impl.h',
'buffered_resource_loader.cc',
'buffered_resource_loader.h',
- 'encrypted_media_player_support.cc',
- 'encrypted_media_player_support.h',
'cache_util.cc',
'cache_util.h',
+ 'cdm_result_promise.h',
+ 'cdm_result_promise_helper.cc',
+ 'cdm_result_promise_helper.h',
+ 'encrypted_media_player_support.cc',
+ 'encrypted_media_player_support.h',
+ 'new_session_cdm_result_promise.cc',
+ 'new_session_cdm_result_promise.h',
'null_encrypted_media_player_support.cc',
'null_encrypted_media_player_support.h',
'texttrack_impl.cc',
diff --git a/media/blink/new_session_cdm_result_promise.cc b/media/blink/new_session_cdm_result_promise.cc
new file mode 100644
index 0000000..6ac5247
--- /dev/null
+++ b/media/blink/new_session_cdm_result_promise.cc
@@ -0,0 +1,44 @@
+// Copyright 2014 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 "media/blink/new_session_cdm_result_promise.h"
+
+#include "base/logging.h"
+#include "media/blink/cdm_result_promise_helper.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+
+namespace media {
+
+NewSessionCdmResultPromise::NewSessionCdmResultPromise(
+ const blink::WebContentDecryptionModuleResult& result,
+ const std::string& uma_name,
+ const SessionInitializedCB& new_session_created_cb)
+ : web_cdm_result_(result),
+ uma_name_(uma_name),
+ new_session_created_cb_(new_session_created_cb) {
+}
+
+NewSessionCdmResultPromise::~NewSessionCdmResultPromise() {
+}
+
+void NewSessionCdmResultPromise::resolve(const std::string& web_session_id) {
+ MarkPromiseSettled();
+ ReportCdmResultUMA(uma_name_, SUCCESS);
+ blink::WebContentDecryptionModuleResult::SessionStatus status =
+ new_session_created_cb_.Run(web_session_id);
+ web_cdm_result_.completeWithSession(status);
+}
+
+void NewSessionCdmResultPromise::reject(MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ MarkPromiseSettled();
+ ReportCdmResultUMA(uma_name_,
+ ConvertCdmExceptionToResultForUMA(exception_code));
+ web_cdm_result_.completeWithError(ConvertCdmException(exception_code),
+ system_code,
+ blink::WebString::fromUTF8(error_message));
+}
+
+} // namespace media
diff --git a/media/blink/new_session_cdm_result_promise.h b/media/blink/new_session_cdm_result_promise.h
new file mode 100644
index 0000000..79956cc
--- /dev/null
+++ b/media/blink/new_session_cdm_result_promise.h
@@ -0,0 +1,55 @@
+// Copyright 2014 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.
+
+#ifndef MEDIA_BLINK_NEW_SESSION_CDM_RESULT_PROMISE_H_
+#define MEDIA_BLINK_NEW_SESSION_CDM_RESULT_PROMISE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "media/base/cdm_promise.h"
+#include "media/base/media_export.h"
+#include "media/base/media_keys.h"
+#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
+
+namespace media {
+
+typedef base::Callback<blink::WebContentDecryptionModuleResult::SessionStatus(
+ const std::string& web_session_id)> SessionInitializedCB;
+
+// Special class for resolving a new session promise. Resolving a new session
+// promise returns the session ID (as a string), but the blink promise needs
+// to get passed a SessionStatus. This class converts the session id to a
+// SessionStatus by calling |new_session_created_cb|.
+class MEDIA_EXPORT NewSessionCdmResultPromise
+ : public CdmPromiseTemplate<std::string> {
+ public:
+ NewSessionCdmResultPromise(
+ const blink::WebContentDecryptionModuleResult& result,
+ const std::string& uma_name,
+ const SessionInitializedCB& new_session_created_cb);
+ virtual ~NewSessionCdmResultPromise();
+
+ // CdmPromiseTemplate<T> implementation.
+ virtual void resolve(const std::string& web_session_id) override;
+ virtual void reject(MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) override;
+
+ private:
+ blink::WebContentDecryptionModuleResult web_cdm_result_;
+
+ // UMA name to report result to.
+ std::string uma_name_;
+
+ // Called on resolve() to convert the session ID into a SessionStatus to
+ // be reported to blink.
+ SessionInitializedCB new_session_created_cb_;
+
+ DISALLOW_COPY_AND_ASSIGN(NewSessionCdmResultPromise);
+};
+
+} // namespace media
+
+#endif // MEDIA_BLINK_NEW_SESSION_CDM_RESULT_PROMISE_H_