Add OS_IOS defines for the mobile promo.
[chromium-blink-merge.git] / base / path_service.h
blobe835a1f34e6b4ddd3c4f313145c30c5cc04ad0fb
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
3 // found in the LICENSE file.
5 #ifndef BASE_PATH_SERVICE_H_
6 #define BASE_PATH_SERVICE_H_
8 #include <string>
10 #include "base/base_export.h"
11 #include "base/base_paths.h"
12 #include "build/build_config.h"
14 class FilePath;
16 // The path service is a global table mapping keys to file system paths. It is
17 // OK to use this service from multiple threads.
19 class BASE_EXPORT PathService {
20 public:
21 // Retrieves a path to a special directory or file and places it into the
22 // string pointed to by 'path'. If you ask for a directory it is guaranteed
23 // to NOT have a path separator at the end. For example, "c:\windows\temp"
24 // Directories are also guaranteed to exist when this function succeeds.
26 // Returns true if the directory or file was successfully retrieved. On
27 // failure, 'path' will not be changed.
28 static bool Get(int key, FilePath* path);
30 // Overrides the path to a special directory or file. This cannot be used to
31 // change the value of DIR_CURRENT, but that should be obvious. Also, if the
32 // path specifies a directory that does not exist, the directory will be
33 // created by this method. This method returns true if successful.
35 // If the given path is relative, then it will be resolved against
36 // DIR_CURRENT.
38 // WARNING: Consumers of PathService::Get may expect paths to be constant
39 // over the lifetime of the app, so this method should be used with caution.
40 static bool Override(int key, const FilePath& path);
42 // This function does the same as PathService::Override but it takes an extra
43 // parameter |create| which guides whether the directory to be overriden must
44 // be created in case it doesn't exist already.
45 static bool OverrideAndCreateIfNeeded(int key,
46 const FilePath& path,
47 bool create);
49 // To extend the set of supported keys, you can register a path provider,
50 // which is just a function mirroring PathService::Get. The ProviderFunc
51 // returns false if it cannot provide a non-empty path for the given key.
52 // Otherwise, true is returned.
54 // WARNING: This function could be called on any thread from which the
55 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE.
57 typedef bool (*ProviderFunc)(int, FilePath*);
59 // Call to register a path provider. You must specify the range "[key_start,
60 // key_end)" of supported path keys.
61 static void RegisterProvider(ProviderFunc provider,
62 int key_start,
63 int key_end);
64 private:
65 static bool GetFromCache(int key, FilePath* path);
66 static bool GetFromOverrides(int key, FilePath* path);
67 static void AddToCache(int key, const FilePath& path);
70 #endif // BASE_PATH_SERVICE_H_