ipc/chromium/src/base/path_service.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef BASE_PATH_SERVICE_H__
michael@0 6 #define BASE_PATH_SERVICE_H__
michael@0 7
michael@0 8 #include "build/build_config.h"
michael@0 9 #ifdef OS_WIN
michael@0 10 // TODO(erikkay): this should be removable, but because SetCurrentDirectory
michael@0 11 // is the name of a Windows function, it gets macro-ized to SetCurrentDirectoryW
michael@0 12 // by windows.h, which leads to a different name in the header vs. the impl.
michael@0 13 // Even if we could fix that, it would still hose all callers of the function.
michael@0 14 // The right thing is likely to rename.
michael@0 15 #include <windows.h>
michael@0 16 #endif
michael@0 17
michael@0 18 #include <string>
michael@0 19
michael@0 20 #include "base/base_paths.h"
michael@0 21
michael@0 22 class FilePath;
michael@0 23
michael@0 24 // The path service is a global table mapping keys to file system paths. It is
michael@0 25 // OK to use this service from multiple threads.
michael@0 26 //
michael@0 27 class PathService {
michael@0 28 public:
michael@0 29 // Retrieves a path to a special directory or file and places it into the
michael@0 30 // string pointed to by 'path'. If you ask for a directory it is guaranteed
michael@0 31 // to NOT have a path separator at the end. For example, "c:\windows\temp"
michael@0 32 // Directories are also guaranteed to exist when this function succeeds.
michael@0 33 //
michael@0 34 // Returns true if the directory or file was successfully retrieved. On
michael@0 35 // failure, 'path' will not be changed.
michael@0 36 static bool Get(int key, FilePath* path);
michael@0 37 // This version, producing a wstring, is deprecated and only kept around
michael@0 38 // until we can fix all callers.
michael@0 39 static bool Get(int key, std::wstring* path);
michael@0 40
michael@0 41 // Overrides the path to a special directory or file. This cannot be used to
michael@0 42 // change the value of DIR_CURRENT, but that should be obvious. Also, if the
michael@0 43 // path specifies a directory that does not exist, the directory will be
michael@0 44 // created by this method. This method returns true if successful.
michael@0 45 //
michael@0 46 // If the given path is relative, then it will be resolved against
michael@0 47 // DIR_CURRENT.
michael@0 48 //
michael@0 49 // WARNING: Consumers of PathService::Get may expect paths to be constant
michael@0 50 // over the lifetime of the app, so this method should be used with caution.
michael@0 51 static bool Override(int key, const std::wstring& path);
michael@0 52
michael@0 53 // Return whether a path was overridden.
michael@0 54 static bool IsOverridden(int key);
michael@0 55
michael@0 56 // Sets the current directory.
michael@0 57 static bool SetCurrentDirectory(const std::wstring& current_directory);
michael@0 58
michael@0 59 // To extend the set of supported keys, you can register a path provider,
michael@0 60 // which is just a function mirroring PathService::Get. The ProviderFunc
michael@0 61 // returns false if it cannot provide a non-empty path for the given key.
michael@0 62 // Otherwise, true is returned.
michael@0 63 //
michael@0 64 // WARNING: This function could be called on any thread from which the
michael@0 65 // PathService is used, so the ProviderFunc MUST BE THREADSAFE.
michael@0 66 //
michael@0 67 typedef bool (*ProviderFunc)(int, FilePath*);
michael@0 68
michael@0 69 // Call to register a path provider. You must specify the range "[key_start,
michael@0 70 // key_end)" of supported path keys.
michael@0 71 static void RegisterProvider(ProviderFunc provider,
michael@0 72 int key_start,
michael@0 73 int key_end);
michael@0 74 private:
michael@0 75 static bool GetFromCache(int key, FilePath* path);
michael@0 76 static void AddToCache(int key, const FilePath& path);
michael@0 77
michael@0 78 };
michael@0 79
michael@0 80 #endif // BASE_PATH_SERVICE_H__

mercurial