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

Unified Diff: base/win/scoped_handle.h

Issue 10828160: [Chromoting] Move CreateSessionToken() next to launch process utilities. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Making GenericScopedHandle a move-only type. Created 8 years, 4 months 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 | « no previous file | remoting/host/daemon_process_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/scoped_handle.h
diff --git a/base/win/scoped_handle.h b/base/win/scoped_handle.h
index 458519d9bfe85f1348e5a193cec221b24cbe8922..6be2946129c570e2e8227e42c84a3524588cd744 100644
--- a/base/win/scoped_handle.h
+++ b/base/win/scoped_handle.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/move.h"
namespace base {
namespace win {
@@ -36,6 +37,8 @@ extern "C" {
// takes a raw handle pointer only.
template <class Traits, class Verifier>
class GenericScopedHandle {
+ MOVE_ONLY_TYPE_FOR_CPP_03(GenericScopedHandle, RValue)
+
public:
typedef typename Traits::Handle Handle;
@@ -45,6 +48,14 @@ class GenericScopedHandle {
Set(handle);
}
+ // Move constructor for C++03 move emulation of this type.
+ GenericScopedHandle(RValue& other)
+ // The type of the underlying object is GenericScopedHandle; we have to
+ // reinterpret_cast back to the original type for the call to release to
+ // be valid. (See C++11 5.2.10.7)
+ : handle_(reinterpret_cast<GenericScopedHandle&>(other).Take()) {
jar (doing other things) 2012/08/07 01:00:30 Should be a static_cast (possibly of pointers)? I
alexeypa (please no reviews) 2012/08/07 17:55:14 This code was copied from scoped_handle.h. It rein
+ }
+
~GenericScopedHandle() {
Close();
}
@@ -53,6 +64,12 @@ class GenericScopedHandle {
return Traits::IsHandleValid(handle_);
}
+ // Move operator= for C++03 move emulation of this type.
+ GenericScopedHandle& operator=(RValue& other) {
jar (doing other things) 2012/08/07 01:00:30 I'm a little surprised you didn't pass in a const
alexeypa (please no reviews) 2012/08/07 17:55:14 This is copied from scoped_ptr too. |other| has to
+ Swap(other);
+ return *this;
+ }
+
void Set(Handle handle) {
if (handle_ != handle) {
Close();
@@ -82,6 +99,12 @@ class GenericScopedHandle {
return &handle_;
}
+ void Swap(GenericScopedHandle& other) {
+ Handle tmp = handle_;
+ handle_ = other.handle_;
+ other.handle_ = tmp;
+ }
+
// Transfers ownership away from this object.
Handle Take() {
Handle temp = handle_;
@@ -106,8 +129,6 @@ class GenericScopedHandle {
private:
Handle handle_;
-
- DISALLOW_COPY_AND_ASSIGN(GenericScopedHandle);
};
#undef BASE_WIN_GET_CALLER
« no previous file with comments | « no previous file | remoting/host/daemon_process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698