| 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 42 // 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 |
| 43 // 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 |
| 44 // created by this method. This method returns true if successful. | 44 // created by this method. This method returns true if successful. |
| 45 // | 45 // |
| 46 // If the given path is relative, then it will be resolved against | 46 // If the given path is relative, then it will be resolved against |
| 47 // DIR_CURRENT. | 47 // DIR_CURRENT. |
| 48 // | 48 // |
| 49 // WARNING: Consumers of PathService::Get may expect paths to be constant | 49 // WARNING: Consumers of PathService::Get may expect paths to be constant |
| 50 // over the lifetime of the app, so this method should be used with caution. | 50 // over the lifetime of the app, so this method should be used with caution. |
| 51 static bool Override(int key, const FilePath& path); | 51 static bool Override(int key, const FilePath& path); |
| 52 // This version, using a wstring, is deprecated and only kept around | |
| 53 // until we can fix all callers. | |
| 54 static bool Override(int key, const std::wstring& path); | |
| 55 | 52 |
| 56 // Return whether a path was overridden. | 53 // Return whether a path was overridden. |
| 57 static bool IsOverridden(int key); | 54 static bool IsOverridden(int key); |
| 58 | 55 |
| 59 // Sets the current directory. | 56 // Sets the current directory. |
| 60 static bool SetCurrentDirectory(const std::wstring& current_directory); | 57 static bool SetCurrentDirectory(const std::wstring& current_directory); |
| 61 | 58 |
| 62 // To extend the set of supported keys, you can register a path provider, | 59 // To extend the set of supported keys, you can register a path provider, |
| 63 // which is just a function mirroring PathService::Get. The ProviderFunc | 60 // which is just a function mirroring PathService::Get. The ProviderFunc |
| 64 // returns false if it cannot provide a non-empty path for the given key. | 61 // returns false if it cannot provide a non-empty path for the given key. |
| 65 // Otherwise, true is returned. | 62 // Otherwise, true is returned. |
| 66 // | 63 // |
| 67 // WARNING: This function could be called on any thread from which the | 64 // WARNING: This function could be called on any thread from which the |
| 68 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. | 65 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. |
| 69 // | 66 // |
| 70 typedef bool (*ProviderFunc)(int, FilePath*); | 67 typedef bool (*ProviderFunc)(int, FilePath*); |
| 71 | 68 |
| 72 // Call to register a path provider. You must specify the range "[key_start, | 69 // Call to register a path provider. You must specify the range "[key_start, |
| 73 // key_end)" of supported path keys. | 70 // key_end)" of supported path keys. |
| 74 static void RegisterProvider(ProviderFunc provider, | 71 static void RegisterProvider(ProviderFunc provider, |
| 75 int key_start, | 72 int key_start, |
| 76 int key_end); | 73 int key_end); |
| 77 private: | 74 private: |
| 78 static bool GetFromCache(int key, FilePath* path); | 75 static bool GetFromCache(int key, FilePath* path); |
| 79 static void AddToCache(int key, const FilePath& path); | 76 static void AddToCache(int key, const FilePath& path); |
| 80 | |
| 81 }; | 77 }; |
| 82 | 78 |
| 83 #endif // BASE_PATH_SERVICE_H__ | 79 #endif // BASE_PATH_SERVICE_H_ |
| OLD | NEW |