Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: media/base/key_systems.cc

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Fix presubmit comments. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/android/media_service_throttler.cc ('k') | media/base/media.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "media/base/key_systems.h" 5 #include "media/base/key_systems.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 12 #include "base/logging.h"
14 #include "base/macros.h" 13 #include "base/macros.h"
15 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
16 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
17 #include "base/time/time.h" 16 #include "base/time/time.h"
18 #include "build/build_config.h" 17 #include "build/build_config.h"
19 #include "media/base/key_system_names.h" 18 #include "media/base/key_system_names.h"
20 #include "media/base/key_system_properties.h" 19 #include "media/base/key_system_properties.h"
21 #include "media/base/media.h" 20 #include "media/base/media.h"
22 #include "media/base/media_switches.h" 21 #include "media/base/media_switches.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 222
224 void UpdateSupportedKeySystems(); 223 void UpdateSupportedKeySystems();
225 224
226 void AddSupportedKeySystems( 225 void AddSupportedKeySystems(
227 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems); 226 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems);
228 227
229 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask); 228 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask);
230 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type, 229 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type,
231 SupportedCodecs codecs_mask) const; 230 SupportedCodecs codecs_mask) const;
232 231
233 friend struct base::DefaultLazyInstanceTraits<KeySystemsImpl>;
234
235 typedef base::hash_map<std::string, std::unique_ptr<KeySystemProperties>> 232 typedef base::hash_map<std::string, std::unique_ptr<KeySystemProperties>>
236 KeySystemPropertiesMap; 233 KeySystemPropertiesMap;
237 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap; 234 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap;
238 typedef base::hash_map<std::string, EmeCodec> CodecsMap; 235 typedef base::hash_map<std::string, EmeCodec> CodecsMap;
239 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; 236 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap;
240 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap; 237 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap;
241 238
242 // TODO(sandersd): Separate container enum from codec mask value. 239 // TODO(sandersd): Separate container enum from codec mask value.
243 // http://crbug.com/417440 240 // http://crbug.com/417440
244 // Potentially pass EmeMediaType and a container enum. 241 // Potentially pass EmeMediaType and a container enum.
(...skipping 11 matching lines...) Expand all
256 253
257 SupportedCodecs audio_codec_mask_; 254 SupportedCodecs audio_codec_mask_;
258 SupportedCodecs video_codec_mask_; 255 SupportedCodecs video_codec_mask_;
259 256
260 // Makes sure all methods are called from the same thread. 257 // Makes sure all methods are called from the same thread.
261 base::ThreadChecker thread_checker_; 258 base::ThreadChecker thread_checker_;
262 259
263 DISALLOW_COPY_AND_ASSIGN(KeySystemsImpl); 260 DISALLOW_COPY_AND_ASSIGN(KeySystemsImpl);
264 }; 261 };
265 262
266 static base::LazyInstance<KeySystemsImpl>::Leaky g_key_systems =
267 LAZY_INSTANCE_INITIALIZER;
268
269 KeySystemsImpl* KeySystemsImpl::GetInstance() { 263 KeySystemsImpl* KeySystemsImpl::GetInstance() {
270 KeySystemsImpl* key_systems = g_key_systems.Pointer(); 264 static KeySystemsImpl* key_systems = new KeySystemsImpl();
271 key_systems->UpdateIfNeeded(); 265 key_systems->UpdateIfNeeded();
272 return key_systems; 266 return key_systems;
273 } 267 }
274 268
275 // Because we use a LazyInstance, the key systems info must be populated when 269 // Because we use a thread-safe static, the key systems info must be populated
276 // the instance is lazily initiated. 270 // when the instance is constructed.
277 KeySystemsImpl::KeySystemsImpl() : 271 KeySystemsImpl::KeySystemsImpl()
278 audio_codec_mask_(EME_CODEC_AUDIO_ALL), 272 : audio_codec_mask_(EME_CODEC_AUDIO_ALL),
279 video_codec_mask_(EME_CODEC_VIDEO_ALL) { 273 video_codec_mask_(EME_CODEC_VIDEO_ALL) {
280 for (size_t i = 0; i < arraysize(kCodecStrings); ++i) { 274 for (size_t i = 0; i < arraysize(kCodecStrings); ++i) {
281 const std::string& name = kCodecStrings[i].name; 275 const std::string& name = kCodecStrings[i].name;
282 DCHECK(!codec_string_map_.count(name)); 276 DCHECK(!codec_string_map_.count(name));
283 codec_string_map_[name] = kCodecStrings[i].type; 277 codec_string_map_[name] = kCodecStrings[i].type;
284 } 278 }
285 for (size_t i = 0; i < arraysize(kMimeTypeToCodecMasks); ++i) { 279 for (size_t i = 0; i < arraysize(kMimeTypeToCodecMasks); ++i) {
286 RegisterMimeType(kMimeTypeToCodecMasks[i].name, 280 RegisterMimeType(kMimeTypeToCodecMasks[i].name,
287 kMimeTypeToCodecMasks[i].type); 281 kMimeTypeToCodecMasks[i].type);
288 } 282 }
289 283
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 uint32_t mask) { 730 uint32_t mask) {
737 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); 731 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask);
738 } 732 }
739 733
740 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, 734 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type,
741 uint32_t mask) { 735 uint32_t mask) {
742 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); 736 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask);
743 } 737 }
744 738
745 } // namespace media 739 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_service_throttler.cc ('k') | media/base/media.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698