Commit aa83588d authored by dominickn's avatar dominickn Committed by Commit bot

Rename DesktopEngagement* to DesktopSessionDuration*.

The DesktopEngagementService measures session length times on desktop.
Its name is very similar to the SiteEngagementService, which measures
how much user interaction a site has in total. This CL renames
DesktopEngagement* to DesktopSessionDuration* to clarify its role and
make it more distinct from Site Engagement.

BUG=646216

Review-Url: https://codereview.chromium.org/2333113002
Cr-Commit-Position: refs/heads/master@{#418773}
parent a34fa703
......@@ -2454,14 +2454,14 @@ split_static_library("browser") {
if (!is_android && !is_chromeos) {
sources += [
"metrics/desktop_engagement/audible_contents_tracker.cc",
"metrics/desktop_engagement/audible_contents_tracker.h",
"metrics/desktop_engagement/chrome_visibility_observer.cc",
"metrics/desktop_engagement/chrome_visibility_observer.h",
"metrics/desktop_engagement/desktop_engagement_observer.cc",
"metrics/desktop_engagement/desktop_engagement_observer.h",
"metrics/desktop_engagement/desktop_engagement_service.cc",
"metrics/desktop_engagement/desktop_engagement_service.h",
"metrics/desktop_session_duration/audible_contents_tracker.cc",
"metrics/desktop_session_duration/audible_contents_tracker.h",
"metrics/desktop_session_duration/chrome_visibility_observer.cc",
"metrics/desktop_session_duration/chrome_visibility_observer.h",
"metrics/desktop_session_duration/desktop_session_duration_observer.cc",
"metrics/desktop_session_duration/desktop_session_duration_observer.h",
"metrics/desktop_session_duration/desktop_session_duration_tracker.cc",
"metrics/desktop_session_duration/desktop_session_duration_tracker.h",
"net/disk_cache_dir_policy_handler.cc",
"net/disk_cache_dir_policy_handler.h",
"platform_util.cc",
......
......@@ -65,7 +65,7 @@ void UmaSessionStats::UmaEndSession(JNIEnv* env,
base::TimeDelta duration = base::TimeTicks::Now() - session_start_time_;
// Note: This metric is recorded separately on desktop in
// DesktopEngagementService::EndSession.
// DesktopSessionDurationTracker::EndSession.
UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", duration);
DCHECK(g_browser_process);
......
......@@ -275,7 +275,7 @@
#if defined(OS_WIN) || defined(OS_MACOSX) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_tracker.h"
#endif
using content::BrowserThread;
......@@ -919,7 +919,7 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
#if defined(OS_WIN) || defined(OS_MACOSX) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
metrics::DesktopEngagementService::Initialize();
metrics::DesktopSessionDurationTracker::Initialize();
#endif
#if defined(OS_WIN)
......
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h"
#include "chrome/browser/metrics/desktop_session_duration/audible_contents_tracker.h"
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_tracker.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_AUDIBLE_CONTENTS_TRACKER_H_
#define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_AUDIBLE_CONTENTS_TRACKER_H_
#ifndef CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_AUDIBLE_CONTENTS_TRACKER_H_
#define CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_AUDIBLE_CONTENTS_TRACKER_H_
#include <set>
......@@ -18,8 +18,8 @@ class AudibleContentsTracker : public chrome::BrowserListObserver,
public TabStripModelObserver {
public:
// Interface for an observer of the AudibleContentsTracker. The only client
// of this class is the DesktopEngagementService, but an observer interface
// has been created for ease of testing.
// of this class is the DesktopSessionDurationTracker, but an observer
// interface has been created for ease of testing.
class Observer {
public:
Observer() {}
......@@ -73,4 +73,4 @@ class AudibleContentsTracker : public chrome::BrowserListObserver,
} // namespace metrics
#endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_AUDIBLE_CONTENTS_TRACKER_H_
#endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_AUDIBLE_CONTENTS_TRACKER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h"
#include "chrome/browser/metrics/desktop_session_duration/audible_contents_tracker.h"
#include "base/path_service.h"
#include "chrome/test/base/in_process_browser_test.h"
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/desktop_engagement/chrome_visibility_observer.h"
#include "chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.h"
#include "base/memory/singleton.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_tracker.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "components/variations/variations_associated_data.h"
......@@ -24,7 +24,7 @@ ChromeVisibilityObserver::~ChromeVisibilityObserver() {
}
void ChromeVisibilityObserver::SendVisibilityChangeEvent(bool active) {
DesktopEngagementService::Get()->OnVisibilityChanged(active);
DesktopSessionDurationTracker::Get()->OnVisibilityChanged(active);
}
void ChromeVisibilityObserver::CancelVisibilityChange() {
......@@ -60,7 +60,7 @@ void ChromeVisibilityObserver::InitVisibilityGapTimeout() {
int timeout_seconds = kDefaultVisibilityGapTimeout;
std::string param_value = variations::GetVariationParamValue(
"DesktopEngagement", "visibility_gap_timeout");
"DesktopSessionDuration", "visibility_gap_timeout");
if (!param_value.empty())
base::StringToInt(param_value, &timeout_seconds);
......
......@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_CHROME_VISIBILITY_OBSERVER_H_
#define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_CHROME_VISIBILITY_OBSERVER_H_
#ifndef CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_CHROME_VISIBILITY_OBSERVER_H_
#define CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_CHROME_VISIBILITY_OBSERVER_H_
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/browser_list_observer.h"
namespace metrics {
// Observer for tracking browser visibility events.
class ChromeVisibilityObserver : public chrome::BrowserListObserver {
public:
......@@ -17,8 +16,8 @@ class ChromeVisibilityObserver : public chrome::BrowserListObserver {
~ChromeVisibilityObserver() override;
protected:
// Notifies |DesktopEngagementService| of visibility changes. Overridden by
// tests.
// Notifies |DesktopSessionDurationTracker| of visibility changes. Overridden
// by tests.
virtual void SendVisibilityChangeEvent(bool active);
private:
......@@ -46,4 +45,4 @@ class ChromeVisibilityObserver : public chrome::BrowserListObserver {
} // namespace metrics
#endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_CHROME_VISIBILITY_OBSERVER_H_
#endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_CHROME_VISIBILITY_OBSERVER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/desktop_engagement/chrome_visibility_observer.h"
#include "chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.h"
#include "base/memory/singleton.h"
#include "chrome/browser/chrome_notification_types.h"
......
......@@ -2,59 +2,60 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_observer.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_observer.h"
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_tracker.h"
#include "content/public/browser/render_view_host.h"
DEFINE_WEB_CONTENTS_USER_DATA_KEY(metrics::DesktopEngagementObserver);
DEFINE_WEB_CONTENTS_USER_DATA_KEY(metrics::DesktopSessionDurationObserver);
namespace metrics {
DesktopEngagementObserver::DesktopEngagementObserver(
DesktopSessionDurationObserver::DesktopSessionDurationObserver(
content::WebContents* web_contents,
DesktopEngagementService* service)
DesktopSessionDurationTracker* service)
: content::WebContentsObserver(web_contents), service_(service) {
RegisterInputEventObserver(web_contents->GetRenderViewHost());
}
DesktopEngagementObserver::~DesktopEngagementObserver() {}
DesktopSessionDurationObserver::~DesktopSessionDurationObserver() {}
// static
DesktopEngagementObserver* DesktopEngagementObserver::CreateForWebContents(
DesktopSessionDurationObserver*
DesktopSessionDurationObserver::CreateForWebContents(
content::WebContents* web_contents) {
DCHECK(web_contents);
if (!DesktopEngagementService::IsInitialized())
if (!DesktopSessionDurationTracker::IsInitialized())
return nullptr;
DesktopEngagementObserver* observer = FromWebContents(web_contents);
DesktopSessionDurationObserver* observer = FromWebContents(web_contents);
if (!observer) {
observer = new DesktopEngagementObserver(web_contents,
DesktopEngagementService::Get());
observer = new DesktopSessionDurationObserver(
web_contents, DesktopSessionDurationTracker::Get());
web_contents->SetUserData(UserDataKey(), observer);
}
return observer;
}
void DesktopEngagementObserver::RegisterInputEventObserver(
void DesktopSessionDurationObserver::RegisterInputEventObserver(
content::RenderViewHost* host) {
if (host != nullptr)
host->GetWidget()->AddInputEventObserver(this);
}
void DesktopEngagementObserver::UnregisterInputEventObserver(
void DesktopSessionDurationObserver::UnregisterInputEventObserver(
content::RenderViewHost* host) {
if (host != nullptr)
host->GetWidget()->RemoveInputEventObserver(this);
}
void DesktopEngagementObserver::OnInputEvent(
void DesktopSessionDurationObserver::OnInputEvent(
const blink::WebInputEvent& event) {
service_->OnUserEvent();
}
void DesktopEngagementObserver::RenderViewHostChanged(
void DesktopSessionDurationObserver::RenderViewHostChanged(
content::RenderViewHost* old_host,
content::RenderViewHost* new_host) {
UnregisterInputEventObserver(old_host);
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_OBSERVER_H_
#define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_OBSERVER_H_
#ifndef CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_OBSERVER_H_
#define CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_OBSERVER_H_
#include "base/macros.h"
#include "content/public/browser/render_widget_host.h"
......@@ -14,24 +14,24 @@
namespace metrics {
class DesktopEngagementService;
class DesktopSessionDurationTracker;
// Tracks user input events from web contents and notifies
// |DesktopEngagementService|.
class DesktopEngagementObserver
// |DesktopSessionDurationTracker|.
class DesktopSessionDurationObserver
: public content::WebContentsObserver,
public content::WebContentsUserData<DesktopEngagementObserver>,
public content::WebContentsUserData<DesktopSessionDurationObserver>,
public content::RenderWidgetHost::InputEventObserver {
public:
DesktopEngagementObserver(content::WebContents* web_contents,
DesktopEngagementService* service);
~DesktopEngagementObserver() override;
DesktopSessionDurationObserver(content::WebContents* web_contents,
DesktopSessionDurationTracker* service);
~DesktopSessionDurationObserver() override;
static DesktopEngagementObserver* CreateForWebContents(
static DesktopSessionDurationObserver* CreateForWebContents(
content::WebContents* web_contents);
private:
friend class content::WebContentsUserData<DesktopEngagementObserver>;
friend class content::WebContentsUserData<DesktopSessionDurationObserver>;
// Register / Unregister input event callback to given RenderViewHost
void RegisterInputEventObserver(content::RenderViewHost* host);
......@@ -44,11 +44,11 @@ class DesktopEngagementObserver
void RenderViewHostChanged(content::RenderViewHost* old_host,
content::RenderViewHost* new_host) override;
DesktopEngagementService* service_;
DesktopSessionDurationTracker* service_;
DISALLOW_COPY_AND_ASSIGN(DesktopEngagementObserver);
DISALLOW_COPY_AND_ASSIGN(DesktopSessionDurationObserver);
};
} // namespace metrics
#endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_OBSERVER_H_
#endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_OBSERVER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_tracker.h"
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
......@@ -13,33 +13,33 @@ namespace metrics {
namespace {
DesktopEngagementService* g_instance = nullptr;
DesktopSessionDurationTracker* g_instance = nullptr;
} // namespace
// static
void DesktopEngagementService::Initialize() {
g_instance = new DesktopEngagementService;
void DesktopSessionDurationTracker::Initialize() {
g_instance = new DesktopSessionDurationTracker;
}
// static
bool DesktopEngagementService::IsInitialized() {
bool DesktopSessionDurationTracker::IsInitialized() {
return g_instance != nullptr;
}
// static
DesktopEngagementService* DesktopEngagementService::Get() {
DesktopSessionDurationTracker* DesktopSessionDurationTracker::Get() {
DCHECK(g_instance);
return g_instance;
}
void DesktopEngagementService::StartTimer(base::TimeDelta duration) {
void DesktopSessionDurationTracker::StartTimer(base::TimeDelta duration) {
timer_.Start(FROM_HERE, duration,
base::Bind(&DesktopEngagementService::OnTimerFired,
base::Bind(&DesktopSessionDurationTracker::OnTimerFired,
weak_factory_.GetWeakPtr()));
}
void DesktopEngagementService::OnVisibilityChanged(bool visible) {
void DesktopSessionDurationTracker::OnVisibilityChanged(bool visible) {
is_visible_ = visible;
if (is_visible_ && !is_first_session_) {
OnUserEvent();
......@@ -49,7 +49,7 @@ void DesktopEngagementService::OnVisibilityChanged(bool visible) {
}
}
void DesktopEngagementService::OnUserEvent() {
void DesktopSessionDurationTracker::OnUserEvent() {
if (!is_visible_)
return;
......@@ -61,7 +61,7 @@ void DesktopEngagementService::OnUserEvent() {
}
}
void DesktopEngagementService::OnAudioStart() {
void DesktopSessionDurationTracker::OnAudioStart() {
// This may start session.
is_audio_playing_ = true;
if (!in_session_) {
......@@ -70,7 +70,7 @@ void DesktopEngagementService::OnAudioStart() {
}
}
void DesktopEngagementService::OnAudioEnd() {
void DesktopSessionDurationTracker::OnAudioEnd() {
is_audio_playing_ = false;
// If the timer is not running, this means that no user events happened in the
......@@ -81,7 +81,7 @@ void DesktopEngagementService::OnAudioEnd() {
}
}
DesktopEngagementService::DesktopEngagementService()
DesktopSessionDurationTracker::DesktopSessionDurationTracker()
: session_start_(base::TimeTicks::Now()),
last_user_event_(session_start_),
audio_tracker_(this),
......@@ -89,9 +89,9 @@ DesktopEngagementService::DesktopEngagementService()
InitInactivityTimeout();
}
DesktopEngagementService::~DesktopEngagementService() {}
DesktopSessionDurationTracker::~DesktopSessionDurationTracker() {}
void DesktopEngagementService::OnTimerFired() {
void DesktopSessionDurationTracker::OnTimerFired() {
base::TimeDelta remaining =
inactivity_timeout_ - (base::TimeTicks::Now() - last_user_event_);
if (remaining.ToInternalValue() > 0) {
......@@ -106,14 +106,14 @@ void DesktopEngagementService::OnTimerFired() {
}
}
void DesktopEngagementService::StartSession() {
void DesktopSessionDurationTracker::StartSession() {
in_session_ = true;
is_first_session_ = false;
session_start_ = base::TimeTicks::Now();
StartTimer(inactivity_timeout_);
}
void DesktopEngagementService::EndSession() {
void DesktopSessionDurationTracker::EndSession() {
in_session_ = false;
base::TimeDelta delta = base::TimeTicks::Now() - session_start_;
......@@ -129,12 +129,12 @@ void DesktopEngagementService::EndSession() {
UMA_HISTOGRAM_LONG_TIMES("Session.TotalDuration", delta);
}
void DesktopEngagementService::InitInactivityTimeout() {
void DesktopSessionDurationTracker::InitInactivityTimeout() {
const int kDefaultInactivityTimeoutMinutes = 5;
int timeout_minutes = kDefaultInactivityTimeoutMinutes;
std::string param_value = variations::GetVariationParamValue(
"DesktopEngagement", "inactivity_timeout");
"DesktopSessionDuration", "inactivity_timeout");
if (!param_value.empty())
base::StringToInt(param_value, &timeout_minutes);
......
......@@ -2,31 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_
#define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_
#ifndef CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_TRACKER_H_
#define CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_TRACKER_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/metrics/desktop_engagement/audible_contents_tracker.h"
#include "chrome/browser/metrics/desktop_engagement/chrome_visibility_observer.h"
#include "chrome/browser/metrics/desktop_session_duration/audible_contents_tracker.h"
#include "chrome/browser/metrics/desktop_session_duration/chrome_visibility_observer.h"
namespace metrics {
// Class for tracking and recording user engagement based on browser visibility,
// audio and user interaction.
class DesktopEngagementService : public AudibleContentsTracker::Observer {
// Class for tracking and recording session length on desktop based on browser
// visibility, audio and user interaction.
class DesktopSessionDurationTracker : public AudibleContentsTracker::Observer {
public:
// Creates the |DesktopEngagementService| instance and initializes the
// observes that notify to it.
// Creates the |DesktopSessionDurationTracker| instance and initializes the
// observers that notify to it.
static void Initialize();
// Returns true if the |DesktopEngagementService| instance has been created.
// Returns true if the |DesktopSessionDurationTracker| instance has been
// created.
static bool IsInitialized();
// Returns the |DesktopEngagementService| instance.
static DesktopEngagementService* Get();
// Returns the |DesktopSessionDurationTracker| instance.
static DesktopSessionDurationTracker* Get();
// Called when user interaction with the browser is caught.
void OnUserEvent();
......@@ -43,8 +44,8 @@ class DesktopEngagementService : public AudibleContentsTracker::Observer {
}
protected:
DesktopEngagementService();
~DesktopEngagementService() override;
DesktopSessionDurationTracker();
~DesktopSessionDurationTracker() override;
// AudibleContentsTracker::Observer
void OnAudioStart() override;
......@@ -87,11 +88,11 @@ class DesktopEngagementService : public AudibleContentsTracker::Observer {
ChromeVisibilityObserver visibility_observer_;
AudibleContentsTracker audio_tracker_;
base::WeakPtrFactory<DesktopEngagementService> weak_factory_;
base::WeakPtrFactory<DesktopSessionDurationTracker> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DesktopEngagementService);
DISALLOW_COPY_AND_ASSIGN(DesktopSessionDurationTracker);
};
} // namespace metrics
#endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_
#endif // CHROME_BROWSER_METRICS_DESKTOP_SESSION_DURATION_DESKTOP_SESSION_DURATION_TRACKER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_tracker.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
......@@ -10,33 +10,34 @@
#include "base/test/test_mock_time_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
// Mock class for |DesktopEngagementService| for testing.
class MockDesktopEngagementService : public metrics::DesktopEngagementService {
// Mock class for |DesktopSessionDurationTracker| for testing.
class MockDesktopSessionDurationTracker
: public metrics::DesktopSessionDurationTracker {
public:
MockDesktopEngagementService() {}
MockDesktopSessionDurationTracker() {}
bool is_timeout() const { return time_out_; }
using metrics::DesktopEngagementService::OnAudioStart;
using metrics::DesktopEngagementService::OnAudioEnd;
using metrics::DesktopSessionDurationTracker::OnAudioStart;
using metrics::DesktopSessionDurationTracker::OnAudioEnd;
protected:
void OnTimerFired() override {
DesktopEngagementService::OnTimerFired();
DesktopSessionDurationTracker::OnTimerFired();
time_out_ = true;
}
private:
bool time_out_ = false;
DISALLOW_COPY_AND_ASSIGN(MockDesktopEngagementService);
DISALLOW_COPY_AND_ASSIGN(MockDesktopSessionDurationTracker);
};
TEST(DesktopEngagementServiceTest, TestVisibility) {
TEST(DesktopSessionDurationTrackerTest, TestVisibility) {
base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
base::HistogramTester histogram_tester;
MockDesktopEngagementService instance;
MockDesktopSessionDurationTracker instance;
// The browser becomes visible but it shouldn't start the session.
instance.OnVisibilityChanged(true);
......@@ -74,11 +75,11 @@ TEST(DesktopEngagementServiceTest, TestVisibility) {
histogram_tester.ExpectTotalCount("Session.TotalDuration", 2);
}
TEST(DesktopEngagementServiceTest, TestUserEvent) {
TEST(DesktopSessionDurationTrackerTest, TestUserEvent) {
base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
base::HistogramTester histogram_tester;
MockDesktopEngagementService instance;
MockDesktopSessionDurationTracker instance;
instance.SetInactivityTimeoutForTesting(1);
EXPECT_FALSE(instance.in_session());
......@@ -111,11 +112,11 @@ TEST(DesktopEngagementServiceTest, TestUserEvent) {
histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
}
TEST(DesktopEngagementServiceTest, TestAudioEvent) {
TEST(DesktopSessionDurationTrackerTest, TestAudioEvent) {
base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
base::HistogramTester histogram_tester;
MockDesktopEngagementService instance;
MockDesktopSessionDurationTracker instance;
instance.SetInactivityTimeoutForTesting(1);
instance.OnVisibilityChanged(true);
......@@ -157,14 +158,14 @@ TEST(DesktopEngagementServiceTest, TestAudioEvent) {
TEST(DesktopEngagementServiceTest, MAYBE_TestTimeoutDiscount) {
base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
base::HistogramTester histogram_tester;
MockDesktopEngagementService instance;
MockDesktopSessionDurationTracker instance;
int inactivity_interval = 2;
instance.SetInactivityTimeoutForTesting(inactivity_interval);
instance.OnVisibilityChanged(true);
base::TimeTicks before_session_start = base::TimeTicks::Now();
instance.OnUserEvent(); // This should start the session
instance.OnUserEvent(); // This should start the session
histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
// Wait until the session expires.
......@@ -178,7 +179,6 @@ TEST(DesktopEngagementServiceTest, MAYBE_TestTimeoutDiscount) {
// interval.
base::Bucket bucket =
histogram_tester.GetAllSamples("Session.TotalDuration")[0];
EXPECT_LE(
bucket.min + inactivity_interval,
(after_session_end - before_session_start).InSeconds());
EXPECT_LE(bucket.min + inactivity_interval,
(after_session_end - before_session_start).InSeconds());
}
......@@ -21,7 +21,7 @@
#include "chrome/browser/history/history_tab_helper.h"
#include "chrome/browser/history/top_sites_factory.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/metrics/desktop_engagement/desktop_engagement_observer.h"
#include "chrome/browser/metrics/desktop_session_duration/desktop_session_duration_observer.h"
#include "chrome/browser/net/net_error_tab_helper.h"
#include "chrome/browser/net/predictor_tab_helper.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_initialize.h"
......@@ -240,7 +240,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
#if defined(OS_WIN) || defined(OS_MACOSX) || \
(defined(OS_LINUX) && !defined(OS_CHROMEOS))
metrics::DesktopEngagementObserver::CreateForWebContents(web_contents);
metrics::DesktopSessionDurationObserver::CreateForWebContents(web_contents);
#endif
// --- Feature tab helpers behind flags ---
......
......@@ -2520,8 +2520,8 @@ test("browser_tests") {
if (is_mac || is_win || (is_linux && !is_chromeos)) {
sources += [
# Tests for non mobile and non CrOS (includes Linux, Win, Mac).
"../browser/metrics/desktop_engagement/audible_contents_tracker_browsertest.cc",
"../browser/metrics/desktop_engagement/chrome_visibility_observer_browsertest.cc",
"../browser/metrics/desktop_session_duration/audible_contents_tracker_browsertest.cc",
"../browser/metrics/desktop_session_duration/chrome_visibility_observer_browsertest.cc",
"../browser/profiles/profile_statistics_browsertest.cc",
]
}
......@@ -4634,7 +4634,7 @@ test("unit_tests") {
if (!is_android && !is_chromeos) {
sources += [
"../browser/media/webrtc/native_desktop_media_list_unittest.cc",
"../browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc",
"../browser/metrics/desktop_session_duration/desktop_session_duration_tracker_unittest.cc",
"../browser/signin/cross_device_promo_unittest.cc",
"../browser/signin/signin_global_error_unittest.cc",
"../browser/sync/sync_global_error_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment