1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/path_service.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_PATH_SERVICE_H_ 1.9 +#define BASE_PATH_SERVICE_H_ 1.10 + 1.11 +#include <string> 1.12 + 1.13 +#include "base/base_export.h" 1.14 +#include "base/base_paths.h" 1.15 +#include "base/gtest_prod_util.h" 1.16 +#include "build/build_config.h" 1.17 + 1.18 +namespace base { 1.19 +class FilePath; 1.20 +class ScopedPathOverride; 1.21 +} // namespace 1.22 + 1.23 +// The path service is a global table mapping keys to file system paths. It is 1.24 +// OK to use this service from multiple threads. 1.25 +// 1.26 +class BASE_EXPORT PathService { 1.27 + public: 1.28 + // Retrieves a path to a special directory or file and places it into the 1.29 + // string pointed to by 'path'. If you ask for a directory it is guaranteed 1.30 + // to NOT have a path separator at the end. For example, "c:\windows\temp" 1.31 + // Directories are also guaranteed to exist when this function succeeds. 1.32 + // 1.33 + // Returns true if the directory or file was successfully retrieved. On 1.34 + // failure, 'path' will not be changed. 1.35 + static bool Get(int key, base::FilePath* path); 1.36 + 1.37 + // Overrides the path to a special directory or file. This cannot be used to 1.38 + // change the value of DIR_CURRENT, but that should be obvious. Also, if the 1.39 + // path specifies a directory that does not exist, the directory will be 1.40 + // created by this method. This method returns true if successful. 1.41 + // 1.42 + // If the given path is relative, then it will be resolved against 1.43 + // DIR_CURRENT. 1.44 + // 1.45 + // WARNING: Consumers of PathService::Get may expect paths to be constant 1.46 + // over the lifetime of the app, so this method should be used with caution. 1.47 + static bool Override(int key, const base::FilePath& path); 1.48 + 1.49 + // This function does the same as PathService::Override but it takes an extra 1.50 + // parameter |create| which guides whether the directory to be overriden must 1.51 + // be created in case it doesn't exist already. 1.52 + static bool OverrideAndCreateIfNeeded(int key, 1.53 + const base::FilePath& path, 1.54 + bool create); 1.55 + 1.56 + // To extend the set of supported keys, you can register a path provider, 1.57 + // which is just a function mirroring PathService::Get. The ProviderFunc 1.58 + // returns false if it cannot provide a non-empty path for the given key. 1.59 + // Otherwise, true is returned. 1.60 + // 1.61 + // WARNING: This function could be called on any thread from which the 1.62 + // PathService is used, so a the ProviderFunc MUST BE THREADSAFE. 1.63 + // 1.64 + typedef bool (*ProviderFunc)(int, base::FilePath*); 1.65 + 1.66 + // Call to register a path provider. You must specify the range "[key_start, 1.67 + // key_end)" of supported path keys. 1.68 + static void RegisterProvider(ProviderFunc provider, 1.69 + int key_start, 1.70 + int key_end); 1.71 + 1.72 + // Disable internal cache. 1.73 + static void DisableCache(); 1.74 + 1.75 + private: 1.76 + friend class base::ScopedPathOverride; 1.77 + FRIEND_TEST_ALL_PREFIXES(PathServiceTest, RemoveOverride); 1.78 + 1.79 + // Removes an override for a special directory or file. Returns true if there 1.80 + // was an override to remove or false if none was present. 1.81 + // NOTE: This function is intended to be used by tests only! 1.82 + static bool RemoveOverride(int key); 1.83 +}; 1.84 + 1.85 +#endif // BASE_PATH_SERVICE_H_