Change blimp README to use Markdown.
[chromium-blink-merge.git] / media / base / cdm_promise_adapter.h
blobb078c0dd0a5393ba22174cc5e34a1161fad19d06
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_CDM_PROMISE_ADAPTER_H_
6 #define MEDIA_BASE_CDM_PROMISE_ADAPTER_H_
8 #include "base/basictypes.h"
9 #include "base/containers/scoped_ptr_hash_map.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/cdm_promise.h"
13 #include "media/base/media_export.h"
15 namespace media {
17 // Helps convert CdmPromises to an integer identifier and vice versa. The
18 // integer identifier is needed where we cannot pass CdmPromises through, such
19 // as PPAPI, IPC and JNI.
20 class MEDIA_EXPORT CdmPromiseAdapter {
21 public:
22 CdmPromiseAdapter();
23 ~CdmPromiseAdapter();
25 // Takes ownership of |promise| and returns an integer promise ID.
26 uint32_t SavePromise(scoped_ptr<media::CdmPromise> promise);
28 // Takes the promise for |promise_id|, sanity checks its |type|, and resolves
29 // it with |result|.
30 template <typename... T>
31 void ResolvePromise(uint32_t promise_id, const T&... result);
33 // Takes the promise for |promise_id| and rejects it with |exception_code|,
34 // |system_code| and |error_message|.
35 void RejectPromise(uint32_t promise_id,
36 MediaKeys::Exception exception_code,
37 uint32 system_code,
38 const std::string& error_message);
40 // Rejects and clears all |promises_|.
41 void Clear();
43 private:
44 // A map between promise IDs and CdmPromises. It owns the CdmPromises.
45 typedef base::ScopedPtrHashMap<uint32_t, scoped_ptr<CdmPromise>> PromiseMap;
47 // Finds, takes the ownership of and returns the promise for |promise_id|.
48 // Returns null if no promise can be found.
49 scoped_ptr<CdmPromise> TakePromise(uint32_t promise_id);
51 uint32_t next_promise_id_;
52 PromiseMap promises_;
54 DISALLOW_COPY_AND_ASSIGN(CdmPromiseAdapter);
57 } // namespace media
59 #endif // MEDIA_BASE_CDM_PROMISE_ADAPTER_H_