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

Unified Diff: base/test/mock_log.cc

Issue 966423003: Moving ScopedMockLog from net/test to base/test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@separate-port-range
Patch Set: Addressed Ricardo's code review feedback. Created 5 years, 10 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 | « base/test/mock_log.h ('k') | net/net.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/mock_log.cc
diff --git a/net/test/scoped_mock_log.cc b/base/test/mock_log.cc
similarity index 43%
rename from net/test/scoped_mock_log.cc
rename to base/test/mock_log.cc
index 3bc99cb3d42b005e91af466f10224cd018c080d5..fa511d44d08645e4f45b8cc33622205239441c1f 100644
--- a/net/test/scoped_mock_log.cc
+++ b/base/test/mock_log.cc
@@ -1,28 +1,30 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2015 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 "net/test/scoped_mock_log.h"
+#include "base/test/mock_log.h"
-#include "base/logging.h"
-
-namespace net {
+namespace base {
namespace test {
// static
-ScopedMockLog* ScopedMockLog::g_instance_ = NULL;
+MockLog* MockLog::g_instance_ = nullptr;
+Lock MockLog::g_lock;
-ScopedMockLog::ScopedMockLog() : is_capturing_logs_(false) {}
+MockLog::MockLog() : is_capturing_logs_(false) {
+}
-ScopedMockLog::~ScopedMockLog() {
+MockLog::~MockLog() {
if (is_capturing_logs_) {
StopCapturingLogs();
}
}
-void ScopedMockLog::StartCapturingLogs() {
+void MockLog::StartCapturingLogs() {
+ AutoLock scoped_lock(g_lock);
+
// We don't use CHECK(), which can generate a new LOG message, and
- // thus can confuse ScopedMockLog objects or other registered
+ // thus can confuse MockLog objects or other registered
// LogSinks.
RAW_CHECK(!is_capturing_logs_);
RAW_CHECK(!g_instance_);
@@ -33,26 +35,34 @@ void ScopedMockLog::StartCapturingLogs() {
logging::SetLogMessageHandler(LogMessageHandler);
}
-void ScopedMockLog::StopCapturingLogs() {
+void MockLog::StopCapturingLogs() {
+ AutoLock scoped_lock(g_lock);
+
// We don't use CHECK(), which can generate a new LOG message, and
- // thus can confuse ScopedMockLog objects or other registered
+ // thus can confuse MockLog objects or other registered
// LogSinks.
RAW_CHECK(is_capturing_logs_);
RAW_CHECK(g_instance_ == this);
is_capturing_logs_ = false;
logging::SetLogMessageHandler(previous_handler_);
- g_instance_ = NULL;
+ g_instance_ = nullptr;
}
// static
-bool ScopedMockLog::LogMessageHandler(int severity,
- const char* file,
- int line,
- size_t message_start,
- const std::string& str) {
+bool MockLog::LogMessageHandler(int severity,
+ const char* file,
+ int line,
+ size_t message_start,
+ const std::string& str) {
+ // gMock guarantees thread-safety for calling a mocked method
+ // (https://code.google.com/p/googlemock/wiki/CookBook#Using_Google_Mock_and_Threads)
+ // but we also need to make sure that Start/StopCapturingLogs are synchronized
+ // with LogMessageHandler.
+ AutoLock scoped_lock(g_lock);
+
return g_instance_->Log(severity, file, line, message_start, str);
}
} // namespace test
-} // namespace net
+} // namespace base
« no previous file with comments | « base/test/mock_log.h ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698