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

Side by Side Diff: remoting/host/native_messaging/log_message_handler.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up, MockLog uses listener Created 4 years, 5 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 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 #include "remoting/host/native_messaging/log_message_handler.h" 5 #include "remoting/host/native_messaging/log_message_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 18 matching lines...) Expand all
29 const Delegate& delegate) 29 const Delegate& delegate)
30 : delegate_(delegate), 30 : delegate_(delegate),
31 suppress_logging_(false), 31 suppress_logging_(false),
32 caller_task_runner_(base::ThreadTaskRunnerHandle::Get()), 32 caller_task_runner_(base::ThreadTaskRunnerHandle::Get()),
33 weak_ptr_factory_(this) { 33 weak_ptr_factory_(this) {
34 base::AutoLock lock(g_log_message_handler_lock.Get()); 34 base::AutoLock lock(g_log_message_handler_lock.Get());
35 if (g_log_message_handler) { 35 if (g_log_message_handler) {
36 LOG(FATAL) << "LogMessageHandler is already registered. Only one instance " 36 LOG(FATAL) << "LogMessageHandler is already registered. Only one instance "
37 << "per process is allowed."; 37 << "per process is allowed.";
38 } 38 }
39 previous_log_message_handler_ = logging::GetLogMessageHandler(); 39 logging::PushLogMessageHandler(&LogMessageHandler::OnLogMessage);
40 logging::SetLogMessageHandler(&LogMessageHandler::OnLogMessage);
41 g_log_message_handler = this; 40 g_log_message_handler = this;
42 } 41 }
43 42
44 LogMessageHandler::~LogMessageHandler() { 43 LogMessageHandler::~LogMessageHandler() {
45 base::AutoLock lock(g_log_message_handler_lock.Get()); 44 base::AutoLock lock(g_log_message_handler_lock.Get());
46 if (logging::GetLogMessageHandler() != &LogMessageHandler::OnLogMessage) { 45 if (logging::GetTopLogMessageHandler() != &LogMessageHandler::OnLogMessage) {
47 LOG(FATAL) << "LogMessageHandler is not the top-most message handler. " 46 LOG(FATAL) << "LogMessageHandler is not the top-most message handler. "
48 << "Cannot unregister."; 47 << "Cannot unregister.";
49 } 48 }
Dan Beam 2016/07/15 03:11:19 ^ do we still need this?
wychen 2016/07/18 15:44:12 Cleaned this up to simplify logic.
50 logging::SetLogMessageHandler(previous_log_message_handler_); 49 logging::PopLogMessageHandler(&LogMessageHandler::OnLogMessage);
51 g_log_message_handler = nullptr; 50 g_log_message_handler = nullptr;
52 } 51 }
53 52
54 // static 53 // static
55 const char* LogMessageHandler::kDebugMessageTypeName = "_debug_log"; 54 const char* LogMessageHandler::kDebugMessageTypeName = "_debug_log";
56 55
57 // static 56 // static
58 bool LogMessageHandler::OnLogMessage( 57 bool LogMessageHandler::OnLogMessage(
59 logging::LogSeverity severity, 58 logging::LogSeverity severity,
60 const char* file, 59 const char* file,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 dictionary->SetString("message", message); 122 dictionary->SetString("message", message);
124 dictionary->SetString("file", file); 123 dictionary->SetString("file", file);
125 dictionary->SetInteger("line", line); 124 dictionary->SetInteger("line", line);
126 125
127 delegate_.Run(std::move(dictionary)); 126 delegate_.Run(std::move(dictionary));
128 127
129 suppress_logging_ = false; 128 suppress_logging_ = false;
130 } 129 }
131 130
132 } // namespace remoting 131 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698