1 // Copyright (c) 2016 Marshall A. Greenblatt. Portions copyright (c) 2011 2 // Google Inc. All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following disclaimer 12 // in the documentation and/or other materials provided with the 13 // distribution. 14 // * Neither the name of Google Inc. nor the name Chromium Embedded 15 // Framework nor the names of its contributors may be used to endorse 16 // or promote products derived from this software without specific prior 17 // written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 // 31 // --------------------------------------------------------------------------- 32 // 33 // The contents of this file are only available to applications that link 34 // against the libcef_dll_wrapper target. 35 // 36 37 #ifndef CEF_INCLUDE_SCOPED_TEMP_DIR_H_ 38 #define CEF_INCLUDE_SCOPED_TEMP_DIR_H_ 39 #pragma once 40 41 #include "include/base/cef_build.h" 42 #include "include/cef_base.h" 43 44 /// 45 // An object representing a temporary / scratch directory that should be cleaned 46 // up (recursively) when this object goes out of scope. Note that since 47 // deletion occurs during the destructor, no further error handling is possible 48 // if the directory fails to be deleted. As a result, deletion is not 49 // guaranteed by this class. 50 // 51 // Multiple calls to the methods which establish a temporary directory 52 // (CreateUniqueTempDir, CreateUniqueTempDirUnderPath, and Set) must have 53 // intervening calls to Delete or Take, or the calls will fail. 54 /// 55 class CefScopedTempDir { 56 public: 57 /// 58 // No directory is owned/created initially. 59 /// 60 CefScopedTempDir(); 61 62 CefScopedTempDir(const CefScopedTempDir&) = delete; 63 CefScopedTempDir& operator=(const CefScopedTempDir&) = delete; 64 65 /// 66 // Recursively delete path. 67 /// 68 ~CefScopedTempDir(); 69 70 /// 71 // Creates a unique directory in TempPath, and takes ownership of it. 72 // See file_util::CreateNewTemporaryDirectory. 73 /// 74 bool CreateUniqueTempDir() WARN_UNUSED_RESULT; 75 76 /// 77 // Creates a unique directory under a given path, and takes ownership of it. 78 /// 79 bool CreateUniqueTempDirUnderPath(const CefString& path) WARN_UNUSED_RESULT; 80 81 /// 82 // Takes ownership of directory at |path|, creating it if necessary. 83 // Don't call multiple times unless Take() has been called first. 84 /// 85 bool Set(const CefString& path) WARN_UNUSED_RESULT; 86 87 /// 88 // Deletes the temporary directory wrapped by this object. 89 /// 90 bool Delete() WARN_UNUSED_RESULT; 91 92 /// 93 // Caller takes ownership of the temporary directory so it won't be destroyed 94 // when this object goes out of scope. 95 /// 96 CefString Take(); 97 98 /// 99 // Returns the path to the created directory. Call one of the 100 // CreateUniqueTempDir* methods before getting the path. 101 /// 102 const CefString& GetPath() const; 103 104 /// 105 // Returns true if path_ is empty. 106 /// 107 bool IsEmpty() const; 108 109 /// 110 // Returns true if path_ is non-empty and exists. 111 /// 112 bool IsValid() const; 113 114 private: 115 CefString path_; 116 }; 117 118 #endif // CEF_INCLUDE_SCOPED_TEMP_DIR_H_ 119