summaryrefslogtreecommitdiff
path: root/chromium/media/mojo/services/mojo_cdm_service_context.cc
blob: 297d5831af29a97b0bbc1f05acaee98d23fb1c2e (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
// Copyright 2015 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/mojo/services/mojo_cdm_service_context.h"

#include "base/bind.h"
#include "base/logging.h"
#include "media/mojo/services/mojo_cdm_service.h"

namespace media {

MojoCdmServiceContext::MojoCdmServiceContext() : weak_ptr_factory_(this) {}

MojoCdmServiceContext::~MojoCdmServiceContext() {
}

base::WeakPtr<MojoCdmServiceContext> MojoCdmServiceContext::GetWeakPtr() {
  return weak_ptr_factory_.GetWeakPtr();
}

void MojoCdmServiceContext::RegisterCdm(int cdm_id,
                                        MojoCdmService* cdm_service) {
  DCHECK(!cdm_services_.count(cdm_id));
  DCHECK(cdm_service);
  cdm_services_[cdm_id] = cdm_service;
}

void MojoCdmServiceContext::UnregisterCdm(int cdm_id) {
  DCHECK(cdm_services_.count(cdm_id));
  cdm_services_.erase(cdm_id);
}

CdmContext* MojoCdmServiceContext::GetCdmContext(int32_t cdm_id) {
  auto cdm_service = cdm_services_.find(cdm_id);
  if (cdm_service == cdm_services_.end()) {
    LOG(ERROR) << "CDM context not found: " << cdm_id;
    return nullptr;
  }

  return cdm_service->second->GetCdmContext();
}

}  // namespace media