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

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

Issue 2091023006: Adds EngineGeolocationFeature for Blimp Geolocation project. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: In response to Wez's #23 comment 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 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 <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 message.blob_channel().transfer_blob().blob_id().size()), 293 message.blob_channel().transfer_blob().blob_id().size()),
294 output); 294 output);
295 AddField("payload_size", 295 AddField("payload_size",
296 message.blob_channel().transfer_blob().payload().size(), output); 296 message.blob_channel().transfer_blob().payload().size(), output);
297 break; 297 break;
298 case BlobChannelMessage::TypeCase::TYPE_NOT_SET: // unknown 298 case BlobChannelMessage::TypeCase::TYPE_NOT_SET: // unknown
299 break; 299 break;
300 } 300 }
301 } 301 }
302 302
303 // Logs fields from GEOLOCATION messages.
304 void ExtractGeolocationMessageFields(const BlimpMessage& message,
305 LogFields* output) {
306 switch (message.geolocation().type_case()) {
307 case GeolocationMessage::TypeCase::kUpdateListenState:
308 AddField("subtype", "UPDATE_LISTEN_STATE", output);
309 AddField("listen_state",
310 message.geolocation().update_listen_state().listen_state(),
311 output);
312 break;
313 case GeolocationMessage::TypeCase::kRequestRefresh:
314 AddField("subtype", "REQUEST_REFRESH", output);
315 break;
316 case GeolocationMessage::TypeCase::kLocation: {
317 const GeolocationPositionMessage& location =
318 message.geolocation().location();
319 AddField("subtype", "LOCATION", output);
320 AddField("latitude", location.coordinates().latitude(), output);
321 AddField("longitude", location.coordinates().longitude(), output);
322 AddField("altitude", location.coordinates().altitude(), output);
323 AddField("accuracy", location.coordinates().accuracy(), output);
324 AddField("altitude_accuracy", location.coordinates().altitude_accuracy(),
325 output);
326 AddField("heading", location.coordinates().heading(), output);
327 AddField("speed", location.coordinates().speed(), output);
328 AddField("timestamp_millis", location.timestamp_millis(), output);
329 break;
330 }
331 case GeolocationMessage::TypeCase::kError:
332 AddField("subtype", "ERROR", output);
333 AddField("error_code", message.geolocation().error().error_code(),
334 output);
335 AddField("error_message", message.geolocation().error().error_message(),
336 output);
337 break;
338 case GeolocationMessage::TypeCase::TYPE_NOT_SET:
339 break;
340 }
341 }
342
303 } // namespace 343 } // namespace
304 344
305 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) { 345 std::ostream& operator<<(std::ostream& out, const BlimpMessage& message) {
306 LogFields fields; 346 LogFields fields;
307 347
308 switch (message.feature_case()) { 348 switch (message.feature_case()) {
309 case BlimpMessage::kCompositor: 349 case BlimpMessage::kCompositor:
310 AddField("type", "COMPOSITOR", &fields); 350 AddField("type", "COMPOSITOR", &fields);
311 ExtractCompositorMessageFields(message, &fields); 351 ExtractCompositorMessageFields(message, &fields);
312 break; 352 break;
(...skipping 22 matching lines...) Expand all
335 ExtractTabControlMessageFields(message, &fields); 375 ExtractTabControlMessageFields(message, &fields);
336 break; 376 break;
337 case BlimpMessage::kBlobChannel: 377 case BlimpMessage::kBlobChannel:
338 AddField("type", "BLOB_CHANNEL", &fields); 378 AddField("type", "BLOB_CHANNEL", &fields);
339 ExtractBlobChannelMessageFields(message, &fields); 379 ExtractBlobChannelMessageFields(message, &fields);
340 break; 380 break;
341 case BlimpMessage::kIme: 381 case BlimpMessage::kIme:
342 AddField("type", "IME", &fields); 382 AddField("type", "IME", &fields);
343 ExtractImeMessageFields(message, &fields); 383 ExtractImeMessageFields(message, &fields);
344 break; 384 break;
385 case BlimpMessage::kGeolocation:
386 AddField("type", "GEOLOCATION", &fields);
387 ExtractGeolocationMessageFields(message, &fields);
388 break;
345 case BlimpMessage::FEATURE_NOT_SET: 389 case BlimpMessage::FEATURE_NOT_SET:
346 AddField("type", "<UNKNOWN>", &fields); 390 AddField("type", "<UNKNOWN>", &fields);
347 break; 391 break;
348 } 392 }
349 393
350 // Append "target_tab_id" (if present) and "byte_size" to the field set. 394 // Append "target_tab_id" (if present) and "byte_size" to the field set.
351 if (message.has_target_tab_id()) { 395 if (message.has_target_tab_id()) {
352 AddField("target_tab_id", message.target_tab_id(), &fields); 396 AddField("target_tab_id", message.target_tab_id(), &fields);
353 } 397 }
354 AddField("byte_size", message.ByteSize(), &fields); 398 AddField("byte_size", message.ByteSize(), &fields);
355 399
356 // Format message using the syntax: 400 // Format message using the syntax:
357 // <BlimpMessage field1=value1 field2="value 2"> 401 // <BlimpMessage field1=value1 field2="value 2">
358 out << "<BlimpMessage "; 402 out << "<BlimpMessage ";
359 for (size_t i = 0; i < fields.size(); ++i) { 403 for (size_t i = 0; i < fields.size(); ++i) {
360 out << fields[i].first << "=" << fields[i].second 404 out << fields[i].first << "=" << fields[i].second
361 << (i != fields.size() - 1 ? " " : ""); 405 << (i != fields.size() - 1 ? " " : "");
362 } 406 }
363 out << ">"; 407 out << ">";
364 408
365 return out; 409 return out;
366 } 410 }
367 411
368 } // namespace blimp 412 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698