| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef BASE_PATH_SERVICE_H__ | 5 #ifndef BASE_PATH_SERVICE_H__ |
| 6 #define BASE_PATH_SERVICE_H__ | 6 #define BASE_PATH_SERVICE_H__ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #ifdef OS_WIN | 9 #ifdef OS_WIN |
| 10 // TODO(erikkay): this should be removable, but because SetCurrentDirectory | 10 // TODO(erikkay): this should be removable, but because SetCurrentDirectory |
| 11 // is the name of a Windows function, it gets macro-ized to SetCurrentDirectoryW | 11 // is the name of a Windows function, it gets macro-ized to SetCurrentDirectoryW |
| 12 // by windows.h, which leads to a different name in the header vs. the impl. | 12 // by windows.h, which leads to a different name in the header vs. the impl. |
| 13 // Even if we could fix that, it would still hose all callers of the function. | 13 // Even if we could fix that, it would still hose all callers of the function. |
| 14 // The right thing is likely to rename. | 14 // The right thing is likely to rename. |
| 15 #include <windows.h> | 15 #include <windows.h> |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 #include <string> | 18 #include <string> |
| 19 | 19 |
| 20 #include "base/base_paths.h" | 20 #include "base/base_paths.h" |
| 21 | 21 |
| 22 class FilePath; |
| 23 |
| 22 // The path service is a global table mapping keys to file system paths. It is | 24 // The path service is a global table mapping keys to file system paths. It is |
| 23 // OK to use this service from multiple threads. | 25 // OK to use this service from multiple threads. |
| 24 // | 26 // |
| 25 class PathService { | 27 class PathService { |
| 26 public: | 28 public: |
| 27 // Retrieves a path to a special directory or file and places it into the | 29 // Retrieves a path to a special directory or file and places it into the |
| 28 // string pointed to by 'path'. If you ask for a directory it is guaranteed | 30 // string pointed to by 'path'. If you ask for a directory it is guaranteed |
| 29 // to NOT have a path separator at the end. For example, "c:\windows\temp" | 31 // to NOT have a path separator at the end. For example, "c:\windows\temp" |
| 30 // Directories are also guaranteed to exist when this function succeeds. | 32 // Directories are also guaranteed to exist when this function succeeds. |
| 31 // | 33 // |
| 32 // Returns true if the directory or file was successfully retrieved. On | 34 // Returns true if the directory or file was successfully retrieved. On |
| 33 // failure, 'path' will not be changed. | 35 // failure, 'path' will not be changed. |
| 36 static bool Get(int key, FilePath* path); |
| 37 // This version, producing a wstring, is deprecated and only kept around |
| 38 // until we can fix all callers. |
| 34 static bool Get(int key, std::wstring* path); | 39 static bool Get(int key, std::wstring* path); |
| 35 | 40 |
| 36 // Overrides the path to a special directory or file. This cannot be used to | 41 // Overrides the path to a special directory or file. This cannot be used to |
| 37 // change the value of DIR_CURRENT, but that should be obvious. Also, if the | 42 // change the value of DIR_CURRENT, but that should be obvious. Also, if the |
| 38 // path specifies a directory that does not exist, the directory will be | 43 // path specifies a directory that does not exist, the directory will be |
| 39 // created by this method. This method returns true if successful. | 44 // created by this method. This method returns true if successful. |
| 40 // | 45 // |
| 41 // If the given path is relative, then it will be resolved against DIR_CURRENT
. | 46 // If the given path is relative, then it will be resolved against DIR_CURRENT
. |
| 42 // | 47 // |
| 43 // WARNING: Consumers of PathService::Get may expect paths to be constant | 48 // WARNING: Consumers of PathService::Get may expect paths to be constant |
| (...skipping 15 matching lines...) Expand all Loading... |
| 59 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. | 64 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. |
| 60 // | 65 // |
| 61 typedef bool (*ProviderFunc)(int, std::wstring*); | 66 typedef bool (*ProviderFunc)(int, std::wstring*); |
| 62 | 67 |
| 63 // Call to register a path provider. You must specify the range "[key_start, | 68 // Call to register a path provider. You must specify the range "[key_start, |
| 64 // key_end)" of supported path keys. | 69 // key_end)" of supported path keys. |
| 65 static void RegisterProvider(ProviderFunc provider, | 70 static void RegisterProvider(ProviderFunc provider, |
| 66 int key_start, | 71 int key_start, |
| 67 int key_end); | 72 int key_end); |
| 68 private: | 73 private: |
| 69 static bool GetFromCache(int key, std::wstring* path); | 74 static bool GetFromCache(int key, FilePath* path); |
| 70 static void AddToCache(int key, const std::wstring& path); | 75 static void AddToCache(int key, const FilePath& path); |
| 71 | 76 |
| 72 }; | 77 }; |
| 73 | 78 |
| 74 #endif // BASE_PATH_SERVICE_H__ | 79 #endif // BASE_PATH_SERVICE_H__ |
| 75 | 80 |
| OLD | NEW |