File: visible_time_request_trigger.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 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 (79 lines) | stat: -rw-r--r-- 3,516 bytes parent folder | download | duplicates (7)
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
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_VISIBLE_TIME_REQUEST_TRIGGER_H_
#define CONTENT_BROWSER_RENDERER_HOST_VISIBLE_TIME_REQUEST_TRIGGER_H_

#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/widget/record_content_to_visible_time_request.mojom.h"

namespace base {
class TimeTicks;
}  // namespace base

namespace content {

// Records the time of an event that will make a WebContents become visible,
// and the reason it will become visible. This time will be passed to the
// compositor and used to calculate the latency before the visible WebContents
// appears.
//
// This class holds a single RecordContentToVisibleTimeRequestPtr that is
// modified whenever UpdateRequest is called, and cleared whenever TakeRequest
// is called. This means that calling UpdateRequest for multiple overlapping
// events without calling TakeRequest in between will record metrics for all
// events using the same timestamps instead of tracking each event separately.
//
// TODO(crbug.com/40203057): Stop doing that. There should be a separate start
// time for each event.
class CONTENT_EXPORT VisibleTimeRequestTrigger {
 public:
  VisibleTimeRequestTrigger();
  ~VisibleTimeRequestTrigger();

  VisibleTimeRequestTrigger(const VisibleTimeRequestTrigger&) = delete;
  VisibleTimeRequestTrigger& operator=(const VisibleTimeRequestTrigger&) =
      delete;

  // Returns a RecordContentToVisibleTimeRequestPtr that combines all passed
  // requests, OR'ing all flags and using the minimum start time. Any null
  // requests are ignored. The return value will only be nullptr if all
  // arguments are nullptr. This function consumes its arguments.
  static blink::mojom::RecordContentToVisibleTimeRequestPtr
  ConsumeAndMergeRequests(
      blink::mojom::RecordContentToVisibleTimeRequestPtr request1,
      blink::mojom::RecordContentToVisibleTimeRequestPtr request2);

  // Set the last time a content to visible event starts to be processed for
  // this WebContents. Will merge with the previous value if it exists (which
  // means that several events may happen at the same time and must be
  // individually reported). |start_time| marks event start time to calculate
  // the duration later.
  //
  // |destination_is_loaded| is true when
  //   ResourceCoordinatorTabHelper::IsLoaded() is true for the new tab
  //   contents. It is only used when |show_reason_tab_switching| is true.
  // |show_reason_tab_switching| is true when tab switch event should be
  //   reported.
  // |show_reason_bfcache_restore| is true when page restored from bfcache event
  //   should be reported.
  void UpdateRequest(base::TimeTicks start_time,
                     bool destination_is_loaded,
                     bool show_reason_tab_switching,
                     bool show_reason_bfcache_restore);

  // Returns the time set by UpdateRequest. If this was not preceded by a call
  // to UpdateRequest it will return nullptr. Calling this will reset
  // |last_request_| to null.
  blink::mojom::RecordContentToVisibleTimeRequestPtr TakeRequest();

 private:
  // The last visible event start request. This should only be set and
  // retrieved using UpdateRequest and TakeRequest.
  blink::mojom::RecordContentToVisibleTimeRequestPtr last_request_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_VISIBLE_TIME_REQUEST_TRIGGER_H_