Index: base/mac/scoped_cffiledescriptorref.h |
diff --git a/base/mac/scoped_launch_data.h b/base/mac/scoped_cffiledescriptorref.h |
similarity index 18% |
copy from base/mac/scoped_launch_data.h |
copy to base/mac/scoped_cffiledescriptorref.h |
index e4343b89399ecf87d3a16504b77294b5fc48f9c9..07196aa92126e6f8839402b175993bdd86534536 100644 |
--- a/base/mac/scoped_launch_data.h |
+++ b/base/mac/scoped_cffiledescriptorref.h |
@@ -1,13 +1,11 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2012 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_MAC_SCOPED_LAUNCH_DATA_H_ |
-#define BASE_MAC_SCOPED_LAUNCH_DATA_H_ |
+#ifndef BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_ |
+#define BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_ |
-#include <launch.h> |
- |
-#include <algorithm> |
+#include <CoreFoundation/CoreFoundation.h> |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
@@ -15,61 +13,63 @@ |
namespace base { |
namespace mac { |
-// Just like scoped_ptr<> but for launch_data_t. |
-class ScopedLaunchData { |
+// ScopedCFFileDescriptorRef is designed after ScopedCFTypeRef<>. On |
blundell
2012/11/26 16:05:06
Due to the fact that I'm using git, this file beco
|
+// destruction, it will invalidate the file descriptor. |
+// ScopedCFFileDescriptorRef (unlike ScopedCFTypeRef<>) does not support RETAIN |
+// semantics, copying, or assignment, as doing so would increase the chances |
+// that a file descriptor is invalidated while still in use. |
+class ScopedCFFileDescriptorRef { |
public: |
- typedef launch_data_t element_type; |
- |
- explicit ScopedLaunchData(launch_data_t object = NULL) |
- : object_(object) { |
+ explicit ScopedCFFileDescriptorRef(CFFileDescriptorRef fdref = NULL) |
+ : fdref_(fdref) { |
} |
- ~ScopedLaunchData() { |
- if (object_) |
- launch_data_free(object_); |
- } |
- |
- void reset(launch_data_t object = NULL) { |
- if (object != object_) { |
- if (object_) |
- launch_data_free(object_); |
- object_ = object; |
+ ~ScopedCFFileDescriptorRef() { |
+ if (fdref_) { |
+ CFFileDescriptorInvalidate(fdref_); |
+ CFRelease(fdref_); |
} |
} |
- bool operator==(launch_data_t that) const { |
- return object_ == that; |
+ void reset(CFFileDescriptorRef fdref = NULL) { |
+ if (fdref_ == fdref) |
+ return; |
+ if (fdref_) { |
+ CFFileDescriptorInvalidate(fdref_); |
+ CFRelease(fdref_); |
+ } |
+ fdref_ = fdref; |
} |
- bool operator!=(launch_data_t that) const { |
- return object_ != that; |
+ bool operator==(CFFileDescriptorRef that) const { |
+ return fdref_ == that; |
} |
- operator launch_data_t() const { |
- return object_; |
+ bool operator!=(CFFileDescriptorRef that) const { |
+ return fdref_ != that; |
} |
- launch_data_t get() const { |
- return object_; |
+ operator CFFileDescriptorRef() const { |
+ return fdref_; |
} |
- void swap(ScopedLaunchData& that) { |
- std::swap(object_, that.object_); |
+ CFFileDescriptorRef get() const { |
+ return fdref_; |
} |
- launch_data_t release() WARN_UNUSED_RESULT { |
- launch_data_t temp = object_; |
- object_ = NULL; |
+ CFFileDescriptorRef release() WARN_UNUSED_RESULT { |
+ CFFileDescriptorRef temp = fdref_; |
+ fdref_ = NULL; |
return temp; |
} |
private: |
- launch_data_t object_; |
+ CFFileDescriptorRef fdref_; |
- DISALLOW_COPY_AND_ASSIGN(ScopedLaunchData); |
+ DISALLOW_COPY_AND_ASSIGN(ScopedCFFileDescriptorRef); |
}; |
} // namespace mac |
} // namespace base |
-#endif // BASE_MAC_SCOPED_LAUNCH_DATA_H_ |
+#endif // BASE_MAC_SCOPED_CFFILEDESCRIPTORREF_H_ |