ipc/chromium/src/base/path_service.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/path_service.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +// Copyright (c) 2006-2008 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 "build/build_config.h"
    1.12 +#ifdef OS_WIN
    1.13 +// TODO(erikkay): this should be removable, but because SetCurrentDirectory
    1.14 +// is the name of a Windows function, it gets macro-ized to SetCurrentDirectoryW
    1.15 +// by windows.h, which leads to a different name in the header vs. the impl.
    1.16 +// Even if we could fix that, it would still hose all callers of the function.
    1.17 +// The right thing is likely to rename.
    1.18 +#include <windows.h>
    1.19 +#endif
    1.20 +
    1.21 +#include <string>
    1.22 +
    1.23 +#include "base/base_paths.h"
    1.24 +
    1.25 +class FilePath;
    1.26 +
    1.27 +// The path service is a global table mapping keys to file system paths.  It is
    1.28 +// OK to use this service from multiple threads.
    1.29 +//
    1.30 +class PathService {
    1.31 + public:
    1.32 +  // Retrieves a path to a special directory or file and places it into the
    1.33 +  // string pointed to by 'path'. If you ask for a directory it is guaranteed
    1.34 +  // to NOT have a path separator at the end. For example, "c:\windows\temp"
    1.35 +  // Directories are also guaranteed to exist when this function succeeds.
    1.36 +  //
    1.37 +  // Returns true if the directory or file was successfully retrieved. On
    1.38 +  // failure, 'path' will not be changed.
    1.39 +  static bool Get(int key, FilePath* path);
    1.40 +  // This version, producing a wstring, is deprecated and only kept around
    1.41 +  // until we can fix all callers.
    1.42 +  static bool Get(int key, std::wstring* path);
    1.43 +
    1.44 +  // Overrides the path to a special directory or file.  This cannot be used to
    1.45 +  // change the value of DIR_CURRENT, but that should be obvious.  Also, if the
    1.46 +  // path specifies a directory that does not exist, the directory will be
    1.47 +  // created by this method.  This method returns true if successful.
    1.48 +  //
    1.49 +  // If the given path is relative, then it will be resolved against
    1.50 +  // DIR_CURRENT.
    1.51 +  //
    1.52 +  // WARNING: Consumers of PathService::Get may expect paths to be constant
    1.53 +  // over the lifetime of the app, so this method should be used with caution.
    1.54 +  static bool Override(int key, const std::wstring& path);
    1.55 +
    1.56 +  // Return whether a path was overridden.
    1.57 +  static bool IsOverridden(int key);
    1.58 +
    1.59 +  // Sets the current directory.
    1.60 +  static bool SetCurrentDirectory(const std::wstring& current_directory);
    1.61 +
    1.62 +  // To extend the set of supported keys, you can register a path provider,
    1.63 +  // which is just a function mirroring PathService::Get.  The ProviderFunc
    1.64 +  // returns false if it cannot provide a non-empty path for the given key.
    1.65 +  // Otherwise, true is returned.
    1.66 +  //
    1.67 +  // WARNING: This function could be called on any thread from which the
    1.68 +  // PathService is used, so the ProviderFunc MUST BE THREADSAFE.
    1.69 +  //
    1.70 +  typedef bool (*ProviderFunc)(int, FilePath*);
    1.71 +
    1.72 +  // Call to register a path provider.  You must specify the range "[key_start,
    1.73 +  // key_end)" of supported path keys.
    1.74 +  static void RegisterProvider(ProviderFunc provider,
    1.75 +                               int key_start,
    1.76 +                               int key_end);
    1.77 + private:
    1.78 +  static bool GetFromCache(int key, FilePath* path);
    1.79 +  static void AddToCache(int key, const FilePath& path);
    1.80 +
    1.81 +};
    1.82 +
    1.83 +#endif // BASE_PATH_SERVICE_H__

mercurial