net_log_entry.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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
  3. // found in the LICENSE file.
  4. #include "net/log/net_log_entry.h"
  5. #include <utility>
  6. #include "base/strings/string_piece.h"
  7. #include "base/time/time.h"
  8. #include "base/values.h"
  9. #include "net/log/net_log.h"
  10. #include "net/log/net_log_event_type.h"
  11. #include "net/log/net_log_source.h"
  12. namespace net {
  13. NetLogEntry::NetLogEntry(NetLogEventType type,
  14. NetLogSource source,
  15. NetLogEventPhase phase,
  16. base::TimeTicks time,
  17. base::Value params)
  18. : type(type),
  19. source(source),
  20. phase(phase),
  21. time(time),
  22. params(std::move(params)) {}
  23. NetLogEntry::~NetLogEntry() = default;
  24. NetLogEntry::NetLogEntry(NetLogEntry&& entry) = default;
  25. NetLogEntry& NetLogEntry::operator=(NetLogEntry&& entry) = default;
  26. base::Value NetLogEntry::ToValue() const {
  27. base::Value::Dict entry_dict;
  28. entry_dict.Set("time", NetLog::TickCountToString(time));
  29. // Set the entry source.
  30. base::Value::Dict source_dict;
  31. source_dict.Set("id", static_cast<int>(source.id));
  32. source_dict.Set("type", static_cast<int>(source.type));
  33. source_dict.Set("start_time", NetLog::TickCountToString(source.start_time));
  34. entry_dict.Set("source", std::move(source_dict));
  35. // Set the event info.
  36. entry_dict.Set("type", static_cast<int>(type));
  37. entry_dict.Set("phase", static_cast<int>(phase));
  38. // Set the event-specific parameters.
  39. if (!params.is_none())
  40. entry_dict.Set("params", params.Clone());
  41. return base::Value(std::move(entry_dict));
  42. }
  43. NetLogEntry NetLogEntry::Clone() const {
  44. return NetLogEntry(type, source, phase, time, params.Clone());
  45. }
  46. bool NetLogEntry::HasParams() const {
  47. return !params.is_none();
  48. }
  49. } // namespace net