Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / mojo / services / mojo_cdm_service_context.h
blobf3c2caf233164ff6e9962a43957768d55d1b3312
1 // Copyright 2015 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_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_
8 #include <map>
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "media/base/cdm_context.h"
13 #include "media/base/media_export.h"
15 namespace media {
17 class MojoCdmService;
19 // A class that creates, owns and manages all MojoCdmService instances.
20 class MEDIA_EXPORT MojoCdmServiceContext : public CdmContextProvider {
21 public:
22 MojoCdmServiceContext();
23 ~MojoCdmServiceContext() override;
25 base::WeakPtr<MojoCdmServiceContext> GetWeakPtr();
27 // Registers The |cdm_service| with |cdm_id|.
28 void RegisterCdm(int cdm_id, MojoCdmService* cdm_service);
30 // Unregisters the CDM. Must be called before the CDM is destroyed.
31 void UnregisterCdm(int cdm_id);
33 // CdmContextProvider implementation.
34 // The returned CdmContext can be destroyed at any time if the pipe is
35 // disconnected.
36 // TODO(xhwang): When implementing SetCdm(), make sure we never dereference
37 // garbage. For example, use media::PlayerTracker.
38 CdmContext* GetCdmContext(int32_t cdm_id) override;
40 private:
41 // A map between CDM ID and MojoCdmService.
42 std::map<int, MojoCdmService*> cdm_services_;
44 // NOTE: Weak pointers must be invalidated before all other member variables.
45 base::WeakPtrFactory<MojoCdmServiceContext> weak_ptr_factory_;
47 DISALLOW_COPY_AND_ASSIGN(MojoCdmServiceContext);
50 } // namespace media
52 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_