ipc/chromium/src/base/scoped_temp_dir.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/scoped_temp_dir.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +// Copyright (c) 2009 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_SCOPED_TEMP_DIR_H_
     1.9 +#define BASE_SCOPED_TEMP_DIR_H_
    1.10 +
    1.11 +// An object representing a temporary / scratch directory that should be cleaned
    1.12 +// up (recursively) when this object goes out of scope.  Note that since
    1.13 +// deletion occurs during the destructor, no further error handling is possible
    1.14 +// if the directory fails to be deleted.  As a result, deletion is not
    1.15 +// guaranteed by this class.
    1.16 +
    1.17 +#include "base/file_path.h"
    1.18 +
    1.19 +class ScopedTempDir {
    1.20 + public:
    1.21 +  // No directory is owned/created initially.
    1.22 +  ScopedTempDir();
    1.23 +
    1.24 +  // Recursively delete path_
    1.25 +  ~ScopedTempDir();
    1.26 +
    1.27 +  // Creates a unique directory in TempPath, and takes ownership of it.
    1.28 +  // See file_util::CreateNewTemporaryDirectory.
    1.29 +  bool CreateUniqueTempDir();
    1.30 +
    1.31 +  // Takes ownership of directory at |path|, creating it if necessary.
    1.32 +  // Don't call multiple times unless Take() has been called first.
    1.33 +  bool Set(const FilePath& path);
    1.34 +
    1.35 +  // Caller takes ownership of the temporary directory so it won't be destroyed
    1.36 +  // when this object goes out of scope.
    1.37 +  FilePath Take();
    1.38 +
    1.39 +  const FilePath& path() const { return path_; }
    1.40 +
    1.41 +  // Returns true if path_ is non-empty and exists.
    1.42 +  bool IsValid() const;
    1.43 +
    1.44 + private:
    1.45 +  FilePath path_;
    1.46 +
    1.47 +  DISALLOW_COPY_AND_ASSIGN(ScopedTempDir);
    1.48 +};
    1.49 +
    1.50 +#endif  // BASE_SCOPED_TEMP_DIR_H_

mercurial