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

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: rebase 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
« no previous file with comments | « blimp/common/create_blimp_message_unittest.cc ('k') | blimp/common/logging_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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
241 case TabControlMessage::kSize: 243 case TabControlMessage::kSize:
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 {
257 switch (message.blob_channel().type_case()) {
258 case BlobChannelMessage::TypeCase::kTransferBlob:
259 AddField("subtype", "TRANSFER_BLOB", output);
260 AddField("id",
261 base::HexEncode(
262 message.blob_channel().transfer_blob().blob_id().data(),
263 message.blob_channel().transfer_blob().blob_id().size()),
264 output);
265 AddField("payload_size",
266 message.blob_channel().transfer_blob().payload().size(),
267 output);
268 break;
269 case BlobChannelMessage::TypeCase::TYPE_NOT_SET: // unknown
270 break;
271 }
272 }
273 };
274
251 // No fields are extracted from |message|. 275 // No fields are extracted from |message|.
252 class NullLogExtractor : public LogExtractor { 276 class NullLogExtractor : public LogExtractor {
253 void ExtractFields(const BlimpMessage& message, 277 void ExtractFields(const BlimpMessage& message,
254 LogFields* output) const override {} 278 LogFields* output) const override {}
255 }; 279 };
256 280
257 } // namespace 281 } // namespace
258 282
259 BlimpMessageLogger::BlimpMessageLogger() { 283 BlimpMessageLogger::BlimpMessageLogger() {
260 AddHandler("COMPOSITOR", BlimpMessage::kCompositor, 284 AddHandler("COMPOSITOR", BlimpMessage::kCompositor,
261 base::WrapUnique(new CompositorLogExtractor)); 285 base::WrapUnique(new CompositorLogExtractor));
262 AddHandler("INPUT", BlimpMessage::kInput, 286 AddHandler("INPUT", BlimpMessage::kInput,
263 base::WrapUnique(new InputLogExtractor)); 287 base::WrapUnique(new InputLogExtractor));
264 AddHandler("NAVIGATION", BlimpMessage::kNavigation, 288 AddHandler("NAVIGATION", BlimpMessage::kNavigation,
265 base::WrapUnique(new NavigationLogExtractor)); 289 base::WrapUnique(new NavigationLogExtractor));
266 AddHandler("PROTOCOL_CONTROL", BlimpMessage::kProtocolControl, 290 AddHandler("PROTOCOL_CONTROL", BlimpMessage::kProtocolControl,
267 base::WrapUnique(new ProtocolControlLogExtractor)); 291 base::WrapUnique(new ProtocolControlLogExtractor));
268 AddHandler("RENDER_WIDGET", BlimpMessage::kRenderWidget, 292 AddHandler("RENDER_WIDGET", BlimpMessage::kRenderWidget,
269 base::WrapUnique(new RenderWidgetLogExtractor)); 293 base::WrapUnique(new RenderWidgetLogExtractor));
270 AddHandler("SETTINGS", BlimpMessage::kSettings, 294 AddHandler("SETTINGS", BlimpMessage::kSettings,
271 base::WrapUnique(new SettingsLogExtractor)); 295 base::WrapUnique(new SettingsLogExtractor));
272 AddHandler("TAB_CONTROL", BlimpMessage::kTabControl, 296 AddHandler("TAB_CONTROL", BlimpMessage::kTabControl,
273 base::WrapUnique(new TabControlLogExtractor)); 297 base::WrapUnique(new TabControlLogExtractor));
298 AddHandler("BLOB_CHANNEL", BlimpMessage::kBlobChannel,
299 base::WrapUnique(new BlobChannelLogExtractor));
274 } 300 }
275 301
276 BlimpMessageLogger::~BlimpMessageLogger() {} 302 BlimpMessageLogger::~BlimpMessageLogger() {}
277 303
278 void BlimpMessageLogger::AddHandler(const std::string& feature_name, 304 void BlimpMessageLogger::AddHandler(const std::string& feature_name,
279 BlimpMessage::FeatureCase feature_case, 305 BlimpMessage::FeatureCase feature_case,
280 std::unique_ptr<LogExtractor> extractor) { 306 std::unique_ptr<LogExtractor> extractor) {
281 DCHECK(extractors_.find(feature_case) == extractors_.end()); 307 DCHECK(extractors_.find(feature_case) == extractors_.end());
282 DCHECK(!feature_name.empty()); 308 DCHECK(!feature_name.empty());
283 extractors_[feature_case] = make_pair(feature_name, std::move(extractor)); 309 extractors_[feature_case] = make_pair(feature_name, std::move(extractor));
(...skipping 30 matching lines...) Expand all
314 } 340 }
315 *out << ">"; 341 *out << ">";
316 } 342 }
317 343
318 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) { 344 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) {
319 g_logger.Get().LogMessageToStream(message, &out); 345 g_logger.Get().LogMessageToStream(message, &out);
320 return out; 346 return out;
321 } 347 }
322 348
323 } // namespace blimp 349 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/common/create_blimp_message_unittest.cc ('k') | blimp/common/logging_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698