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

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

Issue 14891002: Remove function level static initializers media library initialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « media/base/media.h ('k') | media/base/media_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/base/media.h"
6
7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h"
9 #include "base/path_service.h"
10 #include "base/synchronization/lock.h"
11 #include "build/build_config.h"
12
13 namespace media {
14
15 namespace internal {
16 // Platform specific initialization method.
17 extern bool InitializeMediaLibraryInternal(const base::FilePath& module_dir);
18 } // namespace internal
19
20 // Media must only be initialized once, so use a LazyInstance to ensure this.
21 class MediaInitializer {
22 public:
23 bool Initialize(const base::FilePath& module_dir) {
24 base::AutoLock auto_lock(lock_);
25 if (!tried_initialize_) {
26 tried_initialize_ = true;
27 initialized_ = internal::InitializeMediaLibraryInternal(module_dir);
28 }
29 return initialized_;
30 }
31
32 bool IsInitialized() {
33 base::AutoLock auto_lock(lock_);
34 return initialized_;
35 }
36
37 private:
38 friend struct base::DefaultLazyInstanceTraits<MediaInitializer>;
39
40 MediaInitializer()
41 : initialized_(false),
42 tried_initialize_(false) {
43 // TODO(dalecurtis): Add initialization of YUV and VectorMath libraries.
44 }
45
46 ~MediaInitializer() {
47 NOTREACHED() << "MediaInitializer should be leaky!";
48 }
49
50 base::Lock lock_;
51 bool initialized_;
52 bool tried_initialize_;
53
54 DISALLOW_COPY_AND_ASSIGN(MediaInitializer);
55 };
56
57 static base::LazyInstance<MediaInitializer>::Leaky g_media_library =
58 LAZY_INSTANCE_INITIALIZER;
59
60 bool InitializeMediaLibrary(const base::FilePath& module_dir) {
61 return g_media_library.Get().Initialize(module_dir);
62 }
63
64 void InitializeMediaLibraryForTesting() {
65 base::FilePath module_dir;
66 CHECK(PathService::Get(base::DIR_EXE, &module_dir));
67 CHECK(g_media_library.Get().Initialize(module_dir));
68 }
69
70 bool IsMediaLibraryInitialized() {
71 return g_media_library.Get().IsInitialized();
72 }
73
74 } // namespace media
OLDNEW
« no previous file with comments | « media/base/media.h ('k') | media/base/media_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698