Index: base/test/logging_utils.cc |
diff --git a/base/test/logging_utils.cc b/base/test/logging_utils.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..49bf0abe24b759b2b3865d36f3121ec8499480de |
--- /dev/null |
+++ b/base/test/logging_utils.cc |
@@ -0,0 +1,46 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
Paweł Hajdan Jr.
2017/01/27 17:19:44
nit: 2017, no (c).
alex-ac
2017/02/11 20:12:19
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/test/logging_utils.h" |
+ |
+#include <utility> |
+ |
+namespace logging { |
+ |
+namespace { |
+ |
+// std::swap doesn't works with base::Callback. |
+void SwapHandlers(LogAssertHandlerFunction* a, LogAssertHandlerFunction* b) { |
+ LogAssertHandlerFunction temp = *a; |
+ *a = *b; |
+ *b = temp; |
+} |
+ |
+} // namespace |
+ |
+ScopedLogAssertHandler::ScopedLogAssertHandler() {} |
+ |
+ScopedLogAssertHandler::ScopedLogAssertHandler(LogAssertHandlerFunction handler) |
+ : handler_(handler) { |
+ if (handler_) |
+ SetLogAssertHandler(handler); |
+} |
+ |
+ScopedLogAssertHandler::~ScopedLogAssertHandler() { |
+ if (handler_) |
+ ResetLogAssertHandler(); |
+} |
+ |
+ScopedLogAssertHandler::ScopedLogAssertHandler(ScopedLogAssertHandler&& other) { |
+ SwapHandlers(&handler_, &other.handler_); |
+} |
+ |
+ScopedLogAssertHandler& ScopedLogAssertHandler::operator=( |
+ ScopedLogAssertHandler&& other) { |
+ ScopedLogAssertHandler temp_copy(std::move(other)); |
+ SwapHandlers(&handler_, &temp_copy.handler_); |
+ return *this; |
+} |
+ |
+} // namespace logging |