udp_net_log_parameters.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "net/socket/udp_net_log_parameters.h"
  5. #include <utility>
  6. #include "base/values.h"
  7. #include "net/base/ip_endpoint.h"
  8. #include "net/log/net_log_values.h"
  9. #include "net/log/net_log_with_source.h"
  10. namespace net {
  11. namespace {
  12. base::Value NetLogUDPDataTransferParams(int byte_count,
  13. const char* bytes,
  14. const IPEndPoint* address,
  15. NetLogCaptureMode capture_mode) {
  16. base::Value::Dict dict;
  17. dict.Set("byte_count", byte_count);
  18. if (NetLogCaptureIncludesSocketBytes(capture_mode))
  19. dict.Set("bytes", NetLogBinaryValue(bytes, byte_count));
  20. if (address)
  21. dict.Set("address", address->ToString());
  22. return base::Value(std::move(dict));
  23. }
  24. base::Value NetLogUDPConnectParams(const IPEndPoint& address,
  25. handles::NetworkHandle network) {
  26. base::Value::Dict dict;
  27. dict.Set("address", address.ToString());
  28. if (network != handles::kInvalidNetworkHandle)
  29. dict.Set("bound_to_network", static_cast<int>(network));
  30. return base::Value(std::move(dict));
  31. }
  32. } // namespace
  33. void NetLogUDPDataTransfer(const NetLogWithSource& net_log,
  34. NetLogEventType type,
  35. int byte_count,
  36. const char* bytes,
  37. const IPEndPoint* address) {
  38. DCHECK(bytes);
  39. net_log.AddEvent(type, [&](NetLogCaptureMode capture_mode) {
  40. return NetLogUDPDataTransferParams(byte_count, bytes, address,
  41. capture_mode);
  42. });
  43. }
  44. base::Value CreateNetLogUDPConnectParams(const IPEndPoint& address,
  45. handles::NetworkHandle network) {
  46. return NetLogUDPConnectParams(address, network);
  47. }
  48. } // namespace net