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

Side by Side Diff: media/capture/video/scoped_result_callback.h

Issue 2047633002: Revert of Remove base/move.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CAPTURE_VIDEO_SCOPED_RESULT_CALLBACK_H_ 5 #ifndef MEDIA_CAPTURE_VIDEO_SCOPED_RESULT_CALLBACK_H_
6 #define MEDIA_CAPTURE_VIDEO_SCOPED_RESULT_CALLBACK_H_ 6 #define MEDIA_CAPTURE_VIDEO_SCOPED_RESULT_CALLBACK_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/macros.h"
10 #include "mojo/public/cpp/bindings/callback.h" 9 #include "mojo/public/cpp/bindings/callback.h"
11 10
12 namespace media { 11 namespace media {
13 12
14 // This class guarantees that |callback_| has either been called or will pass it 13 // This class guarantees that |callback_| has either been called or will pass it
15 // to |on_error_callback_| on destruction. Inspired by ScopedWebCallbacks<>. 14 // to |on_error_callback_| on destruction. Inspired by ScopedWebCallbacks<>.
16 template <typename CallbackType> 15 template <typename CallbackType>
17 class ScopedResultCallback { 16 class ScopedResultCallback {
17 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedResultCallback);
18
18 public: 19 public:
19 using OnErrorCallback = base::Callback<void(const CallbackType&)>; 20 using OnErrorCallback = base::Callback<void(const CallbackType&)>;
20 ScopedResultCallback(const CallbackType& callback, 21 ScopedResultCallback(const CallbackType& callback,
21 const OnErrorCallback& on_error_callback) 22 const OnErrorCallback& on_error_callback)
22 : callback_(callback), on_error_callback_(on_error_callback) {} 23 : callback_(callback), on_error_callback_(on_error_callback) {}
23 24
24 ~ScopedResultCallback() { 25 ~ScopedResultCallback() {
25 if (!callback_.is_null()) 26 if (!callback_.is_null())
26 on_error_callback_.Run(callback_); 27 on_error_callback_.Run(callback_);
27 } 28 }
(...skipping 15 matching lines...) Expand all
43 on_error_callback_.Reset(); 44 on_error_callback_.Reset();
44 // TODO(mcasas): Use base::ResetAndReturn() when mojo::Callback<> is 45 // TODO(mcasas): Use base::ResetAndReturn() when mojo::Callback<> is
45 // compatible with base::Callback<>, see https://crbug.com/596521. 46 // compatible with base::Callback<>, see https://crbug.com/596521.
46 callback_.Run(std::forward<Args>(args)...); 47 callback_.Run(std::forward<Args>(args)...);
47 callback_.reset(); 48 callback_.reset();
48 } 49 }
49 50
50 private: 51 private:
51 CallbackType callback_; 52 CallbackType callback_;
52 OnErrorCallback on_error_callback_; 53 OnErrorCallback on_error_callback_;
53
54 DISALLOW_COPY_AND_ASSIGN(ScopedResultCallback);
55 }; 54 };
56 55
57 } // namespace media 56 } // namespace media
58 57
59 #endif // MEDIA_CAPTURE_VIDEO_SCOPED_RESULT_CALLBACK_H_ 58 #endif // MEDIA_CAPTURE_VIDEO_SCOPED_RESULT_CALLBACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698