OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
(...skipping 21 matching lines...) Expand all Loading... |
33 // path specifies a directory that does not exist, the directory will be | 33 // path specifies a directory that does not exist, the directory will be |
34 // created by this method. This method returns true if successful. | 34 // created by this method. This method returns true if successful. |
35 // | 35 // |
36 // If the given path is relative, then it will be resolved against | 36 // If the given path is relative, then it will be resolved against |
37 // DIR_CURRENT. | 37 // DIR_CURRENT. |
38 // | 38 // |
39 // WARNING: Consumers of PathService::Get may expect paths to be constant | 39 // WARNING: Consumers of PathService::Get may expect paths to be constant |
40 // over the lifetime of the app, so this method should be used with caution. | 40 // over the lifetime of the app, so this method should be used with caution. |
41 static bool Override(int key, const FilePath& path); | 41 static bool Override(int key, const FilePath& path); |
42 | 42 |
| 43 // This function does the same as PathService::Override but it takes an extra |
| 44 // parameter |create| which guides whether the directory to be overriden must |
| 45 // be created in case it doesn't exist already. |
| 46 static bool OverrideAndCreateIfNeeded(int key, |
| 47 const FilePath& path, |
| 48 bool create); |
| 49 |
43 // To extend the set of supported keys, you can register a path provider, | 50 // To extend the set of supported keys, you can register a path provider, |
44 // which is just a function mirroring PathService::Get. The ProviderFunc | 51 // which is just a function mirroring PathService::Get. The ProviderFunc |
45 // returns false if it cannot provide a non-empty path for the given key. | 52 // returns false if it cannot provide a non-empty path for the given key. |
46 // Otherwise, true is returned. | 53 // Otherwise, true is returned. |
47 // | 54 // |
48 // WARNING: This function could be called on any thread from which the | 55 // WARNING: This function could be called on any thread from which the |
49 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. | 56 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. |
50 // | 57 // |
51 typedef bool (*ProviderFunc)(int, FilePath*); | 58 typedef bool (*ProviderFunc)(int, FilePath*); |
52 | 59 |
53 // Call to register a path provider. You must specify the range "[key_start, | 60 // Call to register a path provider. You must specify the range "[key_start, |
54 // key_end)" of supported path keys. | 61 // key_end)" of supported path keys. |
55 static void RegisterProvider(ProviderFunc provider, | 62 static void RegisterProvider(ProviderFunc provider, |
56 int key_start, | 63 int key_start, |
57 int key_end); | 64 int key_end); |
58 private: | 65 private: |
59 static bool GetFromCache(int key, FilePath* path); | 66 static bool GetFromCache(int key, FilePath* path); |
60 static bool GetFromOverrides(int key, FilePath* path); | 67 static bool GetFromOverrides(int key, FilePath* path); |
61 static void AddToCache(int key, const FilePath& path); | 68 static void AddToCache(int key, const FilePath& path); |
62 }; | 69 }; |
63 | 70 |
64 #endif // BASE_PATH_SERVICE_H_ | 71 #endif // BASE_PATH_SERVICE_H_ |
OLD | NEW |