license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | 057a8553 | 2009-09-02 17:18:22 | [diff] [blame] | 5 | #ifndef BASE_PATH_SERVICE_H_ |
| 6 | #define BASE_PATH_SERVICE_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 8 | |
[email protected] | 1010f7d | 2008-08-06 16:29:44 | [diff] [blame] | 9 | #include "build/build_config.h" |
[email protected] | 1010f7d | 2008-08-06 16:29:44 | [diff] [blame] | 10 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 11 | #include <string> |
| 12 | |
| 13 | #include "base/base_paths.h" |
| 14 | |
[email protected] | 640517f | 2008-10-30 23:54:04 | [diff] [blame] | 15 | class FilePath; |
| 16 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 17 | // The path service is a global table mapping keys to file system paths. It is |
| 18 | // OK to use this service from multiple threads. |
| 19 | // |
| 20 | class PathService { |
| 21 | public: |
| 22 | // Retrieves a path to a special directory or file and places it into the |
| 23 | // string pointed to by 'path'. If you ask for a directory it is guaranteed |
| 24 | // to NOT have a path separator at the end. For example, "c:\windows\temp" |
| 25 | // Directories are also guaranteed to exist when this function succeeds. |
| 26 | // |
| 27 | // Returns true if the directory or file was successfully retrieved. On |
| 28 | // failure, 'path' will not be changed. |
[email protected] | 640517f | 2008-10-30 23:54:04 | [diff] [blame] | 29 | static bool Get(int key, FilePath* path); |
[email protected] | ab926d55 | 2009-10-19 22:54:41 | [diff] [blame] | 30 | #if defined(OS_WIN) |
[email protected] | 640517f | 2008-10-30 23:54:04 | [diff] [blame] | 31 | // This version, producing a wstring, is deprecated and only kept around |
| 32 | // until we can fix all callers. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 33 | static bool Get(int key, std::wstring* path); |
[email protected] | ab926d55 | 2009-10-19 22:54:41 | [diff] [blame] | 34 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 35 | |
| 36 | // 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 |
| 38 | // path specifies a directory that does not exist, the directory will be |
| 39 | // created by this method. This method returns true if successful. |
| 40 | // |
[email protected] | 52a261f | 2009-03-03 15:01:12 | [diff] [blame] | 41 | // If the given path is relative, then it will be resolved against |
| 42 | // DIR_CURRENT. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 43 | // |
| 44 | // WARNING: Consumers of PathService::Get may expect paths to be constant |
| 45 | // over the lifetime of the app, so this method should be used with caution. |
[email protected] | eca6a4f | 2009-06-25 17:29:09 | [diff] [blame] | 46 | static bool Override(int key, const FilePath& path); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 47 | |
| 48 | // Return whether a path was overridden. |
| 49 | static bool IsOverridden(int key); |
| 50 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 51 | // To extend the set of supported keys, you can register a path provider, |
| 52 | // which is just a function mirroring PathService::Get. The ProviderFunc |
| 53 | // returns false if it cannot provide a non-empty path for the given key. |
| 54 | // Otherwise, true is returned. |
| 55 | // |
| 56 | // WARNING: This function could be called on any thread from which the |
| 57 | // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. |
| 58 | // |
[email protected] | 4792a26 | 2008-11-19 16:50:03 | [diff] [blame] | 59 | typedef bool (*ProviderFunc)(int, FilePath*); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 60 | |
| 61 | // Call to register a path provider. You must specify the range "[key_start, |
| 62 | // key_end)" of supported path keys. |
| 63 | static void RegisterProvider(ProviderFunc provider, |
| 64 | int key_start, |
| 65 | int key_end); |
[email protected] | 1265917f | 2008-08-12 17:33:52 | [diff] [blame] | 66 | private: |
[email protected] | 640517f | 2008-10-30 23:54:04 | [diff] [blame] | 67 | static bool GetFromCache(int key, FilePath* path); |
| 68 | static void AddToCache(int key, const FilePath& path); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 69 | }; |
| 70 | |
[email protected] | 057a8553 | 2009-09-02 17:18:22 | [diff] [blame] | 71 | #endif // BASE_PATH_SERVICE_H_ |