OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/common/logging.h" | 5 #include "blimp/common/logging.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/json/string_escape.h" | 12 #include "base/json/string_escape.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/strings/string_number_conversions.h" | |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "blimp/common/create_blimp_message.h" | |
17 #include "blimp/common/proto/blimp_message.pb.h" | 19 #include "blimp/common/proto/blimp_message.pb.h" |
18 | 20 |
19 namespace blimp { | 21 namespace blimp { |
20 namespace { | 22 namespace { |
21 | 23 |
22 static base::LazyInstance<BlimpMessageLogger> g_logger = | 24 static base::LazyInstance<BlimpMessageLogger> g_logger = |
23 LAZY_INSTANCE_INITIALIZER; | 25 LAZY_INSTANCE_INITIALIZER; |
24 | 26 |
25 // The AddField() suite of functions are used to convert KV pairs with | 27 // The AddField() suite of functions are used to convert KV pairs with |
26 // arbitrarily typed values into string/string KV pairs for logging. | 28 // arbitrarily typed values into string/string KV pairs for logging. |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 case TabControlMessage::SIZE: | 243 case TabControlMessage::SIZE: |
242 AddField("subtype", "SIZE", output); | 244 AddField("subtype", "SIZE", output); |
243 AddField("size", message.tab_control().size(), output); | 245 AddField("size", message.tab_control().size(), output); |
244 break; | 246 break; |
245 default: // unknown | 247 default: // unknown |
246 break; | 248 break; |
247 } | 249 } |
248 } | 250 } |
249 }; | 251 }; |
250 | 252 |
253 // Logs fields from BLOB_CHANNEL messages. | |
254 class BlobChannelLogExtractor : public LogExtractor { | |
255 void ExtractFields(const BlimpMessage& message, | |
256 LogFields* output) const override { | |
Wez
2016/05/20 21:46:17
nit: Want to log the payload size as well?
Kevin M
2016/05/23 20:48:07
Done.
| |
257 switch (message.blob_channel().type()) { | |
258 case BlobChannelMessage::TRANSFER_BLOB: | |
259 AddField("subtype", "TRANSFER_BLOB", output); | |
260 default: | |
261 break; | |
262 } | |
263 if (message.blob_channel().has_blob_id()) { | |
264 AddField("id", base::HexEncode(message.blob_channel().blob_id().data(), | |
265 message.blob_channel().blob_id().size()), | |
266 output); | |
267 } | |
268 } | |
269 }; | |
270 | |
251 // No fields are extracted from |message|. | 271 // No fields are extracted from |message|. |
252 class NullLogExtractor : public LogExtractor { | 272 class NullLogExtractor : public LogExtractor { |
253 void ExtractFields(const BlimpMessage& message, | 273 void ExtractFields(const BlimpMessage& message, |
254 LogFields* output) const override {} | 274 LogFields* output) const override {} |
255 }; | 275 }; |
256 | 276 |
257 } // namespace | 277 } // namespace |
258 | 278 |
259 BlimpMessageLogger::BlimpMessageLogger() { | 279 BlimpMessageLogger::BlimpMessageLogger() { |
260 AddHandler("COMPOSITOR", BlimpMessage::COMPOSITOR, | 280 AddHandler("COMPOSITOR", BlimpMessage::COMPOSITOR, |
261 base::WrapUnique(new CompositorLogExtractor)); | 281 base::WrapUnique(new CompositorLogExtractor)); |
262 AddHandler("INPUT", BlimpMessage::INPUT, | 282 AddHandler("INPUT", BlimpMessage::INPUT, |
263 base::WrapUnique(new InputLogExtractor)); | 283 base::WrapUnique(new InputLogExtractor)); |
264 AddHandler("NAVIGATION", BlimpMessage::NAVIGATION, | 284 AddHandler("NAVIGATION", BlimpMessage::NAVIGATION, |
265 base::WrapUnique(new NavigationLogExtractor)); | 285 base::WrapUnique(new NavigationLogExtractor)); |
266 AddHandler("PROTOCOL_CONTROL", BlimpMessage::PROTOCOL_CONTROL, | 286 AddHandler("PROTOCOL_CONTROL", BlimpMessage::PROTOCOL_CONTROL, |
267 base::WrapUnique(new ProtocolControlLogExtractor)); | 287 base::WrapUnique(new ProtocolControlLogExtractor)); |
268 AddHandler("RENDER_WIDGET", BlimpMessage::RENDER_WIDGET, | 288 AddHandler("RENDER_WIDGET", BlimpMessage::RENDER_WIDGET, |
269 base::WrapUnique(new RenderWidgetLogExtractor)); | 289 base::WrapUnique(new RenderWidgetLogExtractor)); |
270 AddHandler("SETTINGS", BlimpMessage::SETTINGS, | 290 AddHandler("SETTINGS", BlimpMessage::SETTINGS, |
271 base::WrapUnique(new SettingsLogExtractor)); | 291 base::WrapUnique(new SettingsLogExtractor)); |
272 AddHandler("TAB_CONTROL", BlimpMessage::TAB_CONTROL, | 292 AddHandler("TAB_CONTROL", BlimpMessage::TAB_CONTROL, |
273 base::WrapUnique(new TabControlLogExtractor)); | 293 base::WrapUnique(new TabControlLogExtractor)); |
294 AddHandler("BLOB_CHANNEL", BlimpMessage::BLOB_CHANNEL, | |
295 base::WrapUnique(new BlobChannelLogExtractor)); | |
274 } | 296 } |
275 | 297 |
276 BlimpMessageLogger::~BlimpMessageLogger() {} | 298 BlimpMessageLogger::~BlimpMessageLogger() {} |
277 | 299 |
278 void BlimpMessageLogger::AddHandler(const std::string& type_name, | 300 void BlimpMessageLogger::AddHandler(const std::string& type_name, |
279 BlimpMessage::Type type, | 301 BlimpMessage::Type type, |
280 std::unique_ptr<LogExtractor> extractor) { | 302 std::unique_ptr<LogExtractor> extractor) { |
281 DCHECK(extractors_.find(type) == extractors_.end()); | 303 DCHECK(extractors_.find(type) == extractors_.end()); |
282 DCHECK(!type_name.empty()); | 304 DCHECK(!type_name.empty()); |
283 extractors_[type] = make_pair(type_name, std::move(extractor)); | 305 extractors_[type] = make_pair(type_name, std::move(extractor)); |
(...skipping 30 matching lines...) Expand all Loading... | |
314 } | 336 } |
315 *out << ">"; | 337 *out << ">"; |
316 } | 338 } |
317 | 339 |
318 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) { | 340 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) { |
319 g_logger.Get().LogMessageToStream(message, &out); | 341 g_logger.Get().LogMessageToStream(message, &out); |
320 return out; | 342 return out; |
321 } | 343 } |
322 | 344 |
323 } // namespace blimp | 345 } // namespace blimp |
OLD | NEW |