File: audible_metrics.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (74 lines) | stat: -rw-r--r-- 2,494 bytes parent folder | download | duplicates (6)
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
// Copyright 2016 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_MEDIA_AUDIBLE_METRICS_H_
#define CONTENT_BROWSER_MEDIA_AUDIBLE_METRICS_H_

#include <list>
#include <memory>
#include <set>

#include "base/memory/raw_ptr.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "content/common/content_export.h"

namespace content {

class WebContents;

// This class handles metrics regarding audible WebContents.
// It records four different histograms:
// - how many WebContents are audible when a WebContents become audible.
// - how long multiple WebContents are audible at the same time.
// - for a browsing session, how often and how many WebContents get audible at
//   the same time.
// - if an audible tab was closed and we only have one audible tab open anymore
//   then we should record whether we closed the newest or oldest tab.
class CONTENT_EXPORT AudibleMetrics {
 public:
  // This is used for recording whether the audible tab that exited concurrent
  // playback was the most recent. It is used for recording a histogram so
  // values should not be changed.
  enum class ExitConcurrentPlaybackContents {
    kMostRecent = 0,
    kOlder = 1,
    kMaxValue = kOlder,
  };

  AudibleMetrics();

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

  ~AudibleMetrics();

  void UpdateAudibleWebContentsState(const WebContents* web_contents,
                                     bool audible);
  void WebContentsDestroyed(const WebContents* web_contents,
                            bool recently_audible);

  void SetClockForTest(const base::TickClock* test_clock);

  int GetAudibleWebContentsSizeForTest() const {
    return audible_web_contents_.size();
  }

 private:
  void AddAudibleWebContents(const WebContents* web_contents);
  void RemoveAudibleWebContents(const WebContents* web_contents);

  base::TimeTicks concurrent_web_contents_start_time_;
  size_t max_concurrent_audible_web_contents_in_session_;
  raw_ptr<const base::TickClock> clock_;

  // Stores all the web contents that are currently audible. We add a web
  // contents to the set when it becomes currently audible and remove it when it
  // is no longer audible.
  std::set<raw_ptr<const WebContents, SetExperimental>> audible_web_contents_;
};

}  // namespace content

#endif // CONTENT_BROWSER_MEDIA_AUDIBLE_METRICS_H_