diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-12 17:33:52 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-12 17:33:52 +0000 |
commit | 1265917f0c7b19bb242e21111032fb4f35b3767a (patch) | |
tree | 999c4397962987f16d9d20fd4e76f31ae52d397c | |
parent | 5513ee8e5373a2e7e52d2ec32ce2b608d6ac1415 (diff) | |
download | chromium_src-1265917f0c7b19bb242e21111032fb4f35b3767a.zip chromium_src-1265917f0c7b19bb242e21111032fb4f35b3767a.tar.gz chromium_src-1265917f0c7b19bb242e21111032fb4f35b3767a.tar.bz2 |
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
-rw-r--r-- | base/file_util.h | 4 | ||||
-rw-r--r-- | base/file_util_posix.cc | 4 | ||||
-rw-r--r-- | base/file_util_win.cc | 8 | ||||
-rw-r--r-- | base/file_version_info.h | 6 | ||||
-rw-r--r-- | base/file_version_info_mac.mm | 29 | ||||
-rw-r--r-- | base/path_service.cc | 37 | ||||
-rw-r--r-- | base/path_service.h | 2 |
7 files changed, 51 insertions, 39 deletions
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 @@ std::wstring GetDirectoryFromPath(const std::wstring& path); // 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 @@ std::wstring GetDirectoryFromPath(const std::wstring& path) { #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_util_win.cc b/base/file_util_win.cc index 251d030..f415016 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -54,6 +54,14 @@ std::wstring GetDirectoryFromPath(const std::wstring& path) { TrimTrailingSeparator(&directory); return directory; } + +bool AbsolutePath(std::wstring* path) { + wchar_t file_path_buf[MAX_PATH]; + if (!_wfullpath(file_path_buf, path->c_str(), MAX_PATH)) + return false; + *path = file_path_buf; + return true; +} int CountFilesCreatedAfter(const std::wstring& path, const FILETIME& comparison_time) { 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 @@ class FileVersionInfo { // 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 @@ class FileVersionInfo { // 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/file_version_info_mac.mm b/base/file_version_info_mac.mm index a3e3e0c..23d84db 100644 --- a/base/file_version_info_mac.mm +++ b/base/file_version_info_mac.mm @@ -28,37 +28,39 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Copied from base/basictypes.h with some modifications -#import <Cocoa/Cocoa.h> - #include "base/file_version_info.h" +#import <Cocoa/Cocoa.h> + #include "base/logging.h" #include "base/string_util.h" -FileVersionInfo::FileVersionInfo(const std::wstring& file_path, NSBundle *bundle) - : file_path_(file_path), bundle_(bundle) { - if (!bundle_) { - NSString* path = [[NSString alloc] - initWithCString:reinterpret_cast<const char*>(file_path_.c_str()) - encoding:NSUTF32StringEncoding]; - bundle_ = [NSBundle bundleWithPath: path]; - } +FileVersionInfo::FileVersionInfo(const std::wstring& file_path) { + NSString* path = [[NSString alloc] + initWithCString:reinterpret_cast<const char*>(file_path.c_str()) + encoding:NSUTF32StringEncoding]; + bundle_ = [NSBundle bundleWithPath: path]; } -FileVersionInfo::~FileVersionInfo() { +FileVersionInfo::FileVersionInfo(NSBundle *bundle) : bundle_(bundle) { +} +FileVersionInfo::~FileVersionInfo() { + [bundle_ release]; } // static FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { + // TODO(erikkay): this should really use bundleForClass, but we don't have + // a class to hang onto yet. NSBundle* bundle = [NSBundle mainBundle]; - return new FileVersionInfo(L"", bundle); + return new FileVersionInfo(bundle); } // static FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( const std::wstring& file_path) { - return new FileVersionInfo(file_path, nil); + return new FileVersionInfo(file_path); } std::wstring FileVersionInfo::company_name() { @@ -126,7 +128,6 @@ bool FileVersionInfo::is_official_build() { } bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { - std::wstring str; if (bundle_) { NSString* value = [bundle_ objectForInfoDictionaryKey: [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; 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 @@ namespace base { #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 @@ struct PathData { #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 @@ bool PathService::GetFromCache(int key, std::wstring* result) { 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 @@ void PathService::AddToCache(int key, const std::wstring& path) { // 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::Get(int key, std::wstring* result) { } bool PathService::IsOverridden(int key) { + PathData* path_data = GetPathData(); DCHECK(path_data); AutoLock scoped_lock(path_data->lock); @@ -186,26 +193,13 @@ bool PathService::IsOverridden(int key) { } 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 @@ bool PathService::SetCurrentDirectory(const std::wstring& current_directory) { 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 @@ class PathService { 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); |