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

Side by Side Diff: blimp/common/logging.cc

Issue 1970463004: Blimp: Add BlobChannel Helium messages and delegate impls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wez feedback Created 4 years, 7 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 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
24 // TODO(kmarshall): Remove "default" cases from switch statements in favor of
25 // explicit coverage of all enum values, including TYPE_NOT_SET.
Wez 2016/05/25 02:47:44 nit: Let's file a bug for that cleanup, rather tha
Kevin M 2016/05/25 20:23:38 Done, crbug.com/614748
26
22 static base::LazyInstance<BlimpMessageLogger> g_logger = 27 static base::LazyInstance<BlimpMessageLogger> g_logger =
23 LAZY_INSTANCE_INITIALIZER; 28 LAZY_INSTANCE_INITIALIZER;
24 29
25 // The AddField() suite of functions are used to convert KV pairs with 30 // The AddField() suite of functions are used to convert KV pairs with
26 // arbitrarily typed values into string/string KV pairs for logging. 31 // arbitrarily typed values into string/string KV pairs for logging.
27 32
28 // Specialization for string values, surrounding them with quotes and escaping 33 // Specialization for string values, surrounding them with quotes and escaping
29 // characters as necessary. 34 // characters as necessary.
30 void AddField(const std::string& key, 35 void AddField(const std::string& key,
31 const std::string& value, 36 const std::string& value,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 case TabControlMessage::SIZE: 246 case TabControlMessage::SIZE:
242 AddField("subtype", "SIZE", output); 247 AddField("subtype", "SIZE", output);
243 AddField("size", message.tab_control().size(), output); 248 AddField("size", message.tab_control().size(), output);
244 break; 249 break;
245 default: // unknown 250 default: // unknown
246 break; 251 break;
247 } 252 }
248 } 253 }
249 }; 254 };
250 255
256 // Logs fields from BLOB_CHANNEL messages.
257 class BlobChannelLogExtractor : public LogExtractor {
258 void ExtractFields(const BlimpMessage& message,
259 LogFields* output) const override {
260 switch (message.blob_channel().type_case()) {
261 case BlobChannelMessage::TypeCase::kTransferBlob:
262 AddField("subtype", "TRANSFER_BLOB", output);
263 AddField("id",
264 base::HexEncode(
265 message.blob_channel().transfer_blob().blob_id().data(),
266 message.blob_channel().transfer_blob().blob_id().size()),
267 output);
268 AddField("payload_size",
269 message.blob_channel().transfer_blob().payload().size(),
270 output);
271 break;
272 case BlobChannelMessage::TypeCase::TYPE_NOT_SET: // unknown
273 break;
274 }
275 }
276 };
277
251 // No fields are extracted from |message|. 278 // No fields are extracted from |message|.
252 class NullLogExtractor : public LogExtractor { 279 class NullLogExtractor : public LogExtractor {
253 void ExtractFields(const BlimpMessage& message, 280 void ExtractFields(const BlimpMessage& message,
254 LogFields* output) const override {} 281 LogFields* output) const override {}
255 }; 282 };
256 283
257 } // namespace 284 } // namespace
258 285
259 BlimpMessageLogger::BlimpMessageLogger() { 286 BlimpMessageLogger::BlimpMessageLogger() {
260 AddHandler("COMPOSITOR", BlimpMessage::COMPOSITOR, 287 AddHandler("COMPOSITOR", BlimpMessage::COMPOSITOR,
261 base::WrapUnique(new CompositorLogExtractor)); 288 base::WrapUnique(new CompositorLogExtractor));
262 AddHandler("INPUT", BlimpMessage::INPUT, 289 AddHandler("INPUT", BlimpMessage::INPUT,
263 base::WrapUnique(new InputLogExtractor)); 290 base::WrapUnique(new InputLogExtractor));
264 AddHandler("NAVIGATION", BlimpMessage::NAVIGATION, 291 AddHandler("NAVIGATION", BlimpMessage::NAVIGATION,
265 base::WrapUnique(new NavigationLogExtractor)); 292 base::WrapUnique(new NavigationLogExtractor));
266 AddHandler("PROTOCOL_CONTROL", BlimpMessage::PROTOCOL_CONTROL, 293 AddHandler("PROTOCOL_CONTROL", BlimpMessage::PROTOCOL_CONTROL,
267 base::WrapUnique(new ProtocolControlLogExtractor)); 294 base::WrapUnique(new ProtocolControlLogExtractor));
268 AddHandler("RENDER_WIDGET", BlimpMessage::RENDER_WIDGET, 295 AddHandler("RENDER_WIDGET", BlimpMessage::RENDER_WIDGET,
269 base::WrapUnique(new RenderWidgetLogExtractor)); 296 base::WrapUnique(new RenderWidgetLogExtractor));
270 AddHandler("SETTINGS", BlimpMessage::SETTINGS, 297 AddHandler("SETTINGS", BlimpMessage::SETTINGS,
271 base::WrapUnique(new SettingsLogExtractor)); 298 base::WrapUnique(new SettingsLogExtractor));
272 AddHandler("TAB_CONTROL", BlimpMessage::TAB_CONTROL, 299 AddHandler("TAB_CONTROL", BlimpMessage::TAB_CONTROL,
273 base::WrapUnique(new TabControlLogExtractor)); 300 base::WrapUnique(new TabControlLogExtractor));
301 AddHandler("BLOB_CHANNEL", BlimpMessage::BLOB_CHANNEL,
302 base::WrapUnique(new BlobChannelLogExtractor));
274 } 303 }
275 304
276 BlimpMessageLogger::~BlimpMessageLogger() {} 305 BlimpMessageLogger::~BlimpMessageLogger() {}
277 306
278 void BlimpMessageLogger::AddHandler(const std::string& type_name, 307 void BlimpMessageLogger::AddHandler(const std::string& type_name,
279 BlimpMessage::Type type, 308 BlimpMessage::Type type,
280 std::unique_ptr<LogExtractor> extractor) { 309 std::unique_ptr<LogExtractor> extractor) {
281 DCHECK(extractors_.find(type) == extractors_.end()); 310 DCHECK(extractors_.find(type) == extractors_.end());
282 DCHECK(!type_name.empty()); 311 DCHECK(!type_name.empty());
283 extractors_[type] = make_pair(type_name, std::move(extractor)); 312 extractors_[type] = make_pair(type_name, std::move(extractor));
(...skipping 30 matching lines...) Expand all
314 } 343 }
315 *out << ">"; 344 *out << ">";
316 } 345 }
317 346
318 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) { 347 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) {
319 g_logger.Get().LogMessageToStream(message, &out); 348 g_logger.Get().LogMessageToStream(message, &out);
320 return out; 349 return out;
321 } 350 }
322 351
323 } // namespace blimp 352 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698