| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_ |
| 6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_ |
| 7 | 7 |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include <map> |
| 9 |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 10 #include "media/base/cdm_context.h" | 12 #include "media/base/cdm_context.h" |
| 11 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
| 12 #include "media/mojo/services/mojo_cdm_service.h" | |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 | 16 |
| 17 class MojoCdmService; |
| 18 |
| 16 // A class that creates, owns and manages all MojoCdmService instances. | 19 // A class that creates, owns and manages all MojoCdmService instances. |
| 17 class MEDIA_EXPORT MojoCdmServiceContext : public CdmContextProvider { | 20 class MEDIA_EXPORT MojoCdmServiceContext : public CdmContextProvider { |
| 18 public: | 21 public: |
| 19 MojoCdmServiceContext(); | 22 MojoCdmServiceContext(); |
| 20 ~MojoCdmServiceContext() override; | 23 ~MojoCdmServiceContext() override; |
| 21 | 24 |
| 25 base::WeakPtr<MojoCdmServiceContext> GetWeakPtr(); |
| 26 |
| 22 // Registers The |cdm_service| with |cdm_id|. | 27 // Registers The |cdm_service| with |cdm_id|. |
| 23 void RegisterCdm(int cdm_id, MojoCdmService* cdm_service); | 28 void RegisterCdm(int cdm_id, MojoCdmService* cdm_service); |
| 24 | 29 |
| 25 // Unregisters the CDM. Must be called before the CDM is destroyed. | 30 // Unregisters the CDM. Must be called before the CDM is destroyed. |
| 26 void UnregisterCdm(int cdm_id); | 31 void UnregisterCdm(int cdm_id); |
| 27 | 32 |
| 28 // CdmContextProvider implementation. | 33 // CdmContextProvider implementation. |
| 29 // The returned CdmContext can be destroyed at any time if the pipe is | 34 // The returned CdmContext can be destroyed at any time if the pipe is |
| 30 // disconnected. | 35 // disconnected. |
| 31 // TODO(xhwang): When implementing SetCdm(), make sure we never dereference | 36 // TODO(xhwang): When implementing SetCdm(), make sure we never dereference |
| 32 // garbage. For example, use media::PlayerTracker. | 37 // garbage. For example, use media::PlayerTracker. |
| 33 CdmContext* GetCdmContext(int32_t cdm_id) override; | 38 CdmContext* GetCdmContext(int32_t cdm_id) override; |
| 34 | 39 |
| 35 private: | 40 private: |
| 36 // A map between CDM ID and MojoCdmService. | 41 // A map between CDM ID and MojoCdmService. |
| 37 std::map<int, MojoCdmService*> cdm_services_; | 42 std::map<int, MojoCdmService*> cdm_services_; |
| 38 | 43 |
| 44 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 45 base::WeakPtrFactory<MojoCdmServiceContext> weak_ptr_factory_; |
| 46 |
| 39 DISALLOW_COPY_AND_ASSIGN(MojoCdmServiceContext); | 47 DISALLOW_COPY_AND_ASSIGN(MojoCdmServiceContext); |
| 40 }; | 48 }; |
| 41 | 49 |
| 42 } // namespace media | 50 } // namespace media |
| 43 | 51 |
| 44 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_ | 52 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_ |
| OLD | NEW |