diff options
author | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 13:52:53 +0000 |
---|---|---|
committer | vandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-26 13:52:53 +0000 |
commit | 4a4b577d5b84e09dec6937c34c9400cdeed59eaf (patch) | |
tree | 8f467232cf6bb356bbcd3520203e737144d1dfb9 /base | |
parent | 6dddb838189e83de5a1f8b23e4daf36501ad16b8 (diff) | |
download | chromium_src-4a4b577d5b84e09dec6937c34c9400cdeed59eaf.zip chromium_src-4a4b577d5b84e09dec6937c34c9400cdeed59eaf.tar.gz chromium_src-4a4b577d5b84e09dec6937c34c9400cdeed59eaf.tar.bz2 |
Add ScopedPlatformFileCloser to base.
There are several places that need to be sure to close a platform file and have implemented a scoped to ensure that it is done. Instead of adding yet another version of this code, this moves it into base and updates all known implementations to use it.
BUG=NONE
Review URL: https://chromiumcodereview.appspot.com/20154002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213895 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 2 | ||||
-rw-r--r-- | base/files/scoped_platform_file_closer.cc | 16 | ||||
-rw-r--r-- | base/files/scoped_platform_file_closer.h | 26 |
3 files changed, 44 insertions, 0 deletions
diff --git a/base/base.gypi b/base/base.gypi index 5085018..bd89f3e 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -192,6 +192,8 @@ 'files/memory_mapped_file.h', 'files/memory_mapped_file_posix.cc', 'files/memory_mapped_file_win.cc', + 'files/scoped_platform_file_closer.cc', + 'files/scoped_platform_file_closer.h', 'files/scoped_temp_dir.cc', 'files/scoped_temp_dir.h', 'float_util.h', diff --git a/base/files/scoped_platform_file_closer.cc b/base/files/scoped_platform_file_closer.cc new file mode 100644 index 0000000..44f6752 --- /dev/null +++ b/base/files/scoped_platform_file_closer.cc @@ -0,0 +1,16 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/files/scoped_platform_file_closer.h" + +namespace base { +namespace internal { + +void PlatformFileCloser::operator()(PlatformFile* file) const { + if (file && *file != kInvalidPlatformFileValue) + ClosePlatformFile(*file); +} + +} // namespace internal +} // namespace base diff --git a/base/files/scoped_platform_file_closer.h b/base/files/scoped_platform_file_closer.h new file mode 100644 index 0000000..8fe4a28 --- /dev/null +++ b/base/files/scoped_platform_file_closer.h @@ -0,0 +1,26 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_FILES_SCOPED_PLATFORM_FILE_CLOSER_H_ +#define BASE_FILES_SCOPED_PLATFORM_FILE_CLOSER_H_ + +#include "base/memory/scoped_ptr.h" +#include "base/platform_file.h" + +namespace base { + +namespace internal { + +struct BASE_EXPORT PlatformFileCloser { + void operator()(PlatformFile* file) const; +}; + +} // namespace internal + +typedef scoped_ptr<PlatformFile, internal::PlatformFileCloser> + ScopedPlatformFileCloser; + +} // namespace base + +#endif // BASE_FILES_SCOPED_PLATFORM_FILE_CLOSER_H_ |