blob: 4b297385dfb8494ed9c4c68f43f9b8fd3596d3c2 [file] [log] [blame]
[email protected]90509cb2011-03-25 18:46:381// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// 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
initial.commitd7cae122008-07-26 21:49:389#include <string>
10
[email protected]0bea7252011-08-05 15:34:0011#include "base/base_export.h"
initial.commitd7cae122008-07-26 21:49:3812#include "base/base_paths.h"
[email protected]90509cb2011-03-25 18:46:3813#include "build/build_config.h"
initial.commitd7cae122008-07-26 21:49:3814
[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//
[email protected]0bea7252011-08-05 15:34:0020class BASE_EXPORT PathService {
initial.commitd7cae122008-07-26 21:49:3821 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);
initial.commitd7cae122008-07-26 21:49:3830
31 // Overrides the path to a special directory or file. This cannot be used to
32 // change the value of DIR_CURRENT, but that should be obvious. Also, if the
33 // path specifies a directory that does not exist, the directory will be
34 // created by this method. This method returns true if successful.
35 //
[email protected]52a261f2009-03-03 15:01:1236 // If the given path is relative, then it will be resolved against
37 // DIR_CURRENT.
initial.commitd7cae122008-07-26 21:49:3838 //
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.
[email protected]eca6a4f2009-06-25 17:29:0941 static bool Override(int key, const FilePath& path);
initial.commitd7cae122008-07-26 21:49:3842
initial.commitd7cae122008-07-26 21:49:3843 // To extend the set of supported keys, you can register a path provider,
44 // 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.
46 // Otherwise, true is returned.
47 //
48 // WARNING: This function could be called on any thread from which the
49 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE.
50 //
[email protected]4792a262008-11-19 16:50:0351 typedef bool (*ProviderFunc)(int, FilePath*);
initial.commitd7cae122008-07-26 21:49:3852
53 // Call to register a path provider. You must specify the range "[key_start,
54 // key_end)" of supported path keys.
55 static void RegisterProvider(ProviderFunc provider,
56 int key_start,
57 int key_end);
[email protected]1265917f2008-08-12 17:33:5258 private:
[email protected]640517f2008-10-30 23:54:0459 static bool GetFromCache(int key, FilePath* path);
[email protected]34e043b2010-09-09 23:49:0460 static bool GetFromOverrides(int key, FilePath* path);
[email protected]640517f2008-10-30 23:54:0461 static void AddToCache(int key, const FilePath& path);
initial.commitd7cae122008-07-26 21:49:3862};
63
[email protected]057a85532009-09-02 17:18:2264#endif // BASE_PATH_SERVICE_H_