summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 11:49:25 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 11:49:25 +0000
commit1a40dd7f41286f3d8220a3711ff7f89cf7b4efe5 (patch)
tree7138c88a5e12fc12ff0c27d16a72c71acb91b68e
parent7c24af349c6756ada9398c77783794c067a639cc (diff)
downloadchromium_src-1a40dd7f41286f3d8220a3711ff7f89cf7b4efe5.zip
chromium_src-1a40dd7f41286f3d8220a3711ff7f89cf7b4efe5.tar.gz
chromium_src-1a40dd7f41286f3d8220a3711ff7f89cf7b4efe5.tar.bz2
Move media library path resolution into Chrome path provider.
BUG=None TEST=None Review URL: http://codereview.chromium.org/6537022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78532 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/chrome_paths.cc8
-rw-r--r--chrome/common/chrome_paths.h1
-rw-r--r--chrome/renderer/render_process_impl.cc23
-rw-r--r--chrome/renderer/render_process_impl.h1
-rw-r--r--chrome/service/service_process.cc27
-rw-r--r--chrome/service/service_process.h4
-rw-r--r--content/browser/zygote_main_linux.cc10
-rw-r--r--media/base/media.h9
-rw-r--r--media/base/media_posix.cc13
-rw-r--r--media/base/media_win.cc25
10 files changed, 75 insertions, 46 deletions
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc
index 35c01d1..1b3061f 100644
--- a/chrome/common/chrome_paths.cc
+++ b/chrome/common/chrome_paths.cc
@@ -195,6 +195,14 @@ bool PathProvider(int key, FilePath* result) {
if (!GetInternalPluginsDirectory(&cur))
return false;
break;
+ case chrome::DIR_MEDIA_LIBS:
+#if defined(OS_MACOSX)
+ *result = base::mac::MainAppBundlePath();
+ *result = result->Append("Libraries");
+ return true;
+#else
+ return PathService::Get(chrome::DIR_APP, result);
+#endif
case chrome::FILE_LOCAL_STATE:
if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
return false;
diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h
index 008fea1..8b91c49 100644
--- a/chrome/common/chrome_paths.h
+++ b/chrome/common/chrome_paths.h
@@ -39,6 +39,7 @@ enum {
// should check that the path exists before
// using it.
DIR_INTERNAL_PLUGINS, // Directory where internal plugins reside.
+ DIR_MEDIA_LIBS, // Directory where the Media libraries reside.
#if !defined(OS_MACOSX) && defined(OS_POSIX)
DIR_POLICY_FILES, // Directory for system-wide read-only
// policy files that allow sys-admins
diff --git a/chrome/renderer/render_process_impl.cc b/chrome/renderer/render_process_impl.cc
index 34f2138..45c4427 100644
--- a/chrome/renderer/render_process_impl.cc
+++ b/chrome/renderer/render_process_impl.cc
@@ -131,21 +131,18 @@ RenderProcessImpl::RenderProcessImpl()
base::StatisticsRecorder::set_dump_on_exit(true);
}
-#if defined(OS_MACOSX)
- FilePath bundle_path = base::mac::MainAppBundlePath();
-
- initialized_media_library_ =
- media::InitializeMediaLibrary(bundle_path.Append("Libraries"));
-#else
- FilePath module_path;
- initialized_media_library_ =
- PathService::Get(base::DIR_MODULE, &module_path) &&
- media::InitializeMediaLibrary(module_path);
+ // Note that under Linux, the media library will normally already have
+ // been initialized by the Zygote before this instance became a Renderer.
+ FilePath media_path;
+ if (PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path))
+ media::InitializeMediaLibrary(media_path);
+#if !defined(OS_MACOSX)
// TODO(hclam): Add more checks here. Currently this is not used.
- if (CommandLine::ForCurrentProcess()->HasSwitch(
+ if (media::IsMediaLibraryInitialized() &&
+ CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableOpenMax)) {
- media::InitializeOpenMaxLibrary(module_path);
+ media::InitializeOpenMaxLibrary(media_path);
}
#endif
@@ -277,7 +274,7 @@ bool RenderProcessImpl::UseInProcessPlugins() const {
}
bool RenderProcessImpl::HasInitializedMediaLibrary() const {
- return initialized_media_library_;
+ return media::IsMediaLibraryInitialized();
}
bool RenderProcessImpl::GetTransportDIBFromCache(TransportDIB** mem,
diff --git a/chrome/renderer/render_process_impl.h b/chrome/renderer/render_process_impl.h
index dcb6a5a..be53005 100644
--- a/chrome/renderer/render_process_impl.h
+++ b/chrome/renderer/render_process_impl.h
@@ -69,7 +69,6 @@ class RenderProcessImpl : public RenderProcess {
uint32 transport_dib_next_sequence_number_;
bool in_process_plugins_;
- bool initialized_media_library_;
DISALLOW_COPY_AND_ASSIGN(RenderProcessImpl);
};
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index 1335936..d559c46 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -175,23 +175,14 @@ bool ServiceProcess::Initialize(MessageLoopForUI* message_loop,
#if defined(ENABLE_REMOTING)
// Load media codecs, required by the Chromoting host
- bool initialized_media_library = false;
-#if defined(OS_MACOSX)
- FilePath bundle_path = base::mac::MainAppBundlePath();
-
- initialized_media_library =
- media::InitializeMediaLibrary(bundle_path.Append("Libraries"));
-#else
FilePath module_path;
- initialized_media_library =
- PathService::Get(base::DIR_MODULE, &module_path) &&
- media::InitializeMediaLibrary(module_path);
-#endif
-
- // Initialize chromoting host manager.
- remoting_host_manager_ = new remoting::ChromotingHostManager(this);
- remoting_host_manager_->Initialize(message_loop,
- file_thread_->message_loop_proxy());
+ if (PathService::Get(chrome::DIR_MEDIA_LIBS, &module_path) &&
+ media::InitializeMediaLibrary(module_path)) {
+ // Initialize chromoting host manager.
+ remoting_host_manager_ = new remoting::ChromotingHostManager(this);
+ remoting_host_manager_->Initialize(message_loop,
+ file_thread_->message_loop_proxy());
+ }
#endif // ENABLE_REMOTING
// Enable Cloud Print if needed. First check the command-line.
@@ -359,7 +350,3 @@ ServiceProcess::~ServiceProcess() {
Teardown();
g_service_process = NULL;
}
-
-// Disable refcounting for runnable method because it is really not needed
-// when we post tasks on the main message loop.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess);
diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h
index a3b8cdc..19a2043 100644
--- a/chrome/service/service_process.h
+++ b/chrome/service/service_process.h
@@ -142,6 +142,10 @@ class ServiceProcess : public CloudPrintProxy::Client,
DISALLOW_COPY_AND_ASSIGN(ServiceProcess);
};
+// Disable refcounting for runnable method because it is really not needed
+// when we post tasks on the main message loop.
+DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcess);
+
extern ServiceProcess* g_service_process;
#endif // CHROME_SERVICE_SERVICE_PROCESS_H_
diff --git a/content/browser/zygote_main_linux.cc b/content/browser/zygote_main_linux.cc
index ba6bcb1..8a563b3 100644
--- a/content/browser/zygote_main_linux.cc
+++ b/content/browser/zygote_main_linux.cc
@@ -37,6 +37,7 @@
#include "base/sys_info.h"
#include "build/build_config.h"
#include "chrome/common/chrome_descriptors.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pepper_plugin_registry.h"
#include "content/common/font_config_ipc_linux.h"
@@ -597,9 +598,12 @@ static void PreSandboxInit() {
// cached and there's no more need to access the file system.
scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
- FilePath module_path;
- if (PathService::Get(base::DIR_MODULE, &module_path))
- media::InitializeMediaLibrary(module_path);
+ // Each Renderer we spawn will re-attempt initialization of the media
+ // libraries, at which point failure will be detected and handled, so
+ // we do not need to cope with initialization failures here.
+ FilePath media_path;
+ if (PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path))
+ media::InitializeMediaLibrary(media_path);
// Remoting requires NSS to function properly. It is not used for other
// reasons so load NSS only if remoting is enabled.
diff --git a/media/base/media.h b/media/base/media.h
index 3d1a83a..6bbad4c 100644
--- a/media/base/media.h
+++ b/media/base/media.h
@@ -13,13 +13,22 @@ class FilePath;
namespace media {
// Attempts to initialize the media library (loading DLLs, DSOs, etc.).
+//
// If |module_dir| is the emptry string, then the system default library paths
// are searched for the dynamic libraries. If a |module_dir| is provided, then
// only the specified |module_dir| will be searched for the dynamic libraries.
//
+// If multiple initializations are attempted with different |module_dir|s
+// specified then the first one to succeed remains effective for the lifetime
+// of the process.
+//
// Returns true if everything was successfully initialized, false otherwise.
bool InitializeMediaLibrary(const FilePath& module_dir);
+// Use this if you need to check whether the media library is initialized
+// for the this process, without actually trying to initialize it.
+bool IsMediaLibraryInitialized();
+
// Attempts to initialize OpenMAX library.
//
// Returns true if OpenMAX was successfully initialized and loaded.
diff --git a/media/base/media_posix.cc b/media/base/media_posix.cc
index 08684e7..3621bd6 100644
--- a/media/base/media_posix.cc
+++ b/media/base/media_posix.cc
@@ -66,9 +66,14 @@ static std::string GetDSOName(tp_ffmpeg::StubModules stub_key) {
}
}
+static bool g_media_library_is_initialized = false;
+
// Attempts to initialize the media library (loading DSOs, etc.).
// Returns true if everything was successfully initialized, false otherwise.
bool InitializeMediaLibrary(const FilePath& module_dir) {
+ if (g_media_library_is_initialized)
+ return true;
+
// TODO(ajwong): We need error resolution.
tp_ffmpeg::StubPathMap paths;
for (int i = 0; i < static_cast<int>(tp_ffmpeg::kNumStubModules); ++i) {
@@ -82,8 +87,12 @@ bool InitializeMediaLibrary(const FilePath& module_dir) {
paths[module].push_back(path.value());
}
- bool ret = tp_ffmpeg::InitializeStubs(paths);
- return ret;
+ g_media_library_is_initialized = tp_ffmpeg::InitializeStubs(paths);
+ return g_media_library_is_initialized;
+}
+
+bool IsMediaLibraryInitialized() {
+ return g_media_library_is_initialized;
}
#if defined(OS_LINUX)
diff --git a/media/base/media_win.cc b/media/base/media_win.cc
index 82f8596..ce47ba9 100644
--- a/media/base/media_win.cc
+++ b/media/base/media_win.cc
@@ -44,9 +44,14 @@ static FilePath::CharType* GetDLLName(FFmpegDLLKeys dll_key) {
}
}
+static bool g_media_library_is_initialized = false;
+
// Attempts to initialize the media library (loading DLLs, DSOs, etc.).
// Returns true if everything was successfully initialized, false otherwise.
bool InitializeMediaLibrary(const FilePath& base_path) {
+ if (g_media_library_is_initialized)
+ return true;
+
FFmpegDLLKeys path_keys[] = {
media::FILE_LIBAVCODEC,
media::FILE_LIBAVFORMAT,
@@ -78,15 +83,21 @@ bool InitializeMediaLibrary(const FilePath& base_path) {
// Check that we loaded all libraries successfully. We only need to check the
// last array element because the loop above will break without initializing
// it on any prior error.
- if (libs[arraysize(libs)-1])
- return true;
+ g_media_library_is_initialized = (libs[arraysize(libs)-1] != NULL);
- // Free any loaded libraries if we weren't successful.
- for (size_t i = 0; i < arraysize(libs) && libs[i] != NULL; ++i) {
- FreeLibrary(libs[i]);
- libs[i] = NULL; // Just to be safe.
+ if (!g_media_library_is_initialized) {
+ // Free any loaded libraries if we weren't successful.
+ for (size_t i = 0; i < arraysize(libs) && libs[i] != NULL; ++i) {
+ FreeLibrary(libs[i]);
+ libs[i] = NULL; // Just to be safe.
+ }
}
- return false;
+
+ return g_media_library_is_initialized;
+}
+
+bool IsMediaLibraryInitialized() {
+ return g_media_library_is_initialized;
}
bool InitializeOpenMaxLibrary(const FilePath& module_dir) {