Index: cc/resources/scoped_release_callback.cc |
diff --git a/cc/resources/scoped_release_callback.cc b/cc/resources/scoped_release_callback.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c18eadc0d05505679872a7622f33e2b7c62b0b52 |
--- /dev/null |
+++ b/cc/resources/scoped_release_callback.cc |
@@ -0,0 +1,40 @@ |
+// 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 "cc/resources/scoped_release_callback.h" |
+ |
+#include "base/callback_helpers.h" |
+#include "base/logging.h" |
+ |
+namespace cc { |
+ |
+ScopedReleaseCallback::ScopedReleaseCallback() {} |
+ |
+ScopedReleaseCallback::ScopedReleaseCallback(const ReleaseCallback& callback) |
awong
2013/09/13 07:07:19
Doesn't this already violate the rule that there c
danakj
2013/09/13 17:32:59
Well, the callback has to come from somewhere. I'd
|
+ : callback_(callback) {} |
+ |
+ScopedReleaseCallback::ScopedReleaseCallback(RValue other) |
+ : callback_(base::ResetAndReturn(&other.object->callback_)) {} |
piman
2013/09/13 06:08:30
nit: callback_(other.object->Leak())
|
+ |
+ScopedReleaseCallback::~ScopedReleaseCallback() { |
+ DCHECK(callback_.is_null()) << "ScopedReleaseCallback was never run."; |
+} |
+ |
+void ScopedReleaseCallback::RunAndReset(unsigned sync_point, bool is_lost) { |
+ base::ResetAndReturn(&callback_).Run(sync_point, is_lost); |
+} |
+ |
+ScopedReleaseCallback& ScopedReleaseCallback::operator=( |
+ ScopedReleaseCallback rhs) { |
+ DCHECK(callback_.is_null()); |
+ callback_ = rhs.callback_; |
+ rhs.callback_ = ReleaseCallback(); |
piman
2013/09/13 06:08:30
nit: replace those 2 lines by callback_ = rhs.Leak
|
+ return *this; |
+} |
+ |
+ReleaseCallback ScopedReleaseCallback::Leak() { |
+ return base::ResetAndReturn(&callback_); |
+} |
+ |
+} // namespace cc |