summaryrefslogtreecommitdiff
path: root/chromium/net/log/net_log_entry.cc
blob: 1258139f74897fa64fa3fa3be22e113ceb5bbd83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/log/net_log_entry.h"

#include <utility>

#include "base/callback.h"
#include "base/values.h"
#include "net/log/net_log.h"

namespace net {

std::unique_ptr<base::Value> NetLogEntry::ToValue() const {
  std::unique_ptr<base::DictionaryValue> entry_dict(
      new base::DictionaryValue());

  entry_dict->SetString("time", NetLog::TickCountToString(data_->time));

  // Set the entry source.
  std::unique_ptr<base::DictionaryValue> source_dict(
      new base::DictionaryValue());
  source_dict->SetInteger("id", data_->source.id);
  source_dict->SetInteger("type", static_cast<int>(data_->source.type));
  entry_dict->Set("source", std::move(source_dict));

  // Set the event info.
  entry_dict->SetInteger("type", static_cast<int>(data_->type));
  entry_dict->SetInteger("phase", static_cast<int>(data_->phase));

  // Set the event-specific parameters.
  if (data_->parameters_callback) {
    std::unique_ptr<base::Value> value(
        data_->parameters_callback->Run(capture_mode_));
    if (value)
      entry_dict->Set("params", std::move(value));
  }

  return std::move(entry_dict);
}

std::unique_ptr<base::Value> NetLogEntry::ParametersToValue() const {
  if (data_->parameters_callback)
    return data_->parameters_callback->Run(capture_mode_);
  return nullptr;
}

NetLogEntryData::NetLogEntryData(
    NetLogEventType type,
    NetLogSource source,
    NetLogEventPhase phase,
    base::TimeTicks time,
    const NetLogParametersCallback* parameters_callback)
    : type(type),
      source(source),
      phase(phase),
      time(time),
      parameters_callback(parameters_callback) {}

NetLogEntryData::~NetLogEntryData() {}

NetLogEntry::NetLogEntry(const NetLogEntryData* data,
                         NetLogCaptureMode capture_mode)
    : data_(data), capture_mode_(capture_mode) {}

NetLogEntry::~NetLogEntry() {}

}  // namespace net