summaryrefslogtreecommitdiffstats
path: root/media/blink/new_session_cdm_result_promise.h
blob: c4b657da122ff44f4c8bb9857b8753ed6d1b8f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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& 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);
  ~NewSessionCdmResultPromise() override;

  // CdmPromiseTemplate<T> implementation.
  void resolve(const std::string& session_id) override;
  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_