Chromium Code Reviews| Index: media/base/cdm_promise.h |
| diff --git a/media/base/cdm_promise.h b/media/base/cdm_promise.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ac248c4a341f0681815a2220d17ecd7d6dbdbd7a |
| --- /dev/null |
| +++ b/media/base/cdm_promise.h |
| @@ -0,0 +1,74 @@ |
| +// 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_BASE_CDM_PROMISE_H_ |
| +#define MEDIA_BASE_CDM_PROMISE_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback.h" |
| +#include "media/base/media_export.h" |
| +#include "media/base/media_keys.h" |
| + |
| +namespace media { |
| + |
| +typedef base::Callback<void(MediaKeys::Exception exception_code, |
| + uint32 system_code, |
| + const std::string& error_message)> |
| + PromiseRejectedCB; |
|
xhwang
2014/05/22 16:44:14
This seems to be only used in class CdmPromise. Ho
jrummell
2014/05/29 00:54:40
Done.
|
| + |
| +// Interface for promises being resolved/rejected in response to various |
| +// session actions. These may be called synchronously or asynchronously. |
| +// Only one method may be called on any promise. It is expected that the |
| +// caller free the promise once it is resolved/rejected. |
| +template <typename T> |
| +class MEDIA_EXPORT CdmPromise { |
|
xhwang
2014/05/23 06:01:23
See above for the idea of having a base class for
jrummell
2014/05/29 00:54:40
Done.
|
| + public: |
| + CdmPromise(base::Callback<void(const T&)> resolve_cb, |
| + PromiseRejectedCB rejected_cb); |
| + virtual ~CdmPromise(); |
| + |
| + // Used to indicate that operation succeeded. |
| + virtual void resolve(const T& result); |
| + |
| + // Used to indicate that the operation failed. |exception_code| must be |
| + // specified. |system_code| is a Key System-specific value for the error |
| + // that occurred, or 0 if there is no associated status code or such status |
| + // codes are not supported by the Key System. |error_message| is optional. |
| + virtual void reject(MediaKeys::Exception exception_code, |
| + uint32 system_code, |
| + const std::string& error_message); |
| + |
| + private: |
| + base::Callback<void(const T&)> resolve_cb_; |
| + PromiseRejectedCB rejected_cb_; |
|
xhwang
2014/05/22 16:44:14
we have |resolve_cb_| but |reject"ed"_cb_|. Shall
jrummell
2014/05/29 00:54:40
Done.
|
| + bool is_pending_; |
|
xhwang
2014/05/22 16:44:14
Add comment for |is_pending_|.
jrummell
2014/05/29 00:54:40
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(CdmPromise); |
| +}; |
| + |
| +// Specialization for no parameter to resolve(). |
| +template <> |
| +class MEDIA_EXPORT CdmPromise<void> { |
| + public: |
| + CdmPromise(base::Callback<void(void)> resolve_cb, |
| + PromiseRejectedCB rejected_cb); |
| + virtual ~CdmPromise(); |
| + virtual void resolve(); |
| + virtual void reject(MediaKeys::Exception exception_code, |
| + uint32 system_code, |
| + const std::string& error_message); |
| + |
| + private: |
| + base::Callback<void(void)> resolve_cb_; |
|
xhwang
2014/05/22 16:44:14
Actually base::Callback<void(void)> == base::Closu
xhwang
2014/05/22 16:44:14
How about having a template class
template <type
jrummell
2014/05/29 00:54:40
I put it this way so that it maps to the basic tem
jrummell
2014/05/29 00:54:40
With the refactoring to CdmPromiseTemplate, not mu
|
| + PromiseRejectedCB rejected_cb_; |
| + bool is_pending_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CdmPromise); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_CDM_PROMISE_H_ |