Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Side by Side Diff: base/path_service.h

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/nix/xdg_util.h ('k') | base/perftimer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 14
15 namespace base {
15 class FilePath; 16 class FilePath;
16
17 namespace base {
18 class ScopedPathOverride; 17 class ScopedPathOverride;
19 } // namespace 18 } // namespace
20 19
21 // The path service is a global table mapping keys to file system paths. It is 20 // The path service is a global table mapping keys to file system paths. It is
22 // OK to use this service from multiple threads. 21 // OK to use this service from multiple threads.
23 // 22 //
24 class BASE_EXPORT PathService { 23 class BASE_EXPORT PathService {
25 public: 24 public:
26 // Retrieves a path to a special directory or file and places it into the 25 // Retrieves a path to a special directory or file and places it into the
27 // string pointed to by 'path'. If you ask for a directory it is guaranteed 26 // string pointed to by 'path'. If you ask for a directory it is guaranteed
28 // to NOT have a path separator at the end. For example, "c:\windows\temp" 27 // to NOT have a path separator at the end. For example, "c:\windows\temp"
29 // Directories are also guaranteed to exist when this function succeeds. 28 // Directories are also guaranteed to exist when this function succeeds.
30 // 29 //
31 // Returns true if the directory or file was successfully retrieved. On 30 // Returns true if the directory or file was successfully retrieved. On
32 // failure, 'path' will not be changed. 31 // failure, 'path' will not be changed.
33 static bool Get(int key, FilePath* path); 32 static bool Get(int key, base::FilePath* path);
34 33
35 // Overrides the path to a special directory or file. This cannot be used to 34 // Overrides the path to a special directory or file. This cannot be used to
36 // change the value of DIR_CURRENT, but that should be obvious. Also, if the 35 // change the value of DIR_CURRENT, but that should be obvious. Also, if the
37 // path specifies a directory that does not exist, the directory will be 36 // path specifies a directory that does not exist, the directory will be
38 // created by this method. This method returns true if successful. 37 // created by this method. This method returns true if successful.
39 // 38 //
40 // If the given path is relative, then it will be resolved against 39 // If the given path is relative, then it will be resolved against
41 // DIR_CURRENT. 40 // DIR_CURRENT.
42 // 41 //
43 // WARNING: Consumers of PathService::Get may expect paths to be constant 42 // WARNING: Consumers of PathService::Get may expect paths to be constant
44 // over the lifetime of the app, so this method should be used with caution. 43 // over the lifetime of the app, so this method should be used with caution.
45 static bool Override(int key, const FilePath& path); 44 static bool Override(int key, const base::FilePath& path);
46 45
47 // This function does the same as PathService::Override but it takes an extra 46 // This function does the same as PathService::Override but it takes an extra
48 // parameter |create| which guides whether the directory to be overriden must 47 // parameter |create| which guides whether the directory to be overriden must
49 // be created in case it doesn't exist already. 48 // be created in case it doesn't exist already.
50 static bool OverrideAndCreateIfNeeded(int key, 49 static bool OverrideAndCreateIfNeeded(int key,
51 const FilePath& path, 50 const base::FilePath& path,
52 bool create); 51 bool create);
53 52
54 // To extend the set of supported keys, you can register a path provider, 53 // To extend the set of supported keys, you can register a path provider,
55 // which is just a function mirroring PathService::Get. The ProviderFunc 54 // which is just a function mirroring PathService::Get. The ProviderFunc
56 // returns false if it cannot provide a non-empty path for the given key. 55 // returns false if it cannot provide a non-empty path for the given key.
57 // Otherwise, true is returned. 56 // Otherwise, true is returned.
58 // 57 //
59 // WARNING: This function could be called on any thread from which the 58 // WARNING: This function could be called on any thread from which the
60 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. 59 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE.
61 // 60 //
62 typedef bool (*ProviderFunc)(int, FilePath*); 61 typedef bool (*ProviderFunc)(int, base::FilePath*);
63 62
64 // Call to register a path provider. You must specify the range "[key_start, 63 // Call to register a path provider. You must specify the range "[key_start,
65 // key_end)" of supported path keys. 64 // key_end)" of supported path keys.
66 static void RegisterProvider(ProviderFunc provider, 65 static void RegisterProvider(ProviderFunc provider,
67 int key_start, 66 int key_start,
68 int key_end); 67 int key_end);
69 68
70 // Disable internal cache. 69 // Disable internal cache.
71 static void DisableCache(); 70 static void DisableCache();
72 71
73 private: 72 private:
74 friend class base::ScopedPathOverride; 73 friend class base::ScopedPathOverride;
75 FRIEND_TEST_ALL_PREFIXES(PathServiceTest, RemoveOverride); 74 FRIEND_TEST_ALL_PREFIXES(PathServiceTest, RemoveOverride);
76 75
77 // Removes an override for a special directory or file. Returns true if there 76 // Removes an override for a special directory or file. Returns true if there
78 // was an override to remove or false if none was present. 77 // was an override to remove or false if none was present.
79 // NOTE: This function is intended to be used by tests only! 78 // NOTE: This function is intended to be used by tests only!
80 static bool RemoveOverride(int key); 79 static bool RemoveOverride(int key);
81 }; 80 };
82 81
83 #endif // BASE_PATH_SERVICE_H_ 82 #endif // BASE_PATH_SERVICE_H_
OLDNEW
« no previous file with comments | « base/nix/xdg_util.h ('k') | base/perftimer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698