| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CONTENT_CHILD_SCOPED_WEB_CALLBACKS_H_ | 5 #ifndef CONTENT_CHILD_SCOPED_WEB_CALLBACKS_H_ |
| 6 #define CONTENT_CHILD_SCOPED_WEB_CALLBACKS_H_ | 6 #define CONTENT_CHILD_SCOPED_WEB_CALLBACKS_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 template <typename CallbacksType> | 67 template <typename CallbacksType> |
| 68 class ScopedWebCallbacks { | 68 class ScopedWebCallbacks { |
| 69 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedWebCallbacks); | 69 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedWebCallbacks); |
| 70 | 70 |
| 71 public: | 71 public: |
| 72 using DestructionCallback = | 72 using DestructionCallback = |
| 73 base::Callback<void(scoped_ptr<CallbacksType> callbacks)>; | 73 base::Callback<void(scoped_ptr<CallbacksType> callbacks)>; |
| 74 | 74 |
| 75 ScopedWebCallbacks(scoped_ptr<CallbacksType> callbacks, | 75 ScopedWebCallbacks(scoped_ptr<CallbacksType> callbacks, |
| 76 const DestructionCallback& destruction_callback) | 76 const DestructionCallback& destruction_callback) |
| 77 : callbacks_(callbacks.Pass()), | 77 : callbacks_(std::move(callbacks)), |
| 78 destruction_callback_(destruction_callback) {} | 78 destruction_callback_(destruction_callback) {} |
| 79 | 79 |
| 80 ~ScopedWebCallbacks() { | 80 ~ScopedWebCallbacks() { |
| 81 if (callbacks_) | 81 if (callbacks_) |
| 82 destruction_callback_.Run(callbacks_.Pass()); | 82 destruction_callback_.Run(std::move(callbacks_)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 ScopedWebCallbacks(ScopedWebCallbacks&& other) { *this = std::move(other); } | 85 ScopedWebCallbacks(ScopedWebCallbacks&& other) { *this = std::move(other); } |
| 86 | 86 |
| 87 ScopedWebCallbacks& operator=(ScopedWebCallbacks&& other) { | 87 ScopedWebCallbacks& operator=(ScopedWebCallbacks&& other) { |
| 88 callbacks_ = std::move(other.callbacks_); | 88 callbacks_ = std::move(other.callbacks_); |
| 89 destruction_callback_ = other.destruction_callback_; | 89 destruction_callback_ = other.destruction_callback_; |
| 90 return *this; | 90 return *this; |
| 91 } | 91 } |
| 92 | 92 |
| 93 scoped_ptr<CallbacksType> PassCallbacks() { return callbacks_.Pass(); } | 93 scoped_ptr<CallbacksType> PassCallbacks() { return std::move(callbacks_); } |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 scoped_ptr<CallbacksType> callbacks_; | 96 scoped_ptr<CallbacksType> callbacks_; |
| 97 DestructionCallback destruction_callback_; | 97 DestructionCallback destruction_callback_; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 template <typename CallbacksType> | 100 template <typename CallbacksType> |
| 101 ScopedWebCallbacks<CallbacksType> make_scoped_web_callbacks( | 101 ScopedWebCallbacks<CallbacksType> make_scoped_web_callbacks( |
| 102 CallbacksType* callbacks, | 102 CallbacksType* callbacks, |
| 103 const typename ScopedWebCallbacks<CallbacksType>::DestructionCallback& | 103 const typename ScopedWebCallbacks<CallbacksType>::DestructionCallback& |
| 104 destruction_callback) { | 104 destruction_callback) { |
| 105 return ScopedWebCallbacks<CallbacksType>(make_scoped_ptr(callbacks), | 105 return ScopedWebCallbacks<CallbacksType>(make_scoped_ptr(callbacks), |
| 106 destruction_callback); | 106 destruction_callback); |
| 107 } | 107 } |
| 108 | 108 |
| 109 #endif // CONTENT_CHILD_SCOPED_WEB_CALLBACKS_H_ | 109 #endif // CONTENT_CHILD_SCOPED_WEB_CALLBACKS_H_ |
| OLD | NEW |