blob: 2b5924779f2a7827b5b52daa5b2958b83f9685cd [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
[email protected]057a85532009-09-02 17:18:225#ifndef BASE_PATH_SERVICE_H_
6#define BASE_PATH_SERVICE_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commitd7cae122008-07-26 21:49:388
[email protected]1010f7d2008-08-06 16:29:449#include "build/build_config.h"
[email protected]1010f7d2008-08-06 16:29:4410
initial.commitd7cae122008-07-26 21:49:3811#include <string>
12
13#include "base/base_paths.h"
14
[email protected]640517f2008-10-30 23:54:0415class FilePath;
16
initial.commitd7cae122008-07-26 21:49:3817// 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//
20class 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]640517f2008-10-30 23:54:0429 static bool Get(int key, FilePath* path);
[email protected]ab926d552009-10-19 22:54:4130#if defined(OS_WIN)
[email protected]640517f2008-10-30 23:54:0431 // This version, producing a wstring, is deprecated and only kept around
32 // until we can fix all callers.
initial.commitd7cae122008-07-26 21:49:3833 static bool Get(int key, std::wstring* path);
[email protected]ab926d552009-10-19 22:54:4134#endif
initial.commitd7cae122008-07-26 21:49:3835
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]52a261f2009-03-03 15:01:1241 // If the given path is relative, then it will be resolved against
42 // DIR_CURRENT.
initial.commitd7cae122008-07-26 21:49:3843 //
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]eca6a4f2009-06-25 17:29:0946 static bool Override(int key, const FilePath& path);
initial.commitd7cae122008-07-26 21:49:3847
48 // Return whether a path was overridden.
49 static bool IsOverridden(int key);
50
initial.commitd7cae122008-07-26 21:49:3851 // 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]4792a262008-11-19 16:50:0359 typedef bool (*ProviderFunc)(int, FilePath*);
initial.commitd7cae122008-07-26 21:49:3860
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]1265917f2008-08-12 17:33:5266 private:
[email protected]640517f2008-10-30 23:54:0467 static bool GetFromCache(int key, FilePath* path);
68 static void AddToCache(int key, const FilePath& path);
initial.commitd7cae122008-07-26 21:49:3869};
70
[email protected]057a85532009-09-02 17:18:2271#endif // BASE_PATH_SERVICE_H_