Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Merge of "Add metrics regarding concurrent audible tabs in Chromium."
Browse files Browse the repository at this point in the history
These metrics are keeping track of:
- whether there is another audible tab when a tab becomes audible;
- the maximum number of concurrent audible tab in a session;
- how long there are 2 or more audible tabs at the same time.

It is also recording when a tab gain or loses audible status.

BUG=578049

Review URL: https://codereview.chromium.org/1591453005

Cr-Commit-Position: refs/heads/master@{#370435}
(cherry picked from commit 44e4ef4)

Review URL: https://codereview.chromium.org/1618523003 .

Cr-Commit-Position: refs/branch-heads/2623@{#44}
Cr-Branched-From: 92d7753-refs/heads/master@{#369907}
  • Loading branch information
mounirlamouri committed Jan 21, 2016
1 parent 34dc178 commit 1f83af1
Show file tree
Hide file tree
Showing 13 changed files with 684 additions and 28 deletions.
79 changes: 79 additions & 0 deletions content/browser/media/audible_metrics.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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 "content/browser/media/audible_metrics.h"

#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/time/default_tick_clock.h"

namespace content {

AudibleMetrics::AudibleMetrics()
: max_concurrent_audible_web_contents_in_session_(0),
clock_(new base::DefaultTickClock()) {
}

AudibleMetrics::~AudibleMetrics() {
}

void AudibleMetrics::UpdateAudibleWebContentsState(
const WebContents* web_contents, bool audible) {
bool found =
audible_web_contents_.find(web_contents) != audible_web_contents_.end();
if (found == audible)
return;

if (audible)
AddAudibleWebContents(web_contents);
else
RemoveAudibleWebContents(web_contents);
}

void AudibleMetrics::SetClockForTest(scoped_ptr<base::TickClock> test_clock) {
clock_ = std::move(test_clock);
}

void AudibleMetrics::AddAudibleWebContents(const WebContents* web_contents) {
base::RecordAction(base::UserMetricsAction("Media.Audible.AddTab"));

UMA_HISTOGRAM_CUSTOM_COUNTS(
"Media.Audible.ConcurrentTabsWhenStarting", audible_web_contents_.size(),
1, 10, 11);

audible_web_contents_.insert(web_contents);
if (audible_web_contents_.size() > 1 &&
concurrent_web_contents_start_time_.is_null()) {
concurrent_web_contents_start_time_ = clock_->NowTicks();
}

if (audible_web_contents_.size() >
max_concurrent_audible_web_contents_in_session_) {
max_concurrent_audible_web_contents_in_session_ =
audible_web_contents_.size();

UMA_HISTOGRAM_CUSTOM_COUNTS(
"Media.Audible.MaxConcurrentTabsInSession",
max_concurrent_audible_web_contents_in_session_,
1, 10, 11);
}
}

void AudibleMetrics::RemoveAudibleWebContents(const WebContents* web_contents) {
base::RecordAction(base::UserMetricsAction("Media.Audible.RemoveTab"));

audible_web_contents_.erase(web_contents);

if (audible_web_contents_.size() <= 1 &&
!concurrent_web_contents_start_time_.is_null()) {
base::TimeDelta concurrent_total_time =
clock_->NowTicks() - concurrent_web_contents_start_time_;
concurrent_web_contents_start_time_ = base::TimeTicks();

UMA_HISTOGRAM_LONG_TIMES("Media.Audible.ConcurrentTabsTime",
concurrent_total_time);
}
}

} // namespace content
49 changes: 49 additions & 0 deletions content/browser/media/audible_metrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.

#ifndef CONTENT_BROWSER_MEDIA_AUDIBLE_METRICS_H_
#define CONTENT_BROWSER_MEDIA_AUDIBLE_METRICS_H_

#include <set>

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

namespace content {

class WebContents;

// This class handles metrics regarding audible WebContents.
// It does register three different information:
// - 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.
class CONTENT_EXPORT AudibleMetrics {
public:
AudibleMetrics();
~AudibleMetrics();

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

void SetClockForTest(scoped_ptr<base::TickClock> test_clock);

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_;
scoped_ptr<base::TickClock> clock_;

std::set<const WebContents*> audible_web_contents_;

DISALLOW_COPY_AND_ASSIGN(AudibleMetrics);
};

} // namespace content

#endif // CONTENT_BROWSER_MEDIA_AUDIBLE_METRICS_H_
Loading

0 comments on commit 1f83af1

Please sign in to comment.