mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-31 01:43:03 +08:00
4a9b858fbd
Intended for future use to implement util/file/file_writer. There's a similar class in base: https://code.google.com/p/chromium/codesearch#chromium/src/base/win/scoped_handle.h&l=28 However (perhaps for historical reasons) it does not distinguish between the possible types of HANDLEs which have different invalid values, resulting in a need to copy a bunch of code rather than simply using ScopedGeneric. Instead, distinguish between the types so the caller can use the correct one. Refs: http://blogs.msdn.com/b/oldnewthing/archive/2004/03/02/82639.aspx http://msdn.microsoft.com/en-us/magazine/cc302328.aspx (Figure 2) R=mark@chromium.org BUG=crashpad:1 Review URL: https://codereview.chromium.org/813873004
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
// Copyright 2014 The Crashpad Authors. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef CRASHPAD_UTIL_WIN_SCOPED_HANDLE_H_
|
|
#define CRASHPAD_UTIL_WIN_SCOPED_HANDLE_H_
|
|
|
|
#include <windows.h>
|
|
|
|
#include "base/scoped_generic.h"
|
|
|
|
namespace crashpad {
|
|
|
|
namespace internal {
|
|
|
|
struct ScopedFileHANDLECloseTraits {
|
|
static HANDLE InvalidValue() {
|
|
return INVALID_HANDLE_VALUE;
|
|
}
|
|
static void Free(HANDLE handle);
|
|
};
|
|
|
|
struct ScopedKernelHANDLECloseTraits {
|
|
static HANDLE InvalidValue() {
|
|
return nullptr;
|
|
}
|
|
static void Free(HANDLE handle);
|
|
};
|
|
|
|
} // namespace internal
|
|
|
|
using ScopedFileHANDLE =
|
|
base::ScopedGeneric<HANDLE, internal::ScopedFileHANDLECloseTraits>;
|
|
using ScopedKernelHANDLE =
|
|
base::ScopedGeneric<HANDLE, internal::ScopedKernelHANDLECloseTraits>;
|
|
|
|
} // namespace crashpad
|
|
|
|
#endif // CRASHPAD_UTIL_WIN_SCOPED_HANDLE_H_
|