Chromium Code Reviews| Index: chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h |
| diff --git a/chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h b/chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7e72a68abaefcf9d21363e01015ffec1a724ad8c |
| --- /dev/null |
| +++ b/chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h |
| @@ -0,0 +1,77 @@ |
| +// 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 CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_ |
| +#define CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_ |
| + |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| + |
| +// Class for tracking and recording user engagement based on browser visibility, |
| +// audio and user interaction. |
| +class DesktopEngagementService { |
| + public: |
| + // Creates the |DesktopEngagementService| instance and initializes the |
| + // observes that notify to it. |
| + static void Initialize(); |
| + // Returns true if the |DesktopEngagementService| instance has been created. |
|
Alexei Svitkine (slow)
2016/07/26 22:00:41
Please add empty lines between functions. Fix thro
gayane -on leave until 09-2017
2016/07/27 21:10:25
Done.
|
| + static bool IsInitialized(); |
| + // Returns the |DesktopEngagementService| instance. |
| + static DesktopEngagementService* Get(); |
| + |
| + // Called when user interaction with the browser is caught. |
| + void OnUserEvent(); |
| + |
| + // Called when visibility of the browser changes. |
| + void OnVisibilityChanged(bool visible); |
| + |
| + // Called when audio starts or ends. |
| + void OnAudioStart(); |
| + void OnAudioEnd(); |
| + |
| + private: |
| + friend class MockDesktopEngagementService; |
| + |
| + DesktopEngagementService(); |
| + ~DesktopEngagementService(); |
| + |
| + // Decides whether session should be ended. Called when timer for inactivity |
| + // timeout was fired. Overridden by tests. |
| + virtual void OnTimerFired(); |
| + // Starts timer based on |inactivity_timeout_|. |
| + void StartTimer(base::TimeDelta duration); |
| + |
| + // Marks the start of the session. |
| + void StartSession(); |
| + // Ends the session and saves session information into histograms. |
| + void EndSession(); |
| + |
| + // Sets |inactivity_timeout_| based on variation params. |
| + void InitInactivityTimeout(); |
| + |
| + // Used for marking start if the session. |
| + base::TimeTicks session_start_; |
| + // Used for marking last user interaction. |
| + base::TimeTicks last_user_event_; |
| + |
| + // Used for marking current state of the user engagement. |
| + bool is_visible_ = false; |
| + bool in_session_ = false; |
| + bool is_audio_playing_ = false; |
| + bool is_first_session_ = true; |
| + base::TimeDelta inactivity_timeout_; |
| + |
| + base::OneShotTimer timer_; |
| + |
| + base::WeakPtrFactory<DesktopEngagementService> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DesktopEngagementService); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_METRICS_DESKTOP_ENGAGEMENT_DESKTOP_ENGAGEMENT_SERVICE_H_ |