I accidentally committed file_version_info.  Since comments were relatively minor, I created a new CL rather than reverting the old one.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@722 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 1265917f0c7b19bb242e21111032fb4f35b3767a
diff --git a/base/file_util.h b/base/file_util.h
index f74ff97..4aac207 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -95,6 +95,10 @@
 // Appends new_ending to path, adding a separator between the two if necessary.
 void AppendToPath(std::wstring* path, const std::wstring& new_ending);
 
+// Convert provided relative path into an absolute path.  Returns false on
+// error.
+bool AbsolutePath(std::wstring* path);
+
 // Inserts |suffix| after the file name portion of |path| but before the
 // extension.
 // Examples:
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 41a0ac6..510747f 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -54,6 +54,10 @@
 #endif
   return UTF8ToWide(dirname(full_path));
 }
+  
+bool AbsolutePath(std::wstring* path) {
+  return ResolveShortcut(path);
+}
 
 bool Delete(const std::wstring& path, bool recursive) {
   std::string utf8_path = WideToUTF8(path);
diff --git a/base/file_version_info.h b/base/file_version_info.h
index 94b3955..fcde901 100644
--- a/base/file_version_info.h
+++ b/base/file_version_info.h
@@ -54,7 +54,7 @@
   // returned object should be deleted when you are done with it.
   static FileVersionInfo* CreateFileVersionInfo(const std::wstring& file_path);
 
-  // Creates a FileVersionInfo for the current application. Returns NULL in case
+  // Creates a FileVersionInfo for the current module. Returns NULL in case
   // of error. The returned object should be deleted when you are done with it.
   static FileVersionInfo*
       FileVersionInfo::CreateFileVersionInfoForCurrentModule();
@@ -102,9 +102,9 @@
   // This is a pointer into the data_ if it exists. Otherwise NULL.
   VS_FIXEDFILEINFO* fixed_file_info_;
 #elif defined(OS_MACOSX)
-  FileVersionInfo(const std::wstring& file_path, NSBundle *bundle);
+  explicit FileVersionInfo(NSBundle *bundle);
+  explicit FileVersionInfo(const std::wstring& file_path);
   
-  const std::wstring& file_path_;
   NSBundle *bundle_;
 #endif
 
diff --git a/base/path_service.cc b/base/path_service.cc
index 1601513..e8d92a5 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -39,6 +39,7 @@
 #include "base/file_util.h"
 #include "base/lock.h"
 #include "base/logging.h"
+#include "base/singleton.h"
 #include "base/string_util.h"
 
 namespace base {
@@ -46,7 +47,7 @@
 #if defined(OS_WIN)
   bool PathProviderWin(int key, std::wstring* result);
 #elif defined (OS_MACOSX)
-  bool PathProviderMac(int key, std::wstring* ressult);
+  bool PathProviderMac(int key, std::wstring* result);
 #endif
 }
 
@@ -114,15 +115,17 @@
 #endif
   }
 };
-
-// We rely on the path service not being used prior to 'main' execution, and
-// we are happy to let this data structure leak at process exit.
-PathData* path_data = new PathData();
+  
+static PathData* GetPathData() {
+  return Singleton<PathData>::get();
+}
 
 }  // namespace
 
 
+// static
 bool PathService::GetFromCache(int key, std::wstring* result) {
+  PathData* path_data = GetPathData();
   AutoLock scoped_lock(path_data->lock);
   
   // check for a cached version
@@ -134,7 +137,9 @@
   return false;
 }
 
+// static
 void PathService::AddToCache(int key, const std::wstring& path) {
+  PathData* path_data = GetPathData();
   AutoLock scoped_lock(path_data->lock);
   // Save the computed path in our cache.
   path_data->cache[key] = path;
@@ -145,6 +150,7 @@
 // moot, but we should keep this in mind for the future.
 // static
 bool PathService::Get(int key, std::wstring* result) {
+  PathData* path_data = GetPathData();
   DCHECK(path_data);
   DCHECK(result);
   DCHECK(key >= base::DIR_CURRENT);
@@ -179,6 +185,7 @@
 }
 
 bool PathService::IsOverridden(int key) {
+  PathData* path_data = GetPathData();
   DCHECK(path_data);
 
   AutoLock scoped_lock(path_data->lock);
@@ -186,26 +193,13 @@
 }
 
 bool PathService::Override(int key, const std::wstring& path) {
+  PathData* path_data = GetPathData();
   DCHECK(path_data);
   DCHECK(key > base::DIR_CURRENT) << "invalid path key";
 
-  // TODO(erikkay): pull this into file_util*
-#if defined(OS_WIN)
-  wchar_t file_path_buf[MAX_PATH];
-  if (!_wfullpath(file_path_buf, path.c_str(), MAX_PATH))
+  std::wstring file_path = path;
+  if (!file_util::AbsolutePath(&file_path))
     return false;
-  std::wstring file_path(file_path_buf);
-#elif defined(OS_POSIX)
-  // The other (posix-like) platforms don't use wide strings for paths. On the
-  // Mac it's NFD UTF-8, and we have to assume that whatever other platforms
-  // we end up on the native encoding is correct.
-  // TODO: refactor all of the path code throughout the project to use a
-  // per-platform path type
-  char file_path_buf[PATH_MAX];
-  if (!realpath(WideToUTF8(path).c_str(), file_path_buf))
-    return false;
-  std::wstring file_path(UTF8ToWide(file_path_buf));
-#endif
 
   // make sure the directory exists:
   if (!file_util::PathExists(file_path) &&
@@ -227,6 +221,7 @@
 
 void PathService::RegisterProvider(ProviderFunc func, int key_start,
                                    int key_end) {
+  PathData* path_data = GetPathData();
   DCHECK(path_data);
   DCHECK(key_end > key_start);
 
diff --git a/base/path_service.h b/base/path_service.h
index bc21e33..1c9f4dc 100644
--- a/base/path_service.h
+++ b/base/path_service.h
@@ -90,7 +90,7 @@
   static void RegisterProvider(ProviderFunc provider,
                                int key_start,
                                int key_end);
-private:
+ private:
   static bool GetFromCache(int key, std::wstring* path);
   static void AddToCache(int key, const std::wstring& path);