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