• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base/cef_macros.h"
43 #include "include/cef_base.h"
44 
45 ///
46 // An object representing a temporary / scratch directory that should be cleaned
47 // up (recursively) when this object goes out of scope.  Note that since
48 // deletion occurs during the destructor, no further error handling is possible
49 // if the directory fails to be deleted.  As a result, deletion is not
50 // guaranteed by this class.
51 //
52 // Multiple calls to the methods which establish a temporary directory
53 // (CreateUniqueTempDir, CreateUniqueTempDirUnderPath, and Set) must have
54 // intervening calls to Delete or Take, or the calls will fail.
55 ///
56 class CefScopedTempDir {
57  public:
58   ///
59   // No directory is owned/created initially.
60   ///
61   CefScopedTempDir();
62 
63   ///
64   // Recursively delete path.
65   ///
66   ~CefScopedTempDir();
67 
68   ///
69   // Creates a unique directory in TempPath, and takes ownership of it.
70   // See file_util::CreateNewTemporaryDirectory.
71   ///
72   bool CreateUniqueTempDir() WARN_UNUSED_RESULT;
73 
74   ///
75   // Creates a unique directory under a given path, and takes ownership of it.
76   ///
77   bool CreateUniqueTempDirUnderPath(const CefString& path) WARN_UNUSED_RESULT;
78 
79   ///
80   // Takes ownership of directory at |path|, creating it if necessary.
81   // Don't call multiple times unless Take() has been called first.
82   ///
83   bool Set(const CefString& path) WARN_UNUSED_RESULT;
84 
85   ///
86   // Deletes the temporary directory wrapped by this object.
87   ///
88   bool Delete() WARN_UNUSED_RESULT;
89 
90   ///
91   // Caller takes ownership of the temporary directory so it won't be destroyed
92   // when this object goes out of scope.
93   ///
94   CefString Take();
95 
96   ///
97   // Returns the path to the created directory. Call one of the
98   // CreateUniqueTempDir* methods before getting the path.
99   ///
100   const CefString& GetPath() const;
101 
102   ///
103   // Returns true if path_ is empty.
104   ///
105   bool IsEmpty() const;
106 
107   ///
108   // Returns true if path_ is non-empty and exists.
109   ///
110   bool IsValid() const;
111 
112  private:
113   CefString path_;
114 
115   DISALLOW_COPY_AND_ASSIGN(CefScopedTempDir);
116 };
117 
118 #endif  // CEF_INCLUDE_SCOPED_TEMP_DIR_H_
119