security/sandbox/chromium/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) 2012 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 <string>
michael@0 9
michael@0 10 #include "base/base_export.h"
michael@0 11 #include "base/base_paths.h"
michael@0 12 #include "base/gtest_prod_util.h"
michael@0 13 #include "build/build_config.h"
michael@0 14
michael@0 15 namespace base {
michael@0 16 class FilePath;
michael@0 17 class ScopedPathOverride;
michael@0 18 } // namespace
michael@0 19
michael@0 20 // The path service is a global table mapping keys to file system paths. It is
michael@0 21 // OK to use this service from multiple threads.
michael@0 22 //
michael@0 23 class BASE_EXPORT PathService {
michael@0 24 public:
michael@0 25 // Retrieves a path to a special directory or file and places it into the
michael@0 26 // string pointed to by 'path'. If you ask for a directory it is guaranteed
michael@0 27 // to NOT have a path separator at the end. For example, "c:\windows\temp"
michael@0 28 // Directories are also guaranteed to exist when this function succeeds.
michael@0 29 //
michael@0 30 // Returns true if the directory or file was successfully retrieved. On
michael@0 31 // failure, 'path' will not be changed.
michael@0 32 static bool Get(int key, base::FilePath* path);
michael@0 33
michael@0 34 // Overrides the path to a special directory or file. This cannot be used to
michael@0 35 // change the value of DIR_CURRENT, but that should be obvious. Also, if the
michael@0 36 // path specifies a directory that does not exist, the directory will be
michael@0 37 // created by this method. This method returns true if successful.
michael@0 38 //
michael@0 39 // If the given path is relative, then it will be resolved against
michael@0 40 // DIR_CURRENT.
michael@0 41 //
michael@0 42 // WARNING: Consumers of PathService::Get may expect paths to be constant
michael@0 43 // over the lifetime of the app, so this method should be used with caution.
michael@0 44 static bool Override(int key, const base::FilePath& path);
michael@0 45
michael@0 46 // This function does the same as PathService::Override but it takes an extra
michael@0 47 // parameter |create| which guides whether the directory to be overriden must
michael@0 48 // be created in case it doesn't exist already.
michael@0 49 static bool OverrideAndCreateIfNeeded(int key,
michael@0 50 const base::FilePath& path,
michael@0 51 bool create);
michael@0 52
michael@0 53 // To extend the set of supported keys, you can register a path provider,
michael@0 54 // which is just a function mirroring PathService::Get. The ProviderFunc
michael@0 55 // returns false if it cannot provide a non-empty path for the given key.
michael@0 56 // Otherwise, true is returned.
michael@0 57 //
michael@0 58 // WARNING: This function could be called on any thread from which the
michael@0 59 // PathService is used, so a the ProviderFunc MUST BE THREADSAFE.
michael@0 60 //
michael@0 61 typedef bool (*ProviderFunc)(int, base::FilePath*);
michael@0 62
michael@0 63 // Call to register a path provider. You must specify the range "[key_start,
michael@0 64 // key_end)" of supported path keys.
michael@0 65 static void RegisterProvider(ProviderFunc provider,
michael@0 66 int key_start,
michael@0 67 int key_end);
michael@0 68
michael@0 69 // Disable internal cache.
michael@0 70 static void DisableCache();
michael@0 71
michael@0 72 private:
michael@0 73 friend class base::ScopedPathOverride;
michael@0 74 FRIEND_TEST_ALL_PREFIXES(PathServiceTest, RemoveOverride);
michael@0 75
michael@0 76 // Removes an override for a special directory or file. Returns true if there
michael@0 77 // was an override to remove or false if none was present.
michael@0 78 // NOTE: This function is intended to be used by tests only!
michael@0 79 static bool RemoveOverride(int key);
michael@0 80 };
michael@0 81
michael@0 82 #endif // BASE_PATH_SERVICE_H_

mercurial