blob: e449efa9cad1eba65166d10372e1f8526a4745f6 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commitd7cae122008-07-26 21:49:384
5#ifndef BASE_PATH_SERVICE_H__
6#define BASE_PATH_SERVICE_H__
7
[email protected]1010f7d2008-08-06 16:29:448#include "build/build_config.h"
9#ifdef OS_WIN
10// TODO(erikkay): this should be removable, but because SetCurrentDirectory
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.
13// Even if we could fix that, it would still hose all callers of the function.
14// The right thing is likely to rename.
15#include <windows.h>
16#endif
17
initial.commitd7cae122008-07-26 21:49:3818#include <string>
19
20#include "base/base_paths.h"
21
22// The path service is a global table mapping keys to file system paths. It is
23// OK to use this service from multiple threads.
24//
25class PathService {
26 public:
27 // Retrieves a path to a special directory or file and places it into the
28 // string pointed to by 'path'. If you ask for a directory it is guaranteed
29 // to NOT have a path separator at the end. For example, "c:\windows\temp"
30 // Directories are also guaranteed to exist when this function succeeds.
31 //
32 // Returns true if the directory or file was successfully retrieved. On
33 // failure, 'path' will not be changed.
34 static bool Get(int key, std::wstring* path);
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 //
41 // If the given path is relative, then it will be resolved against DIR_CURRENT.
42 //
43 // 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.
45 static bool Override(int key, const std::wstring& path);
46
47 // Return whether a path was overridden.
48 static bool IsOverridden(int key);
49
50 // Sets the current directory.
51 static bool SetCurrentDirectory(const std::wstring& current_directory);
52
53 // To extend the set of supported keys, you can register a path provider,
54 // which is just a function mirroring PathService::Get. The ProviderFunc
55 // returns false if it cannot provide a non-empty path for the given key.
56 // Otherwise, true is returned.
57 //
58 // WARNING: This function could be called on any thread from which the
59 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE.
60 //
61 typedef bool (*ProviderFunc)(int, std::wstring*);
62
63 // Call to register a path provider. You must specify the range "[key_start,
64 // key_end)" of supported path keys.
65 static void RegisterProvider(ProviderFunc provider,
66 int key_start,
67 int key_end);
[email protected]1265917f2008-08-12 17:33:5268 private:
[email protected]6723f832008-08-11 15:38:2769 static bool GetFromCache(int key, std::wstring* path);
70 static void AddToCache(int key, const std::wstring& path);
71
initial.commitd7cae122008-07-26 21:49:3872};
73
74#endif // BASE_PATH_SERVICE_H__
license.botbf09a502008-08-24 00:55:5575