Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef MEDIA_BASE_CDM_PROMISE_H_ | 5 #ifndef MEDIA_BASE_CDM_PROMISE_H_ |
| 6 #define MEDIA_BASE_CDM_PROMISE_H_ | 6 #define MEDIA_BASE_CDM_PROMISE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
| 13 #include "media/base/media_keys.h" | 13 #include "media/base/media_keys.h" |
| 14 | 14 |
| 15 namespace media { | 15 namespace media { |
| 16 | 16 |
| 17 // Interface for promises being resolved/rejected in response to various | 17 // Interface for promises being resolved/rejected in response to various |
| 18 // session actions. These may be called synchronously or asynchronously. | 18 // session actions. These may be called synchronously or asynchronously. |
| 19 // The promise must be resolved or rejected exactly once. It is expected that | 19 // The promise must be resolved or rejected exactly once. It is expected that |
| 20 // the caller free the promise once it is resolved/rejected. | 20 // the caller free the promise once it is resolved/rejected. |
| 21 // | 21 // |
| 22 // This is only the base class, as parameter to resolve() varies. | 22 // This is only the base class, as parameter to resolve() varies. |
| 23 class MEDIA_EXPORT CdmPromise { | 23 class MEDIA_EXPORT CdmPromise { |
| 24 public: | 24 public: |
| 25 // A superset of media::MediaKeys::Exception for UMA reporting. | |
| 26 enum ResultCodeForUMA { | |
| 27 SUCCESS, | |
| 28 NOT_SUPPORTED_ERROR, | |
| 29 INVALID_STATE_ERROR, | |
| 30 INVALID_ACCESS_ERROR, | |
| 31 QUOTA_EXCEEDED_ERROR, | |
| 32 UNKNOWN_ERROR, | |
|
ddorwin
2014/08/08 03:35:40
These 3 may be removed someday. Oh well. (It will
sandersd (OOO until July 31)
2014/08/08 17:22:24
Acknowledged.
| |
| 33 CLIENT_ERROR, | |
| 34 OUTPUT_ERROR, | |
| 35 NUM_RESULT_CODES | |
| 36 }; | |
| 37 | |
| 25 typedef base::Callback<void(MediaKeys::Exception exception_code, | 38 typedef base::Callback<void(MediaKeys::Exception exception_code, |
| 26 uint32 system_code, | 39 uint32 system_code, |
| 27 const std::string& error_message)> | 40 const std::string& error_message)> |
| 28 PromiseRejectedCB; | 41 PromiseRejectedCB; |
| 29 | 42 |
| 30 virtual ~CdmPromise(); | 43 virtual ~CdmPromise(); |
| 31 | 44 |
| 32 // Used to indicate that the operation failed. |exception_code| must be | 45 // Used to indicate that the operation failed. |exception_code| must be |
| 33 // specified. |system_code| is a Key System-specific value for the error | 46 // specified. |system_code| is a Key System-specific value for the error |
| 34 // that occurred, or 0 if there is no associated status code or such status | 47 // that occurred, or 0 if there is no associated status code or such status |
| 35 // codes are not supported by the Key System. |error_message| is optional. | 48 // codes are not supported by the Key System. |error_message| is optional. |
| 36 virtual void reject(MediaKeys::Exception exception_code, | 49 virtual void reject(MediaKeys::Exception exception_code, |
| 37 uint32 system_code, | 50 uint32 system_code, |
| 38 const std::string& error_message); | 51 const std::string& error_message); |
| 39 | 52 |
| 40 protected: | 53 protected: |
| 41 CdmPromise(); | 54 CdmPromise(); |
| 42 CdmPromise(PromiseRejectedCB reject_cb); | 55 CdmPromise(PromiseRejectedCB reject_cb); |
| 56 CdmPromise(PromiseRejectedCB reject_cb, const std::string& uma_name); | |
|
ddorwin
2014/08/08 03:35:40
We should probably document that a UMA will be rep
sandersd (OOO until July 31)
2014/08/08 17:22:24
Done.
| |
| 43 | 57 |
| 44 PromiseRejectedCB reject_cb_; | 58 PromiseRejectedCB reject_cb_; |
| 45 | 59 |
| 46 // Keep track of whether the promise hasn't been resolved or rejected yet. | 60 // Keep track of whether the promise hasn't been resolved or rejected yet. |
| 47 bool is_pending_; | 61 bool is_pending_; |
| 48 | 62 |
| 63 // UMA to report result to. | |
| 64 std::string uma_name_; | |
| 65 | |
| 49 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | 66 DISALLOW_COPY_AND_ASSIGN(CdmPromise); |
| 50 }; | 67 }; |
| 51 | 68 |
| 52 template <typename T> | 69 template <typename T> |
| 53 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise { | 70 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise { |
| 54 public: | 71 public: |
| 55 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb, | 72 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb, |
| 56 PromiseRejectedCB rejected_cb); | 73 PromiseRejectedCB rejected_cb); |
| 74 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb, | |
| 75 PromiseRejectedCB rejected_cb, | |
| 76 const std::string& uma_name); | |
| 57 virtual ~CdmPromiseTemplate(); | 77 virtual ~CdmPromiseTemplate(); |
| 58 virtual void resolve(const T& result); | 78 virtual void resolve(const T& result); |
| 59 | 79 |
| 60 private: | 80 private: |
| 61 base::Callback<void(const T&)> resolve_cb_; | 81 base::Callback<void(const T&)> resolve_cb_; |
| 62 | 82 |
| 63 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 83 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); |
| 64 }; | 84 }; |
| 65 | 85 |
| 66 // Specialization for no parameter to resolve(). | 86 // Specialization for no parameter to resolve(). |
| 67 template <> | 87 template <> |
| 68 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise { | 88 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise { |
| 69 public: | 89 public: |
| 70 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | 90 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, |
| 71 PromiseRejectedCB rejected_cb); | 91 PromiseRejectedCB rejected_cb); |
| 92 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | |
| 93 PromiseRejectedCB rejected_cb, | |
| 94 const std::string& uma_name); | |
| 72 virtual ~CdmPromiseTemplate(); | 95 virtual ~CdmPromiseTemplate(); |
| 73 virtual void resolve(); | 96 virtual void resolve(); |
| 74 | 97 |
| 75 protected: | 98 protected: |
| 76 // Allow subclasses to completely override the implementation. | 99 // Allow subclasses to completely override the implementation. |
| 77 CdmPromiseTemplate(); | 100 CdmPromiseTemplate(); |
| 78 | 101 |
| 79 private: | 102 private: |
| 80 base::Callback<void(void)> resolve_cb_; | 103 base::Callback<void(void)> resolve_cb_; |
| 81 | 104 |
| 82 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 105 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); |
| 83 }; | 106 }; |
| 84 | 107 |
| 85 } // namespace media | 108 } // namespace media |
| 86 | 109 |
| 87 #endif // MEDIA_BASE_CDM_PROMISE_H_ | 110 #endif // MEDIA_BASE_CDM_PROMISE_H_ |
| OLD | NEW |