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

Side by Side Diff: net/test/scoped_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, 9 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
« no previous file with comments | « net/test/scoped_mock_log.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/test/scoped_mock_log.h"
6
7 #include "base/logging.h"
8
9 namespace net {
10 namespace test {
11
12 // static
13 ScopedMockLog* ScopedMockLog::g_instance_ = NULL;
14
15 ScopedMockLog::ScopedMockLog() : is_capturing_logs_(false) {}
16
17 ScopedMockLog::~ScopedMockLog() {
18 if (is_capturing_logs_) {
19 StopCapturingLogs();
20 }
21 }
22
23 void ScopedMockLog::StartCapturingLogs() {
24 // We don't use CHECK(), which can generate a new LOG message, and
25 // thus can confuse ScopedMockLog objects or other registered
26 // LogSinks.
27 RAW_CHECK(!is_capturing_logs_);
28 RAW_CHECK(!g_instance_);
29
30 is_capturing_logs_ = true;
31 g_instance_ = this;
32 previous_handler_ = logging::GetLogMessageHandler();
33 logging::SetLogMessageHandler(LogMessageHandler);
34 }
35
36 void ScopedMockLog::StopCapturingLogs() {
37 // We don't use CHECK(), which can generate a new LOG message, and
38 // thus can confuse ScopedMockLog objects or other registered
39 // LogSinks.
40 RAW_CHECK(is_capturing_logs_);
41 RAW_CHECK(g_instance_ == this);
42
43 is_capturing_logs_ = false;
44 logging::SetLogMessageHandler(previous_handler_);
45 g_instance_ = NULL;
46 }
47
48 // static
49 bool ScopedMockLog::LogMessageHandler(int severity,
50 const char* file,
51 int line,
52 size_t message_start,
53 const std::string& str) {
54 return g_instance_->Log(severity, file, line, message_start, str);
55 }
56
57 } // namespace test
58 } // namespace net
OLDNEW
« no previous file with comments | « net/test/scoped_mock_log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698