File: page_load_metrics_forward_observer.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (509 lines) | stat: -rw-r--r-- 19,427 bytes parent folder | download | duplicates (3)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/page_load_metrics/browser/page_load_metrics_forward_observer.h"

#include "content/public/browser/auction_result.h"

namespace page_load_metrics {

PageLoadMetricsForwardObserver::PageLoadMetricsForwardObserver(
    base::WeakPtr<PageLoadMetricsObserverInterface> parent_observer)
    : parent_observer_(std::move(parent_observer)) {
  DCHECK(parent_observer_);
}

PageLoadMetricsForwardObserver::~PageLoadMetricsForwardObserver() = default;

const char* PageLoadMetricsForwardObserver::GetObserverName() const {
  // Returns the target ovserver's name so that it works even in cascaded cases,
  // i.e. an instance in the child page decides to forward to the page this
  // forward observer is tracking. Metrics from such child page should be also
  // forwarded to the parent page.
  if (parent_observer_)
    return parent_observer_->GetObserverName();
  return nullptr;
}

const PageLoadMetricsObserverDelegate&
PageLoadMetricsForwardObserver::GetDelegate() const {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
  const PageLoadMetricsObserverDelegate* null_value = nullptr;
  return *null_value;
}

void PageLoadMetricsForwardObserver::SetDelegate(
    PageLoadMetricsObserverDelegate* delegate) {
  // No need to set. Ignore.
}

// Registration and initialization of PageLoadMetricsForwardObserver is
// different from ones of other PageLoadMetricsObserver subclasses.
// PageLoadMetricsForwardObserver is registered in
// `components/page_load_metrics/browser/page_load_tracker.cc` and methods
// OnStart, OnFencedFramesStart, and OnPrerenderingStart are never called.
PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url,
    bool started_in_foreground) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
  return STOP_OBSERVING;
}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnFencedFramesStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
  return STOP_OBSERVING;
}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnPrerenderStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
  return STOP_OBSERVING;
}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnPreviewStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
  return STOP_OBSERVING;
}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnNavigationHandleTimingUpdated(
    content::NavigationHandle* navigation_handle) {
  // New events don't support forward observers.
  return CONTINUE_OBSERVING;
}

// Main frame events will be converted as sub-frame events on forwarding, and
// OnRedirect is an event only for the main frame. We just mask it here.
PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnRedirect(
    content::NavigationHandle* navigation_handle) {
  return CONTINUE_OBSERVING;
}

// OnCommit and OnDidInternalNavigationAbort are handled at PageLoadTracker to
// forward events as a sub-frame navigation regardless of each observer's
// policy.
PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnCommit(
    content::NavigationHandle* navigation_handle) {
  return CONTINUE_OBSERVING;
}

void PageLoadMetricsForwardObserver::OnDidInternalNavigationAbort(
    content::NavigationHandle* navigation_handle) {}

// ReadyToCommitNextNavigation is an event only for main frames. As main frame
// events are converted to sub-frames events on forwarding, this event is just
// masked here.
void PageLoadMetricsForwardObserver::ReadyToCommitNextNavigation(
    content::NavigationHandle* navigation_handle) {}

// OnDidFinishSubFrameNavigation is handled at PageLoadTracker to forward events
// regardless of each observer's policy.
void PageLoadMetricsForwardObserver::OnDidFinishSubFrameNavigation(
    content::NavigationHandle* navigation_handle) {}

// OnCommitSameDocumentNavigation is handled at PageLoadTracker to forward
// events as a sub-frame navigation regardless of each observer's policy.
void PageLoadMetricsForwardObserver::OnCommitSameDocumentNavigation(
    content::NavigationHandle* navigation_handle) {}

// Inner pages' OnHidden and OnShown are ignored to avoid duplicated calls in
// the parent observer.
PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnHidden(const mojom::PageLoadTiming& timing) {
  return CONTINUE_OBSERVING;
}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnShown() {
  return CONTINUE_OBSERVING;
}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::OnEnterBackForwardCache(
    const mojom::PageLoadTiming& timing) {
  return CONTINUE_OBSERVING;
}

void PageLoadMetricsForwardObserver::OnRestoreFromBackForwardCache(
    const mojom::PageLoadTiming& timing,
    content::NavigationHandle* navigation_handle) {}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::ShouldObserveMimeType(
    const std::string& mime_type) const {
  if (!parent_observer_ ||
      parent_observer_->ShouldObserveMimeType(mime_type) == STOP_OBSERVING) {
    return STOP_OBSERVING;
  }
  return CONTINUE_OBSERVING;
}

PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::ShouldObserveScheme(const GURL& url) const {
  if (!parent_observer_ ||
      parent_observer_->ShouldObserveScheme(url) == STOP_OBSERVING) {
    return STOP_OBSERVING;
  }
  return CONTINUE_OBSERVING;
}

// As PageLoadTracker handles OnTimingUpdate to dispatch also for the parent
// page, do not forward the event to the target here.
void PageLoadMetricsForwardObserver::OnTimingUpdate(
    content::RenderFrameHost* subframe_rfh,
    const mojom::PageLoadTiming& timing) {}

// Soft navigations only happen in outermost top-level documents.
void PageLoadMetricsForwardObserver::OnSoftNavigationUpdated(
    const mojom::SoftNavigationMetrics&) {}

void PageLoadMetricsForwardObserver::OnInputTimingUpdate(
    content::RenderFrameHost* subframe_rfh,
    const mojom::InputTiming& input_timing_delta) {}

void PageLoadMetricsForwardObserver::OnPageInputTimingUpdate(
    uint64_t num_interactions) {}

void PageLoadMetricsForwardObserver::OnPageRenderDataUpdate(
    const mojom::FrameRenderDataUpdate& render_data,
    bool is_main_frame) {}

void PageLoadMetricsForwardObserver::OnSubFrameRenderDataUpdate(
    content::RenderFrameHost* subframe_rfh,
    const mojom::FrameRenderDataUpdate& render_data) {
  if (!parent_observer_)
    return;
  parent_observer_->OnSubFrameRenderDataUpdate(subframe_rfh, render_data);
}

// As PageLoadTracker handles OnCpuTimingUpdate to dispatch also for the parent
// page, do not forward the event to the target here.
void PageLoadMetricsForwardObserver::OnCpuTimingUpdate(
    content::RenderFrameHost* subframe_rfh,
    const mojom::CpuTiming& timing) {}

// OnUserInput is always dispatched only to the primary page.
void PageLoadMetricsForwardObserver::OnUserInput(
    const blink::WebInputEvent& event,
    const mojom::PageLoadTiming& timing) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
}

// Following events should be ignored as they are controlled at
// DispatchObserverTimingCallbacks in PageLoadTracker to be called once per
// observer. Relevant event sources are forwarded at PageLoadTracker layer.
void PageLoadMetricsForwardObserver::OnDomContentLoadedEventStart(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnLoadEventStart(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnParseStart(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnParseStop(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnConnectStart(
    const mojom::PageLoadTiming& timing) {}
void PageLoadMetricsForwardObserver::OnConnectEnd(
    const mojom::PageLoadTiming& timing) {}
void PageLoadMetricsForwardObserver::OnDomainLookupStart(
    const mojom::PageLoadTiming& timing) {}
void PageLoadMetricsForwardObserver::OnDomainLookupEnd(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnFirstPaintInPage(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnFirstImagePaintInPage(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnFirstContentfulPaintInPage(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::
    OnFirstPaintAfterBackForwardCacheRestoreInPage(
        const mojom::BackForwardCacheTiming& timing,
        size_t index) {
  // Today, pages in which fenced frames are restored from BFCache can hit this
  // line. However, we shouldn't forward any metrics to the parent observer
  // here, because fenced frames are never restored from BFCache independently
  // of their top-level page.
}

void PageLoadMetricsForwardObserver::
    OnFirstInputAfterBackForwardCacheRestoreInPage(
        const mojom::BackForwardCacheTiming& timing,
        size_t index) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED() << "Not supported.";
}

void PageLoadMetricsForwardObserver::
    OnRequestAnimationFramesAfterBackForwardCacheRestoreInPage(
        const mojom::BackForwardCacheTiming& timing,
        size_t index) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED() << "Not supported.";
}

void PageLoadMetricsForwardObserver::OnFirstMeaningfulPaintInMainFrameDocument(
    const mojom::PageLoadTiming& timing) {}

void PageLoadMetricsForwardObserver::OnFirstInputInPage(
    const mojom::PageLoadTiming& timing) {}

// OnLoadingBehaviorObserved and OnJavaScriptFrameworksObserved are called
// through PageLoadTracker::UpdateMetrics. So, the event is always forwarded at
// the PageLoadTracker layer.
void PageLoadMetricsForwardObserver::OnLoadingBehaviorObserved(
    content::RenderFrameHost* rfh,
    int behavior_flags) {}
void PageLoadMetricsForwardObserver::OnJavaScriptFrameworksObserved(
    content::RenderFrameHost* rfh,
    const blink::JavaScriptFrameworkDetectionResult&) {}

void PageLoadMetricsForwardObserver::OnFeaturesUsageObserved(
    content::RenderFrameHost* rfh,
    const std::vector<blink::UseCounterFeature>& features) {
  if (!parent_observer_)
    return;
  parent_observer_->OnFeaturesUsageObserved(rfh, features);
}

// SetUpSharedMemoryForUkms is called only for the outermost page.
void PageLoadMetricsForwardObserver::SetUpSharedMemoryForUkms(
    const base::ReadOnlySharedMemoryRegion& smoothness_memory,
    const base::ReadOnlySharedMemoryRegion& dropped_frames_memory) {
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
}

// PageLoadTracker already aggregates inter-pages data and processes it via
// PageLoadMetricsUpdateDispatcher to dispatch OnResourceDataUseObserved with
// the aggregated data. So, we don't need to forward here.
void PageLoadMetricsForwardObserver::OnResourceDataUseObserved(
    content::RenderFrameHost* rfh,
    const std::vector<mojom::ResourceDataUpdatePtr>& resources) {}

void PageLoadMetricsForwardObserver::MediaStartedPlaying(
    const content::WebContentsObserver::MediaPlayerInfo& video_type,
    content::RenderFrameHost* render_frame_host) {
  if (!parent_observer_)
    return;
  parent_observer_->MediaStartedPlaying(video_type, render_frame_host);
}

void PageLoadMetricsForwardObserver::OnMainFrameIntersectionRectChanged(
    content::RenderFrameHost* rfh,
    const gfx::Rect& main_frame_intersection_rect) {
  if (!parent_observer_)
    return;
  parent_observer_->OnMainFrameIntersectionRectChanged(
      rfh, main_frame_intersection_rect);
}

void PageLoadMetricsForwardObserver::OnMainFrameViewportRectChanged(
    const gfx::Rect& main_frame_viewport_rect) {
  if (!parent_observer_)
    return;
  parent_observer_->OnMainFrameViewportRectChanged(main_frame_viewport_rect);
}

void PageLoadMetricsForwardObserver::OnMainFrameImageAdRectsChanged(
    const base::flat_map<int, gfx::Rect>& main_frame_image_ad_rects) {
  if (!parent_observer_) {
    return;
  }
  parent_observer_->OnMainFrameImageAdRectsChanged(main_frame_image_ad_rects);
}

// Don't need to forward FlushMetricsOnAppEnterBackground and OnComplete as they
// are dispatched to all trackers.
PageLoadMetricsObserverInterface::ObservePolicy
PageLoadMetricsForwardObserver::FlushMetricsOnAppEnterBackground(
    const mojom::PageLoadTiming& timing) {
  return CONTINUE_OBSERVING;
}

void PageLoadMetricsForwardObserver::OnComplete(
    const mojom::PageLoadTiming& timing) {}

// OnFailedProvisionalLoad are handled at PageLoadTracker to forward events as a
// sub-frame navigation regardless of each observer's policy.
void PageLoadMetricsForwardObserver::OnFailedProvisionalLoad(
    const FailedProvisionalLoadInfo& failed_provisional_load_info) {}

void PageLoadMetricsForwardObserver::OnLoadedResource(
    const ExtraRequestCompleteInfo& extra_request_complete_info) {
  if (!parent_observer_)
    return;
  parent_observer_->OnLoadedResource(extra_request_complete_info);
}

void PageLoadMetricsForwardObserver::FrameReceivedUserActivation(
    content::RenderFrameHost* render_frame_host) {
  if (!parent_observer_)
    return;
  parent_observer_->FrameReceivedUserActivation(render_frame_host);
}

void PageLoadMetricsForwardObserver::FrameDisplayStateChanged(
    content::RenderFrameHost* render_frame_host,
    bool is_display_none) {
  if (!parent_observer_)
    return;
  parent_observer_->FrameDisplayStateChanged(render_frame_host,
                                             is_display_none);
}

void PageLoadMetricsForwardObserver::FrameSizeChanged(
    content::RenderFrameHost* render_frame_host,
    const gfx::Size& frame_size) {
  if (!parent_observer_)
    return;
  parent_observer_->FrameSizeChanged(render_frame_host, frame_size);
}

// OnRenderFrameDeleted and OnSubFrameDeleted are handled at PageLoadTracker to
// forward events as sub-frames deletion regardless of each observer's policy.
void PageLoadMetricsForwardObserver::OnRenderFrameDeleted(
    content::RenderFrameHost* render_frame_host) {}

void PageLoadMetricsForwardObserver::OnSubFrameDeleted(
    content::FrameTreeNodeId frame_tree_node_id) {}

void PageLoadMetricsForwardObserver::OnCookiesRead(
    const GURL& url,
    const GURL& first_party_url,
    bool blocked_by_policy,
    bool is_ad_tagged,
    const net::CookieSettingOverrides& cookie_setting_overrides,
    bool is_partitioned_access) {
  if (!parent_observer_)
    return;
  parent_observer_->OnCookiesRead(url, first_party_url, blocked_by_policy,
                                  is_ad_tagged, cookie_setting_overrides,
                                  is_partitioned_access);
}

void PageLoadMetricsForwardObserver::OnCookieChange(
    const GURL& url,
    const GURL& first_party_url,
    const net::CanonicalCookie& cookie,
    bool blocked_by_policy,
    bool is_ad_tagged,
    const net::CookieSettingOverrides& cookie_setting_overrides,
    bool is_partitioned_access) {
  if (!parent_observer_)
    return;
  parent_observer_->OnCookieChange(
      url, first_party_url, cookie, blocked_by_policy, is_ad_tagged,
      cookie_setting_overrides, is_partitioned_access);
}

void PageLoadMetricsForwardObserver::OnStorageAccessed(
    const GURL& url,
    const GURL& first_party_url,
    bool blocked_by_policy,
    StorageType access_type) {
  if (!parent_observer_)
    return;
  parent_observer_->OnStorageAccessed(url, first_party_url, blocked_by_policy,
                                      access_type);
}

void PageLoadMetricsForwardObserver::OnPrefetchLikely() {
  // This event is delivered only for the primary page.
  // TODO(crbug.com/40895492): Investigate whether this should truly be
  // unreachable. Note that all NOTREACHED()s were made non-fatal in this file,
  // they are not all necessarily hit.
  DUMP_WILL_BE_NOTREACHED();
}

void PageLoadMetricsForwardObserver::DidActivatePrerenderedPage(
    content::NavigationHandle* navigation_handle) {}

void PageLoadMetricsForwardObserver::DidActivatePreviewedPage(
    base::TimeTicks activation_time) {}

void PageLoadMetricsForwardObserver::OnV8MemoryChanged(
    const std::vector<MemoryUpdate>& memory_updates) {
  if (!parent_observer_)
    return;
  parent_observer_->OnV8MemoryChanged(memory_updates);
}

void PageLoadMetricsForwardObserver::OnSharedStorageWorkletHostCreated() {
  if (!parent_observer_)
    return;
  parent_observer_->OnSharedStorageWorkletHostCreated();
}

void PageLoadMetricsForwardObserver::OnSharedStorageSelectURLCalled() {
  if (!parent_observer_) {
    return;
  }
  parent_observer_->OnSharedStorageSelectURLCalled();
}

void PageLoadMetricsForwardObserver::OnCustomUserTimingMarkObserved(
    const std::vector<mojom::CustomUserTimingMarkPtr>& timings) {
  // This new API doesn't support FORWARD_OBSERVING that is discouraged for new
  // observers.
}

void PageLoadMetricsForwardObserver::OnAdAuctionComplete(
    bool is_server_auction,
    bool is_on_device_auction,
    content::AuctionResult result) {
  if (!parent_observer_) {
    return;
  }
  parent_observer_->OnAdAuctionComplete(is_server_auction, is_on_device_auction,
                                        result);
}

void PageLoadMetricsForwardObserver::OnPrimaryPageRenderProcessGone() {
  DUMP_WILL_BE_NOTREACHED() << "Not supported.";
}

}  // namespace page_load_metrics