summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/loader/fetch/resource_load_timing.cc
blob: 94af06e1f6e11db7db7e122d08edd2637a695a54 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Copyright 2015 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 "third_party/blink/renderer/platform/loader/fetch/resource_load_timing.h"

#include "services/network/public/mojom/load_timing_info.mojom-blink.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"

namespace blink {

ResourceLoadTiming::ResourceLoadTiming() = default;

ResourceLoadTiming::ResourceLoadTiming(
    base::TimeTicks request_time,
    base::TimeTicks proxy_start,
    base::TimeTicks proxy_end,
    base::TimeTicks dns_start,
    base::TimeTicks dns_end,
    base::TimeTicks connect_start,
    base::TimeTicks connect_end,
    base::TimeTicks worker_start,
    base::TimeTicks worker_ready,
    base::TimeTicks worker_fetch_start,
    base::TimeTicks worker_respond_with_settled,
    base::TimeTicks send_start,
    base::TimeTicks send_end,
    base::TimeTicks receive_headers_start,
    base::TimeTicks receive_headers_end,
    base::TimeTicks ssl_start,
    base::TimeTicks ssl_end,
    base::TimeTicks push_start,
    base::TimeTicks push_end)
    : request_time_(request_time),
      proxy_start_(proxy_start),
      proxy_end_(proxy_end),
      dns_start_(dns_start),
      dns_end_(dns_end),
      connect_start_(connect_start),
      connect_end_(connect_end),
      worker_start_(worker_start),
      worker_ready_(worker_ready),
      worker_fetch_start_(worker_fetch_start),
      worker_respond_with_settled_(worker_respond_with_settled),
      send_start_(send_start),
      send_end_(send_end),
      receive_headers_start_(receive_headers_start),
      receive_headers_end_(receive_headers_end),
      ssl_start_(ssl_start),
      ssl_end_(ssl_end),
      push_start_(push_start),
      push_end_(push_end) {}

scoped_refptr<ResourceLoadTiming> ResourceLoadTiming::Create() {
  return base::AdoptRef(new ResourceLoadTiming);
}

scoped_refptr<ResourceLoadTiming> ResourceLoadTiming::FromMojo(
    const network::mojom::blink::LoadTimingInfo* mojo_timing) {
  if (!mojo_timing)
    return ResourceLoadTiming::Create();
  return base::AdoptRef(new ResourceLoadTiming(
      mojo_timing->request_start, mojo_timing->proxy_resolve_start,
      mojo_timing->proxy_resolve_end, mojo_timing->connect_timing->dns_start,
      mojo_timing->connect_timing->dns_end,
      mojo_timing->connect_timing->connect_start,
      mojo_timing->connect_timing->connect_end,
      mojo_timing->service_worker_start_time,
      mojo_timing->service_worker_ready_time,
      mojo_timing->service_worker_fetch_start,
      mojo_timing->service_worker_respond_with_settled, mojo_timing->send_start,
      mojo_timing->send_end, mojo_timing->receive_headers_start,
      mojo_timing->receive_headers_end, mojo_timing->connect_timing->ssl_start,
      mojo_timing->connect_timing->ssl_end, mojo_timing->push_start,
      mojo_timing->push_end));
}

network::mojom::blink::LoadTimingInfoPtr ResourceLoadTiming::ToMojo() const {
  network::mojom::blink::LoadTimingInfoPtr timing =
      network::mojom::blink::LoadTimingInfo::New(
          false, 0, base::Time(), request_time_, proxy_start_, proxy_end_,
          network::mojom::blink::LoadTimingInfoConnectTiming::New(
              dns_start_, dns_end_, connect_start_, connect_end_, ssl_start_,
              ssl_end_),
          send_start_, send_end_, receive_headers_start_, receive_headers_end_,
          /*receive_non_informational_headers_start=*/base::TimeTicks::Now(),
          /*first_early_hints_time=*/base::TimeTicks::Now(), push_start_,
          push_end_, worker_start_, worker_ready_, worker_fetch_start_,
          worker_respond_with_settled_);
  return timing;
}

bool ResourceLoadTiming::operator==(const ResourceLoadTiming& other) const {
  return request_time_ == other.request_time_ &&
         proxy_start_ == other.proxy_start_ && proxy_end_ == other.proxy_end_ &&
         dns_start_ == other.dns_start_ && dns_end_ == other.dns_end_ &&
         connect_start_ == other.connect_start_ &&
         connect_end_ == other.connect_end_ &&
         worker_start_ == other.worker_start_ &&
         worker_ready_ == other.worker_ready_ &&
         worker_fetch_start_ == other.worker_fetch_start_ &&
         worker_respond_with_settled_ == other.worker_respond_with_settled_ &&
         send_start_ == other.send_start_ && send_end_ == other.send_end_ &&
         receive_headers_start_ == other.receive_headers_start_ &&
         receive_headers_end_ == other.receive_headers_end_ &&
         ssl_start_ == other.ssl_start_ && ssl_end_ == other.ssl_end_ &&
         push_start_ == other.push_start_ && push_end_ == other.push_end_;
}

bool ResourceLoadTiming::operator!=(const ResourceLoadTiming& other) const {
  return !(*this == other);
}

void ResourceLoadTiming::SetDnsStart(base::TimeTicks dns_start) {
  dns_start_ = dns_start;
}

void ResourceLoadTiming::SetRequestTime(base::TimeTicks request_time) {
  request_time_ = request_time;
}

void ResourceLoadTiming::SetProxyStart(base::TimeTicks proxy_start) {
  proxy_start_ = proxy_start;
}

void ResourceLoadTiming::SetProxyEnd(base::TimeTicks proxy_end) {
  proxy_end_ = proxy_end;
}

void ResourceLoadTiming::SetDnsEnd(base::TimeTicks dns_end) {
  dns_end_ = dns_end;
}

void ResourceLoadTiming::SetConnectStart(base::TimeTicks connect_start) {
  connect_start_ = connect_start;
}

void ResourceLoadTiming::SetConnectEnd(base::TimeTicks connect_end) {
  connect_end_ = connect_end;
}

void ResourceLoadTiming::SetWorkerStart(base::TimeTicks worker_start) {
  worker_start_ = worker_start;
}

void ResourceLoadTiming::SetWorkerReady(base::TimeTicks worker_ready) {
  worker_ready_ = worker_ready;
}

void ResourceLoadTiming::SetWorkerFetchStart(
    base::TimeTicks worker_fetch_start) {
  worker_fetch_start_ = worker_fetch_start;
}

void ResourceLoadTiming::SetWorkerRespondWithSettled(
    base::TimeTicks worker_respond_with_settled) {
  worker_respond_with_settled_ = worker_respond_with_settled;
}

void ResourceLoadTiming::SetSendStart(base::TimeTicks send_start) {
  TRACE_EVENT_MARK_WITH_TIMESTAMP0("blink.user_timing", "requestStart",
                                   send_start);
  send_start_ = send_start;
}

void ResourceLoadTiming::SetSendEnd(base::TimeTicks send_end) {
  send_end_ = send_end;
}

void ResourceLoadTiming::SetReceiveHeadersStart(
    base::TimeTicks receive_headers_start) {
  receive_headers_start_ = receive_headers_start;
}

void ResourceLoadTiming::SetReceiveHeadersEnd(
    base::TimeTicks receive_headers_end) {
  receive_headers_end_ = receive_headers_end;
}

void ResourceLoadTiming::SetSslStart(base::TimeTicks ssl_start) {
  ssl_start_ = ssl_start;
}

void ResourceLoadTiming::SetSslEnd(base::TimeTicks ssl_end) {
  ssl_end_ = ssl_end;
}

void ResourceLoadTiming::SetPushStart(base::TimeTicks push_start) {
  push_start_ = push_start;
}

void ResourceLoadTiming::SetPushEnd(base::TimeTicks push_end) {
  push_end_ = push_end;
}

double ResourceLoadTiming::CalculateMillisecondDelta(
    base::TimeTicks time) const {
  return time.is_null() ? -1 : (time - request_time_).InMillisecondsF();
}

}  // namespace blink