Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Unified Diff: base/win/scoped_handle.h

Issue 92173002: Merge 237541 "Revert of https://codereview.chromium.org/71013004/" (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1721/src/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/launch_win.cc ('k') | base/win/scoped_handle_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/scoped_handle.h
===================================================================
--- base/win/scoped_handle.h (revision 237598)
+++ base/win/scoped_handle.h (working copy)
@@ -39,6 +39,22 @@
public:
typedef typename Traits::Handle Handle;
+ // Helper object to contain the effect of Receive() to the function that needs
+ // a pointer, and allow proper tracking of the handle.
+ class Receiver {
+ public:
+ explicit Receiver(GenericScopedHandle* owner)
+ : handle_(Traits::NullHandle()),
+ owner_(owner) {}
+ ~Receiver() { owner_->Set(handle_); }
+
+ operator Handle*() { return &handle_; }
+
+ private:
+ Handle handle_;
+ GenericScopedHandle* owner_;
+ };
+
GenericScopedHandle() : handle_(Traits::NullHandle()) {}
explicit GenericScopedHandle(Handle handle) : handle_(Traits::NullHandle()) {
@@ -86,6 +102,16 @@
return handle_;
}
+ // This method is intended to be used with functions that require a pointer to
+ // a destination handle, like so:
+ // void CreateRequiredHandle(Handle* out_handle);
+ // ScopedHandle a;
+ // CreateRequiredHandle(a.Receive());
+ Receiver Receive() {
+ DCHECK(!Traits::IsHandleValid(handle_)) << "Handle must be NULL";
+ return Receiver(this);
+ }
+
// Transfers ownership away from this object.
Handle Take() {
Handle temp = handle_;
« no previous file with comments | « base/process/launch_win.cc ('k') | base/win/scoped_handle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698